diff options
Diffstat (limited to 'markdown/util.py')
-rw-r--r-- | markdown/util.py | 17 |
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 |