aboutsummaryrefslogtreecommitdiffstats
path: root/markdown.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2008-10-20 10:11:34 -0400
committerWaylan Limberg <waylan@gmail.com>2008-10-20 10:11:34 -0400
commit952d12302ab156cc9b289c45a96d0e3f0e7766e0 (patch)
tree6642436baa2d403ffe34f0bcc33a18a859fe5eca /markdown.py
parent3fc06a968ee2548254efd08d46b5a4d46ac7e3a8 (diff)
downloadmarkdown-952d12302ab156cc9b289c45a96d0e3f0e7766e0.tar.gz
markdown-952d12302ab156cc9b289c45a96d0e3f0e7766e0.tar.bz2
markdown-952d12302ab156cc9b289c45a96d0e3f0e7766e0.zip
Combined the TextPreprocessors and Preprocessors into Preprocessors. Updated extensions and docs as well.
Diffstat (limited to 'markdown.py')
-rwxr-xr-xmarkdown.py41
1 files changed, 7 insertions, 34 deletions
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>", "%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 "<reference"
@@ -1890,10 +1867,6 @@ class Markdown:
source = source.replace("\r\n", "\n").replace("\r", "\n") + "\n\n"
source = source.expandtabs(TAB_LENGTH)
- # Run the text preprocessors
- for pp in self.textPreprocessors.heapsorted():
- source = pp.run(source)
-
# Split into lines and run the line preprocessors.
self.lines = source.split("\n")
for prep in self.preprocessors.heapsorted():