diff --git a/block.go b/block.go index 64a0578..538817b 100644 --- a/block.go +++ b/block.go @@ -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 { diff --git a/html.go b/html.go index 3bcd6b3..cf3cbf6 100644 --- a/html.go +++ b/html.go @@ -384,13 +384,17 @@ func htmlListItem(out *bytes.Buffer, text []byte, flags int, opaque interface{}) out.WriteString("\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("

") - out.Write(text) + if !text() { + out.Truncate(marker) + return + } out.WriteString("

\n") } diff --git a/latex.go b/latex.go index 34f49e6..7d2763f 100644 --- a/latex.go +++ b/latex.go @@ -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") } diff --git a/markdown.go b/markdown.go index 45a8fca..a03a33d 100644 --- a/markdown.go +++ b/markdown.go @@ -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{})