2021-01-18 18:40:19 +01:00
|
|
|
const Helper = require("./Helper")
|
|
|
|
const { SafeString } = require("handlebars")
|
|
|
|
|
2021-01-19 19:44:29 +01:00
|
|
|
const HTML_SWAPS = {
|
|
|
|
"<": "<",
|
|
|
|
">": ">",
|
|
|
|
}
|
|
|
|
|
2021-01-18 18:40:19 +01:00
|
|
|
const HELPERS = [
|
2021-01-19 19:44:29 +01:00
|
|
|
// external helpers
|
2021-01-18 18:40:19 +01:00
|
|
|
new Helper("object", value => {
|
|
|
|
return new SafeString(JSON.stringify(value))
|
|
|
|
}),
|
2021-01-19 19:44:29 +01:00
|
|
|
// this help is applied to all statements
|
|
|
|
new Helper("all", value => {
|
|
|
|
let text = unescape(value).replace(/&/g, '&');
|
|
|
|
if (text == null || typeof text !== "string") {
|
|
|
|
return text
|
|
|
|
}
|
|
|
|
return text.replace(/[<>]/g, tag => {
|
|
|
|
return HTML_SWAPS[tag] || tag
|
|
|
|
})
|
|
|
|
})
|
2021-01-18 18:40:19 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
module.exports.registerAll = handlebars => {
|
|
|
|
for (let helper of HELPERS) {
|
|
|
|
helper.register(handlebars)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.unregisterAll = handlebars => {
|
|
|
|
for (let helper of HELPERS) {
|
|
|
|
helper.unregister(handlebars)
|
|
|
|
}
|
|
|
|
}
|