diff options
Diffstat (limited to 'markdown/preprocessors.py')
-rw-r--r-- | markdown/preprocessors.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index c532702..1b5bc7e 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -154,9 +154,8 @@ class HtmlBlockPreprocessor(Preprocessor): def _nested_markdown_in_html(self, items): """Find and process html child elements of the given element block.""" - i = 0 - while i < len(items): - if self.left_tag_re.match(items[i]): + for i, item in enumerate(items): + if self.left_tag_re.match(item): left_tag, left_index, attrs = \ self._get_left_tag(''.join(items[i:])) right_tag, data_index = self._get_right_tag( @@ -164,10 +163,10 @@ class HtmlBlockPreprocessor(Preprocessor): right_listindex = \ self._stringindex_to_listindex(data_index, items[i:]) + i if 'markdown' in attrs.keys(): + items[i] = items[i][left_index:] # remove opening tag placeholder = self.markdown.htmlStash.store_tag( left_tag, attrs, i + 1, right_listindex + 1) - items = items[:i] + [placeholder] + \ - [items[i][left_index:]] + items[i + 1:] + items.insert(i, placeholder) if len(items) - right_listindex <= 1: # last nest, no tail right_listindex -= 1 items[right_listindex] = items[right_listindex][ @@ -179,7 +178,6 @@ class HtmlBlockPreprocessor(Preprocessor): items[i:right_listindex])) del items[i:right_listindex] items.insert(i, placeholder) - i += 1 return items def run(self, lines): @@ -272,8 +270,12 @@ class HtmlBlockPreprocessor(Preprocessor): if self.markdown_in_raw and 'markdown' in attrs.keys(): items[0] = items[0][left_index:] items[-1] = items[-1][:-len(right_tag) - 2] + if items[len(items) - 1]: # not a newline/empty string + right_index = len(items) + 3 + else: + right_index = len(items) + 2 new_blocks.append(self.markdown.htmlStash.store_tag( - left_tag, attrs, 0, len(items) + 2)) + left_tag, attrs, 0, right_index)) placeholderslen = len(self.markdown.htmlStash.tag_data) new_blocks.extend( self._nested_markdown_in_html(items)) @@ -290,9 +292,13 @@ class HtmlBlockPreprocessor(Preprocessor): if self.markdown_in_raw and 'markdown' in attrs.keys(): items[0] = items[0][left_index:] items[-1] = items[-1][:-len(right_tag) - 2] + if items[len(items) - 1]: # not a newline/empty string + right_index = len(items) + 3 + else: + right_index = len(items) + 2 new_blocks.append( self.markdown.htmlStash.store_tag( - left_tag, attrs, 0, len(items) + 2)) + left_tag, attrs, 0, right_index)) placeholderslen = len(self.markdown.htmlStash.tag_data) new_blocks.extend(self._nested_markdown_in_html(items)) nests = len(self.markdown.htmlStash.tag_data) - placeholderslen |