nl2br.py 783 B

123456789101112131415161718192021222324252627282930313233
  1. """
  2. NL2BR Extension
  3. ===============
  4. A Python-Markdown extension to treat newlines as hard breaks; like
  5. GitHub-flavored Markdown does.
  6. See <https://Python-Markdown.github.io/extensions/nl2br>
  7. for documentation.
  8. Oringinal code Copyright 2011 [Brian Neal](https://deathofagremmie.com/)
  9. All changes Copyright 2011-2014 The Python Markdown Project
  10. License: [BSD](https://opensource.org/licenses/bsd-license.php)
  11. """
  12. from . import Extension
  13. from ..inlinepatterns import SubstituteTagInlineProcessor
  14. BR_RE = r'\n'
  15. class Nl2BrExtension(Extension):
  16. def extendMarkdown(self, md):
  17. br_tag = SubstituteTagInlineProcessor(BR_RE, 'br')
  18. md.inlinePatterns.register(br_tag, 'nl', 5)
  19. def makeExtension(**kwargs): # pragma: no cover
  20. return Nl2BrExtension(**kwargs)