diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 935313d0f..b434e62b0 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -257,9 +257,12 @@ const definitionLists = { } 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) { - currentDefinition.dd = [this.lexer.inlineTokens('')]; + const newDefinitions = match[2].split('::').filter((item)=>item).map((s)=>this.lexer.inlineTokens(s.trim())); + console.log(newDefinitions); + if(newDefinitions?.length) { + currentDefinition.dd.push(newDefinitions); + } else { + currentDefinition.dd.push([this.lexer.inlineTokens('')]); } } if(currentDefinition.hasOwnProperty('dt')) { allDefinitions.push(currentDefinition); } @@ -274,8 +277,10 @@ const definitionLists = { renderer(token) { let returnVal = `
`; token.definitions.forEach((def)=>{ - const dds = def.dd.map((s)=>`
${this.parser.parseInline(s)}
`).join('\n'); - returnVal += `
${this.parser.parseInline(def.dt)}
\n${dds}\n`; + const dds = def.dd.map((ddef)=>{ + return ddef.map((s)=>`
${this.parser.parseInline(s)}
`).join(''); + }).join('\n'); + returnVal += `
${this.parser.parseInline(def.dt)}
${dds.indexOf('\n') > -1 ? '\n' : ''}${dds}\n`; }); return `${returnVal}
`; } diff --git a/tests/markdown/marked-extensions.test.js b/tests/markdown/marked-extensions.test.js index 003934d63..d4446de68 100644 --- a/tests/markdown/marked-extensions.test.js +++ b/tests/markdown/marked-extensions.test.js @@ -6,25 +6,24 @@ describe('Dictionary Terms', ()=>{ test('Single Definition', function() { const source = 'My term :: My First Definition\n\n'; const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
My term
\n
My First Definition
\n
'); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
My term
My First Definition
\n
'); }); test('Two Definitions', function() { const source = 'My term :: My First Definition :: My Second Definition\n\n'; const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
My term
\n
My First Definition
\n
My Second Definition
\n
'); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
My term
My First Definition
My Second Definition
\n
'); }); test('Three Definitions', function() { const source = 'My term :: My First Definition :: My Second Definition :: My Third Definition\n\n'; const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
My term
\n
My First Definition
\n
My Second Definition
\n
My Third Definition
\n
'); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
My term
My First Definition
My Second Definition
My Third Definition
\n
'); }); - test('Multiline Definitions', function() { - const source = '**Example** :: V3 uses HTML *definition lists* to create "lists" with hanging indents.\n::Three\n::Four\n\nHello::I\'m a different\n::List\n\n'; + test('Multiple Definition Terms, multiple mixed-line definitions', function() { + const source = 'Term 1::Definition 1 of Term 1\n::Definition 2 of Term 1::Definition 3 of Term 1\nTerm 2::Definition of Term 2'; const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Example
\n
V3 uses HTML definition lists to create “lists” with hanging indents.
\n
Three
\n
Four
\n
Hello
\n
I\’m a different
\n
List
\n
'); }); });