From 20b76bdeadeca3860cd686d533c50fdd785672b0 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 13 Jan 2024 11:55:43 -0600 Subject: [PATCH] Fix issue when pattern matches a DD without DT ``` Test ::One ``` WOuld previously break the browser. --- shared/naturalcrit/markdown.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index f016218ba..935313d0f 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -243,17 +243,19 @@ const definitionLists = { let match; const endIndex = src.match(`\n\n`)?.index + 2; const allDefinitions = []; - let currentDefinition = []; + let currentDefinition = {}; while (match = regex.exec(src)) { if(match[1].trim()?.length) { if(currentDefinition?.dt?.length) { allDefinitions.push(currentDefinition); - currentDefinition = []; + currentDefinition = {}; } currentDefinition = { dt : this.lexer.inlineTokens(match[1].trim()), dd : [] }; + } else if(_.isEmpty(currentDefinition)) { + return; } currentDefinition.dd = currentDefinition.dd.concat(match[2].split('::').filter((item)=>item).map((s)=>this.lexer.inlineTokens(s.trim()))); if(!currentDefinition.dd?.length) { @@ -273,7 +275,7 @@ const definitionLists = { let returnVal = `
`; token.definitions.forEach((def)=>{ const dds = def.dd.map((s)=>`
${this.parser.parseInline(s)}
`).join('\n'); - returnVal += `
${this.parser.parseInline(def.dt)}
${dds}
`; + returnVal += `
${this.parser.parseInline(def.dt)}
\n${dds}\n`; }); return `${returnVal}
`; }