Class MarkupParser
- Namespace
- SharpConsoleUI.Parsing
- Assembly
- SharpConsoleUI.dll
Parses Spectre-compatible markup strings directly into Cell sequences, bypassing the ANSI roundtrip. Supports [bold red on blue]text[/] syntax, [rgb(r,g,b)], [#RRGGBB], and nested/closing tags.
public static class MarkupParser
- Inheritance
-
MarkupParser
- Inherited Members
Methods
CountLinks(string)
Counts the number of clickable links in a markup string without building cells.
Expands any [markdown]…[/] regions first so that Markdown-style links
(converted to [link=…]…[/]) are included in the count.
public static int CountLinks(string markup)
Parameters
markupstringThe markup string to inspect. May be
null.
Returns
- int
The number of
[link=…]opening tags found, which equals the number of clickable link spans the string would produce if fully parsed. Returns 0 fornullor empty input.
Escape(string)
Escapes brackets in plain text so they won't be interpreted as markup.
public static string Escape(string text)
Parameters
textstring
Returns
Parse(string, Color, Color)
Parses markup into a sequence of cells using the given default colors. Also supports the inline [spinner] / [spinner <style>] tag, which renders an animated spinner glyph.
public static List<Cell> Parse(string markup, Color defaultFg, Color defaultBg)
Parameters
Returns
Parse(string, Color, Color, MarkdownStyle?)
Parses markup into cells using a specific Markdown style for any [markdown] regions.
public static List<Cell> Parse(string markup, Color defaultFg, Color defaultBg, MarkdownStyle? markdownStyle)
Parameters
markupstringdefaultFgColordefaultBgColormarkdownStyleMarkdownStyle
Returns
Parse(string, Color, Color, out List<LinkSpan>, MarkdownStyle?)
Parses markup into cells, additionally reporting clickable link spans recorded from
[link=<escaped-url>]…[/] tags (half-open [StartCol,EndCol) in display columns).
public static List<Cell> Parse(string markup, Color defaultFg, Color defaultBg, out List<LinkSpan> links, MarkdownStyle? markdownStyle = null)
Parameters
Returns
ParseLines(string, int, Color, Color)
Parses markup with word-wrapping into multiple lines of cells. Carries the active style stack across line breaks.
public static List<List<Cell>> ParseLines(string markup, int width, Color defaultFg, Color defaultBg)
Parameters
markupstringMarkup string to parse and wrap.
widthintMaximum width per line in visible characters.
defaultFgColorDefault foreground color.
defaultBgColorDefault background color.
Returns
ParseLines(string, int, Color, Color, MarkdownStyle?)
Word-wrapping parse using a specific Markdown style for any [markdown] regions.
public static List<List<Cell>> ParseLines(string markup, int width, Color defaultFg, Color defaultBg, MarkdownStyle? markdownStyle)
Parameters
markupstringwidthintdefaultFgColordefaultBgColormarkdownStyleMarkdownStyle
Returns
ParseLines(string, int, Color, Color, out List<List<LinkSpan>>, MarkdownStyle?)
Word-wrapping parse that also reports per-row link spans, re-sliced so a link crossing a wrap boundary becomes one span per row (each carrying the same URL/Text).
public static List<List<Cell>> ParseLines(string markup, int width, Color defaultFg, Color defaultBg, out List<List<LinkSpan>> linksPerLine, MarkdownStyle? markdownStyle = null)
Parameters
markupstringMarkup string to parse and wrap.
widthintMaximum width per line in visible characters.
defaultFgColorDefault foreground color.
defaultBgColorDefault background color.
linksPerLineList<List<LinkSpan>>Receives one link-span list per returned row (empty list when a row has no links). Always index-aligned with the returned cell rows.
markdownStyleMarkdownStyleStyle for any
[markdown]regions;nulluses the default.
Returns
Remove(string)
Removes all markup tags from a string, returning only the plain text content. Escaped brackets ([[, ]]) are converted to single brackets.
public static string Remove(string markup)
Parameters
markupstring
Returns
StripLength(string)
Returns the visible character length of a markup string (strips all tags).
public static int StripLength(string markup)
Parameters
markupstring
Returns
Truncate(string, int)
Truncates a markup string to maxLength visible characters, preserving and properly closing all tags.
public static string Truncate(string markup, int maxLength)
Parameters
Returns
TryParseSpinnerTagForTests(string, out SpinnerStyle, out int)
Test-only wrapper over TryParseSpinnerTag(string, out SpinnerStyle, out int, out int) (style + interval only).
public static bool TryParseSpinnerTagForTests(string tagContent, out SpinnerStyle style, out int intervalMs)
Parameters
tagContentstringstyleSpinnerStyleintervalMsint
Returns
TryParseSpinnerTagForTests(string, out SpinnerStyle, out int, out int)
Test-only wrapper over TryParseSpinnerTag(string, out SpinnerStyle, out int, out int) (style + interval + width).
public static bool TryParseSpinnerTagForTests(string tagContent, out SpinnerStyle style, out int intervalMs, out int width)
Parameters
tagContentstringstyleSpinnerStyleintervalMsintwidthint