Fixed crash on no 'externalContext' in md files.
This commit is contained in:
parent
7fa8f0b308
commit
4529f395fd
|
@ -1,6 +1,10 @@
|
||||||
export function parseExternalContext(externalContext) {
|
export function parseExternalContext(externalContext) {
|
||||||
// Remove start and end tag
|
// If there's no external context, return nothing.
|
||||||
externalContext = externalContext.replace(/%%-\n|-%%\n/g, "")
|
if (!externalContext)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
// Remove start and end tag ↓ Only care about the first "externalConext"
|
||||||
|
externalContext = externalContext[0].replace(/%%-\n|-%%\n/g, "")
|
||||||
|
|
||||||
let parsedContext = {}
|
let parsedContext = {}
|
||||||
externalContext.split("\n").forEach(line => {
|
externalContext.split("\n").forEach(line => {
|
||||||
|
|
|
@ -24,7 +24,7 @@ export function mdRenderer(path) {
|
||||||
|
|
||||||
// Separate the actual markdown from potential 'externalContext'
|
// 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 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.
|
// Pre-render the template for analysis during context generation.
|
||||||
const prerenderedNjk = njk.renderString(njkFile, { externalMarkdown })
|
const prerenderedNjk = njk.renderString(njkFile, { externalMarkdown })
|
||||||
|
|
Loading…
Reference in New Issue
Block a user