diff options
Diffstat (limited to 'markdown')
-rw-r--r-- | markdown/__init__.py | 2 | ||||
-rw-r--r-- | markdown/postprocessors.py | 13 | ||||
-rw-r--r-- | markdown/preprocessors.py | 44 | ||||
-rw-r--r-- | markdown/util.py | 46 |
4 files changed, 50 insertions, 55 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py index 8658e60..88f805b 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -217,7 +217,7 @@ class Markdown: } self.references = {} - self.htmlStash = preprocessors.HtmlStash() + self.htmlStash = util.HtmlStash() self.registerExtensions(extensions = extensions, configs = extension_configs) self.set_output_format(output_format) diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py index 4ce5324..b4b36de 100644 --- a/markdown/postprocessors.py +++ b/markdown/postprocessors.py @@ -8,16 +8,9 @@ processing. """ - import util -import preprocessors - -class Processor: - def __init__(self, markdown_instance=None): - if markdown_instance: - self.markdown = markdown_instance -class Postprocessor(Processor): +class Postprocessor(util.Processor): """ Postprocessors are run after the ElementTree it converted back into text. @@ -55,9 +48,9 @@ class RawHtmlPostprocessor(Postprocessor): html = util.HTML_REMOVED_TEXT if safe or not self.markdown.safeMode: text = text.replace("<p>%s</p>" % - (preprocessors.HTML_PLACEHOLDER % i), + (util.HTML_PLACEHOLDER % i), html + "\n") - text = text.replace(preprocessors.HTML_PLACEHOLDER % i, + text = text.replace(util.HTML_PLACEHOLDER % i, html) return text diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index 3b19953..567621b 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -8,18 +8,10 @@ complicated. """ import re - import util -HTML_PLACEHOLDER_PREFIX = util.STX+"wzxhzdk:" -HTML_PLACEHOLDER = HTML_PLACEHOLDER_PREFIX + "%d" + util.ETX - -class Processor: - def __init__(self, markdown_instance=None): - if markdown_instance: - self.markdown = markdown_instance -class Preprocessor (Processor): +class Preprocessor(util.Processor): """ Preprocessors are run after the text is broken into lines. @@ -39,40 +31,6 @@ class Preprocessor (Processor): """ pass -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 = [] - class HtmlBlockPreprocessor(Preprocessor): """Remove html blocks from the text and store them for later retrieval.""" 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 = [] + + |