diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index a71879546d..08ee396636 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -418,6 +418,9 @@ export class _Tokenizer { if (lastItem) { lastItem.raw = lastItem.raw.trimEnd(); lastItem.text = lastItem.text.trimEnd(); + } else { + // not a list since there were no items + return; } list.raw = list.raw.trimEnd(); diff --git a/test/unit/marked.test.js b/test/unit/marked.test.js index 294bdf2930..40622968c6 100644 --- a/test/unit/marked.test.js +++ b/test/unit/marked.test.js @@ -127,6 +127,20 @@ describe('marked unit', () => { assert.strictEqual(html, '
Not Underlined A
\nUnderlined B\nNot Underlined C\n:Not Underlined D
\n'); }); + it('should not return list if no items', () => { + const noHr = { + tokenizer: { + hr() { + return undefined; + }, + }, + }; + marked.use(noHr); + const markdown = '- - -'; + const html = marked.parse(markdown); + assert.strictEqual(html, '- - -
\n'); + }); + it('should use custom inline tokenizer + renderer extensions', () => { const underline = { name: 'underline',