OLD | NEW |
(Empty) | |
| 1 """ |
| 2 NL2BR Extension |
| 3 =============== |
| 4 |
| 5 A Python-Markdown extension to treat newlines as hard breaks; like |
| 6 GitHub-flavored Markdown does. |
| 7 |
| 8 Usage: |
| 9 |
| 10 >>> import markdown |
| 11 >>> print markdown.markdown('line 1\\nline 2', extensions=['nl2br']) |
| 12 <p>line 1<br /> |
| 13 line 2</p> |
| 14 |
| 15 Copyright 2011 [Brian Neal](http://deathofagremmie.com/) |
| 16 |
| 17 Dependencies: |
| 18 * [Python 2.4+](http://python.org) |
| 19 * [Markdown 2.1+](http://packages.python.org/Markdown/) |
| 20 |
| 21 """ |
| 22 |
| 23 from __future__ import absolute_import |
| 24 from __future__ import unicode_literals |
| 25 from . import Extension |
| 26 from ..inlinepatterns import SubstituteTagPattern |
| 27 |
| 28 BR_RE = r'\n' |
| 29 |
| 30 class Nl2BrExtension(Extension): |
| 31 |
| 32 def extendMarkdown(self, md, md_globals): |
| 33 br_tag = SubstituteTagPattern(BR_RE, 'br') |
| 34 md.inlinePatterns.add('nl', br_tag, '_end') |
| 35 |
| 36 |
| 37 def makeExtension(configs=None): |
| 38 return Nl2BrExtension(configs) |
OLD | NEW |