Core Span Tokens

These span tokens are defined in the CommonMark specification.

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)[source]

Bases: mistletoe.base_elements.SpanToken

classmethod read(match: Pattern)[source]

Take a pattern match and return the instatiated token.

classmethod find(string)[source]

Find all tokens, matching a pattern in the given string

Strong

class mistletoe.span_tokens.Strong(*, content: Optional[str] = None, children: Optional[list] = 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)[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: Tuple[int, int] = None)[source]

Bases: mistletoe.base_elements.SpanToken

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

Parameters
  • children (list) – a single RawText node for alternative text.

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

classmethod read(match: Pattern)[source]

Take a pattern match and return the instatiated token.

classmethod find(string)[source]

Find all tokens, matching a pattern in the given string

Image

class mistletoe.span_tokens.Image(*, src: str, title: str = None, children: list = NOTHING, position: Tuple[int, int] = 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 (Tuple[int, int]) – Line position in source text (start, end) (default: None)

classmethod read(match: Pattern)[source]

Take a pattern match and return the instatiated token.

EscapeSequence

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

Bases: mistletoe.base_elements.SpanToken

Escape sequences. (“\*”)

This should be set first in the token parse list.

Parameters
  • children (list) – a single RawText node for alternative text.

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

classmethod read(match: Pattern)[source]

Take a pattern match and return the instatiated token.

LineBreak

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

Bases: mistletoe.base_elements.SpanToken

Hard or soft line breaks.

Parameters
  • content (bool) – raw content. (default: “”)

  • soft (bool) – if the break is soft or hard.

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

classmethod read(match: Pattern)[source]

Take a pattern match and return the instatiated token.

RawText

class mistletoe.span_tokens.RawText(content: bool, position: Tuple[int, int] = 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
  • content (bool) – raw string content of the token

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

classmethod read(content: str)[source]

Take a pattern match and return the instatiated token.

HTMLSpan

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

Bases: mistletoe.base_elements.SpanToken

Span-level HTML tokens.

Parameters
  • content – raw string content of the token

  • children – list of child tokens