aboutsummaryrefslogtreecommitdiffstats
path: root/markdown
diff options
context:
space:
mode:
authorryneeverett <ryneeverett@gmail.com>2013-10-03 16:51:07 -0400
committerryneeverett <ryneeverett@gmail.com>2013-11-19 18:28:02 -0500
commitb11926de44429e8a17df5ea74db7a1edcc6b2dcb (patch)
tree82a1dad4c737ee326589713d134ddb9901f235b1 /markdown
parent03029616a9f40b4e8affab981818e47a9507acd9 (diff)
downloadmarkdown-b11926de44429e8a17df5ea74db7a1edcc6b2dcb.tar.gz
markdown-b11926de44429e8a17df5ea74db7a1edcc6b2dcb.tar.bz2
markdown-b11926de44429e8a17df5ea74db7a1edcc6b2dcb.zip
Miscellaneous improvements and bug fixes.
Diffstat (limited to 'markdown')
-rw-r--r--markdown/extensions/extra.py12
-rw-r--r--markdown/preprocessors.py22
2 files changed, 19 insertions, 15 deletions
diff --git a/markdown/extensions/extra.py b/markdown/extensions/extra.py
index dd70305..c4a0a97 100644
--- a/markdown/extensions/extra.py
+++ b/markdown/extensions/extra.py
@@ -75,8 +75,8 @@ class MarkdownInHtmlProcessor(BlockProcessor):
# Build list of indexes of each nest within the parent element.
nest_index = [] # a list of tuples: (left index, right index)
i = self.parser.blockprocessors.tag_counter + 1
- while len(self.parser.markdown.htmlStash.tag_data) > i and self.\
- parser.markdown.htmlStash.tag_data[i]['left_index']:
+ is_nest = self.parser.markdown.htmlStash.tag_data[i]['left_index']
+ while len(self.parser.markdown.htmlStash.tag_data) > i and is_nest:
left_child_index = \
self.parser.markdown.htmlStash.tag_data[i]['left_index']
right_child_index = \
@@ -85,11 +85,9 @@ class MarkdownInHtmlProcessor(BlockProcessor):
i += 1
# Create each nest subelement.
- i = 0
- for n in nest_index[:-1]:
- self.run(element, block[n[0]:n[1]],
- block[n[1]:nest_index[i + 1][0]], True)
- i += 1
+ for i, (left_index, right_index) in enumerate(nest_index[:-1]):
+ self.run(element, block[left_index:right_index],
+ block[right_index:nest_index[i + 1][0]], True)
self.run(element, block[nest_index[-1][0]:nest_index[-1][1]], # last
block[nest_index[-1][1]:], True) # nest
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