Markup
ConsoleMonster.Text
Parses the Spectre.Console markup dialect: nested style tags ([bold red on blue], [cadetblue], [#ff8800], [link=https://…]), theme tokens ([pass], [muted]), [/] to close the innermost tag, and [[ / ]] for literal brackets.
Inheritance
- object
- Markup
Remarks
Lenient parsing (the default) never throws. A tag that is not a known style is removed and its text kept when a later [/] closes it (so [unknowncolour]text[/] shows text); an unknown tag that is never closed stays literal, because it is most likely text such as [x]. Set Markup.Strict (or pass strict: true) to throw a FormatException for anything Markup.Validate rejects instead.
Methods
public static string Escape(string? text) #Escapes brackets so text is shown literally inside markup (Spectre's Markup.Escape).
Parameters
- text string?
- Plain text, or null.
Returns
string Escaped text.public static string Interpolate(FormattableString value) #Builds markup from an interpolated string, escaping every argument (format specifiers apply first), so values never become tags: Markup.Interpolate($"[pass]{name}[/] took {elapsed:N1}s").
Parameters
- value System.FormattableString
- The interpolated string.
Returns
string Markup with escaped arguments.public static string Interpolate(IFormatProvider? provider, FormattableString value) #Builds markup from an interpolated string with an explicit culture, escaping every argument.
Parameters
- provider System.IFormatProvider?
- The culture for formatting the arguments.
- value System.FormattableString
- The interpolated string.
Returns
string Markup with escaped arguments.public static StyledText Parse(string? markup, ITheme? theme = null, ColorDepth depth = TrueColor) #Parses markup; lenient unless Markup.Strict is set (see the remarks on Markup).
Parameters
- markup string?
- Markup, or null for empty text.
- theme ConsoleMonster.Styling.ITheme? = null
- Theme token resolver; defaults to the built-in dark theme.
- depth ConsoleMonster.Capabilities.ColorDepth = TrueColor
- Target colour depth.
Exceptions
FormatException– The markup is invalid and Markup.Strict is set.
public static StyledText Parse(string? markup, ITheme? theme, ColorDepth depth, bool strict) #Parses markup, leniently or strictly.
Parameters
- markup string?
- Markup, or null for empty text.
- theme ConsoleMonster.Styling.ITheme?
- Theme token resolver; defaults to the built-in dark theme.
- depth ConsoleMonster.Capabilities.ColorDepth
- Target colour depth.
- strict bool
- Whether invalid markup throws instead of being rendered leniently.
Exceptions
FormatException– The markup is invalid and strict is true.
public static string Strip(string? markup) #Removes tags and resolves escapes (lenient: an unknown tag that is never closed stays literal).
Parameters
- markup string?
- Markup, or null.
Returns
string Plain text with normalized newlines and expanded tabs.public static bool TryParseStyle(string? specification, ITheme? theme, ColorDepth depth, out Style style) #Parses a style, including decorations, foreground/background colours, links and theme tokens.
Parameters
- specification string?
- Style words.
- theme ConsoleMonster.Styling.ITheme?
- Token resolver; defaults to the built-in dark theme.
- depth ConsoleMonster.Capabilities.ColorDepth
- Target colour depth.
- style ConsoleMonster.Styling.Style
- Parsed style, or plain when invalid.
Returns
bool Whether the entire specification is valid.public static bool Validate(string markup, out string? error) #Strictly checks tags, escapes and nesting using built-in theme tokens.
Parameters
- markup string
- Markup to validate.
- error string?
- First error, or null when valid.
Returns
bool Whether all tags are recognized and balanced.public static bool Validate(string markup, ITheme? theme, out string? error) #Strictly checks markup with a custom theme token resolver.
Parameters
- markup string
- Markup to validate.
- theme ConsoleMonster.Styling.ITheme?
- Token resolver; defaults to the built-in dark theme.
- error string?
- First error, or null when valid.
Returns
bool Whether all tags are recognized and balanced.Inherited Methods
Properties
public static bool Strict { get; set; } #When true, Markup.Parse and everything built on it (for example Terminal.WriteMarkupLine) throw a FormatException for invalid markup: unknown tags, unbalanced tags and unescaped brackets. Useful in tests and migration checks. Default false.
public static bool Shortcodes { get; set; } #When true, :name: shortcodes in the text of markup become emoji (:white_check_mark: is ✅; see Shortcodes). Off by default, so colons in data are never touched. The emoji are written as they are on every glyph tier; the Emoji cell presenter turns them into Basic or ASCII equivalents.