Code Highlighting & Enhancement
This page explains code block configuration: highlight engine and themes (prismjs/highlightjs), code block interaction enhancements (collapse/wrap/expand/copy/fullscreen), language labels and copy copyright. Everything lives in the code section of the theme config.
The authoritative source of the theme config is
userConfig/_config.tmp.yml(it overwrites the theme config at CI time). Note: server-side prismjs rendering at the Markdown renderer level is handled by theprismjsplugin in the root_config.yml; this section covers the theme-level code block display config.Reading guide: every section follows 「How to enable → Common options → All tunable keys → Boundaries & conflicts」 — check the Effect first, then the Corresponding config that produces it, and copy it to use.
1. Highlight Engine (highlight)
Purpose: choose the highlight implementation library, and control line numbers plus the light/dark theme pair.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
1.1 How to enable
Effect: ``` code blocks in posts are colored by the selected library, line numbers appear on the left, and dark mode automatically switches to the dark theme.
Corresponding config (theme config, code.highlight section):
code:
highlight:
enable: true # master switch
line_number: true # whether to show line numbers
lib: "prismjs" # highlight library: highlightjs | prismjs1.2 Common options
① Turn off line numbers
Effect: the 1, 2, 3… gutter on the left of code blocks disappears, giving the code area more width.
Corresponding config:
code:
highlight:
line_number: false② Switch engine
Effect: highlighting is done by highlight.js instead, and the theme names and syntax coverage change accordingly (see §3).
Corresponding config:
code:
highlight:
lib: "highlightjs"③ Disable highlighting entirely
Effect: code blocks become plain text with no coloring and no line numbers.
Corresponding config:
code:
highlight:
enable: false1.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
code.highlight.enable | bool | true | true / false | Highlight master switch |
code.highlight.line_number | bool | true | true / false | Show line numbers |
code.highlight.lib | string | "prismjs" | highlightjs / prismjs | Highlight library |
1.4 Boundaries & conflicts
libdecides which engine is used and activates the matching sub-config below —prismjsreadscode.highlight.prismjs,highlightjsreadscode.highlight.highlightjs; both exist but only one takes effect.- This blog uses prismjs.
- Engine-level highlighting and the
prismjsplugin in the root_config.ymlare two separate channels; changing the theme config does not change server-side rendering behavior.
1.5 Summary
- Minimal setup:
enable: true+lib - Line numbers feel cramped:
line_number: false - Switching libraries: change
lib, and remember to change the style in §2 or §3 to match
2. prismjs Themes & Render Mode
Purpose: the light/dark highlight theme pair (following light/dark mode), and how the highlight HTML is generated.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
2.1 How to enable
Effect: in light mode code blocks use the default palette and switch to tomorrow night automatically in dark mode; the three enhancement plugins treeview/autolinker/diffhighlight are active.
Corresponding config (theme config, code.highlight.prismjs section):
code:
highlight:
prismjs:
style: "default" # light theme: pick a style from the round buttons at prismjs.com, or a CSS link
style_dark: "tomorrow night" # dark theme
preprocess: false # true = generated statically at build; false = generated by browser JS
treeview: true # show treeview in code blocks (tree -F tree form)
autolinker: true # links inside code blocks clickable
diffhighlight: true # code diff highlight (+/- lines)2.2 Common options
① Change the light theme
Effect: code block colors switch to the chosen theme (background, keywords, and string colors all change).
Corresponding config:
code:
highlight:
prismjs:
style: "tomorrow"② Change the dark theme
Effect: code blocks use the new palette in dark mode.
Corresponding config:
code:
highlight:
prismjs:
style_dark: "dark"③ Switch to static rendering at build time
Effect: the highlight HTML is generated at build time, so coloring is visible even without JS (but treeview/autolinker/diffhighlight become unavailable).
Corresponding config:
code:
highlight:
prismjs:
preprocess: true④ Turn off diff highlighting
Effect: +/- lines no longer get green/red backgrounds.
Corresponding config:
code:
highlight:
prismjs:
diffhighlight: falseTwo render modes compared (preprocess):
| Mode | Description | Trade-off |
|---|---|---|
preprocess: true | static highlight HTML generated at build | no JS dependency, SEO friendly; but only some prismjs plugins supported |
preprocess: false (current) | highlight generated by JS in the browser | all plugins supported (treeview/autolinker/diffhighlight); one extra JS execution on first paint |
2.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
code.highlight.prismjs.style | string | "default" | prismjs theme name or CSS link | Light theme |
code.highlight.prismjs.style_dark | string | "tomorrow night" | prismjs theme name or CSS link | Dark theme |
code.highlight.prismjs.preprocess | bool | false | true / false | Static generation at build |
code.highlight.prismjs.treeview | bool | true | true / false | treeview tree display |
code.highlight.prismjs.autolinker | bool | true | true / false | Links in code clickable |
code.highlight.prismjs.diffhighlight | bool | true | true / false | diff highlight |
2.4 Boundaries & conflicts
- Pick a style name at prismjs.com and fill it in (e.g.
"tomorrow night"), or paste a CSS link directly. style_darkapplies automatically in dark mode; no manual switching needed.preprocess: trueconflicts withtreeview/autolinker/diffhighlight: static generation supports only some plugins, so all three stop working.
2.5 Summary
- Minimal setup:
style+style_dark - Want the enhancement plugins: keep
preprocess: false - Want SEO / no JS:
preprocess: true, and accept that the enhancements stop working - Dark mode hard to read: tune
style_darkfirst
3. highlightjs Themes (backup engine)
Purpose: use the following config if you switch to
lib: "highlightjs".Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
3.1 How to enable
Effect: code blocks are colored by highlight.js — github gist for light, dark for dark.
Corresponding config (theme config, code.highlight.highlightjs section):
code:
highlight:
highlightjs:
style: "github gist" # light theme (pick at highlightjs.org/static/demo)
style_dark: "dark" # dark themeYou must also set
code.highlight.libto"highlightjs", otherwise this section has no effect.
3.2 Common options
① Change the light theme
Effect: the light-mode palette of code blocks changes.
Corresponding config:
code:
highlight:
highlightjs:
style: "atom-one-light"② Change the dark theme
Effect: the palette in dark mode changes.
Corresponding config:
code:
highlight:
highlightjs:
style_dark: "atom-one-dark"3.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
code.highlight.highlightjs.style | string | "github gist" | highlight.js theme name | Light theme |
code.highlight.highlightjs.style_dark | string | "dark" | highlight.js theme name | Dark theme |
3.4 Boundaries & conflicts
- This section only takes effect when
lib: "highlightjs"; with prismjs, changing it does nothing. - highlight.js has no equivalent of treeview/autolinker/diffhighlight.
3.5 Summary
- To switch: change
libfirst, then fill in the two styles - Where theme names come from: the demo page at highlightjs.org
- If you use prismjs, leave this section alone
4. Code Block Enhancements (code section)
Purpose: display and interaction behavior of code blocks: folding, wrapping, expand-all, fullscreen, copy button, language label.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
4.1 How to enable
Effect: a copy button and a fullscreen button appear at the top-right of code blocks; overly tall blocks collapse by default and show “expand all”; the language label appears at the top-left (TEXT when unspecified); long lines scroll horizontally instead of wrapping.
Corresponding config (theme config, code section):
code:
shrink: true # code block collapsible (fold)
break: false # wrap lines (false = long lines scroll horizontally)
show_full: true # show the whole code
height_limit: "450px" # show_full height threshold: "expand all" button above this
show_expand: true # fullscreen code box
copy_btn: true # copy code button
language:
enable: true # code block language label
default: "TEXT" # default label when no language given4.2 Common options
① Wrap long lines
Effect: overly long lines wrap automatically instead of scrolling horizontally (this breaks alignment).
Corresponding config:
code:
break: true② Adjust the “expand all” threshold
Effect: the smaller the threshold, the more code blocks get collapsed.
Corresponding config:
code:
height_limit: "300px"③ Turn off the copy button
Effect: code blocks no longer show the copy icon.
Corresponding config:
code:
copy_btn: false④ Change the default language label
Effect: code blocks without a language name show the new label.
Corresponding config:
code:
language:
default: "Code"Effect notes (item by item):
show_full: true+height_limit: overly tall code blocks collapse by default; click “expand all” to view — prevents long code from blowing up the pagebreak: false: long lines scroll horizontally instead of wrapping, preserving code formattingcopy_btn: true: copy button appears on hover, one-click copycode.language.default: code blocks with no language name show theTEXTlabel (can be changed to"Code"etc.)
4.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
code.shrink | bool | true | true / false | Code block collapsible |
code.break | bool | false | true / false | Whether long lines wrap |
code.show_full | bool | true | true / false | Collapse overly tall blocks |
code.height_limit | string | "450px" | Length with unit (e.g. "300px") | Expand button threshold |
code.show_expand | bool | true | true / false | Fullscreen button |
code.copy_btn | bool | true | true / false | Copy button |
code.language.enable | bool | true | true / false | Language label |
code.language.default | string | "TEXT" | any string | Label when no language given |
4.4 Boundaries & conflicts
height_limitmust be a string with a unit ("450px"); a bare number is ignored.- When
show_full: false,height_limitis meaningless — long code is fully expanded. - With both
break: trueand line numbers enabled, continuation lines of a wrapped line have no line number, which hurts readability.
4.5 Summary
- Minimal setup: keep the defaults
- Long code blowing up the page:
show_full+ a suitableheight_limit - Horizontal scrolling annoying on mobile:
break: true - Want a localized label:
language.default
5. Copy Copyright (code.copyright)
Purpose: when copied post content (including code) exceeds a character threshold, automatically append a copyright notice to the clipboard.
Learning path: How to enable → Common options → All tunable keys → Boundaries & conflicts
5.1 How to enable
Effect: after a reader copies more than 120 characters of body text/code, a line — “The copyright of this article belongs to the author. Please credit the source for any form of reproduction.” — is appended to the pasted content.
Corresponding config (theme config, code.copyright section):
code:
copyright:
enable: true
minCharNumber: 120 # minimum copied chars before appending the notice
description: The copyright of this article belongs to the author. Please credit the source for any form of reproduction.5.2 Common options
① Adjust the trigger threshold
Effect: with minCharNumber: 300, short copies get nothing appended; only long selections carry the notice.
Corresponding config:
code:
copyright:
minCharNumber: 300② Change the notice text
Effect: the copyright text produced on paste changes.
Corresponding config:
code:
copyright:
description: Please credit the source and keep the original link when reproducing.③ Turn off copy copyright
Effect: nothing is appended to copied content.
Corresponding config:
code:
copyright:
enable: false5.3 All tunable keys
| Key | Type | Default | Allowed values / range | Description |
|---|---|---|---|---|
code.copyright.enable | bool | true | true / false | Append copyright on copy |
code.copyright.minCharNumber | number | 120 | positive integer (characters) | Trigger threshold |
code.copyright.description | string | see above | any string | Appended copyright text |
5.4 Boundaries & conflicts
- This is copy-behavior copyright protection (distinct from the post-bottom copyright card
post.copyright): after readers copy body/code, the pasted content ends with an auto-appended source notice. - The threshold counts characters; copying a whole code block usually far exceeds 120.
- It is independent of
post.copyright; each can be toggled separately.
5.5 Summary
- Minimal setup:
enable: true - Find it annoying: raise
minCharNumber - Want different text: change only
description - It is not the same thing as the post copyright card
Appendix: Code Highlight Quick Reference
| Config item | Location | Description |
|---|---|---|
| Highlight engine | code.highlight.lib | prismjs (current) | highlightjs |
| Line numbers | code.highlight.line_number | true/false |
| prism themes | code.highlight.prismjs.style / style_dark | light/dark pair |
| Render mode | code.highlight.prismjs.preprocess | false = browser-generated (current) |
| prism extras | treeview / autolinker / diffhighlight | tree/link/diff highlight |
| Collapse/wrap | code.shrink / code.break | folding and long-line handling |
| Expand all | code.show_full + height_limit | collapse tall blocks + threshold |
| Fullscreen | code.show_expand | fullscreen code box |
| Copy button | code.copy_btn | hover to copy |
| Language label | code.language | default TEXT |
| Copy copyright | code.copyright | append copyright after 120+ chars |