aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2014-05-22 10:34:00 -0400
committerWaylan Limberg <waylan.limberg@icloud.com>2014-05-22 10:34:00 -0400
commitbdb1bda20f484ee15f766c06f9e327bede3aea58 (patch)
treea82f139b79fd833fa73d58f40c597235fb689801
parent85be15973e754da6cdee855968f9464676520667 (diff)
parenta47899fd0f8f6086a3682abbbbbd75b60928d8c7 (diff)
downloadmarkdown-bdb1bda20f484ee15f766c06f9e327bede3aea58.tar.gz
markdown-bdb1bda20f484ee15f766c06f9e327bede3aea58.tar.bz2
markdown-bdb1bda20f484ee15f766c06f9e327bede3aea58.zip
Merge pull request #310 from ryneeverett/issue308
Fix issue308 and fix (unrelated) failure to break out of nest loop.
-rw-r--r--markdown/extensions/extra.py32
-rw-r--r--markdown/preprocessors.py6
-rw-r--r--tests/extensions/extra/raw-html.html8
-rw-r--r--tests/extensions/extra/raw-html.txt7
4 files changed, 30 insertions, 23 deletions
diff --git a/markdown/extensions/extra.py b/markdown/extensions/extra.py
index c4a0a97..8986ba6 100644
--- a/markdown/extensions/extra.py
+++ b/markdown/extensions/extra.py
@@ -75,12 +75,9 @@ 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
- 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 = \
- self.parser.markdown.htmlStash.tag_data[i]['right_index']
+ while len(self._tag_data) > i and self._tag_data[i]['left_index']:
+ left_child_index = self._tag_data[i]['left_index']
+ right_child_index = self._tag_data[i]['right_index']
nest_index.append((left_child_index - 1, right_child_index))
i += 1
@@ -92,35 +89,32 @@ class MarkdownInHtmlProcessor(BlockProcessor):
block[nest_index[-1][1]:], True) # nest
def run(self, parent, blocks, tail=None, nest=False):
+ self._tag_data = self.parser.markdown.htmlStash.tag_data
+
self.parser.blockprocessors.tag_counter += 1
- tag_data = self.parser.markdown.htmlStash.tag_data[
- self.parser.blockprocessors.tag_counter]
+ tag = self._tag_data[self.parser.blockprocessors.tag_counter]
# Create Element
- markdown_value = tag_data['attrs'].pop('markdown')
- element = util.etree.SubElement(parent, tag_data['tag'],
- tag_data['attrs'])
+ markdown_value = tag['attrs'].pop('markdown')
+ element = util.etree.SubElement(parent, tag['tag'], tag['attrs'])
# Slice Off Block
if nest:
self.parser.parseBlocks(parent, tail) # Process Tail
block = blocks[1:]
else: # includes nests since a third level of nesting isn't supported
- block = blocks[tag_data['left_index'] + 1:
- tag_data['right_index']]
- del blocks[:tag_data['right_index']]
+ block = blocks[tag['left_index'] + 1: tag['right_index']]
+ del blocks[:tag['right_index']]
# Process Text
if (self.parser.blockprocessors.contain_span_tags.match( # Span Mode
- tag_data['tag']) and markdown_value != 'block') or \
+ tag['tag']) and markdown_value != 'block') or \
markdown_value == 'span':
element.text = '\n'.join(block)
else: # Block Mode
i = self.parser.blockprocessors.tag_counter + 1
- if len(self.parser.markdown.htmlStash.tag_data) > i and self.\
- parser.markdown.htmlStash.tag_data[i]['left_index']:
- first_subelement_index = self.parser.markdown.htmlStash.\
- tag_data[i]['left_index'] - 1
+ if len(self._tag_data) > i and self._tag_data[i]['left_index']:
+ first_subelement_index = self._tag_data[i]['left_index'] - 1
self.parser.parseBlocks(
element, block[:first_subelement_index])
if not nest:
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py
index 1e10cfc..5bfca55 100644
--- a/markdown/preprocessors.py
+++ b/markdown/preprocessors.py
@@ -143,7 +143,7 @@ class HtmlBlockPreprocessor(Preprocessor):
"""
Same effect as concatenating the strings in items,
finding the character to which stringindex refers in that string,
- and returning the item in which that character resides.
+ and returning the index of the item in which that character resides.
"""
items.append('dummy')
i, count = 0, 0
@@ -175,8 +175,8 @@ class HtmlBlockPreprocessor(Preprocessor):
if len(items) - right_listindex <= 1: # last element
right_listindex -= 1
placeholder = self.markdown.htmlStash.store('\n\n'.join(
- items[i:right_listindex]))
- del items[i:right_listindex]
+ items[i:right_listindex + 1]))
+ del items[i:right_listindex + 1]
items.insert(i, placeholder)
return items
diff --git a/tests/extensions/extra/raw-html.html b/tests/extensions/extra/raw-html.html
index 897ad24..f8874c3 100644
--- a/tests/extensions/extra/raw-html.html
+++ b/tests/extensions/extra/raw-html.html
@@ -27,5 +27,11 @@ Note: Subelements are not required to have tail text.</div>
Raw html blocks may also be nested.
</div>
+
+
</div>
-<p>This text is after the markdown in html.</p> \ No newline at end of file
+<p>This text is after the markdown in html.</p>
+<div name="issue308">
+<p><span>1</span>
+<span>2</span></p>
+</div> \ No newline at end of file
diff --git a/tests/extensions/extra/raw-html.txt b/tests/extensions/extra/raw-html.txt
index e906910..0a82ccf 100644
--- a/tests/extensions/extra/raw-html.txt
+++ b/tests/extensions/extra/raw-html.txt
@@ -44,3 +44,10 @@ Raw html blocks may also be nested.
</div>
This text is after the markdown in html.
+
+<div markdown="1" name="issue308">
+
+<span>1</span>
+<span>2</span>
+
+</div>