-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace GuildWars2.Markup; | ||
|
||
/// <summary>Provides functionality to convert markup strings to other formats.</summary> | ||
[PublicAPI] | ||
public static class MarkupConverter | ||
{ | ||
private static readonly MarkupLexer Lexer = new(); | ||
|
||
private static readonly MarkupParser Parser = new(); | ||
|
||
private static readonly MarkupTextConverter TextConverter = new(); | ||
|
||
private static readonly MarkupHtmlConverter HtmlConverter = new(); | ||
|
||
/// <summary>Converts a markup string to a string with all markup formatting removed.</summary> | ||
/// <param name="markup">The markup string to convert.</param> | ||
/// <returns>The text with all markup formatting removed.</returns> | ||
public static string ToPlainText(string markup) | ||
{ | ||
if (string.IsNullOrWhiteSpace(markup)) | ||
{ | ||
return markup; | ||
} | ||
|
||
var tokens = Lexer.Tokenize(markup); | ||
var rootNode = Parser.Parse(tokens); | ||
return TextConverter.Convert(rootNode); | ||
} | ||
|
||
/// <summary>Converts a markup string to a string with HTML formatting.</summary> | ||
/// <param name="markup">The markup string to convert.</param> | ||
/// <returns>The HTML string.</returns> | ||
public static string ToHtml(string markup) | ||
{ | ||
if (string.IsNullOrWhiteSpace(markup)) | ||
{ | ||
return markup; | ||
} | ||
|
||
var tokens = Lexer.Tokenize(markup); | ||
var rootNode = Parser.Parse(tokens); | ||
return HtmlConverter.Convert(rootNode); | ||
} | ||
|
||
} |