aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerry LaMontagne <gjlama94@gmail.com>2010-08-29 22:31:04 -0400
committerGerry LaMontagne <gjlama94@gmail.com>2010-08-29 22:31:04 -0400
commitae30d3a3070c3e3bdf24595bf28bd7c150bc7abf (patch)
treebdf06a7f6f0351e5c5d0cca84e54fe5bfe3eb7d9
parent5ee12763465d123a313d43fc0fb497636f727d34 (diff)
downloadmarkdown-ae30d3a3070c3e3bdf24595bf28bd7c150bc7abf.tar.gz
markdown-ae30d3a3070c3e3bdf24595bf28bd7c150bc7abf.tar.bz2
markdown-ae30d3a3070c3e3bdf24595bf28bd7c150bc7abf.zip
Replaced block.rfind in _get_right_tag with custom search function.
-rw-r--r--markdown/preprocessors.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py
index ab44f96..c23d728 100644
--- a/markdown/preprocessors.py
+++ b/markdown/preprocessors.py
@@ -82,9 +82,23 @@ class HtmlBlockPreprocessor(Preprocessor):
return tag, len(tag)+2, {}
def _get_right_tag(self, left_tag, left_index, block):
+ def recursive_tagfind(start_index, ltag, rtag):
+ while 1:
+ i = block.find(rtag, start_index)
+ if i == -1:
+ return -1
+ j = block.find(ltag, start_index)
+ # if no ltag, or rtag found before another ltag, return index
+ if (j > i or j == -1):
+ return i + len(rtag)
+ start_index = recursive_tagfind(j + len(ltag) + 1, ltag, rtag)
+
for p in self.right_tag_patterns:
tag = p % left_tag
- i = block.rfind(tag)
+ i = recursive_tagfind(left_index, "<%s" % left_tag, tag)
+# i = block.rfind(tag)
+ if i != -1:
+ i = i - len(tag)
if i > 2:
return tag.lstrip("<").rstrip(">"), i + len(p)-2 + left_index-2
return block.rstrip()[-left_index:-1].lower(), len(block)