MarkupString.Ansi 1.1.0

dotnet add package MarkupString.Ansi --version 1.1.0
                    
NuGet\Install-Package MarkupString.Ansi -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MarkupString.Ansi" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MarkupString.Ansi" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MarkupString.Ansi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MarkupString.Ansi --version 1.1.0
                    
#r "nuget: MarkupString.Ansi, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MarkupString.Ansi@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MarkupString.Ansi&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MarkupString.Ansi&version=1.1.0
                    
Install as a Cake Tool

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.

Styling the HTML output

The HTML-family emitters write ms-* classes for the attributes with a fixed rendering (bold, italic, underline, strike, overline, faint, blink, invert, and command links) and inline style for colours, which are open-ended. AnsiCss.Fixed is the stylesheet for those classes — include it once per page, or copy its rules into your own sheet.

Extension points

  • IAnsiStyleSource — implement it on your own IMarkup and 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 MXP <send>, an anchor, a span — rendered as itself in the HTML, Pueblo and MXP formats, folded into terminal styling elsewhere, with the stylesheet for the ms-* classes the emitters write.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 46 9/7/2026
1.0.0 42 9/7/2026