mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: keep duplicate link definitions in the tokens (#4132)
This commit is contained in:
+8
-5
@@ -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;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<ul>
|
||||
<li><a href="/a">foo</a></li>
|
||||
</ul>
|
||||
@@ -0,0 +1,5 @@
|
||||
[foo]: /a
|
||||
|
||||
- [foo]: /b
|
||||
[foo]: /c
|
||||
[foo]
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user