fix: keep duplicate link definitions in the tokens (#4132)

This commit is contained in:
Wahid Rizka Fathurrohman
2026-10-25 23:29:11 -06:00
committed by GitHub
parent 4b7b5b2d1e
commit 2784acce37
4 changed files with 41 additions and 5 deletions
+8 -5
View File
@@ -222,11 +222,14 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
lastToken.raw += (lastToken.raw.endsWith('\n') ? '' : '\n') + token.raw;
lastToken.text += '\n' + token.raw;
this.inlineQueue.at(-1)!.src = lastToken.text;
} else if (!this.tokens.links[token.tag]) {
this.tokens.links[token.tag] = {
href: token.href,
title: token.title,
};
} else {
// The first definition of a label wins, but a later one still consumes its text
if (!this.tokens.links[token.tag]) {
this.tokens.links[token.tag] = {
href: token.href,
title: token.title,
};
}
tokens.push(token);
}
continue;
+3
View File
@@ -0,0 +1,3 @@
<ul>
<li><a href="/a">foo</a></li>
</ul>
+5
View File
@@ -0,0 +1,5 @@
[foo]: /a
- [foo]: /b
[foo]: /c
[foo]
+25
View File
@@ -1642,6 +1642,31 @@ paragraph
],
});
});
it('duplicate label', () => {
expectTokens({
md: '[link]: https://example.com\n[link]: https://example.org',
links: {
link: { href: 'https://example.com', title: undefined },
},
tokens: [
{
type: 'def',
raw: '[link]: https://example.com\n',
tag: 'link',
href: 'https://example.com',
title: undefined,
},
{
type: 'def',
raw: '[link]: https://example.org',
tag: 'link',
href: 'https://example.org',
title: undefined,
},
],
});
});
});
describe('inline', () => {