LotgdFormat 0.15.1
dotnet add package LotgdFormat --version 0.15.1
NuGet\Install-Package LotgdFormat -Version 0.15.1
<PackageReference Include="LotgdFormat" Version="0.15.1" />
paket add LotgdFormat --version 0.15.1
#r "nuget: LotgdFormat, 0.15.1"
// Install LotgdFormat as a Cake Addin #addin nuget:?package=LotgdFormat&version=0.15.1 // Install LotgdFormat as a Cake Tool #tool nuget:?package=LotgdFormat&version=0.15.1
LotgdFormat
A C# implementation of the LotgD style formatting code for text formatting.
How to use this library
See API documentation. (TODO)
Acknowledgements
This library is based on the appoencode()
function found in LotgD 0.9.7. DragonSlayer V2.5. Known contributors to that specific version of the function are:
- MightyE
- JT Traub
- Eliwood
- Talion
Known issues
The original handles tags followed by "`0" differently than this library. I am not quite sure if the original has a bug there or if the behavior should be replicated here.
Example - original:
input:
`$red`Hnavhi`0 still red`0 still red.
output (indented for easier reading):
<span class="c36">
red
<span class='navhi'>
navhi
</span>
still red
still red.
Same input in this libary:
input:
`$red`Hnavhi`0 still red`0 still red.
output (indented for easier reading):
<span class=\"c36\">
red
<span class=\"navhi\">
navhi
</span>
</span>
<span class=\"navhi\">
still red still red.
How to use
First, instantiate a formatter, then use AddText()
var formatter = new Formatter([
new LotgdFormatCode('n', tag: "br", selfClosing: true),
new LotgdFormatCode('b', tag: "b"),
new LotgdFormatCode('i', tag: "i"),
new LotgdFormatCode('@', color: "00FF00"),
new LotgdFormatCode('$', color: "00FF00"),
]);
var html = formatter.AddText("`bLegend`b of the `@Green`0 Dragon.");
// html = "<b>Legend<b> of the <span class='c64'>Green</span> Dragon"
The formatter does keep track of tags that were opened but not closed.
You can check the status via Formatter.IsClear()
.
And generate the appropriate closing tags with Formatter.CloseOpenTags()
.
Code syntax
Every code is marked with a backtick ` and consists of a single arbitrary character.
Example:
This text is `@green from here.
There are 4 types of codes:
- Color codes.
- Single format codes
- Paired format codes
- The closing code.
Color codes
A color code creates a span
tag with a specific class to change the text color within. The tag will encapsulate all text until either:
- The end of the text.
- The next color is encountered
- The closing code is encountered.
Examples:
`@this is green `$this is red.
=>
<span class="c64">this is green</span>
<span class="c36">this is red</span>
This library treats all codes that only have a token and a color as color codes.
Self-closing format codes
A self-closing format codes is used to generate self closing tags in the output. The most prominent example in LotgD is n
for a <br>
. Another possible usecase would be for creating an hr
tag.
Since they are self contained, they have no interactions with other codes other than possibily being embedded.
Example:
This is line one.`nThis is line two.
=>
This is line one.<br/>This is line two.
This library only treats codes configured as such to be self closing.
Regular format codes
These create a formatting tag such as strong
, i
, or center
. They enclose the text following the tag until either the end of the text or if another instance of the same tag is encountered.
The closing tag does not affect them.
Example:
`bThis is bold `ithis is italic
=>
<strong>This is bold <i>this is bold and italic<i></strong>
They can however be closed with themselves:
`bThis is bold`b `ithis is bold and italic`i. This is normal.
=>
<strong>This is bold</strong> <i>this is italic<i>. This is normal.
This library treats all codes as regular format codes if they have a tag specified, even if also a color is specified.
The closing code
The code 0
closes the currently open color span.
`bBold `iand italic `$and red`0. This is no longer red.
=>
<strong>
Bold
<i>
and italic
<span class="lotgd-c36">and red</span>
</i>
</strong>
<strong>
<i>
. This is no longer red.
</i>
</strong>
This code is reserved and not configurable.
Escaping
To render the backtick (`), the backtick needs to be doubled up:
This is a backtick: ``
=>
This is a backtick: `
Appendix
The code definitions used in this files examples are:
Token | Color | HTML-Tag | Self-closing |
---|---|---|---|
n | - | <br> |
true |
b | - | <strong> |
false |
i | - | <i> |
false |
@ | 00FF00 | none | false |
$ | FF0000 | none | false |
0 | - | - | - |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.15.1 | 103 | 11/1/2024 |
0.15.0 | 90 | 10/5/2024 |
0.14.0 | 100 | 7/21/2024 |
0.13.4 | 127 | 4/4/2024 |
0.13.3 | 126 | 4/3/2024 |
0.13.2 | 121 | 3/27/2024 |
0.13.1 | 126 | 3/18/2024 |
0.13.0 | 83 | 3/18/2024 |
0.12.0 | 137 | 2/3/2024 |
0.11.1 | 164 | 1/11/2024 |
0.11.0 | 212 | 11/18/2023 |
0.10.1 | 124 | 11/14/2023 |
0.10.0 | 132 | 11/13/2023 |
0.9.0 | 130 | 10/30/2023 |
0.8.1 | 169 | 9/2/2023 |
0.7.5 | 191 | 8/5/2023 |
0.7.4 | 171 | 7/31/2023 |
0.7.3 | 301 | 12/30/2022 |
0.7.2 | 292 | 12/18/2022 |
0.7.1 | 297 | 12/11/2022 |
0.7.0 | 299 | 12/10/2022 |
0.6.3 | 311 | 12/9/2022 |
0.6.2 | 321 | 12/3/2022 |
0.6.1 | 332 | 12/3/2022 |
0.6.0 | 318 | 12/3/2022 |
0.5.0 | 340 | 12/2/2022 |