Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``<br>`` inside inline elements (especially table
cells) are replaced by spaces. This can be confusing in some contexts.
Setting this option replaces it by plain ``<br>`` tags, allowing actual line
breaks in Markdown renderers that support it.

code_language
Defines the language that should be assumed for all ``<pre>`` sections.
Useful, if all code on a page is in the same programming language and
Expand Down
8 changes: 7 additions & 1 deletion markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <br> tags for line breaks inside inline elements.
# We can choose to keep them with inline_br.
if self.options['inline_br']:
return '<br>'
else:
return ' '

if self.options['newline_style'].lower() == BACKSLASH:
return '\\\n'
Expand Down
3 changes: 3 additions & 0 deletions markdownify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def main(argv=sys.argv[1:]):
choices=(SPACES, BACKSLASH),
help="Defines the style of <br> 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 <br> 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 "
"'<pre>' sections.")
Expand Down