Skip to content
Open core software, built in Singapore Established 2018  /  Five utilities
Jering
Talk to us

Quick Start

Web.SyntaxHighlighters.HighlightJS Jering documentation Open source NuGet package
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

Package Manager
dotnet add package Jering.Web.SyntaxHighlighters.HighlightJS

Create the service

C#
var services = new ServiceCollection();
services.AddHighlightJS();
var provider = services.BuildServiceProvider();
var highlighter = provider.GetRequiredService<IHighlightJSService>();

Highlight code

C#
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.

C#
var html = await highlighter.HighlightAsync(code, "csharp", "code-");

Next

Read Advanced for service lifetime and configuration notes.

Reference shelf