more robust whitespace stripping and matching corrections to tests
This commit is contained in:
parent
9a0217f7aa
commit
c8f7e789d4
19
inline.go
19
inline.go
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue