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:
parent
dce6df90b9
commit
08233481ed
16
block.go
16
block.go
@ -245,9 +245,11 @@ func (p *parser) prefixHeader(data []byte) int {
|
|||||||
if id == "" && p.flags&AutoHeaderIDs != 0 {
|
if id == "" && p.flags&AutoHeaderIDs != 0 {
|
||||||
id = sanitized_anchor_name.Create(string(data[i:end]))
|
id = sanitized_anchor_name.Create(string(data[i:end]))
|
||||||
}
|
}
|
||||||
tocMarker := p.r.BeginHeader(out, level, id)
|
p.r.BeginHeader(level, id)
|
||||||
p.inline(out, data[i:end])
|
header := p.r.CopyWrites(func() {
|
||||||
p.r.EndHeader(out, level, id, tocMarker)
|
p.inline(data[i:end])
|
||||||
|
})
|
||||||
|
p.r.EndHeader(level, id, header)
|
||||||
}
|
}
|
||||||
return skip
|
return skip
|
||||||
}
|
}
|
||||||
@ -1320,9 +1322,11 @@ func (p *parser) paragraph(data []byte) int {
|
|||||||
id = sanitized_anchor_name.Create(string(data[prev:eol]))
|
id = sanitized_anchor_name.Create(string(data[prev:eol]))
|
||||||
}
|
}
|
||||||
|
|
||||||
tocMarker := p.r.BeginHeader(out, level, id)
|
p.r.BeginHeader(level, id)
|
||||||
p.inline(out, data[prev:eol])
|
header := p.r.CopyWrites(func() {
|
||||||
p.r.EndHeader(out, level, id, tocMarker)
|
p.inline(data[prev:eol])
|
||||||
|
})
|
||||||
|
p.r.EndHeader(level, id, header)
|
||||||
|
|
||||||
// find the end of the underline
|
// find the end of the underline
|
||||||
for data[i] != '\n' {
|
for data[i] != '\n' {
|
||||||
|
8
html.go
8
html.go
@ -281,7 +281,7 @@ func (r *Html) TitleBlock(text []byte) {
|
|||||||
out.WriteString("\n</h1>")
|
out.WriteString("\n</h1>")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Html) BeginHeader(level int, id string) int {
|
func (r *Html) BeginHeader(level int, id string) {
|
||||||
doubleSpace(out)
|
doubleSpace(out)
|
||||||
|
|
||||||
if id == "" && r.flags&Toc != 0 {
|
if id == "" && r.flags&Toc != 0 {
|
||||||
@ -303,14 +303,12 @@ func (r *Html) BeginHeader(level int, id string) int {
|
|||||||
} else {
|
} else {
|
||||||
out.WriteString(fmt.Sprintf("<h%d>", level))
|
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?
|
// are we building a table of contents?
|
||||||
if r.flags&Toc != 0 {
|
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))
|
out.WriteString(fmt.Sprintf("</h%d>\n", level))
|
||||||
|
5
latex.go
5
latex.go
@ -72,7 +72,7 @@ func (r *Latex) BlockHtml(text []byte) {
|
|||||||
out.WriteString("\n\\end{verbatim}\n")
|
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 {
|
switch level {
|
||||||
case 1:
|
case 1:
|
||||||
out.WriteString("\n\\section{")
|
out.WriteString("\n\\section{")
|
||||||
@ -87,10 +87,9 @@ func (r *Latex) BeginHeader(level int, id string) int {
|
|||||||
case 6:
|
case 6:
|
||||||
out.WriteString("\n\\textbf{")
|
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")
|
out.WriteString("}\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,8 +163,8 @@ type Renderer interface {
|
|||||||
BlockCode(text []byte, lang string)
|
BlockCode(text []byte, lang string)
|
||||||
BlockQuote(text []byte)
|
BlockQuote(text []byte)
|
||||||
BlockHtml(text []byte)
|
BlockHtml(text []byte)
|
||||||
BeginHeader(level int, id string) int
|
BeginHeader(level int, id string)
|
||||||
EndHeader(level int, id string, tocMarker int)
|
EndHeader(level int, id string, header []byte)
|
||||||
HRule()
|
HRule()
|
||||||
BeginList(flags ListType)
|
BeginList(flags ListType)
|
||||||
EndList(flags ListType)
|
EndList(flags ListType)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user