Fixed crash on no 'externalContext' in md files.

master
BurnyLlama 2021-08-08 19:00:30 +02:00
parent 7fa8f0b308
commit 4529f395fd
2 changed files with 7 additions and 3 deletions

View File

@ -1,6 +1,10 @@
export function parseExternalContext(externalContext) {
// Remove start and end tag
externalContext = externalContext.replace(/%%-\n|-%%\n/g, "")
// If there's no external context, return nothing.
if (!externalContext)
return {}
// Remove start and end tag ↓ Only care about the first "externalConext"
externalContext = externalContext[0].replace(/%%-\n|-%%\n/g, "")
let parsedContext = {}
externalContext.split("\n").forEach(line => {

View File

@ -24,7 +24,7 @@ export function mdRenderer(path) {
// Separate the actual markdown from potential 'externalContext'
const externalMarkdown = externalMarkdownFile.replace(/^%%-\n[\S\s]*-%%\n/, "").replace(/```\w*[\s\S]*?```/g, match => match.replace(/ /g, "•"))
const externalContext = externalMarkdownFile.match(/^%%-\n[\S\s]*-%%\n/)[0]
const externalContext = externalMarkdownFile.match(/^%%-\n[\S\s]*-%%\n/)
// Pre-render the template for analysis during context generation.
const prerenderedNjk = njk.renderString(njkFile, { externalMarkdown })