2021-01-21 18:56:00 +01:00
|
|
|
const { FIND_HBS_REGEX } = require("../utilities")
|
|
|
|
const preprocessor = require("./preprocessor")
|
|
|
|
const postprocessor = require("./postprocessor")
|
|
|
|
|
|
|
|
function process(string, processors) {
|
|
|
|
for (let processor of processors) {
|
|
|
|
// re-run search each time incase previous processor updated/removed a match
|
|
|
|
let regex = new RegExp(FIND_HBS_REGEX)
|
|
|
|
let matches = string.match(regex)
|
|
|
|
if (matches == null) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for (let match of matches) {
|
|
|
|
string = processor.process(string, match)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return string
|
|
|
|
}
|
|
|
|
|
2021-01-22 18:57:38 +01:00
|
|
|
module.exports.preprocess = (string, finalise = true) => {
|
|
|
|
let processors = preprocessor.processors
|
|
|
|
// the pre-processor finalisation stops handlebars from ever throwing an error
|
|
|
|
// might want to pre-process for other benefits but still want to see errors
|
|
|
|
if (!finalise) {
|
2021-01-22 18:58:01 +01:00
|
|
|
processors = processors.filter(
|
|
|
|
processor => processor.name !== preprocessor.PreprocessorNames.FINALISE
|
|
|
|
)
|
2021-01-22 18:57:38 +01:00
|
|
|
}
|
|
|
|
return process(string, processors)
|
2021-01-21 18:56:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.postprocess = string => {
|
|
|
|
return process(string, postprocessor.processors)
|
2021-01-21 18:56:22 +01:00
|
|
|
}
|