diff options
author | Waylan Limberg <waylan@gmail.com> | 2010-07-06 14:09:02 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2010-07-06 14:09:02 -0400 |
commit | 2b6754adb0f43e1853726f2c936dbf81c1b40736 (patch) | |
tree | 8a34ee9497053a89b67cefb18e4197649220951d /markdown/util.py | |
parent | 543027d73f2d9bf66fc8b56c18acfd1c987b1a8d (diff) | |
download | markdown-2b6754adb0f43e1853726f2c936dbf81c1b40736.tar.gz markdown-2b6754adb0f43e1853726f2c936dbf81c1b40736.tar.bz2 markdown-2b6754adb0f43e1853726f2c936dbf81c1b40736.zip |
Moved HtmlStash and base Prosessor classes to the new util module.
Diffstat (limited to 'markdown/util.py')
-rw-r--r-- | markdown/util.py | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/markdown/util.py b/markdown/util.py index c170368..d1485db 100644 --- a/markdown/util.py +++ b/markdown/util.py @@ -33,7 +33,8 @@ ETX = u'\u0003' # Use ETX ("End of text") for end-of-placeholder INLINE_PLACEHOLDER_PREFIX = STX+"klzzwxh:" INLINE_PLACEHOLDER = INLINE_PLACEHOLDER_PREFIX + "%s" + ETX AMP_SUBSTITUTE = STX+"amp"+ETX - +HTML_PLACEHOLDER_PREFIX = STX+"wzxhzdk:" +HTML_PLACEHOLDER = HTML_PLACEHOLDER_PREFIX + "%d" + ETX """ Constants you probably do not need to change @@ -70,3 +71,46 @@ MISC AUXILIARY CLASSES class AtomicString(unicode): """A string which should not be further processed.""" pass + + +class Processor: + def __init__(self, markdown_instance=None): + if markdown_instance: + self.markdown = markdown_instance + + +class HtmlStash: + """ + This class is used for stashing HTML objects that we extract + in the beginning and replace with place-holders. + """ + + def __init__ (self): + """ Create a HtmlStash. """ + self.html_counter = 0 # for counting inline html segments + self.rawHtmlBlocks=[] + + def store(self, html, safe=False): + """ + Saves an HTML segment for later reinsertion. Returns a + placeholder string that needs to be inserted into the + document. + + Keyword arguments: + + * html: an html segment + * safe: label an html segment as safe for safemode + + Returns : a placeholder string + + """ + self.rawHtmlBlocks.append((html, safe)) + placeholder = HTML_PLACEHOLDER % self.html_counter + self.html_counter += 1 + return placeholder + + def reset(self): + self.html_counter = 0 + self.rawHtmlBlocks = [] + + |