Functions useful for simple parses:
mistletoe.
markdown
Render text with a given renderer.
iterable – string or list of strings
init_token – The initial token to use for parsing the text token.read
kwargs – key-word arguments to parse to the renderer initialisation
mistletoe.block_tokenizer.
tokenize_main
Searches for token_types in an iterable.
iterable – list of strings (each line must end with a newline n!).
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.
store_definitions – store LinkDefinitions specifically in the syntax tree (or just record their target mappings globally and discard.)
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
copy
get_parse_context
Return the current ParseContext.
set_parse_context
Set an existing ParseContext.
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.