Remove callback from Header renderer event Split Header into two events: BeginHeader and EndHeader, removing the need for callback.
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 26 Oct 2015 20:25:23 +0200
4 files changed,
19 insertions(+),
21 deletions(-)
M
block.go
→
block.go
@@ -245,10 +245,9 @@ if end > i {
if id == "" && p.flags&AutoHeaderIDs != 0 { id = sanitized_anchor_name.Create(string(data[i:end])) } - work := func() { - p.inline(out, data[i:end]) - } - p.r.Header(out, work, level, id) + tocMarker := p.r.BeginHeader(out, level, id) + p.inline(out, data[i:end]) + p.r.EndHeader(out, level, id, tocMarker) } return skip }@@ -1318,20 +1317,14 @@ for eol > prev && data[eol-1] == ' ' {
eol-- } - // render the header - // this ugly double closure avoids forcing variables onto the heap - work := func(o *bytes.Buffer, pp *parser, d []byte) func() { - return func() { - pp.inline(o, d) - } - }(out, p, data[prev:eol]) - id := "" if p.flags&AutoHeaderIDs != 0 { id = sanitized_anchor_name.Create(string(data[prev:eol])) } - p.r.Header(out, work, level, id) + tocMarker := p.r.BeginHeader(out, level, id) + p.inline(out, data[prev:eol]) + p.r.EndHeader(out, level, id, tocMarker) // find the end of the underline for data[i] != '\n' {
M
html.go
→
html.go
@@ -202,7 +202,7 @@ out.Write(text)
out.WriteString("\n</h1>") } -func (options *Html) Header(out *bytes.Buffer, text func(), level int, id string) { +func (options *Html) BeginHeader(out *bytes.Buffer, level int, id string) int { doubleSpace(out) if id == "" && options.flags&Toc != 0 {@@ -225,12 +225,13 @@ } else {
out.WriteString(fmt.Sprintf("<h%d>", level)) } - tocMarker := out.Len() - text() + return out.Len() +} +func (r *Html) EndHeader(out *bytes.Buffer, level int, id string, tocMarker int) { // are we building a table of contents? - if options.flags&Toc != 0 { - options.TocHeaderWithAnchor(out.Bytes()[tocMarker:], level, id) + if r.flags&Toc != 0 { + r.TocHeaderWithAnchor(out.Bytes()[tocMarker:], 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 (options *Latex) Header(out *bytes.Buffer, text func(), level int, id string) { +func (r *Latex) BeginHeader(out *bytes.Buffer, level int, id string) int { switch level { case 1: out.WriteString("\n\\section{")@@ -87,7 +87,10 @@ out.WriteString("\n\\subparagraph{")
case 6: out.WriteString("\n\\textbf{") } - text() + return out.Len() +} + +func (r *Latex) EndHeader(out *bytes.Buffer, level int, id string, tocMarker int) { out.WriteString("}\n") }
M
markdown.go
→
markdown.go
@@ -163,7 +163,8 @@ // block-level callbacks
BlockCode(out *bytes.Buffer, text []byte, lang string) BlockQuote(out *bytes.Buffer, text []byte) BlockHtml(out *bytes.Buffer, text []byte) - Header(out *bytes.Buffer, text func(), level int, id string) + BeginHeader(out *bytes.Buffer, level int, id string) int + EndHeader(out *bytes.Buffer, level int, id string, tocMarker int) HRule(out *bytes.Buffer) List(out *bytes.Buffer, text func(), flags ListType) ListItem(out *bytes.Buffer, text []byte, flags ListType)