MarkupString.Ansi
1.0.0
See the version list below for details.
dotnet add package MarkupString.Ansi --version 1.0.0
NuGet\Install-Package MarkupString.Ansi -Version 1.0.0
<PackageReference Include="MarkupString.Ansi" Version="1.0.0" />
<PackageVersion Include="MarkupString.Ansi" Version="1.0.0" />
<PackageReference Include="MarkupString.Ansi" />
paket add MarkupString.Ansi --version 1.0.0
#r "nuget: MarkupString.Ansi, 1.0.0"
#:package MarkupString.Ansi@1.0.0
#addin nuget:?package=MarkupString.Ansi&version=1.0.0
#tool nuget:?package=MarkupString.Ansi&version=1.0.0
MarkupString.Ansi
Terminal styling for MarkupString: colours (the 16
standard ones, xterm-256 and truecolor), bold/faint/italic/underline/overline/strike/blink/invert,
and links — either a URL or a command for the client to send.
One AnsiMarkup layer per span; a run's stack of layers folds into a single SGR sequence for the
terminal, one <span> for HTML, or the nearest equivalent in the other formats. Transitions are
written as diffs, so nested spans do not restate what is already in effect.
dotnet add package MarkupString.Ansi
Usage
using MarkupString;
using MarkupString.Ansi;
using MarkupString.Html;
MarkupRegistry.Default = MarkupRegistry.Empty.WithAnsi().WithHtml();
var text = MarkupText.Concat(
MarkupText.Plain("Hello, "),
MarkupText.Wrap(AnsiCodeParser.Parse("hr"), "world"));
text.Render(MarkupFormat.Ansi); // Hello, \e[1;31mworld\e[0m
text.Render(MarkupFormat.Html); // Hello, <span style="color: #ff5555">world</span>
var json = MarkupTextSerializer.Serialize(text);
var back = MarkupTextSerializer.Deserialize(json);
AnsiCodeParser.Parse takes MUSH ansi() syntax — hr, /R, +xterm200, #ff5555,
<255 0 0> — and AnsiMarkup.Create(...) builds the same thing from named arguments.
Formats
WithAnsi() registers emitters for Ansi, Html, Pueblo, Mxp and BBCode. Plain needs
none: the body passes through.
Extension points
IAnsiStyleSource— implement it on your ownIMarkupand this package's fold picks the style up, so a layer of yours can contribute bold or a colour without its own emitter per format.IMarkupEmitter/IMarkupSetEmitter/IMarkupCodec— replace any of this package's registrations by adding yours to the registry afterwards.
AOT and trimming
IsAotCompatible; no reflection, no dynamic code. Registration is an explicit WithAnsi() call,
so nothing depends on a type surviving the trimmer by name.
Licence
Apache-2.0. Source, guides and issues: SharpMUSH/MarkupString.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- MarkupString (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MarkupString.Ansi:
| Package | Downloads |
|---|---|
|
MarkupString.Html
Raw HTML tag markup for MarkupString — an anchor, a pre, a span — rendered as itself in the HTML, Pueblo and MXP formats and folded into terminal styling elsewhere, with checked construction and tag policies for untrusted input. |
GitHub repositories
This package is not used by any popular GitHub repositories.