Neo Zero

highlight

Pool

Zero-dependency syntax highlighter - Fast, modern, tree-shakeable with React adapter and auto-scan support

$ lpm install @lpm.dev/[email protected]
134 exportsTypeScript

dist

Functions

tokenize
function tokenize(code: string, grammar: Grammar): Token[]

Tokenize source code using a grammar definition.

ParameterTypeDescription
code
string- The source code to tokenize
grammar
Grammar- The grammar definition to use
getPlainText
function getPlainText(tokens: Token[]): string

Get the plain text from an array of tokens.

ParameterTypeDescription
tokens
Token[]
createRegistry
function createRegistry(grammars: Grammar[]): Map<string, Grammar>

Create a grammar registry from an array of grammars.

ParameterTypeDescription
grammars
Grammar[]
renderToHTML
function renderToHTML(tokens: Token[], options?: RenderOptions): string

Render tokens to an HTML string.

ParameterTypeDescription
tokens
Token[]- Array of tokens from the tokenizer
optionsoptional
RenderOptions- Rendering options (theme, line numbers, etc.)
getThemeStylesheet
function getThemeStylesheet(theme: Theme | string, classPrefix?: string): string

Generate a complete CSS stylesheet for a theme. Useful for SSR or injecting into <style> tags.

ParameterTypeDescription
theme
Theme | string
classPrefixoptional
string
registerTheme
function registerTheme(theme: Theme): void

Register a theme for name-based lookup.

ParameterTypeDescription
theme
Theme
registerThemes
function registerThemes(themes: Theme[]): void

Register multiple themes.

ParameterTypeDescription
themes
Theme[]
getTheme
function getTheme(name: string): Theme | undefined

Get a theme by name from the registry.

ParameterTypeDescription
name
string
resolveTheme
function resolveTheme(theme: Theme | string): Theme | undefined

Resolve a theme — accepts either a Theme object or a string name. Returns the theme object, or undefined if not found.

ParameterTypeDescription
theme
Theme | string
getThemeCSS
function getThemeCSS(theme: Theme, classPrefix?: string): string

Generate CSS string for a theme using CSS custom properties.

ParameterTypeDescription
theme
Theme
classPrefixoptional
string
applyTheme
function applyTheme(theme: Theme | string, classPrefix?: string): (() => void) | undefined

Apply a theme by injecting a <style> tag into the document. Returns a cleanup function to remove the style element.

ParameterTypeDescription
theme
Theme | string- Theme object or name
classPrefixoptional
string- CSS class prefix
clearDetectCache
function clearDetectCache(): void

Clear the detection cache.

scoreTokenization
function scoreTokenization(tokens: Token[], codeLength: number): number

Score a tokenization result for how well a grammar matches the code.

ParameterTypeDescription
tokens
Token[]- Tokenized output
codeLength
number- Length of the original code
detectLanguage
function detectLanguage(code: string, grammars: Grammar[], options?: DetectOptions): DetectResult | undefined

Detect the most likely language for a code snippet.

ParameterTypeDescription
code
string- Source code to analyze
grammars
Grammar[]- Array of candidate grammars
optionsoptional
DetectOptions- Detection options

dist/copy-button-CVhoMdTs

Functions

scan
function scan(options: ScanOptions): number

Scan a container for code elements and highlight them.

ParameterTypeDescription
options
ScanOptions- Scan options
observe
function observe(options: ScanOptions): () => void

Observe a container for new code elements and highlight them automatically. Uses MutationObserver for dynamic content (SPA routing, lazy loading, etc.).

ParameterTypeDescription
options
ScanOptions- Scan options (observe option is ignored)
autoHighlight
function autoHighlight(options: ScanOptions): () => void

Auto-highlight: scan and optionally observe for new code blocks. Convenience function combining scan() and observe().

ParameterTypeDescription
options
ScanOptions- Scan options
renderCopyButton
function renderCopyButton(code: string, options?: CopyButtonOptions): string

Render a copy button HTML string. The button stores the code in a `data-code` attribute.

