aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/util.py
diff options
context:
space:
mode:
authorryneeverett <ryneeverett@gmail.com>2013-10-03 16:51:07 -0400
committerryneeverett <ryneeverett@gmail.com>2013-10-14 01:38:14 -0400
commitdaa2d46b567e67aa4578a5c26a7d92e4cf5abc81 (patch)
treec9b329436683582b18e219b5061f9a84ec7f718d /markdown/util.py
parent191d88b26c6bcb1cd9f66cb3a115e106366d1a55 (diff)
downloadmarkdown-daa2d46b567e67aa4578a5c26a7d92e4cf5abc81.tar.gz
markdown-daa2d46b567e67aa4578a5c26a7d92e4cf5abc81.tar.bz2
markdown-daa2d46b567e67aa4578a5c26a7d92e4cf5abc81.zip
Issue #52
Diffstat (limited to 'markdown/util.py')
-rw-r--r--markdown/util.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/markdown/util.py b/markdown/util.py
index d0ef8a3..8c2e6d7 100644
--- a/markdown/util.py
+++ b/markdown/util.py
@@ -40,6 +40,7 @@ INLINE_PLACEHOLDER_RE = re.compile(INLINE_PLACEHOLDER % r'([0-9]{4})')
AMP_SUBSTITUTE = STX+"amp"+ETX
HTML_PLACEHOLDER = STX + "wzxhzdk:%s" + ETX
HTML_PLACEHOLDER_RE = re.compile(HTML_PLACEHOLDER % r'([0-9]+)')
+TAG_PLACEHOLDER = STX + "hzzhzkh:%s" + ETX
"""
@@ -119,10 +120,12 @@ class HtmlStash(object):
in the beginning and replace with place-holders.
"""
- def __init__ (self):
+ def __init__(self):
""" Create a HtmlStash. """
- self.html_counter = 0 # for counting inline html segments
- self.rawHtmlBlocks=[]
+ self.html_counter = 0 # for counting inline html segments
+ self.rawHtmlBlocks = []
+ self.tag_counter = 0
+ self.tag_data = [] # list of dictionaries in the order tags appear
def store(self, html, safe=False):
"""
@@ -150,3 +153,11 @@ class HtmlStash(object):
def get_placeholder(self, key):
return HTML_PLACEHOLDER % key
+ def store_tag(self, tag, attrs, left_index, right_index):
+ """Store tag data and return a placeholder."""
+ self.tag_data.append({'tag': tag, 'attrs': attrs,
+ 'left_index': left_index,
+ 'right_index': right_index})
+ placeholder = TAG_PLACEHOLDER % str(self.tag_counter)
+ self.tag_counter += 1 # equal to the tag's index in self.tag_data
+ return placeholder