more robust whitespace stripping and matching corrections to tests
Russ Ross russ@russross.com
Mon, 27 Jun 2011 16:06:16 -0600
4 files changed,
13 insertions(+),
12 deletions(-)
M
inline.go
→
inline.go
@@ -154,18 +154,19 @@
// newline preceded by two spaces becomes <br> // newline without two spaces works when EXTENSION_HARD_LINE_BREAK is enabled func inlineLineBreak(out *bytes.Buffer, rndr *render, data []byte, offset int) int { - if rndr.flags&EXTENSION_HARD_LINE_BREAK == 0 && - (offset < 2 || data[offset-1] != ' ' || data[offset-2] != ' ') { - return 0 + // remove trailing spaces from out + outBytes := out.Bytes() + end := len(outBytes) + eol := end + for eol > 0 && (outBytes[eol-1] == ' ' || outBytes[eol-1] == '\t') { + eol-- } + out.Truncate(eol) - // remove trailing spaces from out and render - outBytes := out.Bytes() - end := len(outBytes) - for end > 0 && outBytes[end-1] == ' ' { - end-- + // should there be a hard line break here? + if rndr.flags&EXTENSION_HARD_LINE_BREAK == 0 && end-eol < 2 { + return 0 } - out.Truncate(end) if rndr.mk.LineBreak == nil { return 0
M
inline_test.go
→
inline_test.go
@@ -247,7 +247,7 @@ "this line \nhas a break\n",
"<p>this line<br />\nhas a break</p>\n", "this line \ndoes not\n", - "<p>this line \ndoes not</p>\n", + "<p>this line\ndoes not</p>\n", "this has an \nextra space\n", "<p>this has an<br />\nextra space</p>\n",
M
upskirtref/Links, reference style.html
→
upskirtref/Links, reference style.html
@@ -48,5 +48,5 @@
<p>Here's one where the <a href="/url/">link breaks</a> across lines.</p> -<p>Here's another where the <a href="/url/">link +<p>Here's another where the <a href="/url/">link breaks</a> across lines, but with a line-ending space.</p>
M
upskirtref/Links, shortcut references.html
→
upskirtref/Links, shortcut references.html
@@ -3,7 +3,7 @@
<p>This one has a <a href="/foo">line break</a>.</p> -<p>This one has a <a href="/foo">line +<p>This one has a <a href="/foo">line break</a> with a line-ending space.</p> <p><a href="/that">this</a> and the <a href="/other">other</a></p>