Merge pull request #206 from russross/issue-164

Fix footnote followed by a reference style link
pull/212/head
Vytautas Šaltenis 2015-10-19 09:17:51 +03:00
commit 53982c119c
2 changed files with 26 additions and 2 deletions

View File

@ -191,6 +191,13 @@ const (
linkInlineFootnote
)
func isReferenceStyleLink(data []byte, pos int, t linkType) bool {
if t == linkDeferredFootnote {
return false
}
return pos < len(data)-1 && data[pos] == '[' && data[pos+1] != '^'
}
// '[': parse a link or an image or a footnote
func link(p *parser, out *bytes.Buffer, data []byte, offset int) int {
// no links allowed inside regular links, footnote, and deferred footnotes
@ -353,7 +360,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int {
i++
// reference style link
case i < len(data)-1 && data[i] == '[' && data[i+1] != '^':
case isReferenceStyleLink(data, i, t):
var id []byte
altContentConsidered := false
@ -395,7 +402,6 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int {
lr, ok := p.getRef(string(id))
if !ok {
return 0
}
// keep link and title from reference

View File

@ -951,6 +951,24 @@ what happens here
"Some text.[^note1][^note2]\n\n[^note1]: fn1\n[^note2]: fn2\n",
"<p>Some text.<sup class=\"footnote-ref\" id=\"fnref:note1\"><a rel=\"footnote\" href=\"#fn:note1\">1</a></sup><sup class=\"footnote-ref\" id=\"fnref:note2\"><a rel=\"footnote\" href=\"#fn:note2\">2</a></sup></p>\n<div class=\"footnotes\">\n\n<hr />\n\n<ol>\n<li id=\"fn:note1\">fn1\n</li>\n<li id=\"fn:note2\">fn2\n</li>\n</ol>\n</div>\n",
`Bla bla [^1] [WWW][w3]
[^1]: This is a footnote
[w3]: http://www.w3.org/
`,
`<p>Bla bla <sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup> <a href="http://www.w3.org/">WWW</a></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">This is a footnote
</li>
</ol>
</div>
`,
}
func TestFootnotes(t *testing.T) {