mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
Remove callback from Footnotes renderer event
Split Footnotes into two events: BeginFootnotes and EndFootnotes, removing the need for callback.
This commit is contained in:
parent
6d6be3d2b2
commit
bc4735b84d
8
html.go
8
html.go
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
5
latex.go
5
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) {
|
||||
|
|
31
markdown.go
31
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user