This documentation is also published as Markdown for efficient machine reading: the whole site is indexed at /llms.txt, and every page has a clean Markdown copy under /_llms/. These are generated from the same source and cost far fewer tokens to read than this rendered HTML.

Skip to main content Skip to navigation

HighlightingService Pennington.Highlighting

Dispatches code highlighting to the highest-priority ICodeHighlighter that supports the requested language. Falls back to PlainTextHighlighter and emits an Info diagnostic once per unknown language per instance.

Constructors

HighlightingService

#
public HighlightingService(IEnumerable<ICodeHighlighter> highlighters)

Initializes the service with the registered highlighters, ordered by descending Priority.

Parameters

highlighters IEnumerable<ICodeHighlighter>

HighlightingService

#
public HighlightingService(IEnumerable<ICodeHighlighter> highlighters, IHttpContextAccessor httpContextAccessor)

Initializes the service with the registered highlighters and an optional HTTP context accessor used to surface unknown-language Info diagnostics to the per-request DiagnosticContext.

Parameters

highlighters IEnumerable<ICodeHighlighter>
httpContextAccessor IHttpContextAccessor

Methods

Highlight

#
public string Highlight(string code, string language)

Highlight code using the best available highlighter for the language. Returns the highlighted HTML string.

Parameters

code string
language string

Returns

string

Pennington.Highlighting.HighlightingService

namespace Pennington.Highlighting;

/// Dispatches code highlighting to the highest-priority ICodeHighlighter that supports the requested language. Falls back to PlainTextHighlighter and emits an Info diagnostic once per unknown language per instance.
public class HighlightingService
{
    /// Highlight code using the best available highlighter for the language. Returns the highlighted HTML string.
    
public string Highlight(string code, string language)
; /// Initializes the service with the registered highlighters, ordered by descending Priority.
public HighlightingService(IEnumerable<ICodeHighlighter> highlighters)
; /// Initializes the service with the registered highlighters and an optional HTTP context accessor used to surface unknown-language Info diagnostics to the per-request DiagnosticContext.
public HighlightingService(IEnumerable<ICodeHighlighter> highlighters, IHttpContextAccessor httpContextAccessor)
; }