Merge pull request #206 from russross/issue-164 Fix footnote followed by a reference style link
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 19 Oct 2015 09:17:51 +0300
2 files changed,
26 insertions(+),
2 deletions(-)
M
inline.go
→
inline.go
@@ -191,6 +191,13 @@ linkDeferredFootnote
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 @@
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 @@ // find the reference with matching id
lr, ok := p.getRef(string(id)) if !ok { return 0 - } // keep link and title from reference
M
inline_test.go
→
inline_test.go
@@ -951,6 +951,24 @@ "<p>Some text.<sup class=\"footnote-ref\" id=\"fnref:note1\"><a rel=\"footnote\" href=\"#fn:note1\">1</a></sup></p>\n<div class=\"footnotes\">\n\n<hr />\n\n<ol>\n<li id=\"fn:note1\">fn1\n</li>\n</ol>\n</div>\n",
"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) {