Parser

class commonmark.blocks.Parser(options={})[source]
add_child(tag, offset)[source]

Add block of type tag as a child of the tip. If the tip can’t accept children, close and finalize it and try its parent, and so on til we find a block that can accept children.

add_line()[source]

Add a line to the block at the tip. We assume the tip can accept lines – that check should be done before calling this.

close_unmatched_blocks()[source]

Finalize and close any unmatched blocks.

finalize(block, line_number)[source]

Finalize a block. Close it and do any necessary postprocessing, e.g. creating string_content from strings, setting the ‘tight’ or ‘loose’ status of a list, and parsing the beginnings of paragraphs for reference definitions. Reset the tip to the parent of the closed block.

incorporate_line(ln)[source]

Analyze a line of text and update the document appropriately.

We parse markdown text by calling this on each line of input, then finalizing the document.

parse(my_input)[source]

The main parsing function. Returns a parsed document AST.

process_inlines(block)[source]

Walk through a block & children recursively, parsing string content into inline content where appropriate.