Skip to content

tatwd/prism-sharp

Repository files navigation

PrismSharp

A porting of PrismJS to C# or .NET.

All supported language grammars are here.

Getting Started

Tokenize Code

Install PrismSharp.Core package:

dotnet add package PrismSharp.Core --prerelease

Then,

using PrismSharp.Core;

var text = @"<p>Hello world!</p>";
var grammar = LanguageGrammars.Html; // or defined yourself
var tokens = Prism.Tokenize(text, grammar);

Highlight Code

Install PrismSharp.Highlighting.HTML package:

dotnet add package PrismSharp.Highlighting.HTML --prerelease

Then,

using PrismSharp.Core;
using PrismSharp.Highlighting.HTML;

var text = @"<p>Hello world!</p>";
var grammar = LanguageGrammars.Html; // or defined yourself
var highlighter = new HtmlHighlighter();
var html = highlighter.Highlight(text, grammar, "html");

The css styles can customize yourself, or download from PrismJS.