Skip to content

markdown §

Python-Markdown provides two public functions (markdown.markdown and markdown.markdownFromFile) both of which wrap the public class markdown.Markdown. All submodules support these public functions and class and/or provide extension support.

Modules:

Classes:

  • Markdown –

    A parser which converts Markdown to HTML.

Functions:

  • markdown –

    Convert a markdown string to HTML and return HTML as a Unicode string.

  • markdownFromFile –

    Read Markdown text from a file or stream and write HTML output to a file or stream.

markdown.Markdown(**kwargs) §

A parser which converts Markdown to HTML.

Attributes:

  • Markdown.tab_length (int) –

    The number of spaces which correspond to a single tab. Default: 4.

  • Markdown.ESCAPED_CHARS (list[str]) –

    List of characters which get the backslash escape treatment.

  • Markdown.block_level_elements (list[str]) –

    List of HTML tags which get treated as block-level elements. See markdown.util.BLOCK_LEVEL_ELEMENTS for the full list of elements.

  • Markdown.registeredExtensions (list[Extension]) –

    List of extensions which have called registerExtension during setup.

  • Markdown.doc_tag (str) –

    Element used to wrap document. Default: div.

  • Markdown.stripTopLevelTags (bool) –

    Indicates whether the doc_tag should be removed. Default: ‘True’.

  • Markdown.references (dict[str, tuple[str, str]]) –

    A mapping of link references found in a parsed document where the key is the reference name and the value is a tuple of the URL and title.

  • Markdown.htmlStash (HtmlStash) –

    The instance of the HtmlStash used by an instance of this class.

  • Markdown.output_formats (dict[str, Callable[Element]]) –

    A mapping of known output formats by name and their respective serializers. Each serializer must be a callable which accepts an Element and returns a str.

  • Markdown.output_format (str) –

    The output format set by set_output_format.

  • Markdown.serializer (Callable[Element]) –

    The serializer set by set_output_format.

  • Markdown.preprocessors (Registry) –

    A collection of preprocessors.

  • Markdown.parser (BlockParser) –

    A collection of blockprocessors.

  • Markdown.inlinePatterns (Registry) –

    A collection of inlinepatterns.

  • Markdown.treeprocessors (Registry) –

    A collection of treeprocessors.

  • Markdown.postprocessors (Registry) –

    A collection of postprocessors.

Other Parameters:

  • extensions (list[Extension | str]) –

    A list of extensions.

    If an item is an instance of a subclass of markdown.extensions.Extension, the instance will be used as-is. If an item is of type str, it is passed to build_extension with its corresponding extension_configs and the returned instance of markdown.extensions.Extension is used.

  • extension_configs (dict[str, dict[str, Any]]) –

    Configuration settings for extensions.

  • output_format (str) –

    Format of output. Supported formats are:

    • xhtml: Outputs XHTML style tags. Default.
    • html: Outputs HTML style tags.
  • tab_length (int) –

    Length of tabs in the source. Default: 4

Methods:

  • build_parser –

    Build the parser from the various parts.

  • registerExtensions –

    Load a list of extensions into an instance of the Markdown class.

  • build_extension –

    Build extension from a string name, then return an instance using the given configs.

  • registerExtension –

    Register an extension as having a resettable state.

  • reset –

    Resets all state variables to prepare the parser instance for new input.