Core Span Tokens

These span tokens are defined in the CommonMark specification.

Token

Description

Example

RawText

any inline text

any text

EscapeSequence

escaped symbols (to avoid them being interpreted as other syntax elements)

\*

LineBreak

Soft or hard (ends with spaces or backslash)

A hard break\

Strong

bold text

**strong**

Emphasis

italic text

*emphasis*

InlineCode

literal text

`a=1`

AutoLink

link that is shown in final output

<https://www.google.com>

Link

Reference a target or LinkDefinition

[text](target "title") or
[text][key] or
[key]

Image

link to an image

![alt](src "title")

HTMLSpan

any valid HTML (rendered in HTML output only)

<p>some text</p>

Core

This is a special token that runs a nested parse of the inline string and extracts nested tokens.

class mistletoe.span_tokens.CoreTokens(*, content: Optional[str] = None, children: Optional[list] = None, position: Tuple[int, int] = None)[source]

Bases: mistletoe.base_elements.SpanToken

RawText

class mistletoe.span_tokens.RawText(content: bool, position: mistletoe.base_elements.Position = None)[source]

Bases: mistletoe.base_elements.SpanToken

Raw text. A leaf node.

RawText is the only token that accepts a string for its read method, instead of a match object. Also, all recursions should bottom out here.

Parameters

EscapeSequence

class mistletoe.span_tokens.EscapeSequence(*, children: list, position: mistletoe.base_elements.Position = None)[source]

Bases: mistletoe.base_elements.SpanToken

Escape sequences. (“\*”)

This should be set first in the token parse list.

Parameters
pattern = re.compile('\\\\([!\\"#$%&\'()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~])')
parse_inner = False
parse_group = 1

LineBreak

class mistletoe.span_tokens.LineBreak(*, content: bool = '', soft: bool, position: mistletoe.base_elements.Position = None)[source]

Bases: mistletoe.base_elements.SpanToken

Hard or soft line breaks.

Parameters
pattern = re.compile('( *|\\\\)\\n')
parse_inner = False
parse_group = 0

Strong

class mistletoe.span_tokens.Strong(*, content: Optional[str] = None, children: Optional[list] = None, position: Tuple[int, int] = None)[source]

Bases: mistletoe.base_elements.SpanToken

Strong tokens: **some text** or __some text__, read in CoreTokens.read

Parameters
  • content – raw string content of the token

  • children – list of child tokens

Emphasis

class mistletoe.span_tokens.Emphasis(*, content: Optional[str] = None, children: Optional[list] = None, position: Tuple[int, int] = None)[source]

Bases: mistletoe.base_elements.SpanToken

Emphasis tokens *some text* or _some text_, read in CoreTokens.read

Parameters
  • content – raw string content of the token

  • children – list of child tokens

InlineCode

class mistletoe.span_tokens.InlineCode(*, children: list, position: mistletoe.base_elements.Position = None)[source]

Bases: mistletoe.base_elements.SpanToken

Inline code tokens: `some code`, read in CoreTokens.read

Parameters
pattern = re.compile('(?<!\\\\|`)(?:\\\\\\\\)*(`+)(?!`)(.+?)(?<!`)\\1(?!`)', re.DOTALL)
parse_inner = False
parse_group = 2

Image

class mistletoe.span_tokens.Image(*, src: str, title: str = None, children: list = NOTHING, position: mistletoe.base_elements.Position = None)[source]

Bases: mistletoe.base_elements.SpanToken

Image tokens, with inline targets: “![alt](src “title”)”, read in CoreTokens.read

Parameters
  • src (str) – image source

  • title (str) – image title (default: None)

  • children (list) – alternative text. (default: Factory(factory=<class ‘list’>, takes_self=False))

  • position (mistletoe.base_elements.Position) – Line position in source text (default: None)

HTMLSpan

class mistletoe.span_tokens.HTMLSpan(*, content: Optional[str] = None, children: Optional[list] = None, position: Tuple[int, int] = None)[source]

Bases: mistletoe.base_elements.SpanToken

Span-level HTML tokens.

Parameters
  • content – raw string content of the token

  • children – list of child tokens

pattern = re.compile('(?<!\\\\)<[A-Za-z][A-Za-z0-9-]*(?:\\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\\s*=\\s*(?:[^ "\\\'=<>`]+|\\\'[^\\\']*?\\\'|"[^\\"]*?"))?)*\\s*/?>|(?<!\\\\)</[A-Za-z][A-Za-z0-9-]*\\s*>|(?<!\\\\)<!--(?!>|->)(?:(?, re.DOTALL)
parse_inner = False
parse_group = 0