| 1 |
title: New Line to Break Extension |
| 2 |
|
| 3 |
New-Line-to-Break Extension |
| 4 |
=========================== |
| 5 |
|
| 6 |
Summary |
| 7 |
------- |
| 8 |
|
| 9 |
The New-Line-to-Break (`nl2br`) Extension will cause newlines to be treated as |
| 10 |
hard breaks; like StackOverflow and [GitHub][] flavored Markdown do. |
| 11 |
|
| 12 |
[Github]: https://github.github.com/github-flavored-markdown/ |
| 13 |
|
| 14 |
Example |
| 15 |
------- |
| 16 |
|
| 17 |
```pycon |
| 18 |
>>> import markdown |
| 19 |
>>> text = """ |
| 20 |
... Line 1 |
| 21 |
... Line 2 |
| 22 |
... """ |
| 23 |
>>> html = markdown.markdown(text, extensions=['nl2br']) |
| 24 |
>>> print html |
| 25 |
<p>Line 1<br /> |
| 26 |
Line 2</p> |
| 27 |
``` |
| 28 |
|
| 29 |
Usage |
| 30 |
----- |
| 31 |
|
| 32 |
See [Extensions](index.md) for general extension usage. Use `nl2br` as the name |
| 33 |
of the extension. |
| 34 |
|
| 35 |
This extension does not accept any special configuration options. |
| 36 |
|
| 37 |
A trivial example: |
| 38 |
|
| 39 |
```python |
| 40 |
markdown.markdown(some_text, extensions=['nl2br']) |
| 41 |
``` |