markupit.readers package
Submodules
markupit.readers.base_parser module
markupit.readers.markdown_block_parser module
- class markupit.readers.markdown_block_parser.BlockParser[source]
Bases:
BaseParser- GRAMMAR_RULES = {'atx_heading': '^ {0,3}(?P<level>#{1,6})(?!#+)(?P<atx_text>[ \\t]*|[ \\t]+.*?)$', 'blank_line': '(^[ \\t\\v\\f]*\\n)+', 'block_quote': '^ {0,3}>(?P<quote_text>.*?)$', 'code_fenced': '^(?P<fnc_spaces> {0,3})(?P<fnc_marker>`{3,}|~{3,})[ \\t]*(?P<fnc_lang>.*?)$', 'code_indent': '^(?: {4}| *\\t)[^\\n]+(?:\\n+|$)((?:(?: {4}| *\\t)[^\\n]+(?:\\n+|$))|\\s)*', 'horizontal_rule': '^ {0,3}((?:-[ \\t]*){3,}|(?:_[ \\t]*){3,}|(?:\\*[ \\t]*){3,})$', 'list': '^(?P<list_spaces> {0,3})(?P<list_marker>[\\*\\+-]|\\d{1,9}[.)])(?P<list_text>[ \\t]*|[ \\t].+)$', 'setext_heading': '^ {0,3}(?P<sep>=|-){1,}[ \\t]*$'}
- RULES_NAMES = ['code_fenced', 'code_indent', 'atx_heading', 'setext_heading', 'horizontal_rule', 'blank_line', 'block_quote', 'list']
- parse(state: BlockState, rules: list[str] | None = None) None[source]
Parse source Markdown text into blocks. Blocks are stored in the state with the following structure: {
‘type’: str, ‘content’: str, ‘attrs’: dict
}
- visit_atx_heading(m: Match[str], state: BlockState) int[source]
Visit method for ATX headings.
# Header example
- visit_blank_line(m: Match[str], state: BlockState) int[source]
Visit method for BlankLine.
BlankLine is not present in AST, but still needed to prevent reading empty lines as paragraphs.
- visit_block_quote(m: Match[str], state: BlockState) int[source]
Visit method for Block Quote.
> This is a block quote. >
` > It can contain other blocks. > `
- visit_code_fenced(m: Match[str], state: BlockState) int[source]
Visit method for Code Fenced.
` python print("Hello, World!") `
- visit_code_indent(m: Match[str], state: BlockState) int[source]
Visit method for Code Indent (4 spaces before code).
print(“Hello”) print(“World!”)
- visit_horizontal_rule(m: Match[str], state: BlockState) int[source]
Visit method for Horizontal Rule.
—
- visit_list(m: Match[str], state: BlockState) int[source]
Visit method for List.
item 1
item 2
item 1
item 2
- visit_setext_heading(m: Match[str], state: BlockState) int[source]
Visit method for Setext headings.
Header example
markupit.readers.markdown_block_reader module
- class markupit.readers.markdown_block_reader.InlineVisitor[source]
Bases:
NodeVisitor- generic_visit(node, visited_children)[source]
Default visitor method
- Parameters:
node – The node we’re visiting
visited_children – The results of visiting the children of that node, in a list
I’m not sure there’s an implementation of this that makes sense across all (or even most) use cases, so we leave it to subclasses to implement for now.