eliminate a buffering level for paragraphs
Russ Ross russ@russross.com
Sun, 26 Jun 2011 17:21:11 -0600
4 files changed,
19 insertions(+),
9 deletions(-)
M
block.go
→
block.go
@@ -1050,9 +1050,11 @@ if end == beg || rndr.mk.Paragraph == nil {
return } - var work bytes.Buffer - parseInline(&work, rndr, data[beg:end]) - rndr.mk.Paragraph(out, work.Bytes(), rndr.mk.Opaque) + work := func() bool { + parseInline(out, rndr, data[beg:end]) + return true + } + rndr.mk.Paragraph(out, work, rndr.mk.Opaque) } func blockParagraph(out *bytes.Buffer, rndr *render, data []byte) int {
M
html.go
→
html.go
@@ -384,13 +384,17 @@ out.Write(text[:size])
out.WriteString("</li>\n") } -func htmlParagraph(out *bytes.Buffer, text []byte, opaque interface{}) { - if out.Len() > 0 { +func htmlParagraph(out *bytes.Buffer, text func() bool, opaque interface{}) { + marker := out.Len() + if marker > 0 { out.WriteByte('\n') } out.WriteString("<p>") - out.Write(text) + if !text() { + out.Truncate(marker) + return + } out.WriteString("</p>\n") }
M
latex.go
→
latex.go
@@ -127,9 +127,13 @@ out.WriteString("\n\\item ")
out.Write(text) } -func latexParagraph(out *bytes.Buffer, text []byte, opaque interface{}) { +func latexParagraph(out *bytes.Buffer, text func() bool, opaque interface{}) { + marker := out.Len() out.WriteString("\n") - out.Write(text) + if !text() { + out.Truncate(marker) + return + } out.WriteString("\n") }
M
markdown.go
→
markdown.go
@@ -104,7 +104,7 @@ Header func(out *bytes.Buffer, text func() bool, level int, opaque interface{})
HRule func(out *bytes.Buffer, opaque interface{}) List func(out *bytes.Buffer, text func() bool, flags int, opaque interface{}) ListItem func(out *bytes.Buffer, text []byte, flags int, opaque interface{}) - Paragraph func(out *bytes.Buffer, text []byte, opaque interface{}) + Paragraph func(out *bytes.Buffer, text func() bool, opaque interface{}) Table func(out *bytes.Buffer, header []byte, body []byte, columnData []int, opaque interface{}) TableRow func(out *bytes.Buffer, text []byte, opaque interface{}) TableCell func(out *bytes.Buffer, text []byte, flags int, opaque interface{})