docs: introduce JS script to escape for Hexo, fixes #480

This commit is contained in:
Harttle
2022-02-24 01:04:50 +08:00
parent dab8a29070
commit 2b0c5696bc
4 changed files with 24 additions and 10 deletions
+1 -5
View File
@@ -11,8 +11,6 @@ for file in $(find docs/source/api -name "*.md"); do
-e 's/\(\]([^_)]*\)\/_/\1\//g' \
-e 's/\(\]([^)]*\.\)md/\1html/g' \
-e 's/\](_/\](/g' \
-e 's/{%/{% raw %}{%{% endraw %}/g' \
-e 's/{{/{% raw %}{{{% endraw %}/g' \
-e '1 s/"/\"/g' \
-e '1 s/</\&lt;/g' \
-e '1 s/>/\&gt;/g' \
@@ -20,9 +18,7 @@ for file in $(find docs/source/api -name "*.md"); do
-e '1 s/^# \(.*\)/---\ntitle: "\1"\nauto: true\n---/' \
$file
target=${file/\/_/\/}
if [ "$file" != "$target" ]; then
mv $file $target
fi
cat $file | ./bin/escape-nunjucks.js > $target
done
cp -r docs/source/api docs/source/zh-cn/api
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env node
// In Hexo, content inside markdown code/code fences,
// will not go through nunjucks.
// So we're escaping special chars outside code only.
let backTick = 0
process.stdin.on('data', (buffer) => {
for (const c of buffer.toString()) {
if (c === '`') {
backTick++
}
const shouldEscape = '{%%}'.includes(c) && backTick % 2 === 0
if (shouldEscape) {
const code = c.charCodeAt(0).toString(16)
process.stdout.write(`&#x${code};`)
} else process.stdout.write(c)
}
})
+2 -2
View File
@@ -21,11 +21,11 @@ vendor-prefixes = webkit moz ms official
--color-default: #d1d2d4
--color-default-invert: #444
--color-gray: invert(#999)
--color-border: invert(#e3e3e3)
--color-border: #6a6a6a
--color-backgrond: #fff
--color-navy: hsl(210, 25%, 12%)
--color-news-bg: darken(hsl(210, 25%, 12%), 5%)
--color-navy-lighter: lighten(hsl(210, 25%, 12%), 10%)
--color-navy-lighter: lighten(hsl(210, 25%, 12%), 7%)
--color-content-bg: #1c1c1c
--color-link: #0e83cd
--color-link-hover: lighten(#0e83cd, 10%)
+3 -3
View File
@@ -8,14 +8,14 @@ import { InternalUndefinedVariableError } from '../util/error'
export class Context {
/**
* insert a Context-level empty scope,
* for tags like {% capture %} {% assign %} to operate
* for tags like `{% capture %}` `{% assign %}` to operate
*/
private scopes: Scope[] = [{}]
private registers = {}
/**
* user passed in scope
* {% increment %}, {% decrement %} changes this scope,
* whereas {% capture %}, {% assign %} only hide this scope
* `{% increment %}`, `{% decrement %}` changes this scope,
* whereas `{% capture %}`, `{% assign %}` only hide this scope
*/
public environments: Scope
/**