These block tokens are defined in the CommonMark specification.
Token
Description
Example
(ATX)Heading
Level 1-6 headings, denoted by number of #
#
### Heading level 3
SetextHeading
Underlined header (using multiple = or -)
=
-
Header ======
Paragraph
General block of text
any *text*
Quote
quoted block of text
> this is a quote
BlockCode
indented text (4 spaces or a tab)
included as literal
CodeFence
enclosed in 3 or more backticks with an optional language name
```python print('this is python') ```
ThematicBreak
Creates a horizontal line in the output
---
List
bullet points or enumerated.
- item - nested item 1. numbered item
LinkDefinition
A substitution for an inline link, which can have a reference target (no spaces), and an optional title (in “)
[key]: https://www.google.com "a title"
HTMLBlock
Any valid HTML (rendered in HTML output only)
<p>some text</p>
mistletoe.block_tokens.
Document
Bases: mistletoe.base_elements.BlockToken
mistletoe.base_elements.BlockToken
Document container.
children (List[mistletoe.base_elements.Token]) – Child tokens list
link_definitions (dict) – Mapping of keys to (url, title) (default: Factory(factory=<class ‘dict’>, takes_self=False))
footnotes (Dict[str, mistletoe.base_elements.Token]) – Footnote tokens mapped to their target names (default: Factory(factory=<class ‘dict’>, takes_self=False))
footref_order (list) – A set of footnote targets, in the order they are referenced in the document. (default: Factory(factory=<class ‘list’>, takes_self=False))
front_matter (mistletoe.block_tokens.FrontMatter, NoneType) – Front matter YAML block (default: None)
read
Read a document
lines – Lines to parse
reset_definitions – remove any previously stored definitions in the global context (see ParseContext.reset_definitions()).
ParseContext.reset_definitions()
skip_tokens – do not store these token.name in the syntax tree. These are usually tokens that store themselves in the global context.
token.name
front_matter – search for an initial YAML block front matter block (note this is not strictly CommonMark compliant)
Heading
Heading token. ([“### some heading ###n”])
Boundary between span-level and block-level tokens.
level (int) – Heading level
position (mistletoe.base_elements.Position) – Line position in source text (default: None)
start
Takes a line from the document as argument, and returns a boolean representing whether that line marks the start of the current token. Every subclass of BlockToken must define a start function (see block_tokenizer.tokenize_main).
takes the rest of the lines in the document as an iterator (including the start line), and consumes all the lines that should be read into this token.
The default is to stop at an empty line.
Setext headings.
Not included in the parsing process, but returned by Paragraph.read.
Paragraph token. ([“somen”, “continuousn”, “linesn”])
Quote token. ([“> # headingn”, “> paragraphn”]).
Indented code.
language (str) – The code language (for sytax highlighting) (default: “”)
Code fence. ([“`sh\n", "rm -rf /", ..., "`”])
`sh\n", "rm -rf /", ..., "`
See <https://spec.commonmark.org/0.29/#fenced-code-blocks>
arguments (str) – Any string occuring after the language (default: “”)
List token (unordered or ordered)
loose (bool) – Whether list items are separated by blank lines
start_at (int, NoneType) – None if unordered, starting number if ordered.
ListItem
List items.
Not included in the parsing process, but called by List.
leader (str) – The prefix number or bullet point.
prepend (int) –
next_marker (Any) – (default: None)
parse_marker
Returns a pair (prepend, leader) if the line has a valid leader.
LinkDefinition token: [ref]: url “title”
These are stores in Document.link_definitions in the final syntax tree.
definitions (list) – list of (label, dest, title)
Thematic break token (a.k.a. horizontal rule.)
Block-level HTML token.
content (str) – literal strings rendered as-is