all repos — grayfriday @ 6947216efb48973a448b15f18c97acab6e151004

blackfriday fork with a few changes

Move footnote rendering to the renderer

Clean up footnotes part of an AST: don't force HTML-specific pieces
there, just keep a clean list of footnotes. Since some renderers might
want to process footnotes differently, let them know about footnotes by
having a flag on that list.
Vytautas Ĺ altenis vytas@rtfb.lt
Sat, 03 Sep 2016 12:39:16 +0300
commit

6947216efb48973a448b15f18c97acab6e151004

parent

ea8dfc488069987834e0db3ef4443398b0bb4934

4 files changed, 25 insertions(+), 16 deletions(-)

jump to
M html.gohtml.go

@@ -589,10 +589,11 @@ if node.ListFlags&ListTypeDefinition != 0 {

tagName = "dl" } if entering { - // var start = node.listStart; - // if (start !== null && start !== 1) { - // attrs.push(['start', start.toString()]); - // } + if node.IsFootnotesList { + r.out(w, []byte("\n<div class=\"footnotes\">\n\n")) + r.out(w, tag("hr", attrs, r.Flags&UseXHTML != 0)) + r.cr(w) + } r.cr(w) if node.Parent.Type == Item && node.Parent.Parent.Tight { r.cr(w)

@@ -610,6 +611,9 @@ r.cr(w)

} if node.Parent.Type == Document || node.Parent.Type == BlockQuote { r.cr(w) + } + if node.IsFootnotesList { + r.out(w, []byte("\n</div>\n")) } } case Item:
M inline_test.goinline_test.go

@@ -922,6 +922,12 @@ </ol>

</div> `, + + `This text does not reference a footnote. + +[^footnote]: But it has a footnote! And it gets omitted. +`, + "<p>This text does not reference a footnote.</p>\n", } func TestFootnotes(t *testing.T) {
M markdown.gomarkdown.go

@@ -416,9 +416,8 @@ if p.flags&Footnotes == 0 || len(p.notes) == 0 {

return } p.tip = p.doc - finalizeHTMLBlock(p.addBlock(HTMLBlock, []byte(`<div class="footnotes">`))) - p.addBlock(HorizontalRule, nil) block := p.addBlock(List, nil) + block.IsFootnotesList = true block.ListFlags = ListTypeOrdered flags := ListItemBeginningOfList // Note: this loop is intentionally explicit, not range-form. This is

@@ -441,7 +440,6 @@ }

above := block.Parent finalizeList(block) p.tip = above - finalizeHTMLBlock(p.addBlock(HTMLBlock, []byte("</div>"))) block.Walk(func(node *Node, entering bool) WalkStatus { if node.Type == Paragraph || node.Type == Header { p.inline(node, node.content)
M node.gonode.go

@@ -69,20 +69,21 @@ func (t NodeType) String() string {

return nodeTypeNames[t] } -// ListData contains fields relevant to a List node type. +// ListData contains fields relevant to a List and Item node type. type ListData struct { - ListFlags ListType - Tight bool // Skip <p>s around list item data if true - BulletChar byte // '*', '+' or '-' in bullet lists - Delimiter byte // '.' or ')' after the number in ordered lists - RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering + ListFlags ListType + Tight bool // Skip <p>s around list item data if true + BulletChar byte // '*', '+' or '-' in bullet lists + Delimiter byte // '.' or ')' after the number in ordered lists + RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering + IsFootnotesList bool // This is a list of footnotes } // LinkData contains fields relevant to a Link node type. type LinkData struct { - Destination []byte - Title []byte - NoteID int + Destination []byte // Destination is what goes into a href + Title []byte // Title is the tooltip thing that goes in a title attribute + NoteID int // NoteID contains a serial number of a footnote, zero if it's not a footnote } // CodeBlockData contains fields relevant to a CodeBlock node type.