Merge pull request #163 from neclepsio/master
Implement backslash hard line break extension
This commit is contained in:
commit
d3270c47ac
|
@ -167,12 +167,17 @@ func lineBreak(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -332,10 +332,34 @@ func TestLineBreak(t *testing.T) {
|
|||
"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) {
|
||||
|
|
|
@ -42,6 +42,7 @@ const (
|
|||
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 @@ const (
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue