all repos — grayfriday @ f21f06712134055e26c0f95aa39898fefc50f68e

blackfriday fork with a few changes

Merge pull request #215 from russross/issue-193

Fix nested footnotes
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 04 Nov 2015 21:37:52 +0200
commit

f21f06712134055e26c0f95aa39898fefc50f68e

parent

660c9fd283952bff5f651d5b598de779fc9e1bfc

2 files changed, 35 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

@@ -20,6 +20,7 @@ package blackfriday

import ( "bytes" + "fmt" "strings" "unicode/utf8" )

@@ -452,7 +453,8 @@

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 { + ref := p.notes[i] var buf bytes.Buffer if ref.hasBlock { flags |= LIST_ITEM_CONTAINS_BLOCK

@@ -513,6 +515,11 @@ title []byte

noteId int // 0 if not a footnote ref hasBlock bool text []byte +} + +func (r *reference) String() string { + return fmt.Sprintf("{link: %q, title: %q, text: %q, noteId: %d, hasBlock: %v}", + r.link, r.title, r.text, r.noteId, r.hasBlock) } // Check whether or not data starts with a reference link.