aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Yunusov <nedrlab@gmail.com>2008-07-16 22:25:36 +0500
committerArtem Yunusov <nedrlab@gmail.com>2008-07-16 22:25:36 +0500
commit3986ba1df4f404967732add30bf09f0c61bc181f (patch)
tree4f1af24cba0c862b433d4658e5805f63482485d6
parentd1134b2c547c471d85b443404904461941d27d71 (diff)
downloadmarkdown-3986ba1df4f404967732add30bf09f0c61bc181f.tar.gz
markdown-3986ba1df4f404967732add30bf09f0c61bc181f.tar.bz2
markdown-3986ba1df4f404967732add30bf09f0c61bc181f.zip
Aggregated regexp for both backtick and double backtick.
-rw-r--r--markdown.py13
-rw-r--r--tests/safe_mode/script_tags.html4
-rw-r--r--tests/safe_mode/script_tags.txt2
3 files changed, 7 insertions, 12 deletions
diff --git a/markdown.py b/markdown.py
index dcfe18e..5b4fa5f 100644
--- a/markdown.py
+++ b/markdown.py
@@ -507,8 +507,7 @@ BRK = ( r'\[('
+ NOBRACKET + r')\]' )
NOIMG = r'(?<!\!)'
-BACKTICK_RE = r'(?<!\\)(?:`+)(?!`)(.+?)(?<!`)(`+)(?!`)'
-DOUBLE_BACKTICK_RE = r'\`\`(.*?)\`\`' # ``e=f("`")``
+BACKTICK_RE = r'(?<!\\)(`+)(.+?)(?<!`)\2(?!`)' # `e=f()` or ``e=f("`")``
ESCAPE_RE = r'\\(.)' # \<
EMPHASIS_RE = r'\*([^\*]*)\*' # *emphasis*
STRONG_RE = r'\*\*(.*?|[^**]+?)\*\*' # **strong**
@@ -791,8 +790,7 @@ class AutomailPattern (Pattern):
ESCAPE_PATTERN = SimpleTextPattern(ESCAPE_RE)
NOT_STRONG_PATTERN = SimpleTextPattern(NOT_STRONG_RE)
-BACKTICK_PATTERN = BacktickPattern(BACKTICK_RE)
-DOUBLE_BACKTICK_PATTERN = BacktickPattern(DOUBLE_BACKTICK_RE)
+BACKTICK_PATTERN = BacktickPattern(BACKTICK_RE, 3)
STRONG_PATTERN = SimpleTagPattern(STRONG_RE, 'strong')
STRONG_PATTERN_2 = SimpleTagPattern(STRONG_2_RE, 'strong')
EMPHASIS_PATTERN = SimpleTagPattern(EMPHASIS_RE, 'em')
@@ -1188,7 +1186,6 @@ class Markdown:
self.prePatterns = []
self.inlinePatterns = [
- DOUBLE_BACKTICK_PATTERN,
BACKTICK_PATTERN,
ESCAPE_PATTERN,
REFERENCE_PATTERN,
@@ -1674,7 +1671,7 @@ class Markdown:
if not match:
return data, False
-
+
node = pattern.handleMatch(match)
if node is None:
@@ -1692,10 +1689,8 @@ class Markdown:
patternIndex)
pholder = self.inlineStash.add(node, pattern.type())
- left = "".join([match.group(i) for i in xrange(1,
- pattern.contentGroup)])
- return "%s%s%s" % (left, pholder, match.groups()[-1]), True
+ return "%s%s%s" % (match.group(1), pholder, match.groups()[-1]), True
def _processElementText(self, node, subnode, isText=True):
diff --git a/tests/safe_mode/script_tags.html b/tests/safe_mode/script_tags.html
index 4c669dd..940329f 100644
--- a/tests/safe_mode/script_tags.html
+++ b/tests/safe_mode/script_tags.html
@@ -12,7 +12,7 @@ alert(&quot;Hello world!&quot;)
<p>
<code>&lt;script &lt;!--
alert("Hello world!")
-&lt;/script &lt;&gt;</code>`</p>
+&lt;/script &lt;&gt;</code> `</p>
<p>Try another way.</p>
<p>&lt;script &lt;!--
alert(&quot;Hello world!&quot;)
@@ -26,4 +26,4 @@ alert(&quot;Hello world!&quot;)
&lt;/script &lt;&gt;
-</p> \ No newline at end of file
+</p>
diff --git a/tests/safe_mode/script_tags.txt b/tests/safe_mode/script_tags.txt
index 55c60e9..44041c2 100644
--- a/tests/safe_mode/script_tags.txt
+++ b/tests/safe_mode/script_tags.txt
@@ -16,7 +16,7 @@ Now with some weirdness
``<script <!--
alert("Hello world!")
-</script <>```
+</script <>`` `
Try another way.