Skip to content

Commit

Permalink
Re-use compiled regex for block level checks
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan authored Aug 9, 2021
1 parent e11cd25 commit 663a647
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/change_log/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
4 changes: 3 additions & 1 deletion markdown/postprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def run(self, text):
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()
Expand Down Expand Up @@ -99,7 +101,7 @@ def substitute_match(m):
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...
Expand Down

0 comments on commit 663a647

Please sign in to comment.