mirror of
https://github.com/danog/blackfriday.git
synced 2024-11-30 04:29:13 +01:00
Remove callback from List renderer event
Split List into two events: BeginList and EndList, removing the need for callback.
This commit is contained in:
parent
82be6cab6d
commit
af1b26fa04
17
block.go
17
block.go
@ -1050,19 +1050,18 @@ func (p *parser) dliPrefix(data []byte) int {
|
|||||||
func (p *parser) list(out *bytes.Buffer, data []byte, flags ListType) int {
|
func (p *parser) list(out *bytes.Buffer, data []byte, flags ListType) int {
|
||||||
i := 0
|
i := 0
|
||||||
flags |= ListItemBeginningOfList
|
flags |= ListItemBeginningOfList
|
||||||
work := func() {
|
p.r.BeginList(out, flags)
|
||||||
for i < len(data) {
|
|
||||||
skip := p.listItem(out, data[i:], &flags)
|
|
||||||
i += skip
|
|
||||||
|
|
||||||
if skip == 0 || flags&ListItemEndOfList != 0 {
|
for i < len(data) {
|
||||||
break
|
skip := p.listItem(out, data[i:], &flags)
|
||||||
}
|
i += skip
|
||||||
flags &= ^ListItemBeginningOfList
|
if skip == 0 || flags&ListItemEndOfList != 0 {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
flags &= ^ListItemBeginningOfList
|
||||||
}
|
}
|
||||||
|
|
||||||
p.r.List(out, work, flags)
|
p.r.EndList(out, flags)
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
html.go
10
html.go
@ -345,7 +345,9 @@ func (options *Html) TableCell(out *bytes.Buffer, text []byte, align int) {
|
|||||||
func (options *Html) Footnotes(out *bytes.Buffer, text func()) {
|
func (options *Html) Footnotes(out *bytes.Buffer, text func()) {
|
||||||
out.WriteString("<div class=\"footnotes\">\n")
|
out.WriteString("<div class=\"footnotes\">\n")
|
||||||
options.HRule(out)
|
options.HRule(out)
|
||||||
options.List(out, text, ListTypeOrdered)
|
options.BeginList(out, ListTypeOrdered)
|
||||||
|
text()
|
||||||
|
options.EndList(out, ListTypeOrdered)
|
||||||
out.WriteString("</div>\n")
|
out.WriteString("</div>\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,7 +374,7 @@ func (options *Html) FootnoteItem(out *bytes.Buffer, name, text []byte, flags Li
|
|||||||
out.WriteString("</li>\n")
|
out.WriteString("</li>\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (options *Html) List(out *bytes.Buffer, text func(), flags ListType) {
|
func (options *Html) BeginList(out *bytes.Buffer, flags ListType) {
|
||||||
doubleSpace(out)
|
doubleSpace(out)
|
||||||
|
|
||||||
if flags&ListTypeDefinition != 0 {
|
if flags&ListTypeDefinition != 0 {
|
||||||
@ -382,7 +384,9 @@ func (options *Html) List(out *bytes.Buffer, text func(), flags ListType) {
|
|||||||
} else {
|
} else {
|
||||||
out.WriteString("<ul>")
|
out.WriteString("<ul>")
|
||||||
}
|
}
|
||||||
text()
|
}
|
||||||
|
|
||||||
|
func (r *Html) EndList(out *bytes.Buffer, flags ListType) {
|
||||||
if flags&ListTypeDefinition != 0 {
|
if flags&ListTypeDefinition != 0 {
|
||||||
out.WriteString("</dl>\n")
|
out.WriteString("</dl>\n")
|
||||||
} else if flags&ListTypeOrdered != 0 {
|
} else if flags&ListTypeOrdered != 0 {
|
||||||
|
6
latex.go
6
latex.go
@ -98,13 +98,15 @@ func (options *Latex) HRule(out *bytes.Buffer) {
|
|||||||
out.WriteString("\n\\HRule\n")
|
out.WriteString("\n\\HRule\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (options *Latex) List(out *bytes.Buffer, text func(), flags ListType) {
|
func (r *Latex) BeginList(out *bytes.Buffer, flags ListType) {
|
||||||
if flags&ListTypeOrdered != 0 {
|
if flags&ListTypeOrdered != 0 {
|
||||||
out.WriteString("\n\\begin{enumerate}\n")
|
out.WriteString("\n\\begin{enumerate}\n")
|
||||||
} else {
|
} else {
|
||||||
out.WriteString("\n\\begin{itemize}\n")
|
out.WriteString("\n\\begin{itemize}\n")
|
||||||
}
|
}
|
||||||
text()
|
}
|
||||||
|
|
||||||
|
func (r *Latex) EndList(out *bytes.Buffer, flags ListType) {
|
||||||
if flags&ListTypeOrdered != 0 {
|
if flags&ListTypeOrdered != 0 {
|
||||||
out.WriteString("\n\\end{enumerate}\n")
|
out.WriteString("\n\\end{enumerate}\n")
|
||||||
} else {
|
} else {
|
||||||
|
@ -166,7 +166,8 @@ type Renderer interface {
|
|||||||
BeginHeader(out *bytes.Buffer, level int, id string) int
|
BeginHeader(out *bytes.Buffer, level int, id string) int
|
||||||
EndHeader(out *bytes.Buffer, level int, id string, tocMarker int)
|
EndHeader(out *bytes.Buffer, level int, id string, tocMarker int)
|
||||||
HRule(out *bytes.Buffer)
|
HRule(out *bytes.Buffer)
|
||||||
List(out *bytes.Buffer, text func(), flags ListType)
|
BeginList(out *bytes.Buffer, flags ListType)
|
||||||
|
EndList(out *bytes.Buffer, flags ListType)
|
||||||
ListItem(out *bytes.Buffer, text []byte, flags ListType)
|
ListItem(out *bytes.Buffer, text []byte, flags ListType)
|
||||||
Paragraph(out *bytes.Buffer, text func())
|
Paragraph(out *bytes.Buffer, text func())
|
||||||
Table(out *bytes.Buffer, header []byte, body []byte, columnData []int)
|
Table(out *bytes.Buffer, header []byte, body []byte, columnData []int)
|
||||||
|
Loading…
Reference in New Issue
Block a user