mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
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:
@@ -2,6 +2,8 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
require('./prism-bash-extend')
|
||||
|
||||
const { resolve, basename } = require('path')
|
||||
const { readFileSync } = require('fs')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
@@ -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']
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user