From 0887ea58b0c2221c1328ad087b3bf5ee292fc402 Mon Sep 17 00:00:00 2001 From: Gerry LaMontagne Date: Mon, 30 Aug 2010 21:56:27 -0400 Subject: Refactored fix- created method from local function for search. Fixes ticket 62. --- markdown/preprocessors.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'markdown/preprocessors.py') 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 -- cgit v1.2.3