From c8f7e789d43d716164bea2fa6716380600b5a68f Mon Sep 17 00:00:00 2001 From: Russ Ross Date: Mon, 27 Jun 2011 16:06:16 -0600 Subject: [PATCH] more robust whitespace stripping and matching corrections to tests --- inline.go | 19 ++++++++++--------- inline_test.go | 2 +- upskirtref/Links, reference style.html | 2 +- upskirtref/Links, shortcut references.html | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/inline.go b/inline.go index 1556022..62dffd2 100644 --- a/inline.go +++ b/inline.go @@ -154,18 +154,19 @@ func inlineCodeSpan(out *bytes.Buffer, rndr *render, data []byte, offset int) in // newline preceded by two spaces becomes
// 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 diff --git a/inline_test.go b/inline_test.go index 81d21b9..b8680bd 100644 --- a/inline_test.go +++ b/inline_test.go @@ -247,7 +247,7 @@ func TestLineBreak(t *testing.T) { "

this line
\nhas a break

\n", "this line \ndoes not\n", - "

this line \ndoes not

\n", + "

this line\ndoes not

\n", "this has an \nextra space\n", "

this has an
\nextra space

\n", diff --git a/upskirtref/Links, reference style.html b/upskirtref/Links, reference style.html index 1bf6b86..bebefde 100644 --- a/upskirtref/Links, reference style.html +++ b/upskirtref/Links, reference style.html @@ -48,5 +48,5 @@

Here's one where the link breaks across lines.

-

Here's another where the link +

Here's another where the link breaks across lines, but with a line-ending space.

diff --git a/upskirtref/Links, shortcut references.html b/upskirtref/Links, shortcut references.html index bf81e93..0b5e1d6 100644 --- a/upskirtref/Links, shortcut references.html +++ b/upskirtref/Links, shortcut references.html @@ -3,7 +3,7 @@

This one has a line break.

-

This one has a line +

This one has a line break with a line-ending space.

this and the other