aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Yunusov <nedrlab@gmail.com>2008-07-22 02:33:41 +0500
committerArtem Yunusov <nedrlab@gmail.com>2008-07-22 02:33:41 +0500
commitc99366a182afa3b0cd8da12075cd9ff8e15ae089 (patch)
tree912a2c8afb69c9fd959bcdee48adc5c3303d6c41
parent4c9cd2c1d9c589ead5a6543e306b8bf7e6295aa5 (diff)
downloadmarkdown-c99366a182afa3b0cd8da12075cd9ff8e15ae089.tar.gz
markdown-c99366a182afa3b0cd8da12075cd9ff8e15ae089.tar.bz2
markdown-c99366a182afa3b0cd8da12075cd9ff8e15ae089.zip
Missing link defenition bug fixed.
-rw-r--r--markdown.py23
-rw-r--r--tests/misc/missing-link-def.html3
-rw-r--r--tests/misc/missing-link-def.txt4
3 files changed, 22 insertions, 8 deletions
diff --git a/markdown.py b/markdown.py
index 0751463..e4235ff 100644
--- a/markdown.py
+++ b/markdown.py
@@ -1629,17 +1629,18 @@ class Markdown:
Return: String with placeholders.
"""
-
+ startIndex = 0
while patternIndex < len(self.inlinePatterns):
- data, matched = self._applyInline(self.inlinePatterns[patternIndex],
- data, patternIndex)
+ data, matched, startIndex = self._applyInline(
+ self.inlinePatterns[patternIndex],
+ data, patternIndex, startIndex)
if not matched:
patternIndex += 1
return data
- def _applyInline(self, pattern, data, patternIndex):
+ def _applyInline(self, pattern, data, patternIndex, startIndex=0):
"""
Given a pattern name, this function checks if the line
fits the pattern, creates the necessary elements, adds it
@@ -1651,19 +1652,23 @@ class Markdown:
* data: the text to be processed
* pattern: the pattern to be checked
* patternIndex: index of current pattern
+ * startIndex: string index, from wich we starting search
Returns: String with placeholders.
"""
- match = pattern.getCompiledRegExp().match(data)
+ match = pattern.getCompiledRegExp().match(data[startIndex:])
+ leftData = data[:startIndex]
if not match:
- return data, False
+ return data, False, 0
+
node = pattern.handleMatch(match)
if node is None:
- return data, False
+ return data, True, len(leftData) + match.span(len(match.groups()))[0]
+
if not isstr(node):
if not node.tag in ["code", "pre"]:
# We need to process current node too
@@ -1678,7 +1683,9 @@ class Markdown:
pholder = self.inlineStash.add(node, pattern.type())
- return "%s%s%s" % (match.group(1), pholder, match.groups()[-1]), True
+ return "%s%s%s%s" % (leftData,
+ match.group(1),
+ pholder, match.groups()[-1]), True, 0
def _processElementText(self, node, subnode, isText=True):
diff --git a/tests/misc/missing-link-def.html b/tests/misc/missing-link-def.html
new file mode 100644
index 0000000..bab2a75
--- /dev/null
+++ b/tests/misc/missing-link-def.html
@@ -0,0 +1,3 @@
+<p>This is a [missing link][empty] and a <a href="http://example.com">valid</a> and [missing][again].</p>
+
+
diff --git a/tests/misc/missing-link-def.txt b/tests/misc/missing-link-def.txt
new file mode 100644
index 0000000..44bc656
--- /dev/null
+++ b/tests/misc/missing-link-def.txt
@@ -0,0 +1,4 @@
+This is a [missing link][empty] and a [valid][link] and [missing][again].
+
+[link]: http://example.com
+