Skip to content

Commit

Permalink
Fixes #94
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Jan 27, 2020
1 parent faaafa5 commit 39db45a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
13 changes: 13 additions & 0 deletions _test/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,16 @@ _**TL/DR** - [Go see summary.](#my-summary-area)_
//- - - - - - - - -//
<p><em><strong>TL/DR</strong> - <a href="#my-summary-area">Go see summary.</a></em></p>
//= = = = = = = = = = = = = = = = = = = = = = = =//



6
//- - - - - - - - -//
[This link won't be rendered
correctly](https://geeksocket.in/some-long-link-here "This is the
place where everything breaks")
//- - - - - - - - -//
<p><a href="https://geeksocket.in/some-long-link-here" title="This is the
place where everything breaks">This link won't be rendered
correctly</a></p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
31 changes: 24 additions & 7 deletions parser/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,31 @@ func parseLinkTitle(block text.Reader) ([]byte, bool) {
if opener == '(' {
closer = ')'
}
line, _ := block.PeekLine()
pos := util.FindClosure(line[1:], opener, closer, false, true)
if pos < 0 {
return nil, false
savedLine, savedPosition := block.Position()
var title []byte
for i := 0; ; i++ {
line, _ := block.PeekLine()
if line == nil {
block.SetPosition(savedLine, savedPosition)
return nil, false
}
offset := 0
if i == 0 {
offset = 1
}
pos := util.FindClosure(line[offset:], opener, closer, false, true)
if pos < 0 {
title = append(title, line[offset:]...)
block.AdvanceLine()
continue
}
pos += offset + 1 // 1: closer
block.Advance(pos)
if i == 0 { // avoid allocating new slice
return line[offset : pos-1], true
}
return append(title, line[offset:pos-1]...), true
}
pos += 2 // opener + closer
block.Advance(pos)
return line[1 : pos-1], true
}

func (s *linkParser) CloseBlock(parent ast.Node, block text.Reader, pc Context) {
Expand Down

0 comments on commit 39db45a

Please sign in to comment.