fix: fix list with no items looping forever (#3560)

* fix: fix list with no items looping forever

* add test
This commit is contained in:
Tony Brix 2024-12-14 19:19:01 -07:00 committed by GitHub
parent 10020d018d
commit e4198ed70d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -418,6 +418,9 @@ export class _Tokenizer {
if (lastItem) { if (lastItem) {
lastItem.raw = lastItem.raw.trimEnd(); lastItem.raw = lastItem.raw.trimEnd();
lastItem.text = lastItem.text.trimEnd(); lastItem.text = lastItem.text.trimEnd();
} else {
// not a list since there were no items
return;
} }
list.raw = list.raw.trimEnd(); list.raw = list.raw.trimEnd();

View File

@ -127,6 +127,20 @@ describe('marked unit', () => {
assert.strictEqual(html, '<p>Not Underlined A</p>\n<u>Underlined B</u>\n<p>Not Underlined C\n:Not Underlined D</p>\n'); assert.strictEqual(html, '<p>Not Underlined A</p>\n<u>Underlined B</u>\n<p>Not Underlined C\n:Not Underlined D</p>\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, '<p>- - -</p>\n');
});
it('should use custom inline tokenizer + renderer extensions', () => { it('should use custom inline tokenizer + renderer extensions', () => {
const underline = { const underline = {
name: 'underline', name: 'underline',