aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdocs/writing_extensions.txt26
-rwxr-xr-xmarkdown.py55
-rw-r--r--markdown_extensions/codehilite.py6
-rw-r--r--markdown_extensions/footnotes.py10
-rw-r--r--markdown_extensions/rss.py10
-rw-r--r--markdown_extensions/tables.py4
-rw-r--r--markdown_extensions/toc.py6
7 files changed, 58 insertions, 59 deletions
diff --git a/docs/writing_extensions.txt b/docs/writing_extensions.txt
index 734bf84..a97dfdb 100755
--- a/docs/writing_extensions.txt
+++ b/docs/writing_extensions.txt
@@ -22,9 +22,8 @@ features documented here.
* [TextPreprocessors][]
* [Line Preprocessors][]
* [InlinePatterns][]
-* [Postprocessors][]
- * [ElementTree Postprocessors][]
- * [TextProstprocessors][]
+* [Treeprocessors][]
+* [Prostprocessors][]
* [MarkdownParser][]
* [Working with the ElementTree][]
* [Integrating your code into Markdown][]
@@ -157,15 +156,15 @@ a table of contents, or raw html.
There are two types of postprocessors: [ElementTree Postprocessors][] and
[TextPostprocessors][].
-<h4 id="etpostprocessors">ElementTree Postprocessors</h4>
+<h3 id="treeprocessors">Treeprocessors</h3>
-An ElementTree Postprocessor should inherit from ``markdown.Postprocessor``,
-over-ride the ``run`` method which takes one argument ``root`` and returns
-either that root element or a modified root element.
+An Treeprocessor should inherit from ``markdown.Treeprocessor``,
+over-ride the ``run`` method which takes one argument ``root`` (an Elementree
+object) and returns either that root element or a modified root element.
A pseudo example:
- class MyPostprocessor(markdown.Postprocessor):
+ class MyTreeprocessor(markdown.Treeprocessor):
def run(self, root):
#do stufff
return my_modified_root
@@ -173,17 +172,17 @@ A pseudo example:
For specifics on manipulating the ElementTree, see
[Working with the ElementTree][] below.
-<h4 id="textpostprocessors">TextPostprocessors</h4>
+<h3 id="postprocessors">Postprocessors</h3>
-A TextPostprocessor should inherit from ``markdown.TextPostprocessor`` and
+A Postprocessor should inherit from ``markdown.Postprocessor`` and
over-ride the ``run`` method which takes one argument ``text`` and returns a
Unicode string.
-TextPostprocessors are run after the ElementTree has been serialized back into
+Postprocessors are run after the ElementTree has been serialized back into
Unicode text. For example, this may be an appropriate place to add a table of
contents to a document:
- class TocTextPostprocessor(markdown.TextPostprocessor):
+ class TocPostprocessor(markdown.Postprocessor):
def run(self, text):
return MYMARKERRE.sub(MyToc, text)
@@ -461,9 +460,8 @@ than one residing in a module.
[TextPreprocessors]: #textpreprocessors
[Line Preprocessors]: #linepreprocessors
[InlinePatterns]: #inlinepatterns
+[Treeprocessors]: #treeprocessors
[Postprocessors]: #postprocessors
-[ElementTree Postprocessors]: #etpostprocessors
-[TextProstprocessors]: #textpostprocessors
[MarkdownParser]: #markdownparser
[Working with the ElementTree]: #working_with_et
[Integrating your code into Markdown]: #integrating_into_markdown
diff --git a/markdown.py b/markdown.py
index 972e827..ae179b4 100755
--- a/markdown.py
+++ b/markdown.py
@@ -1458,43 +1458,44 @@ Markdown also allows post-processors, which are similar to preprocessors in
that they need to implement a "run" method. However, they are run after core
processing.
-There are two types of post-processors: Postprocessor and TextPostprocessor
+There are two types of post-processors: Treeprocessor and Postprocessor
"""
-class Postprocessor (Processor):
+class Treeprocessor(Processor):
"""
- Postprocessors are run before the ElementTree serialization.
+ Treeprocessors are run on the ElementTree object before serialization.
- Each Postprocessor implements a "run" method that takes a pointer to a
- ElementTree, modifies it as necessary and returns a ElementTree
- document.
+ Each Treeprocessor implements a "run" method that takes a pointer to an
+ ElementTree, modifies it as necessary and returns an ElementTree
+ object.
- Postprocessors must extend markdown.Postprocessor.
+ Treeprocessors must extend markdown.Treeprocessor.
"""
def run(self, root):
"""
- Subclasses of Postprocessor should implement a `run` method, which
- takes a root Element. Method can return another Element, and global
- root Element will be replaced, or just modify current and return None.
+ Subclasses of Treeprocessor should implement a `run` method, which
+ takes a root ElementTree. This method can return another ElementTree
+ object, and the existing root ElementTree will be replaced, or it can
+ modify the current tree and return None.
"""
pass
-class TextPostprocessor (Processor):
+class Postprocessor(Processor):
"""
- TextPostprocessors are run after the ElementTree it converted back into text.
+ Postprocessors are run after the ElementTree it converted back into text.
- Each TextPostprocessor implements a "run" method that takes a pointer to a
+ Each Postprocessor implements a "run" method that takes a pointer to a
text string, modifies it as necessary and returns a text string.
- TextPostprocessors must extend markdown.TextPostprocessor.
+ Postprocessors must extend markdown.Postprocessor.
"""
def run(self, text):
"""
- Subclasses of TextPostprocessor should implement a `run` method, which
+ Subclasses of Postprocessor should implement a `run` method, which
takes the html document as a single text string and returns a
(possibly modified) string.
@@ -1502,7 +1503,7 @@ class TextPostprocessor (Processor):
pass
-class PrettifyPostprocessor(Postprocessor):
+class PrettifyTreeprocessor(Treeprocessor):
"""Add linebreaks to the html document."""
def _prettifyETree(self, elem):
"""Recursively add linebreaks to ElementTree children."""
@@ -1532,7 +1533,7 @@ class PrettifyPostprocessor(Postprocessor):
br.tail = '\n%s' % br.tail
-class RawHtmlTextPostprocessor(TextPostprocessor):
+class RawHtmlPostprocessor(Postprocessor):
""" Restore raw html to the document. """
def run(self, text):
@@ -1560,7 +1561,7 @@ class RawHtmlTextPostprocessor(TextPostprocessor):
return html.replace('"', '&quot;')
-class AndSubstitutePostprocessor(TextPostprocessor):
+class AndSubstitutePostprocessor(Postprocessor):
""" Restore valid entities """
def __init__(self):
pass
@@ -1799,12 +1800,12 @@ class Markdown:
self.preprocessors.add("reference", ReferencePreprocessor(self))
# footnote preprocessor will be inserted with "<reference"
- self.postprocessors = Treap()
- self.postprocessors.add("prettify", PrettifyPostprocessor(self))
+ self.treeprocessors = Treap()
+ self.treeprocessors.add("prettify", PrettifyTreeprocessor(self))
- self.textPostprocessors = Treap()
- self.textPostprocessors.add("raw_html", RawHtmlTextPostprocessor(self))
- self.textPostprocessors.add("amp_substitute", AndSubstitutePostprocessor())
+ self.postprocessors = Treap()
+ self.postprocessors.add("raw_html", RawHtmlPostprocessor(self))
+ self.postprocessors.add("amp_substitute", AndSubstitutePostprocessor())
# footnote postprocessor will be inserted with ">amp_substitute"
self.prePatterns = []
@@ -1920,9 +1921,9 @@ class Markdown:
inlineProcessor = InlineProcessor(self.inlinePatterns.heapsorted())
root = inlineProcessor.applyInlinePatterns(tree).getroot()
- # Run the post-processors
- for postprocessor in self.postprocessors.heapsorted():
- newRoot = postprocessor.run(root)
+ # Run the tree-processors
+ for treeprocessor in self.treeprocessors.heapsorted():
+ newRoot = treeprocessor.run(root)
if newRoot:
root = newRoot
@@ -1932,7 +1933,7 @@ class Markdown:
xml = xml.strip()[44:-7] + "\n"
# Run the text post-processors
- for pp in self.textPostprocessors.heapsorted():
+ for pp in self.postprocessors.heapsorted():
xml = pp.run(xml)
return xml.strip()
diff --git a/markdown_extensions/codehilite.py b/markdown_extensions/codehilite.py
index 9371e79..bc75da2 100644
--- a/markdown_extensions/codehilite.py
+++ b/markdown_extensions/codehilite.py
@@ -175,7 +175,7 @@ class CodeHilite:
# ------------------ The Markdown Extension -------------------------------
-class HilitePostprocessor(markdown.Postprocessor):
+class HiliteTreeprocessor(markdown.Treeprocessor):
""" Hilight source code in code blocks. """
def run(self, root):
@@ -214,9 +214,9 @@ class CodeHiliteExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
""" Add HilitePostprocessor to Markdown instance. """
- hiliter = HilitePostprocessor(md)
+ hiliter = HiliteTreeprocessor(md)
hiliter.config = self.config
- md.postprocessors.add("hilite", hiliter, "_begin")
+ md.treeprocessors.add("hilite", hiliter, "_begin")
def makeExtension(configs={}):
diff --git a/markdown_extensions/footnotes.py b/markdown_extensions/footnotes.py
index 39379f3..2b5795d 100644
--- a/markdown_extensions/footnotes.py
+++ b/markdown_extensions/footnotes.py
@@ -60,11 +60,11 @@ class FootnoteExtension (markdown.Extension):
md.inlinePatterns.add("footnote", FootnotePattern(FOOTNOTE_RE, self),
"<reference")
- # Insert a post-processor that would actually add the footnote div
- md.postprocessors.add("footnote", FootnotePostprocessor(self),
+ # Insert a tree-processor that would actually add the footnote div
+ md.treeprocessors.add("footnote", FootnoteTreeprocessor(self),
"_end")
- md.textPostprocessors.add("footnote", FootnoteTextPostprocessor(self),
+ md.postprocessors.add("footnote", FootnotePostprocessor(self),
">amp_substitute")
def reset(self) :
@@ -216,7 +216,7 @@ class FootnotePattern (markdown.Pattern) :
a.text = str(num)
return sup
-class FootnotePostprocessor (markdown.Postprocessor):
+class FootnoteTreeprocessor (markdown.Treeprocessor):
def __init__ (self, footnotes) :
self.footnotes = footnotes
@@ -239,7 +239,7 @@ class FootnotePostprocessor (markdown.Postprocessor):
else :
root.append(footnotesDiv)
-class FootnoteTextPostprocessor (markdown.Postprocessor):
+class FootnotePostprocessor (markdown.Postprocessor):
def run(self, text) :
return text.replace(FN_BACKLINK_TEXT, "&#8617;")
diff --git a/markdown_extensions/rss.py b/markdown_extensions/rss.py
index b88b9b5..fa05fef 100644
--- a/markdown_extensions/rss.py
+++ b/markdown_extensions/rss.py
@@ -51,14 +51,14 @@ class RssExtension (markdown.Extension):
md.xml_mode = True
- # Insert a post-processor that would actually add the title tag
- postprocessor = RssPostProcessor(self)
- postprocessor.ext = self
- md.postprocessors.append(postprocessor)
+ # Insert a tree-processor that would actually add the title tag
+ treeprocessor = RssTreeProcessor(self)
+ treeprocessor.ext = self
+ md.treeprocessors.append(treeprocessor)
md.stripTopLevelTags = 0
md.docType = '<?xml version="1.0" encoding="utf-8"?>\n'
-class RssPostProcessor (markdown.Postprocessor):
+class RssTreeProcessor (markdown.Treeprocessor):
def __init__(self, md):
diff --git a/markdown_extensions/tables.py b/markdown_extensions/tables.py
index c485f55..5339ae1 100644
--- a/markdown_extensions/tables.py
+++ b/markdown_extensions/tables.py
@@ -38,7 +38,7 @@ class TablePattern(markdown.Pattern) :
return tr
-class TablePostprocessor:
+class TableTreeprocessor(markdown.Treeprocessor):
def _findElement(self, element, name):
result = []
@@ -62,7 +62,7 @@ class TablePostprocessor:
class TableExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
md.inlinePatterns.add('table', TablePattern(md), "<backtick")
- md.postprocessors['table'] = TablePostprocessor()
+ md.treeprocessors['table'] = TableTreeprocessor()
def makeExtension(configs):
diff --git a/markdown_extensions/toc.py b/markdown_extensions/toc.py
index ccc927c..00cf537 100644
--- a/markdown_extensions/toc.py
+++ b/markdown_extensions/toc.py
@@ -12,7 +12,7 @@ import markdown
from markdown import etree
import re
-class TocPostprocessor (markdown.Postprocessor):
+class TocTreeprocessor (markdown.Treeprocessor):
# Iterator wrapper to get parent and child all at once
def iterparent(self, root):
for parent in root.getiterator():
@@ -119,9 +119,9 @@ class TocExtension (markdown.Extension):
return re.sub('[-\s]+','-',value)
def extendMarkdown(self, md, md_globals) :
- tocext = TocPostprocessor(md)
+ tocext = TocTreeprocessor(md)
tocext.config = self.config
- md.postprocessors.add("toc", tocext, "_begin")
+ md.treeprocessors.add("toc", tocext, "_begin")
def makeExtension(configs={}) :
return TocExtension(configs=configs)