markdown_it.token module¶
-
class
markdown_it.token.
NestedTokens
(opening: markdown_it.token.Token, closing: markdown_it.token.Token, children: List[Union[markdown_it.token.Token, NestedTokens]] = NOTHING)[source]¶ Bases:
object
A class that closely resembles a Token, but for a an opening/closing Token pair, and their containing children.
-
attrGet
(name: str) → Union[None, str, int, float][source]¶ Get the value of attribute name, or null if it does not exist.
-
children
¶
-
closing
¶
-
opening
¶
-
-
class
markdown_it.token.
Token
(type: str, tag: str, nesting: int, attrs: Any = NOTHING, map: Optional[List[int]] = None, level: int = 0, children: Optional[List[Token]] = None, content: str = '', markup: str = '', info: str = '', meta: dict = NOTHING, block: bool = False, hidden: bool = False)[source]¶ Bases:
object
-
as_dict
(*, children: bool = True, as_upstream: bool = True, meta_serializer: Optional[Callable[[dict], Any]] = None, filter: Optional[Callable[[attr._make.Attribute, Any], bool]] = None, dict_factory: Type[MutableMapping[str, Any]] = <class 'dict'>) → MutableMapping[str, Any][source]¶ Return the token as a dictionary.
- Parameters
children – Also convert children to dicts
as_upstream – Ensure the output dictionary is equal to that created by markdown-it For example, attrs are converted to null or lists
meta_serializer – hook for serializing
Token.meta
filter – A callable whose return code determines whether an attribute or element is included (
True
) or dropped (False
). Is called with the attr.Attribute as the first argument and the value as the second argument.dict_factory – A callable to produce dictionaries from. For example, to produce ordered dictionaries instead of normal Python dictionaries, pass in
collections.OrderedDict
.
-
attrGet
(name: str) → Union[None, str, int, float][source]¶ Get the value of attribute name, or null if it does not exist.
-
attrJoin
(name: str, value: str) → None[source]¶ Join value to existing attribute via space. Or create new attribute if not exists. Useful to operate with token classes.
-
attrPush
(attrData: Tuple[str, Union[str, int, float]]) → None[source]¶ Add [ name, value ] attribute to list. Init attrs if necessary.
-
attrSet
(name: str, value: Union[str, int, float]) → None[source]¶ Set name attribute to value. Override old value if exists.
-
attrs
¶
-
block
¶
-
children
¶
-
content
¶
-
copy
() → markdown_it.token.Token[source]¶ Return a shallow copy of the instance.
-
classmethod
from_dict
(dct: MutableMapping[str, Any]) → markdown_it.token.Token[source]¶ Convert a dict to a Token.
-
info
¶
-
level
¶
-
map
¶
-
markup
¶
-
meta
¶
-
nesting
¶
-
tag
¶
-
type
¶
-
-
markdown_it.token.
convert_attrs
(value: Any) → Any[source]¶ Convert Token.attrs set as
None
or[[key, value], ...]
to a dict.This improves compatibility with upstream markdown-it.
-
markdown_it.token.
nest_tokens
(tokens: List[markdown_it.token.Token]) → List[Union[markdown_it.token.Token, markdown_it.token.NestedTokens]][source]¶ Convert the token stream to a list of tokens and nested tokens.
NestedTokens
contain the open and close tokens and a list of children of all tokens in between (recursively nested)