aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerry LaMontagne <gjlama94@gmail.com>2010-08-30 12:36:41 -0400
committerGerry LaMontagne <gjlama94@gmail.com>2010-08-30 12:46:26 -0400
commit6ef287f5bafa167c01c74b84778b6ed531988bef (patch)
tree05933d6149dd4b2bf29d7b20463c4429fc914ca9
parentae30d3a3070c3e3bdf24595bf28bd7c150bc7abf (diff)
downloadmarkdown-6ef287f5bafa167c01c74b84778b6ed531988bef.tar.gz
markdown-6ef287f5bafa167c01c74b84778b6ed531988bef.tar.bz2
markdown-6ef287f5bafa167c01c74b84778b6ed531988bef.zip
Further improvements to closing tag search in HtmlBlockProcessors
-rw-r--r--markdown/preprocessors.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py
index c23d728..f2dcd10 100644
--- a/markdown/preprocessors.py
+++ b/markdown/preprocessors.py
@@ -82,7 +82,7 @@ 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):
+ def recursive_tagfind(ltag, rtag, start_index):
while 1:
i = block.find(rtag, start_index)
if i == -1:
@@ -91,16 +91,20 @@ class HtmlBlockPreprocessor(Preprocessor):
# 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)
+ # another ltag found before rtag, use end of ltag as starting
+ # point and search again
+ j = block.find('>', j)
+ start_index = recursive_tagfind(ltag, rtag, j + 1)
+ if start_index == -1:
+ # HTML potentially malformed- ltag has no corresponding
+ # rtag
+ return -1
for p in self.right_tag_patterns:
tag = p % left_tag
- i = recursive_tagfind(left_index, "<%s" % left_tag, tag)
-# i = block.rfind(tag)
- if i != -1:
- i = i - len(tag)
+ i = recursive_tagfind("<%s" % left_tag, tag, left_index)
if i > 2:
- return tag.lstrip("<").rstrip(">"), i + len(p)-2 + left_index-2
+ return tag.lstrip("<").rstrip(">"), i
return block.rstrip()[-left_index:-1].lower(), len(block)
def _equal_tags(self, left_tag, right_tag):