Quick Start
Documentation menu
Install the package, create a highlight.js service and produce highlighted markup from C#.
Before you start
Install Node.js and make sure it is on the PATH. The package has been tested with Node.js 10.5.2 through 12.13.0.
Install
dotnet add package Jering.Web.SyntaxHighlighters.HighlightJS
Create the service
var services = new ServiceCollection();
services.AddHighlightJS();
var provider = services.BuildServiceProvider();
var highlighter = provider.GetRequiredService<IHighlightJSService>();
Highlight code
var code = "public string ExampleFunction(string arg) { return arg; }";
var html = await highlighter.HighlightAsync(code, "csharp");
Set a class prefix
If your stylesheet uses a prefix other than the default, pass it as the third argument. The default prefix is hljs.
var html = await highlighter.HighlightAsync(code, "csharp", "code-");
Next
Read Advanced for service lifetime and configuration notes.