From bc4735b84d3a4ea8d1b108621519c820a61599b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Mon, 26 Oct 2015 20:39:08 +0200 Subject: [PATCH] Remove callback from Footnotes renderer event Split Footnotes into two events: BeginFootnotes and EndFootnotes, removing the need for callback. --- html.go | 8 +++++--- latex.go | 5 ++++- markdown.go | 31 ++++++++++++++++--------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/html.go b/html.go index 2169353..0b375bf 100644 --- a/html.go +++ b/html.go @@ -342,12 +342,14 @@ func (options *Html) TableCell(out *bytes.Buffer, text []byte, align int) { out.WriteString("") } -func (options *Html) Footnotes(out *bytes.Buffer, text func()) { +func (options *Html) BeginFootnotes(out *bytes.Buffer) { out.WriteString("
\n") options.HRule(out) options.BeginList(out, ListTypeOrdered) - text() - options.EndList(out, ListTypeOrdered) +} + +func (r *Html) EndFootnotes(out *bytes.Buffer) { + r.EndList(out, ListTypeOrdered) out.WriteString("
\n") } diff --git a/latex.go b/latex.go index c3f10a9..7f92903 100644 --- a/latex.go +++ b/latex.go @@ -168,8 +168,11 @@ func (options *Latex) TableCell(out *bytes.Buffer, text []byte, align int) { } // TODO: this -func (options *Latex) Footnotes(out *bytes.Buffer, text func()) { +func (r *Latex) BeginFootnotes(out *bytes.Buffer) { +} +// TODO: this +func (r *Latex) EndFootnotes(out *bytes.Buffer) { } func (options *Latex) FootnoteItem(out *bytes.Buffer, name, text []byte, flags ListType) { diff --git a/markdown.go b/markdown.go index a4c03ab..caac06d 100644 --- a/markdown.go +++ b/markdown.go @@ -175,7 +175,8 @@ type Renderer interface { TableRow(out *bytes.Buffer, text []byte) TableHeaderCell(out *bytes.Buffer, text []byte, flags int) TableCell(out *bytes.Buffer, text []byte, flags int) - Footnotes(out *bytes.Buffer, text func()) + BeginFootnotes(out *bytes.Buffer) + EndFootnotes(out *bytes.Buffer) FootnoteItem(out *bytes.Buffer, name, text []byte, flags ListType) TitleBlock(out *bytes.Buffer, text []byte) @@ -456,21 +457,21 @@ func secondPass(p *parser, input []byte) []byte { p.block(&output, input) if p.flags&Footnotes != 0 && len(p.notes) > 0 { - p.r.Footnotes(&output, func() { - flags := ListItemBeginningOfList - for i := 0; i < len(p.notes); i += 1 { - ref := p.notes[i] - var buf bytes.Buffer - if ref.hasBlock { - flags |= ListItemContainsBlock - p.block(&buf, ref.title) - } else { - p.inline(&buf, ref.title) - } - p.r.FootnoteItem(&output, ref.link, buf.Bytes(), flags) - flags &^= ListItemBeginningOfList | ListItemContainsBlock + p.r.BeginFootnotes(&output) + flags := ListItemBeginningOfList + for i := 0; i < len(p.notes); i += 1 { + ref := p.notes[i] + var buf bytes.Buffer + if ref.hasBlock { + flags |= ListItemContainsBlock + p.block(&buf, ref.title) + } else { + p.inline(&buf, ref.title) } - }) + p.r.FootnoteItem(&output, ref.link, buf.Bytes(), flags) + flags &^= ListItemBeginningOfList | ListItemContainsBlock + } + p.r.EndFootnotes(&output) } p.r.DocumentFooter(&output)