diff --git a/README.rst b/README.rst index 059a68f..d83c3a9 100644 --- a/README.rst +++ b/README.rst @@ -100,6 +100,12 @@ newline_style newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of interpreters. +inline_br + By default, linebreaks with ``
`` inside inline elements (especially table + cells) are replaced by spaces. This can be confusing in some contexts. + Setting this option replaces it by plain ``
`` tags, allowing actual line + breaks in Markdown renderers that support it. + code_language Defines the language that should be assumed for all ``
`` sections.
   Useful, if all code on a page is in the same programming language and
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 148d340..6b95396 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -186,6 +186,7 @@ class DefaultOptions:
         escape_underscores = True
         escape_misc = False
         heading_style = UNDERLINED
+        inline_br = False
         keep_inline_images_in = []
         newline_style = SPACES
         strip = None
@@ -475,7 +476,12 @@ def _indent_for_blockquote(match):
 
     def convert_br(self, el, text, parent_tags):
         if '_inline' in parent_tags:
-            return ' '
+            # Some Markdown renderers allow 
tags for line breaks inside inline elements. + # We can choose to keep them with inline_br. + if self.options['inline_br']: + return '
' + else: + return ' ' if self.options['newline_style'].lower() == BACKSLASH: return '\\\n' diff --git a/markdownify/main.py b/markdownify/main.py index ba70671..af99cd3 100755 --- a/markdownify/main.py +++ b/markdownify/main.py @@ -46,6 +46,9 @@ def main(argv=sys.argv[1:]): choices=(SPACES, BACKSLASH), help="Defines the style of
conversions: two spaces " "or backslash at the and of the line thet should break.") + parser.add_argument('--inline-br', action='store_true', + help="A boolean indicating whether
tags should be preserved " + "inside inline elements. If false, spaces will be used instead.") parser.add_argument('--code-language', default='', help="Defines the language that should be assumed for all " "'
' sections.")