💻 Code Syntax Highlighter
Highlight source code with syntax colors in your browser — paste code and copy formatted HTML.
输出预览
浅色主题
点击「高亮渲染」按钮,或「加载示例」快速体验
<span> 由 CSS 主题着色;必须先做 HTML 转义防注入。Highlight source code with syntax colors in your browser — paste code and copy formatted HTML.
代码语法高亮工具是一款纯前端实现的代码着色工具,内置简易词法分析引擎,无需引入 highlight.js、Prism 等第三方库。支持 JavaScript、HTML、CSS、Python、JSON、SQL、Markdown 七种语言,可区分关键字、字符串、注释、数字、函数名、运算符等语法元素并着色显示。
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Highlighting principle | tokenize by language lexer into keywords, strings, comments, numbers | Language lexical grammars |
| Strings and comments | multiline strings and nested comments follow language rules | Language lexical grammars |
| Contrast | text contrast of at least 4.5:1 for readability | WCAG 2.2 (1.4.3) |