‹› markdown.postprocessors

Post-processors run on the text of the entire document after is has been serialized into a string. Postprocessors should be used to work with the text just before output. Usually, they are used add back sections that were extracted in a preprocessor, fix up outgoing encodings, or wrap the whole document.

‹› markdown.postprocessors.build_postprocessors(md: Markdown, **kwargs: Any) -> util.Registry[Postprocessor]

Build the default postprocessors for Markdown.

Return a Registry instance which contains the following collection of classes with their assigned names and priorities.

Class Instance Name Priority
RawHtmlPostprocessor raw_html 30
AndSubstitutePostprocessor amp_substitute 20

‹› markdown.postprocessors.Postprocessor(md: Markdown | None = None)

Bases: Processor

Postprocessors are run after the ElementTree it converted back into text.

Each Postprocessor implements a run method that takes a pointer to a text string, modifies it as necessary and returns a text string.

Postprocessors must extend Postprocessor.

‹› markdown.postprocessors.Postprocessor.run(text: str) -> str

Subclasses of Postprocessor should implement a run method, which takes the html document as a single text string and returns a (possibly modified) string.

‹› markdown.postprocessors.RawHtmlPostprocessor(md: Markdown | None = None)

Bases: Postprocessor

Restore raw html to the document.

‹› markdown.postprocessors.RawHtmlPostprocessor.run(text: str) -> str

Iterate over html stash and restore html.

‹› markdown.postprocessors.RawHtmlPostprocessor.isblocklevel(html: str) -> bool

Check is block of HTML is block-level.

‹› markdown.postprocessors.RawHtmlPostprocessor.stash_to_string(text: str) -> str

Convert a stashed object to a string.

‹› markdown.postprocessors.AndSubstitutePostprocessor(md: Markdown | None = None)

Bases: Postprocessor

Restore valid entities

‹› markdown.postprocessors.UnescapePostprocessor(md: Markdown | None = None) deprecated

Bases: Postprocessor

Deprecated

This class is deprecated and will be removed in the future; use UnescapeTreeprocessor instead.

Restore escaped chars.