all repos — grayfriday @ 9e68ff937bf900f5da964350474414bc0951c69d

blackfriday fork with a few changes

Fix nested footnotes

This is both nasty and neat at the same time. All the code could handle
nested footnotes just fine, the only place that was not working was the
final loop that printed the list. The loop was in a range form, which
couldn't account for another footnote being inserted while processing
existing ones. Changing the loop to the iterative form solves that.

Closes #193.
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 02 Nov 2015 20:17:46 +0200
commit

9e68ff937bf900f5da964350474414bc0951c69d

parent

660c9fd283952bff5f651d5b598de779fc9e1bfc

2 files changed, 29 insertions(+), 1 deletions(-)

jump to
M inline_test.goinline_test.go

@@ -1000,6 +1000,33 @@

doTestsInlineParam(t, tests, Options{Extensions: EXTENSION_FOOTNOTES}, HTML_FOOTNOTE_RETURN_LINKS, params) } +func TestNestedFootnotes(t *testing.T) { + var tests = []string{ + `Paragraph.[^fn1] + +[^fn1]: + Asterisk[^fn2] + +[^fn2]: + Obelisk`, + `<p>Paragraph.<sup class="footnote-ref" id="fnref:fn1"><a rel="footnote" href="#fn:fn1">1</a></sup></p> +<div class="footnotes"> + +<hr /> + +<ol> +<li id="fn:fn1">Asterisk<sup class="footnote-ref" id="fnref:fn2"><a rel="footnote" href="#fn:fn2">2</a></sup> +</li> +<li id="fn:fn2">Obelisk +</li> +</ol> +</div> +`, + } + doTestsInlineParam(t, tests, Options{Extensions: EXTENSION_FOOTNOTES}, 0, + HtmlRendererParameters{}) +} + func TestInlineComments(t *testing.T) { var tests = []string{ "Hello <!-- there ->\n",
M markdown.gomarkdown.go

@@ -452,8 +452,9 @@

if p.flags&EXTENSION_FOOTNOTES != 0 && len(p.notes) > 0 { p.r.Footnotes(&output, func() bool { flags := LIST_ITEM_BEGINNING_OF_LIST - for _, ref := range p.notes { + for i := 0; i < len(p.notes); i += 1 { var buf bytes.Buffer + ref := p.notes[i] if ref.hasBlock { flags |= LIST_ITEM_CONTAINS_BLOCK p.block(&buf, ref.title)