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

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.

public static List<Cell> Parse(string markup, Color defaultFg, Color defaultBg)

Parameters

markup string
defaultFg Color
defaultBg Color

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.

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