diff --git a/lib/markdown2.py b/lib/markdown2.py index 34a270b3..c1954883 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -1362,15 +1362,20 @@ def _run_span_gamut(self, text): text = self._do_smart_punctuation(text) # Do hard breaks: - if 'breaks' in self.extras: - break_tag = ")", break_tag, text) + on_backslash = self.extras.get('breaks', {}).get('on_backslash', False) + on_newline = self.extras.get('breaks', {}).get('on_newline', False) + + if on_backslash and on_newline: + pattern = r' *\\?' + elif on_backslash: + pattern = r'(?: *\\| {2,})' + elif on_newline: + pattern = r' *' else: - text = re.sub(r" {2,}\n", " )", break_tag, text) return text diff --git a/test/tm-cases/admonitions.html b/test/tm-cases/admonitions.html index 2b65647c..e8a7d05e 100644 --- a/test/tm-cases/admonitions.html +++ b/test/tm-cases/admonitions.html @@ -26,7 +26,7 @@ diff --git a/test/tm-cases/break_on_backslash.html b/test/tm-cases/break_on_backslash.html index 81040802..71a26425 100644 --- a/test/tm-cases/break_on_backslash.html +++ b/test/tm-cases/break_on_backslash.html @@ -2,4 +2,5 @@ you to insert a backslash with or without a space, which results in
a hard line break, unless it has \ -been escaped.

+been escaped. It's still possible to
+end the line with two spaces for a line break.

diff --git a/test/tm-cases/break_on_backslash.text b/test/tm-cases/break_on_backslash.text index 0576c564..8a94983d 100644 --- a/test/tm-cases/break_on_backslash.text +++ b/test/tm-cases/break_on_backslash.text @@ -2,4 +2,5 @@ Github flavoured markdown allows \ you to insert a backslash with or without a space, which results in\ a hard line break, unless it has \\ -been escaped. +been escaped. It's still possible to +end the line with two spaces for a line break. diff --git a/test/tm-cases/break_on_newline_and_backslash.html b/test/tm-cases/break_on_newline_and_backslash.html index cb43d6db..17706d82 100644 --- a/test/tm-cases/break_on_newline_and_backslash.html +++ b/test/tm-cases/break_on_newline_and_backslash.html @@ -1,3 +1,3 @@

The breaks extra allows you to insert a hard break on newlines.
-You can also insert hard breaks after backslashes

-although this will result in a double break when both are enabled.

+You can also insert hard breaks after backslashes
+which will result in a single break when both are enabled.

diff --git a/test/tm-cases/break_on_newline_and_backslash.text b/test/tm-cases/break_on_newline_and_backslash.text index 4114125b..84c2b826 100644 --- a/test/tm-cases/break_on_newline_and_backslash.text +++ b/test/tm-cases/break_on_newline_and_backslash.text @@ -1,3 +1,3 @@ The breaks extra allows you to insert a hard break on newlines. You can also insert hard breaks after backslashes \ -although this will result in a double break when both are enabled. +which will result in a single break when both are enabled. diff --git a/test/tm-cases/smarty_pants.html b/test/tm-cases/smarty_pants.html index 200c8977..b44af4da 100644 --- a/test/tm-cases/smarty_pants.html +++ b/test/tm-cases/smarty_pants.html @@ -37,9 +37,9 @@

Edge case: contractions

For common contractions, a space single-prime non-space combination should produce an apostrophe (’) instead of an opening scare quote (‘).

-

Here is the full list: ’tis, ’twas, ’twer, ’neath, ’o, ’n, ’round, ’bout, ’twixt, ’nuff, ’fraid, ’sup
-The full list, capitalized: ’Tis, ’Twas, ’Twer, ’Neath, ’O, ’N, ’Round, ’Bout, ’Twixt, ’Nuff, ’Fraid, ’Sup
-And normal text: ‘random ‘stuff ‘that ‘shouldn’t ‘be ‘detected ‘as ‘contractions
+

Here is the full list: ’tis, ’twas, ’twer, ’neath, ’o, ’n, ’round, ’bout, ’twixt, ’nuff, ’fraid, ’sup
+The full list, capitalized: ’Tis, ’Twas, ’Twer, ’Neath, ’O, ’N, ’Round, ’Bout, ’Twixt, ’Nuff, ’Fraid, ’Sup
+And normal text: ‘random ‘stuff ‘that ‘shouldn’t ‘be ‘detected ‘as ‘contractions
And years: ’29 ’91 ‘1942 ‘2001 ‘2010

Like quotation marks, the year shorthand expects a year, e.g. '29, to be followed by whitespace or sentence-ending punctuation. Numbers like '456.7 will throw it off, but those aren’t entered very often.

diff --git a/test/tm-cases/spoiler.html b/test/tm-cases/spoiler.html index 71e1c8ae..b0d5a3fb 100644 --- a/test/tm-cases/spoiler.html +++ b/test/tm-cases/spoiler.html @@ -7,22 +7,22 @@

[Second]

-

! But this is
+

! But this is
not a spoiler

[Third]

-

A multi-line spoiler
+

A multi-line spoiler
has ! multiple times

[Fourth]

-

Alignment
- has no effect
+

Alignment
+ has no effect
on spoilers

diff --git a/test/tm-cases/wavedrom.html b/test/tm-cases/wavedrom.html index e7a99a47..158fa133 100644 --- a/test/tm-cases/wavedrom.html +++ b/test/tm-cases/wavedrom.html @@ -174,7 +174,7 @@