This commit is contained in:
yuin 2021-10-17 17:29:01 +09:00
parent beafde4b8f
commit 05d89a0b45
2 changed files with 14 additions and 6 deletions

View file

@ -542,7 +542,6 @@ _a[b_c_](d)
<p>[o] :x</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
42: Unclosed link reference titles can interrupt link references
//- - - - - - - - -//
[r]:
@ -556,3 +555,10 @@ x
<p>'</p>
<p>'</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
43: A link containing an image containing a link should disable the outer link
//- - - - - - - - -//
[ ![ [b](c) ](x) ](y)
//- - - - - - - - -//
<p>[ <img src="x" alt=" b " /> ](y)</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//

View file

@ -140,7 +140,7 @@ func (s *linkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.N
}
block.Advance(1)
removeLinkLabelState(pc, last)
if s.containsLink(last) { // a link in a link text is not allowed
if !last.IsImage && s.containsLink(last) { // a link in a link text is not allowed
ast.MergeOrReplaceTextSegment(last.Parent(), last, last.Segment)
return nil
}
@ -182,15 +182,17 @@ func (s *linkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.N
return link
}
func (s *linkParser) containsLink(last *linkLabelState) bool {
if last.IsImage {
func (s *linkParser) containsLink(n ast.Node) bool {
if n == nil {
return false
}
var c ast.Node
for c = last; c != nil; c = c.NextSibling() {
for c := n; c != nil; c = c.NextSibling() {
if _, ok := c.(*ast.Link); ok {
return true
}
if s.containsLink(c.FirstChild()) {
return true
}
}
return false
}