Remove callback from Footnotes renderer event

Split Footnotes into two events: BeginFootnotes and EndFootnotes,
removing the need for callback.
This commit is contained in:
Vytautas Šaltenis 2015-10-26 20:39:08 +02:00
parent 6d6be3d2b2
commit bc4735b84d
3 changed files with 25 additions and 19 deletions

View File

@ -342,12 +342,14 @@ func (options *Html) TableCell(out *bytes.Buffer, text []byte, align int) {
out.WriteString("</td>")
}
func (options *Html) Footnotes(out *bytes.Buffer, text func()) {
func (options *Html) BeginFootnotes(out *bytes.Buffer) {
out.WriteString("<div class=\"footnotes\">\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("</div>\n")
}

View File

@ -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) {

View File

@ -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)