eliminate a buffering level for paragraphs

This commit is contained in:
Russ Ross 2011-06-26 17:21:11 -06:00
parent ea3d80e2d0
commit e22e43bf76
4 changed files with 19 additions and 9 deletions

View File

@ -1050,9 +1050,11 @@ func renderParagraph(out *bytes.Buffer, rndr *render, data []byte) {
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 {

10
html.go
View File

@ -384,13 +384,17 @@ func htmlListItem(out *bytes.Buffer, text []byte, flags int, opaque interface{})
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")
}

View File

@ -127,9 +127,13 @@ func latexListItem(out *bytes.Buffer, text []byte, flags int, opaque interface{}
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")
}

View File

@ -104,7 +104,7 @@ type Renderer struct {
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{})