Skip to content

Commit

Permalink
fix: fix list with no items looping forever (#3560)
Browse files Browse the repository at this point in the history
* fix: fix list with no items looping forever

* add test
  • Loading branch information
UziTech authored Dec 15, 2024
1 parent 10020d0 commit e4198ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
14 changes: 14 additions & 0 deletions test/unit/marked.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

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', () => {
const underline = {
name: 'underline',
Expand Down

0 comments on commit e4198ed

Please sign in to comment.