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.
1. Highlight Engine (highlight)
Purpose: choose the highlight library, control line numbers and the light/dark theme pair.
Config (theme config, code.highlight section):
code:
highlight:
enable: true # master switch
line_number: true # show line numbers
lib: "prismjs" # highlight library: highlightjs | prismjsNotes: lib decides which engine is used and activates the corresponding sub-config below. This blog uses prismjs.
2. prismjs Themes & Render Mode
Purpose: light/dark highlight theme pairs (following light/dark mode) and how highlighting is generated.
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)Two 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 |
Notes: pick a style at prismjs.com and fill in the name (e.g. "tomorrow night"), or a CSS link directly. style_dark applies automatically in dark mode.
3. highlightjs Themes (backup engine)
Purpose: the following config applies if you switch lib: "highlightjs".
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 theme4. Code Block Enhancements (code section)
Purpose: code block display and interaction: collapse, wrapping, expand-all, fullscreen, copy button, language label.
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 givenEffects:
show_full: true+height_limit: overly tall code blocks collapse by default, click “expand all” to view — prevents long code from breaking the pagebreak: false: long lines scroll horizontally instead of wrapping, preserving code formattingcopy_btn: true: copy button on hover, one-click copycode.language.default: blocks without a language show theTEXTlabel (change to"Code"etc.)
5. Copy Copyright (code.copyright)
Purpose: when copying post content (including code) beyond a character threshold, automatically append a copyright notice to the clipboard.
Config (theme config, code.copyright section):
code:
copyright:
enable: true
minCharNumber: 120 # minimum copied chars before appending the notice
description: This article's copyright belongs to the author. Any reproduction must credit the source.Notes: this is copy-behavior copyright protection (distinct from the bottom copyright card post.copyright): after readers copy body/code, the pasted content ends with an auto-appended source notice.
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 |