Meziantou.Framework.SyntaxHighlighting 1.0.1

Prefix Reserved
dotnet add package Meziantou.Framework.SyntaxHighlighting --version 1.0.1
                    
NuGet\Install-Package Meziantou.Framework.SyntaxHighlighting -Version 1.0.1
                    
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="Meziantou.Framework.SyntaxHighlighting" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.SyntaxHighlighting" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.SyntaxHighlighting" />
                    
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 Meziantou.Framework.SyntaxHighlighting --version 1.0.1
                    
#r "nuget: Meziantou.Framework.SyntaxHighlighting, 1.0.1"
                    
#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 Meziantou.Framework.SyntaxHighlighting@1.0.1
                    
#: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=Meziantou.Framework.SyntaxHighlighting&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.SyntaxHighlighting&version=1.0.1
                    
Install as a Cake Tool

Meziantou.Framework.SyntaxHighlighting

Meziantou.Framework.SyntaxHighlighting highlights source code and returns HTML markup with CSS classes.

The package uses class names compatible with highlight.js by default, so you can reuse existing highlight.js themes without changing the generated HTML.

Usage

using Meziantou.Framework.SyntaxHighlighting;

var html = SyntaxHighlighter.Highlight(
    "public class MyClass { }",
    "csharp");

Console.WriteLine(html);
// <span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> { }

Custom CSS prefix

If you do not want to use the default hljs- prefix, you can customize it:

using Meziantou.Framework.SyntaxHighlighting;

var html = SyntaxHighlighter.Highlight(
    "public class MyClass { }",
    "csharp",
    new HighlightOptions { ClassPrefix = "syntax-" });

Console.WriteLine(html);
// <span class="syntax-keyword">public</span> <span class="syntax-keyword">class</span> <span class="syntax-title">MyClass</span> { }

Styling

The package only produces HTML. You must provide the CSS rules for the generated classes.

With the default options, the generated markup is designed to work well with highlight.js themes. For example:

<pre><code><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> { }</code></pre>

Supported languages

The package currently supports these language identifiers and common aliases:

  • bash, sh, zsh, ksh
  • bnf
  • cpp, c++, cc, h++, hpp, hh, hxx, cxx
  • csharp, cs, c#
  • css
  • dockerfile, docker
  • dos, bat, cmd
  • fsharp, fs, f#
  • graphql, gql
  • html, htm, xhtml
  • http, https
  • ini, toml, gitconfig
  • javascript, js, jsx, mjs, cjs
  • json, jsonc
  • less
  • markdown, md, mkdown, mkd
  • msil, il, cil
  • nginx, nginxconf
  • php
  • powershell, pwsh, ps, ps1
  • razor, cshtml, cshtml-razor
  • scss
  • sql
  • typescript, ts, tsx, mts, cts
  • urlencoded, x-www-form-urlencoded
  • vbnet, vb
  • x86asm
  • xml, xsd, xsl, plist, rss, atom, svg
  • yaml, yml
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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 325 7/7/2026
1.0.0 210 5/28/2026