ParameterTypeDescription
code
string- The raw code to be copied
optionsoptional
CopyButtonOptions- Button options
initCopyButtons
function initCopyButtons(container?: Element | undefined, classPrefix?: string): () => void

Initialize click handlers for all copy buttons within a container. Finds all buttons with the `neo-hl-copy-button` class and wires up click events.

ParameterTypeDescription
containeroptional
Element | undefined- Container element to search in (default: document.body)
classPrefixoptional
string- CSS class prefix (default: "neo-hl")

dist/copy-button-D8z-uTDy

Functions

scan
function scan(options: ScanOptions): number

Scan a container for code elements and highlight them.

ParameterTypeDescription
options
ScanOptions- Scan options
observe
function observe(options: ScanOptions): () => void

Observe a container for new code elements and highlight them automatically. Uses MutationObserver for dynamic content (SPA routing, lazy loading, etc.).

ParameterTypeDescription
options
ScanOptions- Scan options (observe option is ignored)
autoHighlight
function autoHighlight(options: ScanOptions): () => void

Auto-highlight: scan and optionally observe for new code blocks. Convenience function combining scan() and observe().

ParameterTypeDescription
options
ScanOptions- Scan options
renderCopyButton
function renderCopyButton(code: string, options?: CopyButtonOptions): string

Render a copy button HTML string. The button stores the code in a `data-code` attribute.

ParameterTypeDescription
code
string- The raw code to be copied
optionsoptional
CopyButtonOptions- Button options
initCopyButtons
function initCopyButtons(container?: Element | undefined, classPrefix?: string): () => void

Initialize click handlers for all copy buttons within a container. Finds all buttons with the `neo-hl-copy-button` class and wires up click events.

ParameterTypeDescription
containeroptional
Element | undefined- Container element to search in (default: document.body)
classPrefixoptional
string- CSS class prefix (default: "neo-hl")

dist/grammars/bash

Variables

bashGrammar

dist/grammars/bash

Variables

bashGrammar

dist/grammars/c

Variables

cGrammar

dist/grammars/c

Variables

cGrammar

dist/grammars/cpp

Variables

cppGrammar

dist/grammars/cpp

Variables

cppGrammar

dist/grammars/csharp

Variables

csharpGrammar

dist/grammars/csharp

Variables

csharpGrammar

dist/grammars/css

Variables

cssGrammar

dist/grammars/css

Variables

cssGrammar

dist/grammars/diff

Variables

diffGrammar

dist/grammars/diff

Variables

diffGrammar

dist/grammars/docker

Variables

dockerGrammar

dist/grammars/docker

Variables

dockerGrammar

dist/grammars/go

Variables

goGrammar

dist/grammars/go

Variables

goGrammar

dist/grammars/graphql

Variables

graphqlGrammar

dist/grammars/graphql

Variables

graphqlGrammar

dist/grammars/html

Variables

htmlGrammar

dist/grammars/html

Variables

htmlGrammar

dist/grammars/ini

Variables

iniGrammar

dist/grammars/ini

Variables

iniGrammar

dist/grammars/java

Variables

javaGrammar

dist/grammars/java

Variables

javaGrammar

dist/grammars/javascript

Variables

javascriptGrammar

dist/grammars/javascript

Variables

javascriptGrammar

dist/grammars/json

Variables

jsonGrammar

dist/grammars/json

Variables

jsonGrammar

dist/grammars/jsx

Variables

jsxGrammar

dist/grammars/jsx

Variables

jsxGrammar

dist/grammars/kotlin

Variables

kotlinGrammar

dist/grammars/kotlin

Variables

kotlinGrammar

dist/grammars/markdown

Variables

markdownGrammar

dist/grammars/markdown

Variables

markdownGrammar

dist/grammars/php

Variables

phpGrammar

dist/grammars/php

Variables

phpGrammar

dist/grammars/python

Variables

pythonGrammar

dist/grammars/python

Variables

pythonGrammar

dist/grammars/regex

Variables

regexGrammar

