Functions useful for simple parses:
mistletoe.
markdown
Render text with a given renderer.
iterable – string or list of strings
renderer – the renderer to use
parse_context (mistletoe.parse_context.ParseContext) – the parse context stores global parsing variables, such as the block/span tokens to search for, and link/footnote definitions that have been collected. If None, a new context will be instatiated, with the default block/span tokens for this renderer.
init_token – The initial token to use for parsing the text init_token.read
read_kwargs – key-word arguments to parse to the init_token.read method
init_token.read
kwargs – key-word arguments to parse to the renderer initialisation
mistletoe.block_tokenizer.
tokenize_main
Searches for token_types in an iterable.
lines – the source lines
token_types – override block-level tokens set in global context
start_line – the source line number corresponding to iterable[0]
expand_spans – After the initial parse the span text is not yet tokenized, but stored instead as raw text in SpanContainer, in order to ensure all link definitons are read first. Setting True, runs a second walk of the syntax tree to replace these SpanContainer with the final span tokens.
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
list of block-level token instances.
mistletoe.span_tokenizer.
tokenize_span
Convert a string to a list of span tokens.
string – the string to parse
list of span-level token instances.
mistletoe.base_elements.
TokenEncoder
Bases: json.encoder.JSONEncoder
json.encoder.JSONEncoder
A JSON encoder for mistletoe tokens.
default
Convert tokens to {token.name: token.to_dict()}, and expand SpanContainer.
serialize_tokens
Serialize one or more tokens, to a JSON representation.
During a single parse, the require token sets and link definitions are stored as a (thread-safe) global instance. You can set this directly before using the functions above.
mistletoe.parse_context.
ParseContext
Bases: object
object
A class to contain context for a single parse.
find_blocks – a list of block tokens to use during the parse. If None, the standard blocks will be used from BaseRenderer.default_block_token.
find_spans – a list of span tokens to use during the parse. If None, the standard blocks will be used from BaseRenderer.default_span_tokens.
link_definitions – a dict of link definitons, obtained from [def]: link
foot_definitions – a dict of footnote definitons, obtained from [^def]: link (if Footnote token active)
nesting_matches – a dict of matches recorded from find_nested_tokenizer
link_definitions
foot_definitions
foot_references
logger
reset_definitions
copy
get_parse_context
Return the current ParseContext (one per thread).
set_parse_context
Set an existing ParseContext (one per thread).
tokens_from_classes
Helper method; take a list of classes and/or class paths (e.g. mistletoe.span_tokens.Math) and return the loaded classes.
tokens_from_module
Helper method; takes a module and returns a list of all token classes specified in module.__all__. Useful when custom tokens are defined in single module.