‹›
markdown.treeprocessors
¶
Tree processors manipulate the tree created by block processors. They can even create an entirely
new ElementTree object. This is an excellent place for creating summaries, adding collected
references, or last minute adjustments.
Classes:
-
Treeprocessor–Treeprocessors are run on theElementTreeobject before serialization. -
InlineProcessor–A
Treeprocessorthat traverses a tree, applying inline patterns. -
PrettifyTreeprocessor–Add line breaks to the html document.
-
UnescapeTreeprocessor–Restore escaped chars
Functions:
-
build_treeprocessors–Build the default
treeprocessorsfor Markdown. -
isString–Return
Trueif object is a string but not anAtomicString.
‹›
markdown.treeprocessors.build_treeprocessors(md: Markdown, **kwargs: Any) -> util.Registry[Treeprocessor]
¶
Build the default treeprocessors for Markdown.
Return a Registry instance which contains the following collection of classes with their assigned names and priorities.
| Class Instance | Name | Priority |
|---|---|---|
InlineProcessor |
inline |
20 |
PrettifyTreeprocessor |
prettify |
10 |
UnescapeTreeprocessor |
unescape |
0 |
‹›
markdown.treeprocessors.isString(s: object) -> bool
¶
Return True if object is a string but not an AtomicString.
‹›
markdown.treeprocessors.Treeprocessor(md: Markdown | None = None)
¶
Bases: Processor
Treeprocessors are run on the ElementTree object before serialization.
Each Treeprocessor implements a run method that takes a pointer to an
Element and modifies it as necessary.
Treeprocessors must extend markdown.Treeprocessor.
Methods:
-
run–Subclasses of
Treeprocessorshould implement arunmethod, which
‹›
markdown.treeprocessors.Treeprocessor.run(root: etree.Element) -> etree.Element | None
¶
Subclasses of Treeprocessor should implement a run method, which
takes a root Element. This method can return another Element
object, and the existing root Element will be replaced, or it can
modify the current tree and return None.
‹›
markdown.treeprocessors.InlineProcessor(md: Markdown)
¶
Bases: Treeprocessor
A Treeprocessor that traverses a tree, applying inline patterns.
Methods:
-
run–Apply inline patterns to a parsed Markdown tree.
‹›
markdown.treeprocessors.InlineProcessor.run(tree: etree.Element, ancestors: list[str] | None = None) -> etree.Element
¶
Apply inline patterns to a parsed Markdown tree.
Iterate over Element, find elements with inline tag, apply inline
patterns and append newly created Elements to tree. To avoid further
processing of string with inline patterns, instead of normal string,
use subclass AtomicString:
node.text = markdown.util.AtomicString("This will not be processed.")
Parameters:
-
tree(Element) –Elementobject, representing Markdown tree. -
ancestors(list[str] | None, default:None) –List of parent tag names that precede the tree node (if needed).
Returns:
-
Element–An element tree object with applied inline patterns.
‹›
markdown.treeprocessors.PrettifyTreeprocessor(md: Markdown | None = None)
¶
Bases: Treeprocessor
Add line breaks to the html document.
Methods:
-
run–Add line breaks to
Elementobject and its children.
‹›
markdown.treeprocessors.UnescapeTreeprocessor(md: Markdown | None = None)
¶
Bases: Treeprocessor
Restore escaped chars
Methods:
-
run–Loop over all elements and unescape all text.

