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.
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 04 Nov 2015 22:14:02 +0200
4 files changed,
17 insertions(+),
16 deletions(-)
M
block.go
→
block.go
@@ -245,9 +245,11 @@ if end > i {
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 @@ if p.flags&AutoHeaderIDs != 0 {
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' {
M
html.go
→
html.go
@@ -281,7 +281,7 @@ out.Write(text)
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 @@ out.WriteString(fmt.Sprintf("<h%d id=\"%s\">", level, id))
} 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))
M
latex.go
→
latex.go
@@ -72,7 +72,7 @@ out.Write(text)
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 @@ out.WriteString("\n\\subparagraph{")
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") }
M
markdown.go
→
markdown.go
@@ -163,8 +163,8 @@ // block-level callbacks
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)