API Reference
Markup
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) #StringEscapes brackets so text is shown literally inside markup (Spectre's Markup.Escape).
Parameters
- text System.String?
- Plain text, or null.
Returns
Escaped text.
public static String Interpolate(FormattableString value) #StringBuilds 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
Markup with escaped arguments.
public static String Interpolate(IFormatProvider? provider, FormattableString value) #StringBuilds 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
Markup with escaped arguments.
public static StyledText Parse(String? markup, ITheme? theme = null, ColorDepth depth = TrueColor) #StyledTextParses markup; lenient unless Markup.Strict is set (see the remarks on Markup).
Parameters
- markup System.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.
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) #StyledTextParses markup, leniently or strictly.
Parameters
- markup System.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 System.Boolean
- 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) #StringRemoves tags and resolves escapes (lenient: an unknown tag that is never closed stays literal).
Parameters
- markup System.String?
- 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) #BooleanParses a style, including decorations, foreground/background colours, links and theme tokens.
Parameters
- specification System.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
Whether the entire specification is valid.
public static Boolean Validate(String markup, out String? error) #BooleanStrictly checks tags, escapes and nesting using built-in theme tokens.
Parameters
- markup System.String
- Markup to validate.
- error System.String?
- 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) #BooleanStrictly checks markup with a custom theme token resolver.
Parameters
- markup System.String
- Markup to validate.
- theme ConsoleMonster.Styling.ITheme?
- Token resolver; defaults to the built-in dark theme.
- error System.String?
- First error, or null when valid.
Returns
Whether all tags are recognized and balanced.
Inherited Methods
public virtual Boolean Equals(Object? obj) #BooleanParameters
- obj Object?
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.