diff --git a/CHANGES.md b/CHANGES.md
index c31d5fce..54dc4966 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -4,7 +4,7 @@
- [pull #524] Fix angles being escaped in style blocks (issue #523)
- [pull #527] Fix base64 images being corrupted in safe mode (issue #526)
-
+- [pull #529] Add `breaks` extra with ability to hard break on backslashes (issue #525)
## python-markdown2 2.4.10
diff --git a/lib/markdown2.py b/lib/markdown2.py
index 7386cc4f..e48cf5c5 100755
--- a/lib/markdown2.py
+++ b/lib/markdown2.py
@@ -41,7 +41,11 @@
see
when True
+* breaks: Control where hard breaks are inserted in the markdown.
+ Options include:
+ - on_newline: Replace single new line characters with
when True
+ - on_backslash: Replace backslashes at the end of a line with
+* break-on-newline: Alias for the on_newline option in the breaks extra.
* code-friendly: Disable _ and __ for em and strong.
* cuddled-lists: Allow lists to be cuddled to the preceding paragraph.
* fenced-code-blocks: Allows a code block to not have to be indented
@@ -235,6 +239,11 @@ def __init__(self, html4tags=False, tab_width=4, safe_mode=None,
self._toc_depth = 6
else:
self._toc_depth = self.extras["toc"].get("depth", 6)
+
+ if 'break-on-newline' in self.extras:
+ self.extras.setdefault('breaks', {})
+ self.extras['breaks']['on_newline'] = True
+
self._instance_extras = self.extras.copy()
if 'link-patterns' in self.extras:
@@ -1318,8 +1327,13 @@ def _run_span_gamut(self, text):
text = self._do_smart_punctuation(text)
# Do hard breaks:
- if "break-on-newline" in self.extras:
- text = re.sub(r" *\n(?!\<(?:\/?(ul|ol|li))\>)", "
)", break_tag, text)
else:
text = re.sub(r" {2,}\n", "
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.
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.