mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: preserve enclosing link state after parsing images (#4123)
* fix: preserve enclosing link state after parsing images * test: move image link regression cases to spec fixtures * test: use standard HTML differ for image link regression
This commit is contained in:
+3
-2
@@ -19,14 +19,15 @@ function outputLink(cap: string[], link: Pick<Tokens.Link, 'href' | 'title'>, ra
|
||||
const text = cap[1].replace(rules.other.outputLinkReplace, '$1');
|
||||
const isImage = cap[0].charAt(0) === '!';
|
||||
|
||||
lexer.state.inLink = true;
|
||||
const outerInLink = lexer.state.inLink;
|
||||
const outerLinkEmitted = lexer.state.linkEmitted;
|
||||
const outerInRawBlock = lexer.state.inRawBlock;
|
||||
lexer.state.inLink = true;
|
||||
lexer.state.linkEmitted = false;
|
||||
const tokens = lexer.inlineTokens(text);
|
||||
const textHasLink = lexer.state.linkEmitted;
|
||||
lexer.state.linkEmitted = outerLinkEmitted;
|
||||
lexer.state.inLink = false;
|
||||
lexer.state.inLink = outerInLink;
|
||||
|
||||
if (!isImage) {
|
||||
// CommonMark: "Links may not contain other links, at any level of nesting."
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<p><a href="https://target.example"><img src="logo.png" alt="logo"> www.example.com</a></p>
|
||||
<p><a href="https://target.example"><img src="logo.png" alt="logo"> https://example.com</a></p>
|
||||
<p><a href="https://target.example"><img src="logo.png" alt="logo"> user@example.com</a></p>
|
||||
<p><a href="https://target.example"><img src="logo.png" alt="logo"> www.example.com</a></p>
|
||||
<p><a href="https://target.example"><img src="outer.png" alt="logo"> www.example.com</a></p>
|
||||
<p><a href="https://target.example"><img src="logo.png" alt="logo"></a> <a href="http://www.example.com">www.example.com</a></p>
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
gfm: true
|
||||
---
|
||||
[ www.example.com](https://target.example)
|
||||
|
||||
[ https://example.com](https://target.example)
|
||||
|
||||
[ user@example.com](https://target.example)
|
||||
|
||||
[![logo][image] www.example.com][target]
|
||||
|
||||
[](outer.png) www.example.com](https://target.example)
|
||||
|
||||
[](https://target.example) www.example.com
|
||||
|
||||
[image]: logo.png
|
||||
[target]: https://target.example
|
||||
Reference in New Issue
Block a user