From 663a64789c18f4c1a4cbfa9c3a8e11043025eab9 Mon Sep 17 00:00:00 2001 From: HebaruSan Date: Mon, 9 Aug 2021 09:17:52 -0500 Subject: Re-use compiled regex for block level checks --- docs/change_log/index.md | 1 + markdown/postprocessors.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) 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... -- cgit v1.2.1