diff options
author | Gerry LaMontagne <gjlama94@gmail.com> | 2010-08-30 21:56:27 -0400 |
---|---|---|
committer | Gerry LaMontagne <gjlama94@gmail.com> | 2010-08-31 16:40:02 -0400 |
commit | 0887ea58b0c2221c1328ad087b3bf5ee292fc402 (patch) | |
tree | a972895dd3a9ca3467218343c3fa003f461294a0 | |
parent | 6ef287f5bafa167c01c74b84778b6ed531988bef (diff) | |
download | markdown-0887ea58b0c2221c1328ad087b3bf5ee292fc402.tar.gz markdown-0887ea58b0c2221c1328ad087b3bf5ee292fc402.tar.bz2 markdown-0887ea58b0c2221c1328ad087b3bf5ee292fc402.zip |
Refactored fix- created method from local function for search. Fixes ticket 62.
-rw-r--r-- | markdown/preprocessors.py | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index f2dcd10..2bd85b0 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -81,32 +81,32 @@ class HtmlBlockPreprocessor(Preprocessor): tag = block[1:].replace(">", " ", 1).split()[0].lower() return tag, len(tag)+2, {} - def _get_right_tag(self, left_tag, left_index, block): - def recursive_tagfind(ltag, rtag, start_index): - 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) - # 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 + def _recursive_tagfind(self, ltag, rtag, start_index, block): + 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) + # another ltag found before rtag, use end of ltag as starting + # point and search again + j = block.find('>', j) + start_index = self._recursive_tagfind(ltag, rtag, j + 1, block) + if start_index == -1: + # HTML potentially malformed- ltag has no corresponding + # rtag + return -1 + def _get_right_tag(self, left_tag, left_index, block): for p in self.right_tag_patterns: tag = p % left_tag - i = recursive_tagfind("<%s" % left_tag, tag, left_index) + i = self._recursive_tagfind("<%s" % left_tag, tag, left_index, block) if i > 2: return tag.lstrip("<").rstrip(">"), i return block.rstrip()[-left_index:-1].lower(), len(block) - + def _equal_tags(self, left_tag, right_tag): if left_tag[0] in ['?', '@', '%']: # handle PHP, etc. return True |