more robust whitespace stripping and matching corrections to tests

This commit is contained in:
Russ Ross 2011-06-27 16:06:16 -06:00
parent 9a0217f7aa
commit c8f7e789d4
4 changed files with 13 additions and 12 deletions

View File

@ -154,18 +154,19 @@ func inlineCodeSpan(out *bytes.Buffer, rndr *render, data []byte, offset int) in
// 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 and render
// remove trailing spaces from out
outBytes := out.Bytes()
end := len(outBytes)
for end > 0 && outBytes[end-1] == ' ' {
end--
eol := end
for eol > 0 && (outBytes[eol-1] == ' ' || outBytes[eol-1] == '\t') {
eol--
}
out.Truncate(eol)
// 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

View File

@ -247,7 +247,7 @@ func TestLineBreak(t *testing.T) {
"<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",