mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
19 lines
523 B
JavaScript
Executable File
19 lines
523 B
JavaScript
Executable File
#!/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)
|
|
}
|
|
})
|