summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHebaruSan <HebaruSan@users.noreply.github.com>2021-08-09 09:17:52 -0500
committerGitHub <noreply@github.com>2021-08-09 10:17:52 -0400
commit663a64789c18f4c1a4cbfa9c3a8e11043025eab9 (patch)
treec59f3d1cb2eb941968cf41dc96eddc081d3d2a99
parente11cd255cae5fd3c5ef5fdd6352cd28e212fd328 (diff)
downloadpython-markdown-663a64789c18f4c1a4cbfa9c3a8e11043025eab9.tar.gz
Re-use compiled regex for block level checks
-rw-r--r--docs/change_log/index.md1
-rw-r--r--markdown/postprocessors.py4
2 files changed, 4 insertions, 1 deletions
diff --git a/docs/change_log/index.md b/docs/change_log/index.md
index fe40094..d1f36c0 100644
--- a/docs/change_log/index.md
+++ b/docs/change_log/index.md
@@ -7,6 +7,7 @@ Under development: version 3.3.5 (a bug-fix release).
* Make the `slugify_unicode` function not remove diacritical marks (#1118).
* Fix `[toc]` detection when used with `nl2br` extension (#1160)
+* Re-use compiled regex for block level checks (#1169)
Feb 24, 2021: version 3.3.4 (a bug-fix release).
diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py
index 2e572f6..f4fb924 100644
--- a/markdown/postprocessors.py
+++ b/markdown/postprocessors.py
@@ -65,6 +65,8 @@ class Postprocessor(util.Processor):
class RawHtmlPostprocessor(Postprocessor):
""" Restore raw html to the document. """
+ BLOCK_LEVEL_REGEX = re.compile(r'^\<\/?([^ >]+)')
+
def run(self, text):
""" Iterate over html stash and restore html. """
replacements = OrderedDict()
@@ -99,7 +101,7 @@ class RawHtmlPostprocessor(Postprocessor):
return self.run(processed_text)
def isblocklevel(self, html):
- m = re.match(r'^\<\/?([^ >]+)', html)
+ m = self.BLOCK_LEVEL_REGEX.match(html)
if m:
if m.group(1)[0] in ('!', '?', '@', '%'):
# Comment, php etc...