Debian Codegraph @

markdown/extensions/nl2br.py

raw
1 # `NL2BR` Extension
2 # ===============
3
4 # A Python-Markdown extension to treat newlines as hard breaks; like
5 # GitHub-flavored Markdown does.
6
7 # See https://Python-Markdown.github.io/extensions/nl2br
8 # for documentation.
9
10 # Original code Copyright 2011 [Brian Neal](https://deathofagremmie.com/)
11
12 # All changes Copyright 2011-2014 The Python Markdown Project
13
14 # License: [BSD](https://opensource.org/licenses/bsd-license.php)
15
16 """
17 A Python-Markdown extension to treat newlines as hard breaks.
18 Similar to GitHub-flavored Markdown's behavior.
19
20 See the [documentation](https://Python-Markdown.github.io/extensions/nl2br)
21 for details.
22 """
23
24 from __future__ import annotations
25
26 from . import Extension
27 from ..inlinepatterns import SubstituteTagInlineProcessor
28
29 BR_RE = r'\n'
30
31
32 class Nl2BrExtension(Extension):
33 """ Newline-to-break extension for Python-Markdown. """
34
35 def extendMarkdown(self, md):
36 """ Register the processor.
37
38 | Class Instance | Registry | Name | Priority |
39 | --------------------------------------------------------------- | ------------------------------------------------------------- | ------ | :------: |
40 | [`SubstituteTagInlineProcessor`][markdown.inlinepatterns.SubstituteTagInlineProcessor] | [`inlinepatterns`][markdown.inlinepatterns.build_inlinepatterns] | `nl` | `5` |
41
42 """
43 # flake8: noqa: E501 38-40
44 br_tag = SubstituteTagInlineProcessor(BR_RE, 'br')
45 md.inlinePatterns.register(br_tag, 'nl', 5)
46
47
48 def makeExtension(**kwargs): # pragma: no cover
49 return Nl2BrExtension(**kwargs)