mirror of
https://github.com/danog/blackfriday.git
synced 2024-11-26 20:14:43 +01:00
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.
This commit is contained in:
parent
660c9fd283
commit
9e68ff937b
@ -1000,6 +1000,33 @@ func TestFootnotesWithParameters(t *testing.T) {
|
||||
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",
|
||||
|
@ -452,8 +452,9 @@ func secondPass(p *parser, input []byte) []byte {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user