Browse Source

Markdown: support `\` EOL to generate a `<br />`

Improve compatibility with some other markdown renderers and translate a
backslash (`\`) at the very end of a line (a line that is *not* inside a
table or code block) into a `<br />` in addition to the two-or-more-spaces
at the end of line translation that already takes place and does the
same thing.

As expected, the backslash can be escaped by doubling it to preserve it
(or by enclosing it in backquotes `\` to make it a code span).

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 3 years ago
parent
commit
f2f8a1e2fe
  1. 1
      Markdown.pl
  2. 5
      syntax.md

1
Markdown.pl

@ -1801,6 +1801,7 @@ sub _RunSpanGamut {
# Do hard breaks:
$text =~ s/ {3,}(\n|\z)/<br clear=\"all\"$opt{empty_element_suffix}$1/g;
$text =~ s/ {2,}\n/<br$opt{empty_element_suffix}\n/g;
$text =~ s/ ?\\\n/<br$opt{empty_element_suffix}\n/g;
$text =~ s/ {2,}\z//g;
return $text;

5
syntax.md

@ -210,6 +210,11 @@ character in a paragraph into a `<br />` tag.
When you *do* want to insert a `<br />` break tag using Markdown, you
end a line with two or more spaces, then type return.
Alternatively, a line ending with a backslash `\` that's at the very end
of the line (that's not inside a table or code block) will also translate
into a `<br />` tag (the `\` is replaced). To keep a literal `\` at the
end of a line (that's not inside a table or code block), double it.
If you end a line with three or more spaces then a `<br clear="all" />`
tag will be generated instead of the plain `<br />` tag.

Loading…
Cancel
Save