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
<PackageReference Include="Meziantou.Framework.SyntaxHighlighting" Version="1.0.1" />
<PackageVersion Include="Meziantou.Framework.SyntaxHighlighting" Version="1.0.1" />
<PackageReference Include="Meziantou.Framework.SyntaxHighlighting" />
paket add Meziantou.Framework.SyntaxHighlighting --version 1.0.1
#r "nuget: Meziantou.Framework.SyntaxHighlighting, 1.0.1"
#:package Meziantou.Framework.SyntaxHighlighting@1.0.1
#addin nuget:?package=Meziantou.Framework.SyntaxHighlighting&version=1.0.1
#tool nuget:?package=Meziantou.Framework.SyntaxHighlighting&version=1.0.1
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,kshbnfcpp,c++,cc,h++,hpp,hh,hxx,cxxcsharp,cs,c#cssdockerfile,dockerdos,bat,cmdfsharp,fs,f#graphql,gqlhtml,htm,xhtmlhttp,httpsini,toml,gitconfigjavascript,js,jsx,mjs,cjsjson,jsonclessmarkdown,md,mkdown,mkdmsil,il,cilnginx,nginxconfphppowershell,pwsh,ps,ps1razor,cshtml,cshtml-razorscsssqltypescript,ts,tsx,mts,ctsurlencoded,x-www-form-urlencodedvbnet,vbx86asmxml,xsd,xsl,plist,rss,atom,svgyaml,yml
| 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. net11.0 is compatible. |
-
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.