Skip to content

Commit 663a647

Browse files
authored
Re-use compiled regex for block level checks
1 parent e11cd25 commit 663a647

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

docs/change_log/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Under development: version 3.3.5 (a bug-fix release).
77

88
* Make the `slugify_unicode` function not remove diacritical marks (#1118).
99
* Fix `[toc]` detection when used with `nl2br` extension (#1160)
10+
* Re-use compiled regex for block level checks (#1169)
1011

1112
Feb 24, 2021: version 3.3.4 (a bug-fix release).
1213

markdown/postprocessors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def run(self, text):
6565
class RawHtmlPostprocessor(Postprocessor):
6666
""" Restore raw html to the document. """
6767

68+
BLOCK_LEVEL_REGEX = re.compile(r'^\<\/?([^ >]+)')
69+
6870
def run(self, text):
6971
""" Iterate over html stash and restore html. """
7072
replacements = OrderedDict()
@@ -99,7 +101,7 @@ def substitute_match(m):
99101
return self.run(processed_text)
100102

101103
def isblocklevel(self, html):
102-
m = re.match(r'^\<\/?([^ >]+)', html)
104+
m = self.BLOCK_LEVEL_REGEX.match(html)
103105
if m:
104106
if m.group(1)[0] in ('!', '?', '@', '%'):
105107
# Comment, php etc...

0 commit comments

Comments
 (0)