all repos — grayfriday @ 812e8d01851b51ca99a3d0dae135b059823c2b03

blackfriday fork with a few changes

refactoring paragraph rendering
Russ Ross russ@russross.com
Sat, 25 Jun 2011 15:18:34 -0600
commit

812e8d01851b51ca99a3d0dae135b059823c2b03

parent

eff64c563f75c50f8af0ec650e719846efff659b

2 files changed, 18 insertions(+), 28 deletions(-)

jump to
M block.goblock.go

@@ -1035,17 +1035,23 @@ }

// render a single paragraph that has already been parsed out func renderParagraph(out *bytes.Buffer, rndr *render, data []byte) { - // trim trailing newlines + // trim leading whitespace + beg := 0 + for beg < len(data) && isspace(data[beg]) { + beg++ + } + + // trim trailing whitespace end := len(data) - for end > 0 && data[end-1] == '\n' { + for end > beg && isspace(data[end-1]) { end-- } - if end == 0 || rndr.mk.Paragraph == nil { + if end == beg || rndr.mk.Paragraph == nil { return } var work bytes.Buffer - parseInline(&work, rndr, data[:end]) + parseInline(&work, rndr, data[beg:end]) rndr.mk.Paragraph(out, work.Bytes(), rndr.mk.Opaque) }
M html.gohtml.go

@@ -388,46 +388,30 @@ }

func htmlParagraph(out *bytes.Buffer, text []byte, opaque interface{}) { options := opaque.(*htmlOptions) - i := 0 if out.Len() > 0 { out.WriteByte('\n') } - if len(text) == 0 { - return - } - - for i < len(text) && isspace(text[i]) { - i++ - } - - if i == len(text) { - return - } - out.WriteString("<p>") if options.flags&HTML_HARD_WRAP != 0 { - for i < len(text) { - org := i - for i < len(text) && text[i] != '\n' { - i++ + org := 0 + for i := 0; i < len(text); i++ { + if text[i] != '\n' { + continue } if i > org { out.Write(text[org:i]) } - - if i >= len(text) { - break - } + org = i - out.WriteString("<br>") + out.WriteString("<br") out.WriteString(options.closeTag) - i++ } + out.Write(text[org:]) } else { - out.Write(text[i:]) + out.Write(text) } out.WriteString("</p>\n") }