highlight-utils
React-free helpers for code highlighting pipelines. Use these from build tools, server-side renderers, Web Workers, or small syntax-highlighting services that need Mantle-compatible Code Block HTML without importing React components.
For ordinary React UI, prefer CodeBlock and mantleCode() from @ngrok/mantle/code-block.
Usage
Decorate Shiki HTML
decorateHighlightedHtml takes trusted Shiki-highlighted HTML and wraps each line in the markup Mantle's CodeBlock.Code expects for line numbers and highlighted lines.
Only pass HTML produced by a trusted highlighter such as Shiki. The returned string is intended to be rendered as HTML by a Code Block pipeline.
Normalize indentation
normalizeIndentation trims leading and trailing blank space, removes the common indentation prefix, and rewrites leading whitespace to tabs or spaces.
Parse languages
Use parseLanguage and isSupportedLanguage when accepting language names from Markdown fences, user input, or service payloads.