Markdown HTML

Syntax Highlighting

@sullux/markdown-html includes a built-in, zero-dependency code syntax highlighter that operates at compile time without requiring bulky runtime highlighting libraries.

Supported Languages

The following language aliases are supported out of the box:

LanguageAliasesDescription
JavaScriptjs, javascriptKeywords, strings, numbers, comments, punctuation, identifiers
JSONjsonKeys, strings, numbers, booleans, null
YAMLyaml, ymlKeys, values, strings, numbers, comments
Bash / Shellbash, sh, zshCommands, flags, strings, variables, comments
HTML / XMLhtml, xmlTags, attributes, strings, comments
SQLsqlKeywords, operators, strings, numbers, comments

Output Token Classes

Highlighted code is wrapped in <pre><code class="language-{lang}"> and uses standard CSS class names for styling:

CSS ClassToken TypeExample
.hl-kwKeywordconst, function, SELECT, if
.hl-strString Literal"hello", 'value'
.hl-numNumber42, 3.14
.hl-commentComment// comment, /* ... */, # comment
.hl-puncPunctuation / Operator{, }, ;, =, =>
.hl-idIdentifier / FunctionmyVar, calculateTotal
.hl-tagHTML/XML Tag Namediv, span, table
.hl-attrHTML/XML Attribute Nameclass, href, id

Adding Custom Tokenizers

You can supply custom tokenizers or override existing ones using the options.tokenizers object:

const { markdownToHtml } = require('@sullux/markdown-html')

const customTokenizers = {
  python: (code) => {
    // Custom zero-dependency tokenizer returning HTML spans
    return code.replace(/\b(def|return|import)\b/g, '<span class="hl-kw">$1</span>')
  },
}

const md = '```python\ndef greet():\n    return "hello"\n```'
const html = markdownToHtml(md, { tokenizers: customTokenizers })