Minor typo fixes

Hope this is helpful, cheers!
This commit is contained in:
Steve Smith 2022-10-19 09:16:49 -04:00 committed by Patrik Svensson
parent 6a4d8c8f30
commit 9df6ed213c

View File

@ -1,109 +1,108 @@
Title: Markup Title: Markup
Order: 30 Order: 30
Description: The Markup class allows you to output rich text to the console. Description: The Markup class allows you to output rich text to the console.
Highlights: Highlights:
- Easily add *color*. - Easily add *color*.
- Add hyperlinks to for supported terminals. - Add hyperlinks to for supported terminals.
- Emoji 🚀 parsing. - Emoji 🚀 parsing.
Reference: Reference:
- M:Spectre.Console.AnsiConsole.Markup(System.String) - M:Spectre.Console.AnsiConsole.Markup(System.String)
- M:Spectre.Console.AnsiConsole.MarkupLine(System.String) - M:Spectre.Console.AnsiConsole.MarkupLine(System.String)
- T:Spectre.Console.Markup - T:Spectre.Console.Markup
--- ---
The `Markup` class allows you to output rich text to the console. The `Markup` class allows you to output rich text to the console.
## Syntax ## Syntax
Console markup uses a syntax inspired by bbcode. If you write the style (see [Styles](xref:styles)) Console markup uses a syntax inspired by bbcode. If you write the style (see [Styles](xref:styles))
in square brackets, e.g. `[bold red]`, that style will apply until it is closed with a `[/]`. in square brackets, e.g. `[bold red]`, that style will apply until it is closed with a `[/]`.
```csharp ```csharp
AnsiConsole.Write(new Markup("[bold yellow]Hello[/] [red]World![/]")); AnsiConsole.Write(new Markup("[bold yellow]Hello[/] [red]World![/]"));
``` ```
The `Markup` class implements `IRenderable` which means that you The `Markup` class implements `IRenderable` which means that you
can use this in tables, grids, and panels. Most classes that support can use this in tables, grids, and panels. Most classes that support
rendering of `IRenderable` also have overloads for rendering rich text. rendering of `IRenderable` also have overloads for rendering rich text.
```csharp ```csharp
var table = new Table(); var table = new Table();
table.AddColumn(new TableColumn(new Markup("[yellow]Foo[/]"))); table.AddColumn(new TableColumn(new Markup("[yellow]Foo[/]")));
table.AddColumn(new TableColumn("[blue]Bar[/]")); table.AddColumn(new TableColumn("[blue]Bar[/]"));
AnsiConsole.Write(table); AnsiConsole.Write(table);
``` ```
## Convenience methods ## Convenience methods
There is also convenience methods on `AnsiConsole` that can be used There are also convenience methods on `AnsiConsole` that can be used
to write markup text to the console without instantiating a new `Markup` to write markup text to the console without instantiating a new `Markup`
instance. instance.
```csharp ```csharp
AnsiConsole.Markup("[underline green]Hello[/] "); AnsiConsole.Markup("[underline green]Hello[/] ");
AnsiConsole.MarkupLine("[bold]World[/]"); AnsiConsole.MarkupLine("[bold]World[/]");
``` ```
## Escaping format characters ## Escaping format characters
To output a `[` you use `[[`, and to output a `]` you use `]]`. To output a `[` you use `[[`, and to output a `]` you use `]]`.
```csharp ```csharp
AnsiConsole.Markup("[[Hello]] "); // [Hello] AnsiConsole.Markup("[[Hello]] "); // [Hello]
AnsiConsole.Markup("[red][[World]][/]"); // [World] AnsiConsole.Markup("[red][[World]][/]"); // [World]
``` ```
You can also use the `EscapeMarkup` extension method. You can also use the `EscapeMarkup` extension method.
```csharp ```csharp
AnsiConsole.Markup("[red]{0}[/]", "Hello [World]".EscapeMarkup()); AnsiConsole.Markup("[red]{0}[/]", "Hello [World]".EscapeMarkup());
``` ```
You can also use the `Markup.Escape` method. You can also use the `Markup.Escape` method.
```csharp ```csharp
AnsiConsole.Markup("[red]{0}[/]", Markup.Escape("Hello [World]")); AnsiConsole.Markup("[red]{0}[/]", Markup.Escape("Hello [World]"));
``` ```
## Escaping Interpolated Strings ## Escaping Interpolated Strings
When working with interpolated string, you can use the `MarkupInterpolated` and `MarkupLineInterpolated` methods to automatically escape the values in the interpolated string holes. When working with interpolated strings, you can use the `MarkupInterpolated` and `MarkupLineInterpolated` methods to automatically escape the values in the interpolated string "holes".
```csharp ```csharp
string hello = "Hello [World]"; string hello = "Hello [World]";
AnsiConsole.MarkupInterpolated($"[red]{hello}[/]"); AnsiConsole.MarkupInterpolated($"[red]{hello}[/]");
``` ```
## Setting background color ## Setting background color
You can set the background color in markup by prefixing the color with You can set the background color in markup by prefixing the color with `on`.
`on`.
```csharp
```csharp AnsiConsole.Markup("[bold yellow on blue]Hello[/]");
AnsiConsole.Markup("[bold yellow on blue]Hello[/]"); AnsiConsole.Markup("[default on blue]World[/]");
AnsiConsole.Markup("[default on blue]World[/]"); ```
```
## Rendering emojis
## Rendering emojis
To output an emoji as part of markup, you can use emoji shortcodes.
To output an emoji as part of markup, you can use emoji shortcodes.
```csharp
```csharp AnsiConsole.Markup("Hello :globe_showing_europe_africa:!");
AnsiConsole.Markup("Hello :globe_showing_europe_africa:!"); ```
```
For a list of emoji, see the [Emojis](xref:emojis) appendix section.
For a list of emoji, see the [Emojis](xref:emojis) appendix section.
## Colors
## Colors
In the examples above, all colors were referenced by their name,
In the examples above, all colors were referenced by their name, but you can also use the hex or rgb representation for colors in markdown.
but you can also use the hex or rgb representation for colors in markdown.
```csharp
```csharp AnsiConsole.Markup("[red]Foo[/] ");
AnsiConsole.Markup("[red]Foo[/] "); AnsiConsole.Markup("[#ff0000]Bar[/] ");
AnsiConsole.Markup("[#ff0000]Bar[/] "); AnsiConsole.Markup("[rgb(255,0,0)]Baz[/] ");
AnsiConsole.Markup("[rgb(255,0,0)]Baz[/] "); ```
```
For a list of colors, see the [Colors](xref:colors) appendix section. For a list of colors, see the [Colors](xref:colors) appendix section.
## Links ## Links
@ -113,8 +112,8 @@ To output a clickable link, you can use the `[link]` style.
```csharp ```csharp
AnsiConsole.Markup("[link]https://spectreconsole.net[/]"); AnsiConsole.Markup("[link]https://spectreconsole.net[/]");
AnsiConsole.Markup("[link=https://spectreconsole.net]Spectre Console Documentation[/]"); AnsiConsole.Markup("[link=https://spectreconsole.net]Spectre Console Documentation[/]");
``` ```
## Styles ## Styles
For a list of styles, see the [Styles](xref:styles) appendix section. For a list of styles, see the [Styles](xref:styles) appendix section.