Remove some cruft
This commit is contained in:
parent
0382dab0c3
commit
dc7d4b68df
62
html.go
62
html.go
|
|
@ -132,85 +132,31 @@ func HtmlRenderer(flags HtmlFlags, title string, css string) Renderer {
|
|||
}
|
||||
|
||||
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,
|
||||
css string, renderParameters HtmlRendererParameters) Renderer {
|
||||
// configure the rendering engine
|
||||
|
|
@ -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++ {
|
||||
|
|
|
|||
30
latex.go
30
latex.go
|
|
@ -38,36 +38,10 @@ func LatexRenderer(flags int) Renderer {
|
|||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -180,9 +154,7 @@ func (r *Latex) Table(header []byte, body []byte, columnData []int) {
|
|||
}
|
||||
|
||||
func (r *Latex) TableRow(text []byte) {
|
||||
if r.w.dirty {
|
||||
r.w.WriteString(" \\\\\n")
|
||||
}
|
||||
r.w.WriteString(" \\\\\n")
|
||||
r.w.Write(text)
|
||||
}
|
||||
|
||||
|
|
|
|||
15
markdown.go
15
markdown.go
|
|
@ -202,10 +202,7 @@ type Renderer interface {
|
|||
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 @@ func firstPass(p *parser, input []byte) []byte {
|
|||
}
|
||||
|
||||
// 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 @@ func secondPass(p *parser, input []byte) []byte {
|
|||
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 @@ func secondPass(p *parser, input []byte) []byte {
|
|||
if p.nesting != 0 {
|
||||
panic("Nesting level did not end at zero")
|
||||
}
|
||||
|
||||
return p.r.GetResult()
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in New Issue