API Reference
Renderers
Convert Markdown to various output formats
- markdown_to_html()
-
Parse CommonMark/GFM and render as HTML.
- markdown_to_latex()
-
Parse CommonMark/GFM and render as LaTeX.
- markdown_to_man()
-
Parse CommonMark/GFM and render as a groff man page.
- markdown_to_commonmark()
-
Parse CommonMark/GFM and render back as normalized CommonMark.
- markdown_to_xml()
-
Parse CommonMark/GFM and render as XML.
Options
Parsing and rendering configuration
- Options
-
CommonMark/GFM parsing and rendering options.
Parsing
Streaming parser, AST nodes, and tree traversal
Parser Methods
Methods for the Parser class
- Parser.feed()
-
Feed a chunk of Markdown text to the parser.
- Parser.finish()
-
Finalize parsing and return the root Node of the AST.
- Parser.render_html()
-
Finish parsing (if needed) and render as HTML.
- Parser.render_xml()
-
Finish parsing (if needed) and render as XML.
- Parser.render_latex()
-
Finish parsing (if needed) and render as LaTeX.
- Parser.render_man()
-
Finish parsing (if needed) and render as a groff man page.
- Parser.render_commonmark()
-
Finish parsing (if needed) and render as normalized CommonMark.
- Parser.close()
-
Release all C resources held by this parser.
- Parser.__enter__()
- Parser.__exit__()
- Parser.__del__()
Node Methods
Methods for the Node class
- Node.new()
-
Create a new detached node of the given type.
- Node.type
-
The node type.
- Node.type_string
-
Human-readable node type name from cmark (e.g.,
'heading'). - Node.parent
-
The parent node, or
Noneif this is the root. - Node.first_child
-
The first child node, or
None. - Node.last_child
-
The last child node, or
None. - Node.next
-
The next sibling, or
None. - Node.previous
-
The previous sibling, or
None. - Node.children
-
Iterate over direct child nodes.
- Node.literal
-
Text content for text, code, and HTML nodes.
Noneif not applicable. - Node.url
-
URL for link and image nodes.
Noneif not applicable. - Node.title
-
Title for link and image nodes.
Noneif not applicable. - Node.heading_level
-
Heading level (1–6) for
HEADINGnodes; 0 otherwise. - Node.list_type
-
List type (
BULLETorORDERED) forLISTnodes. - Node.list_delim
-
Delimiter type for ordered
LISTnodes. - Node.list_start
-
Starting number for ordered
LISTnodes; 0 otherwise. - Node.list_tight
-
Whether a
LISTnode is tight (no blank lines between items). - Node.fence_info
-
Info string for fenced
CODE_BLOCKnodes (e.g.,'python'). - Node.start_line
-
Start line (1-based) in source. 0 if not available.
- Node.start_column
-
Start column (1-based) in source. 0 if not available.
- Node.end_line
-
End line (1-based) in source. 0 if not available.
- Node.end_column
-
End column (1-based) in source. 0 if not available.
- Node.walk()
-
Depth-first walk of the subtree rooted at this node.
- Node.unlink()
-
Remove this node from its parent tree.
- Node.insert_before()
-
Insert sibling as the node immediately before this one.
- Node.insert_after()
-
Insert sibling as the node immediately after this one.
- Node.append_child()
-
Append child as the last child of this node.
- Node.prepend_child()
-
Prepend child as the first child of this node.
- Node.replace()
-
Replace this node in the tree with new_node.
- Node.render_html()
-
Render this subtree as HTML.
- Node.render_xml()
-
Render this subtree as XML.
- Node.render_latex()
-
Render this subtree as LaTeX.
- Node.render_man()
-
Render this subtree as a groff man page.
- Node.render_commonmark()
-
Render this subtree as normalized CommonMark.
- Node.__repr__()
- Node.__eq__()
- Node.__hash__()
Utility
Package information
- cmark_version()
-
Return the version string of the vendored cmark-gfm library.