💻 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) |