dist/grammars/regex

Variables

regexGrammar

dist/grammars/ruby

Variables

rubyGrammar

dist/grammars/ruby

Variables

rubyGrammar

dist/grammars/rust

Variables

rustGrammar

dist/grammars/rust

Variables

rustGrammar

dist/grammars/scss

Variables

scssGrammar

dist/grammars/scss

Variables

scssGrammar

dist/grammars/shell

Variables

shellGrammar

dist/grammars/shell

Variables

shellGrammar

dist/grammars/sql

Variables

sqlGrammar

dist/grammars/sql

Variables

sqlGrammar

dist/grammars/swift

Variables

swiftGrammar

dist/grammars/swift

Variables

swiftGrammar

dist/grammars/toml

Variables

tomlGrammar

dist/grammars/toml

Variables

tomlGrammar

dist/grammars/tsx

Variables

tsxGrammar

dist/grammars/tsx

Variables

tsxGrammar

dist/grammars/typescript

Variables

typescriptGrammar

dist/grammars/typescript

Variables

typescriptGrammar

dist/grammars/yaml

Variables

yamlGrammar

dist/grammars/yaml

Variables

yamlGrammar

dist

Functions

tokenize
function tokenize(code: string, grammar: Grammar): Token[]

Tokenize source code using a grammar definition.

ParameterTypeDescription
code
string- The source code to tokenize
grammar
Grammar- The grammar definition to use
getPlainText
function getPlainText(tokens: Token[]): string

Get the plain text from an array of tokens.

ParameterTypeDescription
tokens
Token[]
createRegistry
function createRegistry(grammars: Grammar[]): Map<string, Grammar>

Create a grammar registry from an array of grammars.

ParameterTypeDescription
grammars
Grammar[]
renderToHTML
function renderToHTML(tokens: Token[], options?: RenderOptions): string

Render tokens to an HTML string.

ParameterTypeDescription
tokens
Token[]- Array of tokens from the tokenizer
optionsoptional
RenderOptions- Rendering options (theme, line numbers, etc.)
getThemeStylesheet
function getThemeStylesheet(theme: Theme | string, classPrefix?: string): string

Generate a complete CSS stylesheet for a theme. Useful for SSR or injecting into <style> tags.

ParameterTypeDescription
theme
Theme | string
classPrefixoptional
string
registerTheme
function registerTheme(theme: Theme): void

Register a theme for name-based lookup.

ParameterTypeDescription
theme
Theme
registerThemes
function registerThemes(themes: Theme[]): void

Register multiple themes.

ParameterTypeDescription
themes
Theme[]
getTheme
function getTheme(name: string): Theme | undefined

Get a theme by name from the registry.

ParameterTypeDescription
name
string
resolveTheme
function resolveTheme(theme: Theme | string): Theme | undefined

Resolve a theme — accepts either a Theme object or a string name. Returns the theme object, or undefined if not found.

ParameterTypeDescription
theme
Theme | string
getThemeCSS
function getThemeCSS(theme: Theme, classPrefix?: string): string

Generate CSS string for a theme using CSS custom properties.

ParameterTypeDescription
theme
Theme
classPrefixoptional
string
applyTheme
function applyTheme(theme: Theme | string, classPrefix?: string): (() => void) | undefined

Apply a theme by injecting a <style> tag into the document. Returns a cleanup function to remove the style element.

ParameterTypeDescription
theme
Theme | string- Theme object or name
classPrefixoptional
string- CSS class prefix
clearDetectCache
function clearDetectCache(): void

Clear the detection cache.

scoreTokenization
function scoreTokenization(tokens: Token[], codeLength: number): number

Score a tokenization result for how well a grammar matches the code.

ParameterTypeDescription
tokens
Token[]- Tokenized output
codeLength
number- Length of the original code
detectLanguage
function detectLanguage(code: string, grammars: Grammar[], options?: DetectOptions): DetectResult | undefined

Detect the most likely language for a code snippet.

