all repos — grayfriday @ dc7d4b68df04979f26d3303fa0fd2a33a2d14774

blackfriday fork with a few changes

Remove some cruft
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 30 Mar 2016 15:56:53 +0300
commit

dc7d4b68df04979f26d3303fa0fd2a33a2d14774

parent

0382dab0c3c3c134189b497f808f4a72530c86be

3 files changed, 7 insertions(+), 100 deletions(-)

jump to
M html.gohtml.go

@@ -132,83 +132,29 @@ return HtmlRendererWithParameters(flags, title, css, HtmlRendererParameters{})

} type HtmlWriter struct { - output bytes.Buffer - captureBuff *bytes.Buffer - copyBuff *bytes.Buffer - dirty bool + output bytes.Buffer } func (w *HtmlWriter) Write(p []byte) (n int, err error) { - w.dirty = true - if w.copyBuff != nil { - w.copyBuff.Write(p) - } - if w.captureBuff != nil { - w.captureBuff.Write(p) - return - } return w.output.Write(p) } func (w *HtmlWriter) WriteString(s string) (n int, err error) { - w.dirty = true - if w.copyBuff != nil { - w.copyBuff.WriteString(s) - } - if w.captureBuff != nil { - w.captureBuff.WriteString(s) - return - } return w.output.WriteString(s) } func (w *HtmlWriter) WriteByte(b byte) error { - w.dirty = true - if w.copyBuff != nil { - w.copyBuff.WriteByte(b) - } - if w.captureBuff != nil { - return w.captureBuff.WriteByte(b) - } return w.output.WriteByte(b) } // Writes out a newline if the output is not pristine. Used at the beginning of // every rendering func func (w *HtmlWriter) Newline() { - if w.dirty { - w.WriteByte('\n') - } -} - -func (r *Html) CaptureWrites(processor func()) []byte { - var output bytes.Buffer - // preserve old captureBuff state for possible nested captures: - tmp := r.w.captureBuff - tmpd := r.w.dirty - r.w.captureBuff = &output - r.w.dirty = false - processor() - // restore: - r.w.captureBuff = tmp - r.w.dirty = tmpd - return output.Bytes() -} - -func (r *Html) CopyWrites(processor func()) []byte { - var output bytes.Buffer - r.w.copyBuff = &output - processor() - r.w.copyBuff = nil - return output.Bytes() + w.WriteByte('\n') } func (r *Html) Write(b []byte) (int, error) { return r.w.Write(b) -} - -func (r *Html) GetResult() []byte { - return r.w.output.Bytes() } func HtmlRendererWithParameters(flags HtmlFlags, title string,

@@ -780,9 +726,7 @@ func (r *Html) Smartypants(text []byte) {

smrt := smartypantsData{false, false} // first do normal entity escaping - text = r.CaptureWrites(func() { - r.attrEscape(text) - }) + r.attrEscape(text) mark := 0 for i := 0; i < len(text); i++ {
M latex.golatex.go

@@ -38,34 +38,8 @@ w: writer,

} } -func (r *Latex) CaptureWrites(processor func()) []byte { - var output bytes.Buffer - // preserve old captureBuff state for possible nested captures: - tmp := r.w.captureBuff - tmpd := r.w.dirty - r.w.captureBuff = &output - r.w.dirty = false - processor() - // restore: - r.w.captureBuff = tmp - r.w.dirty = tmpd - return output.Bytes() -} - -func (r *Latex) CopyWrites(processor func()) []byte { - var output bytes.Buffer - r.w.copyBuff = &output - processor() - r.w.copyBuff = nil - return output.Bytes() -} - func (r *Latex) Write(b []byte) (int, error) { return r.w.Write(b) -} - -func (r *Latex) GetResult() []byte { - return r.w.output.Bytes() } func (r *Latex) GetFlags() HtmlFlags {

@@ -180,9 +154,7 @@ r.w.WriteString("\n\\end{tabular}\n")

} func (r *Latex) TableRow(text []byte) { - if r.w.dirty { - r.w.WriteString(" \\\\\n") - } + r.w.WriteString(" \\\\\n") r.w.Write(text) }
M markdown.gomarkdown.go

@@ -202,10 +202,7 @@ DocumentHeader()

DocumentFooter() GetFlags() HtmlFlags - CaptureWrites(processor func()) []byte - CopyWrites(processor func()) []byte Write(b []byte) (int, error) - GetResult() []byte Render(ast *Node) []byte }

@@ -568,7 +565,7 @@ return out.Bytes()

} // second pass: actual rendering -func secondPass(p *parser, input []byte) []byte { +func secondPass(p *parser, input []byte) { p.r.DocumentHeader() p.block(input)

@@ -580,13 +577,9 @@ ref := p.notes[i]

var buf bytes.Buffer if ref.hasBlock { flags |= ListItemContainsBlock - buf.Write(p.r.CaptureWrites(func() { - p.block(ref.title) - })) + p.block(ref.title) } else { - buf.Write(p.r.CaptureWrites(func() { - p.inline(ref.title) - })) + p.inline(ref.title) } p.r.FootnoteItem(ref.link, buf.Bytes(), flags) flags &^= ListItemBeginningOfList | ListItemContainsBlock

@@ -599,8 +592,6 @@

if p.nesting != 0 { panic("Nesting level did not end at zero") } - - return p.r.GetResult() } //