From 952d12302ab156cc9b289c45a96d0e3f0e7766e0 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 20 Oct 2008 10:11:34 -0400 Subject: Combined the TextPreprocessors and Preprocessors into Preprocessors. Updated extensions and docs as well. --- markdown.py | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) (limited to 'markdown.py') diff --git a/markdown.py b/markdown.py index c16b6d6..a8b4455 100755 --- a/markdown.py +++ b/markdown.py @@ -581,8 +581,7 @@ PRE-PROCESSORS ============================================================================= Preprocessors work on source text before we start doing anything too -complicated. There are two types of preprocessors: TextPreprocessor and -Preprocessor. +complicated. """ class Processor: @@ -590,27 +589,6 @@ class Processor: if markdown_instance: self.markdown = markdown_instance -class TextPreprocessor (Processor): - """ - TextPreprocessors are run before the text is broken into lines. - - Each TextPreprocessor implements a "run" method that takes a pointer to a - text string of the document, modifies it as necessary and returns - either the same pointer or a pointer to a new string. - - TextPreprocessors must extend markdown.TextPreprocessor. - - """ - - def run(self, text): - """ - Each subclass of TextPreprocessor should override the `run` method, - which takes the document text as a single string and returns the - (possibly modified) document as a single string. - - """ - pass - class Preprocessor (Processor): """ @@ -633,7 +611,7 @@ class Preprocessor (Processor): pass -class HtmlBlockPreprocessor(TextPreprocessor): +class HtmlBlockPreprocessor(Preprocessor): """Remove html blocks from the text and store them for later retrieval.""" right_tag_patterns = ["", "%s>"] @@ -665,7 +643,8 @@ class HtmlBlockPreprocessor(TextPreprocessor): def _is_oneliner(self, tag): return (tag in ['hr', 'hr/']) - def run(self, text): + def run(self, lines): + text = "\n".join(lines) new_blocks = [] text = text.split("\n\n") items = [] @@ -742,7 +721,8 @@ class HtmlBlockPreprocessor(TextPreprocessor): new_blocks.append(self.markdown.htmlStash.store('\n\n'.join(items))) new_blocks.append('\n') - return "\n\n".join(new_blocks) + new_text = "\n\n".join(new_blocks) + return new_text.split("\n") class HeaderPreprocessor(Preprocessor): @@ -1781,12 +1761,9 @@ class Markdown: self.docType = "" self.stripTopLevelTags = True - self.textPreprocessors = Treap() - self.textPreprocessors.add("html_block", - HtmlBlockPreprocessor(self)) self.preprocessors = Treap() + self.preprocessors.add("html_block", HtmlBlockPreprocessor(self)) self.preprocessors.add("header", HeaderPreprocessor(self)) - self.preprocessors.add("line", LinePreprocessor(self)) self.preprocessors.add("reference", ReferencePreprocessor(self)) # footnote preprocessor will be inserted with "