Code Syntax Highlighting Engine (lib/highlight.js)

everything · src/teamchat/src/lib/highlight.js · javascript · MIT
ui, security, lang:javascript, tag:syntax, tag:highlighting

Provides secure, on-demand syntax highlighting for fenced code blocks with HTML escaping. Reuse when rendering chat messages or markdown code snippets safely.

// Source: https://github.com/HeyPuter/everything | License: MIT | Copyright 2026 Puter Technologies Inc
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Syntax highlighting for fenced code blocks, loaded on demand (the message
 * renderer imports this module the first time it meets a block with a
 * language hint, so the initial bundle never carries it).
 *
 * Safety first: the input is the block's plain text, every token is escaped
 * with escapeHtml before it is emitted, and the only markup ever produced is
 * a fixed set of `<span class="tok-…">` wrappers. Nothing from the message
 * can reach the output unescaped, whatever the language rules do.
 *
 * Languages are small rule lists, tried in order at the current position;
 * a few (html, css) keep a little state

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key