1
0
mirror of https://github.com/danog/blackfriday.git synced 2025-01-23 05:41:27 +01:00

Fix Begin/EndHeader to use the new 'out'-less interface

Remove the 'out' parameter. Also, instead of returning and passing the
position of TOC, use CopyWrites to capture contents of the header and
pass that captured buffer instead.
This commit is contained in:
Vytautas Šaltenis 2015-11-04 22:14:02 +02:00
parent dce6df90b9
commit 08233481ed
4 changed files with 17 additions and 16 deletions

View File

@ -245,9 +245,11 @@ func (p *parser) prefixHeader(data []byte) int {
if id == "" && p.flags&AutoHeaderIDs != 0 {
id = sanitized_anchor_name.Create(string(data[i:end]))
}
tocMarker := p.r.BeginHeader(out, level, id)
p.inline(out, data[i:end])
p.r.EndHeader(out, level, id, tocMarker)
p.r.BeginHeader(level, id)
header := p.r.CopyWrites(func() {
p.inline(data[i:end])
})
p.r.EndHeader(level, id, header)
}
return skip
}
@ -1320,9 +1322,11 @@ func (p *parser) paragraph(data []byte) int {
id = sanitized_anchor_name.Create(string(data[prev:eol]))
}
tocMarker := p.r.BeginHeader(out, level, id)
p.inline(out, data[prev:eol])
p.r.EndHeader(out, level, id, tocMarker)
p.r.BeginHeader(level, id)
header := p.r.CopyWrites(func() {
p.inline(data[prev:eol])
})
p.r.EndHeader(level, id, header)
// find the end of the underline
for data[i] != '\n' {

View File

@ -281,7 +281,7 @@ func (r *Html) TitleBlock(text []byte) {
out.WriteString("\n</h1>")
}
func (r *Html) BeginHeader(level int, id string) int {
func (r *Html) BeginHeader(level int, id string) {
doubleSpace(out)
if id == "" && r.flags&Toc != 0 {
@ -303,14 +303,12 @@ func (r *Html) BeginHeader(level int, id string) int {
} else {
out.WriteString(fmt.Sprintf("<h%d>", level))
}
return out.Len()
}
func (r *Html) EndHeader(level int, id string, tocMarker int) {
func (r *Html) EndHeader(level int, id string, header []byte) {
// are we building a table of contents?
if r.flags&Toc != 0 {
r.TocHeaderWithAnchor(out.Bytes()[tocMarker:], level, id)
r.TocHeaderWithAnchor(header, level, id)
}
out.WriteString(fmt.Sprintf("</h%d>\n", level))

View File

@ -72,7 +72,7 @@ func (r *Latex) BlockHtml(text []byte) {
out.WriteString("\n\\end{verbatim}\n")
}
func (r *Latex) BeginHeader(level int, id string) int {
func (r *Latex) BeginHeader(level int, id string) {
switch level {
case 1:
out.WriteString("\n\\section{")
@ -87,10 +87,9 @@ func (r *Latex) BeginHeader(level int, id string) int {
case 6:
out.WriteString("\n\\textbf{")
}
return out.Len()
}
func (r *Latex) EndHeader(level int, id string, tocMarker int) {
func (r *Latex) EndHeader(level int, id string, header []byte) {
out.WriteString("}\n")
}

View File

@ -163,8 +163,8 @@ type Renderer interface {
BlockCode(text []byte, lang string)
BlockQuote(text []byte)
BlockHtml(text []byte)
BeginHeader(level int, id string) int
EndHeader(level int, id string, tocMarker int)
BeginHeader(level int, id string)
EndHeader(level int, id string, header []byte)
HRule()
BeginList(flags ListType)
EndList(flags ListType)