function findDefaultMerges(content, mergeFields) {
const startPattern = '\\{\\{\\s*'
const endPattern = '\\s*\\|\\s*([^\}\{\|]+)\\s*\\}\\}'
const defaultValues = mergeFields.reduce((acc, key) => {
const fallbackFinder = new RegExp(startPattern + '(' + key + ')' + endPattern)
const matches = fallbackFinder.exec(sampleText);
if (matches && matches.length >= 3) {
acc[key] = matches[2].trim()
content = content.replace(fallbackFinder, `\{\{ ${key} \}\}`)
}
return acc
}, {})
return {
defaultValues,
content
}
}