Browse files

move this regex to class level, slight perf gain for some cases, no f…

…unctional change
  • Loading branch information...
1 parent 0a4152a commit 63ffce4da79a53a083aa8e5559520a73853245dc @trentm committed Apr 25, 2012
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/markdown2.py
View
16 lib/markdown2.py
@@ -1513,19 +1513,19 @@ def _do_code_blocks(self, text):
return code_block_re.sub(self._code_block_sub, text)
+ _fenced_code_block_re = re.compile(r'''
+ (?:\n\n|\A\n?)
+ ^```([\w+-]+)?[ \t]*\n # opening fence, $1 = optional lang
+ (.*?) # $2 = code block content
+ ^```[ \t]*\n # closing fence
+ ''', re.M | re.X | re.S)
+
def _fenced_code_block_sub(self, match):
return self._code_block_sub(match, is_fenced_code_block=True);
def _do_fenced_code_blocks(self, text):
"""Process ```-fenced unindented code blocks ('fenced-code-blocks' extra)."""
- fenced_code_block_re = re.compile(r'''
- (?:\n\n|\A\n?)
- ^```([\w+-]+)?[ \t]*\n # opening fence, $1 = optional lang
- (.*?) # $2 = code block content
- ^```[ \t]*\n # closing fence
- ''', re.M | re.X | re.S)
-
- return fenced_code_block_re.sub(self._fenced_code_block_sub, text)
+ return self._fenced_code_block_re.sub(self._fenced_code_block_sub, text)
# Rules for a code span:
# - backslash escapes are not interpreted in a code span

0 comments on commit 63ffce4

Please sign in to comment.