Skip to content
Crozzers edited this page Dec 9, 2023 · 3 revisions

The breaks extra, added in 2.4.11, allows you to control when hard breaks (<br />) are inserted into the markdown. This extra includes the functionality of the old break-on-newline extra (added in 2.2.0), which has been kept as an alias of breaks.

Extra options

Two options are provided, both disabled by default:

  • on_newline (replaces break-on-newline extra): replace single newline characters with hard breaks
  • on_backslash: lines ending in a backslash will have a hard break inserted

Examples

on_newline

When `on_newline` is enabled, there will be a `<br />` tag at the end of this line
But not this one, since it's at the end of the file
<p>When <code>on_newline</code> is enabled, there will be a <code>&lt;br /&gt;</code> tag at the end of this line<br />
But not this one, since it's at the end of the file</p>

on_backslash

This line will have a line break \
Due to the backslash
<p>This line will have a line break<br />
Due to the backslash</p>

Module usage

markdown2.markdown(your_text, extras={'breaks': {'on_newline': True, 'on_backslash': True}})