Merge pull request #163 from neclepsio/master Implement backslash hard line break extension
Vytautas Ĺ altenis vytas@rtfb.lt
Thu, 23 Apr 2015 11:58:36 +0300
3 files changed,
33 insertions(+),
2 deletions(-)
M
inline.go
→
inline.go
@@ -167,12 +167,17 @@ }
out.Truncate(eol) precededByTwoSpaces := offset >= 2 && data[offset-2] == ' ' && data[offset-1] == ' ' + precededByBackslash := offset >= 1 && data[offset-1] == '\\' // see http://spec.commonmark.org/0.18/#example-527 + precededByBackslash = precededByBackslash && p.flags&EXTENSION_BACKSLASH_LINE_BREAK != 0 // should there be a hard line break here? - if p.flags&EXTENSION_HARD_LINE_BREAK == 0 && !precededByTwoSpaces { + if p.flags&EXTENSION_HARD_LINE_BREAK == 0 && !precededByTwoSpaces && !precededByBackslash { return 0 } + if precededByBackslash && eol > 0 { + out.Truncate(eol - 1) + } p.r.LineBreak(out) return 1 }
M
inline_test.go
→
inline_test.go
@@ -332,10 +332,34 @@
"this line \ndoes not\n", "<p>this line\ndoes not</p>\n", + "this line\\\ndoes not\n", + "<p>this line\\\ndoes not</p>\n", + + "this line\\ \ndoes not\n", + "<p>this line\\\ndoes not</p>\n", + "this has an \nextra space\n", "<p>this has an<br />\nextra space</p>\n", } doTestsInline(t, tests) + + tests = []string{ + "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", + + "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", + + "this has an \nextra space\n", + "<p>this has an<br />\nextra space</p>\n", + } + doTestsInlineParam(t, tests, EXTENSION_BACKSLASH_LINE_BREAK, 0, HtmlRendererParameters{}) } func TestInlineLink(t *testing.T) {
M
markdown.go
→
markdown.go
@@ -42,6 +42,7 @@ EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK // No need to insert an empty line to start a (code, quote, order list, unorder list)block
EXTENSION_HEADER_IDS // specify header IDs with {#id} EXTENSION_TITLEBLOCK // Titleblock ala pandoc EXTENSION_AUTO_HEADER_IDS // Create the header ID from the text + EXTENSION_BACKSLASH_LINE_BREAK // translate trailing backslashes into line breaks commonHtmlFlags = 0 | HTML_USE_XHTML |@@ -56,7 +57,8 @@ EXTENSION_FENCED_CODE |
EXTENSION_AUTOLINK | EXTENSION_STRIKETHROUGH | EXTENSION_SPACE_HEADERS | - EXTENSION_HEADER_IDS + EXTENSION_HEADER_IDS | + EXTENSION_BACKSLASH_LINE_BREAK ) // These are the possible flag values for the link renderer.