ParameterTypeDescription
code
string- Source code to analyze
grammars
Grammar[]- Array of candidate grammars
optionsoptional
DetectOptions- Detection options

dist/react

Functions

Highlight
function Highlight({ children, language, theme: themeProp, showLineNumbers, highlightLines, diffHighlight, copyButton, copyButtonLabel, copyButtonCopiedLabel, onCopy, classPrefix: classPrefixProp, className, style, }: HighlightProps): react_jsx_runtime.JSX.Element

Component-mode syntax highlighter. Usage: ```tsx <Highlight language={javascript} theme="github-dark"> {`const x = 42;`} </Highlight> ```

ParameterTypeDescription
{ children, language, theme: themeProp, showLineNumbers, highlightLines, diffHighlight, copyButton, copyButtonLabel, copyButtonCopiedLabel, onCopy, classPrefix: classPrefixProp, className, style, }
HighlightProps
AutoHighlight
function AutoHighlight({ children, languages: languagesProp, theme: themeProp, selector, lineNumbers: lineNumbersProp, classPrefix: classPrefixProp, className, style, autoDetect, }: AutoHighlightProps): react_jsx_runtime.JSX.Element

Auto-scan component that highlights all `<code>` elements within its children. Uses MutationObserver to watch for dynamically added content. Usage: ```tsx <AutoHighlight languages={[javascript, python]} theme="github-dark"> <article dangerouslySetInnerHTML={{ __html: markdownHtml }} /> </AutoHighlight> ```

ParameterTypeDescription
{ children, languages: languagesProp, theme: themeProp, selector, lineNumbers: lineNumbersProp, classPrefix: classPrefixProp, className, style, autoDetect, }
AutoHighlightProps
useHighlight
function useHighlight(code: string, language: Grammar, options?: UseHighlightOptions): UseHighlightResult

Hook for syntax highlighting. Returns memoized tokens and HTML string.

ParameterTypeDescription
code
string- Source code to highlight
language
Grammar- Grammar definition
optionsoptional
UseHighlightOptions- Rendering options
CopyButton
function CopyButton({ code, label, copiedLabel, classPrefix, onCopy, className, style, }: CopyButtonProps): react_jsx_runtime.JSX.Element

Copy-to-clipboard button for code blocks. Uses navigator.clipboard.writeText with execCommand fallback. Shows "Copied!" feedback for 2 seconds after click.

ParameterTypeDescription
{ code, label, copiedLabel, classPrefix, onCopy, className, style, }
CopyButtonProps
HighlightProvider
function HighlightProvider({ children, theme, languages, classPrefix, lineNumbers, }: HighlightProviderProps): react_jsx_runtime.JSX.Element
ParameterTypeDescription
{ children, theme, languages, classPrefix, lineNumbers, }
HighlightProviderProps
useHighlightContext
function useHighlightContext(): HighlightContextValue

dist/react

Functions

Highlight
function Highlight({ children, language, theme: themeProp, showLineNumbers, highlightLines, diffHighlight, copyButton, copyButtonLabel, copyButtonCopiedLabel, onCopy, classPrefix: classPrefixProp, className, style, }: HighlightProps): react_jsx_runtime.JSX.Element

Component-mode syntax highlighter. Usage: ```tsx <Highlight language={javascript} theme="github-dark"> {`const x = 42;`} </Highlight> ```

ParameterTypeDescription
{ children, language, theme: themeProp, showLineNumbers, highlightLines, diffHighlight, copyButton, copyButtonLabel, copyButtonCopiedLabel, onCopy, classPrefix: classPrefixProp, className, style, }
HighlightProps
AutoHighlight
function AutoHighlight({ children, languages: languagesProp, theme: themeProp, selector, lineNumbers: lineNumbersProp, classPrefix: classPrefixProp, className, style, autoDetect, }: AutoHighlightProps): react_jsx_runtime.JSX.Element

Auto-scan component that highlights all `<code>` elements within its children. Uses MutationObserver to watch for dynamically added content. Usage: ```tsx <AutoHighlight languages={[javascript, python]} theme="github-dark"> <article dangerouslySetInnerHTML={{ __html: markdownHtml }} /> </AutoHighlight> ```

