mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
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 preceded by two spaces becomes <br>
|
||||||
// newline without two spaces works when EXTENSION_HARD_LINE_BREAK is enabled
|
// newline without two spaces works when EXTENSION_HARD_LINE_BREAK is enabled
|
||||||
func inlineLineBreak(out *bytes.Buffer, rndr *render, data []byte, offset int) int {
|
func inlineLineBreak(out *bytes.Buffer, rndr *render, data []byte, offset int) int {
|
||||||
if rndr.flags&EXTENSION_HARD_LINE_BREAK == 0 &&
|
// remove trailing spaces from out
|
||||||
(offset < 2 || data[offset-1] != ' ' || data[offset-2] != ' ') {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove trailing spaces from out and render
|
|
||||||
outBytes := out.Bytes()
|
outBytes := out.Bytes()
|
||||||
end := len(outBytes)
|
end := len(outBytes)
|
||||||
for end > 0 && outBytes[end-1] == ' ' {
|
eol := end
|
||||||
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 {
|
if rndr.mk.LineBreak == nil {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -247,7 +247,7 @@ func TestLineBreak(t *testing.T) {
|
||||||
"<p>this line<br />\nhas a break</p>\n",
|
"<p>this line<br />\nhas a break</p>\n",
|
||||||
|
|
||||||
"this line \ndoes not\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",
|
"this has an \nextra space\n",
|
||||||
"<p>this has an<br />\nextra space</p>\n",
|
"<p>this has an<br />\nextra space</p>\n",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user