The block parser handles basic parsing of Markdown blocks. It doesn’t concern
itself with inline elements such as
*italics*, but rather just
catches blocks, lists, quotes, etc.
BlockParser is made up of a bunch of
BlockProcessors, each handling a
different type of block. Extensions may add/replace/remove
as they need to alter how Markdown blocks are parsed.
Track the current and nested state of the parser.
This utility class is used to track the state of the
support multiple levels if nesting. It’s just a simple API wrapped around
a list. Each time a state is set, that state is appended to the end of the
list. Each time a state is reset, that state is removed from the end of
Therefore, each time a state is set for a nested block, that state must be reset when we back out of that level of nesting or the state could be corrupted.
While all the methods of a list object are available, only the three defined below need be used.
Parse Markdown blocks into an
A wrapper class that stitches the various
looping through them and creating an
A Markdown instance.
A Markdown instance.
Tracks the nesting level of current location in document being parsed.
A collection of
Parse a Markdown document into an
Given a list of lines, an
ElementTree object (not just a parent
Element) is created and the root element is passed to the parser
as the parent. The
ElementTree object is returned.
This should only be called on an entire document, not pieces.
An element tree.
Parse a chunk of Markdown text and attach to given
text argument is generally assumed to contain multiple
blocks which will be split on blank lines, it could contain only one
block. Generally, this method would be called by extensions when
block parsing is required.
etree Element passed in is altered in place.
Nothing is returned.
The parent element.
The text to parse.
Process blocks of Markdown text and attach to given
Given a list of
blockprocessor is stepped through
until there are no blocks left. While an extension could potentially
call this method directly, it’s generally expected to be used
This is a public method as an extension may need to add/alter
BlockProcessors which call this method to recursively
parse a nested block.