Table of Contents

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

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

markup string

The 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 for null or empty input.

Escape(string)

Escapes brackets in plain text so they won't be interpreted as markup.

public static string Escape(string text)

Parameters

text string

Returns

string

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

markup string
defaultFg Color
defaultBg Color

Returns

List<Cell>

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

markup string
defaultFg Color
defaultBg Color
markdownStyle MarkdownStyle

Returns

List<Cell>

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

markup string
defaultFg Color
defaultBg Color
links List<LinkSpan>
markdownStyle MarkdownStyle

Returns

List<Cell>

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

markup string

Markup string to parse and wrap.

width int

Maximum width per line in visible characters.

defaultFg Color

Default foreground color.

defaultBg Color

Default background color.

Returns

List<List<Cell>>

List of cell lists, one per wrapped line.

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

markup string
width int
defaultFg Color
defaultBg Color
markdownStyle MarkdownStyle

Returns

List<List<Cell>>

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

markup string

Markup string to parse and wrap.

width int

Maximum width per line in visible characters.

defaultFg Color

Default foreground color.

defaultBg Color

Default background color.

linksPerLine List<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.

markdownStyle MarkdownStyle

Style for any [markdown] regions; null uses the default.

Returns

List<List<Cell>>

List of cell lists, one per wrapped line.

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

markup string

Returns

string

StripLength(string)

Returns the visible character length of a markup string (strips all tags).

public static int StripLength(string markup)

Parameters

markup string

Returns

int

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

markup string
maxLength int

Returns

string

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

tagContent string
style SpinnerStyle
intervalMs int

Returns

bool

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

tagContent string
style SpinnerStyle
intervalMs int
width int

Returns

bool