Extension Tokens

These tokens do not form part of the core CommonMark specification, but are commonly implemented extended syntax elements.

Strikethrough

class mistletoe.span_tokens_ext.Strikethrough(*, content: Optional[str] = None, children: Optional[list] = None)[source]

Bases: mistletoe.base_elements.SpanToken

Strikethrough tokens: ~~some text~~.

Must be parsed after CoreTokens.

classmethod find(string)[source]

Find all tokens, matching a pattern in the given string

Math

class mistletoe.span_tokens_ext.Math(*, content: Optional[str] = None, children: Optional[list] = None)[source]

Bases: mistletoe.base_elements.SpanToken

Dollar Math tokens (single or double): $a=1$.

Must be parsed after CoreTokens.

classmethod find(string)[source]

Find all tokens, matching a pattern in the given string

FrontMatter

class mistletoe.block_tokens.FrontMatter(*, content: str, position: Tuple[int, int])[source]

Bases: mistletoe.base_elements.BlockToken

Front matter YAML block, on the first line of the document.

---
a: b
c: d
---

NOTE: The content of the block should be valid YAML, but its parsing (and hence syntax testing) is deferred to the renderers. This is so that, given ‘bad’ YAML, the rest of the of document will still be parsed, and then the renderers can apply there own error reporting.

Not included in the parsing process, but called by Document.read, if front_matter=True.

Parameters
  • content (str) – Source text (should be valid YAML)

  • position (Tuple[int, int]) – Line position in source text (start, end)

classmethod start(line: str) → bool[source]

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).

classmethod read(lines)[source]

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.

Table

class mistletoe.block_tokens_ext.Table(*, children: List[mistletoe.block_tokens_ext.TableRow], header: Optional[mistletoe.block_tokens_ext.TableRow], column_align: list, position: Tuple[int, int])[source]

Bases: mistletoe.base_elements.BlockToken

Table token.

Note: header delimiters must be of at least length 3 ()

Example:

| Left Align  |   Centered  | Right Align   |
| :---        |    :----:   |          ---: |
| Header      | Title       | Here's this   |
| Paragraph   | Text        | And more      |
Parameters
static split_delimiter(delimiter: str)[source]

Helper function; returns a list of align options.

Parameters

delimiter – e.g.: | :— | :—: | —: |

Returns

a list of align options (None, 0 or 1).

static parse_align(column)[source]

Helper function; returns align option from cell content.

Returns

None if align = left; 0 if align = center; 1 if align = right.

static start(line)[source]

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).

classmethod read(lines)[source]

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.

TableRow

class mistletoe.block_tokens_ext.TableRow(*, children: List[mistletoe.block_tokens_ext.TableCell], row_align: list, position: Tuple[int, int])[source]

Bases: mistletoe.base_elements.BlockToken

Table row token.

Parameters
classmethod read(line, row_align=None, lineno=0)[source]

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.

TableCell

class mistletoe.block_tokens_ext.TableCell(*, children: List[mistletoe.base_elements.Token], align: Optional[int], position: Tuple[int, int])[source]

Bases: mistletoe.base_elements.BlockToken

Table cell token.

Boundary between span-level and block-level tokens.

Parameters
  • children (List[mistletoe.base_elements.Token]) – Child tokens list

  • align (int, NoneType) – align options for the cell (left=None (default), center=0, right=1)

  • position (Tuple[int, int]) – Line position in source text (start, end)

classmethod read(content, align=None, expand_spans=False, lineno=0)[source]

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.