docs: highlight npx in bash blocks and polish English copy

Use Prism insertBefore for CLI commands like npx, tighten tutorial and reference wording, and keep YAML titles free of backticks so sidebar and page headings stay correct.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-06-07 13:22:08 +08:00
co-authored by Cursor
parent f7250f4601
commit 5d1b63563a
126 changed files with 224 additions and 217 deletions
+18 -27
View File
@@ -5,7 +5,12 @@
* Hexo loads scripts from docs/scripts/ during init, before `hexo generate`
* highlights fenced code via syntax_highlighter: prismjs.
*
* To highlight another command, add its name to EXTRA_BASH_COMMANDS below.
* Bash highlights known commands via a large hard-coded regex (see prism-bash).
* insertBefore is the supported extension point when a command is not in that list.
* Add names to EXTRA_BASH_COMMANDS as needed.
*
* After editing this file, run `npx hexo clean` before generate/serve so
* Hexo re-highlights cached pages (db.json does not invalidate on script changes).
*/
const EXTRA_BASH_COMMANDS = [
'npx'
@@ -14,30 +19,16 @@ const EXTRA_BASH_COMMANDS = [
const Prism = require('prismjs')
require('prismjs/components/prism-bash')
function extendBashCommandHighlighting (commands) {
const bash = Prism.languages.bash
if (!bash || !bash.function) return
const escaped = EXTRA_BASH_COMMANDS.map((cmd) =>
cmd.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
)
const fnToken = bash.function
const pattern = fnToken.pattern
if (!(pattern instanceof RegExp)) return
const source = pattern.source
const listMatch = source.match(/\(\?:([^)]+)\)(?=\(\?\=)/)
if (!listMatch) return
const existing = listMatch[1]
const toAdd = commands.filter((cmd) => {
const re = new RegExp(`(?:^|\\|)${cmd.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:\\||$)`)
return !re.test(existing)
})
if (toAdd.length === 0) return
const extended = `${existing}|${toAdd.join('|')}`
fnToken.pattern = new RegExp(
source.replace(/\(\?:([^)]+)\)(?=\(\?\=)/, `(?:${extended})`),
pattern.flags
)
}
extendBashCommandHighlighting(EXTRA_BASH_COMMANDS)
Prism.languages.insertBefore('bash', 'function', {
'cli-command': {
pattern: new RegExp(
`(^|[\\s;|&]|[<>]\\()(?:${escaped.join('|')})(?=$|[)\\s;|&])`
),
lookbehind: true,
alias: ['builtin', 'class-name']
}
})