Skip to content
ConsoleMonster

API Reference

Class

Markup

Namespace ConsoleMonster.Text
Assembly ConsoleMonster
Modifiers static

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) #
Returns: String

Escapes brackets so text is shown literally inside markup (Spectre's Markup.Escape).

Parameters

text System.String? requiredposition: 0
Plain text, or null.

Returns

Escaped text.

Interpolate 2 overloads
public static String Interpolate(FormattableString value) #
Returns: String

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 requiredposition: 0
The interpolated string.

Returns

Markup with escaped arguments.

public static String Interpolate(IFormatProvider? provider, FormattableString value) #
Returns: String

Builds markup from an interpolated string with an explicit culture, escaping every argument.

Parameters

provider System.IFormatProvider? requiredposition: 0
The culture for formatting the arguments.
value System.FormattableString requiredposition: 1
The interpolated string.

Returns

Markup with escaped arguments.

Parse 2 overloads
public static StyledText Parse(String? markup, ITheme? theme = null, ColorDepth depth = TrueColor) #
Returns: StyledText

Parses markup; lenient unless Markup.Strict is set (see the remarks on Markup).

Parameters

markup System.String? requiredposition: 0
Markup, or null for empty text.
theme ConsoleMonster.Styling.ITheme? = null optionalposition: 1
Theme token resolver; defaults to the built-in dark theme.
depth ConsoleMonster.Capabilities.ColorDepth = TrueColor optionalposition: 2
Target colour depth.

Returns

Styled lines, with tabs expanded to four spaces.

Exceptions

  • FormatException – The markup is invalid and Markup.Strict is set.
public static StyledText Parse(String? markup, ITheme? theme, ColorDepth depth, Boolean strict) #
Returns: StyledText

Parses markup, leniently or strictly.

Parameters

markup System.String? requiredposition: 0
Markup, or null for empty text.
theme ConsoleMonster.Styling.ITheme? requiredposition: 1
Theme token resolver; defaults to the built-in dark theme.
depth ConsoleMonster.Capabilities.ColorDepth requiredposition: 2
Target colour depth.
strict System.Boolean requiredposition: 3
Whether invalid markup throws instead of being rendered leniently.

Returns

Styled lines, with tabs expanded to four spaces.

Exceptions

  • FormatException – The markup is invalid and strict is true.
public static String Strip(String? markup) #
Returns: String

Removes tags and resolves escapes (lenient: an unknown tag that is never closed stays literal).

Parameters

markup System.String? requiredposition: 0
Markup, or null.

Returns

Plain text with normalized newlines and expanded tabs.

public static Boolean TryParseStyle(String? specification, ITheme? theme, ColorDepth depth, out Style style) #
Returns: Boolean

Parses a style, including decorations, foreground/background colours, links and theme tokens.

Parameters

specification System.String? requiredposition: 0
Style words.
theme ConsoleMonster.Styling.ITheme? requiredposition: 1
Token resolver; defaults to the built-in dark theme.
depth ConsoleMonster.Capabilities.ColorDepth requiredposition: 2
Target colour depth.
style ConsoleMonster.Styling.Style requiredposition: 3
Parsed style, or plain when invalid.

Returns

Whether the entire specification is valid.

Validate 2 overloads
public static Boolean Validate(String markup, out String? error) #
Returns: Boolean

Strictly checks tags, escapes and nesting using built-in theme tokens.

Parameters

markup System.String requiredposition: 0
Markup to validate.
error System.String? requiredposition: 1
First error, or null when valid.

Returns

Whether all tags are recognized and balanced.

public static Boolean Validate(String markup, ITheme? theme, out String? error) #
Returns: Boolean

Strictly checks markup with a custom theme token resolver.

Parameters

markup System.String requiredposition: 0
Markup to validate.
theme ConsoleMonster.Styling.ITheme? requiredposition: 1
Token resolver; defaults to the built-in dark theme.
error System.String? requiredposition: 2
First error, or null when valid.

Returns

Whether all tags are recognized and balanced.

Properties

public static Boolean 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 Boolean 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. On glyph tiers that cannot show emoji, the symbol fallback turns them into ASCII or Basic equivalents.