mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
Improve readability of the docs site with updated light/dark tokens, shared code-block styling, and playground editors that follow system color scheme. Skip CookieHub on localhost, serve the browser bundle from theme source, and use backtick titles on filter/tag reference pages for consistent navigation. Co-authored-by: Cursor <[email protected]>
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
'use strict'
|
|
|
|
/**
|
|
* Extend Prism's bash grammar with extra CLI commands for docs code blocks.
|
|
* 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.
|
|
*/
|
|
const EXTRA_BASH_COMMANDS = [
|
|
'npx'
|
|
]
|
|
|
|
const Prism = require('prismjs')
|
|
require('prismjs/components/prism-bash')
|
|
|
|
function extendBashCommandHighlighting (commands) {
|
|
const bash = Prism.languages.bash
|
|
if (!bash || !bash.function) return
|
|
|
|
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)
|