ParameterTypeDescription
{ children, languages: languagesProp, theme: themeProp, selector, lineNumbers: lineNumbersProp, classPrefix: classPrefixProp, className, style, autoDetect, }
AutoHighlightProps
useHighlight
function useHighlight(code: string, language: Grammar, options?: UseHighlightOptions): UseHighlightResult

Hook for syntax highlighting. Returns memoized tokens and HTML string.

ParameterTypeDescription
code
string- Source code to highlight
language
Grammar- Grammar definition
optionsoptional
UseHighlightOptions- Rendering options
CopyButton
function CopyButton({ code, label, copiedLabel, classPrefix, onCopy, className, style, }: CopyButtonProps): react_jsx_runtime.JSX.Element

Copy-to-clipboard button for code blocks. Uses navigator.clipboard.writeText with execCommand fallback. Shows "Copied!" feedback for 2 seconds after click.

ParameterTypeDescription
{ code, label, copiedLabel, classPrefix, onCopy, className, style, }
CopyButtonProps
HighlightProvider
function HighlightProvider({ children, theme, languages, classPrefix, lineNumbers, }: HighlightProviderProps): react_jsx_runtime.JSX.Element
ParameterTypeDescription
{ children, theme, languages, classPrefix, lineNumbers, }
HighlightProviderProps
useHighlightContext
function useHighlightContext(): HighlightContextValue

dist/themes/dracula

Variables

draculaTheme

dist/themes/dracula

Variables

draculaTheme

dist/themes/github-dark

Variables

githubDarkTheme

dist/themes/github-dark

Variables

githubDarkTheme

dist/themes/github-light

Variables

githubLightTheme

dist/themes/github-light

Variables

githubLightTheme

dist/themes/monokai

Variables

monokaiTheme

dist/themes/monokai

Variables

monokaiTheme

dist/themes/night-owl

Variables

nightOwlTheme

dist/themes/night-owl

Variables

nightOwlTheme

dist/themes/nord

Variables

nordTheme

dist/themes/nord

Variables

nordTheme

dist/themes/one-dark

Variables

oneDarkTheme

dist/themes/one-dark

Variables

oneDarkTheme

dist/themes/solarized-dark

Variables

solarizedDarkTheme

dist/themes/solarized-dark

Variables

solarizedDarkTheme

dist/themes/solarized-light

Variables

solarizedLightTheme

dist/themes/solarized-light

Variables

solarizedLightTheme

dist/themes/tokyo-night

Variables

tokyoNightTheme

dist/themes/tokyo-night

Variables

tokyoNightTheme

dist/vanilla

Functions

highlight
function highlight(code: string, language: Grammar, options?: HighlightOptions): string

Highlight source code and return an HTML string.

ParameterTypeDescription
code
string- Source code to highlight
language
Grammar- Grammar definition
optionsoptional
HighlightOptions- Rendering options
autoHighlight
function autoHighlight(options: ScanOptions): () => void

Auto-highlight: scan the page for code blocks and optionally observe for new ones.

ParameterTypeDescription
options
ScanOptions- Scan options

dist/vanilla

Functions

highlight
function highlight(code: string, language: Grammar, options?: HighlightOptions): string

Highlight source code and return an HTML string.

ParameterTypeDescription
code
string- Source code to highlight
language
Grammar- Grammar definition
optionsoptional
HighlightOptions- Rendering options
autoHighlight
function autoHighlight(options: ScanOptions): () => void

Auto-highlight: scan the page for code blocks and optionally observe for new ones.

ParameterTypeDescription
options
ScanOptions- Scan options
Unlimited AccessInstall as many Pool packages as you need.
Fund Real WorkEvery install you run sends revenue directly to the developer who built it.

Taxes calculated at checkout based on your location.

Weekly Installs
30
Version
1.0.1
Published
LicenseMIT
Size745.78 KB
Files449
Node version>= 18
TypeScriptYes