markdown_it.token module#
- class markdown_it.token.Token(type: 'str', tag: 'str', nesting: 'int', attrs: 'dict[str, str | int | float]' = <factory>, map: 'list[int] | None' = None, level: 'int' = 0, children: 'list[Token] | None' = None, content: 'str' = '', markup: 'str' = '', info: 'str' = '', meta: 'dict' = <factory>, block: 'bool' = False, hidden: 'bool' = False)[source]#
Bases:
object
- as_dict(*, children: bool = True, as_upstream: bool = True, meta_serializer: Callable[[dict], Any] | None = None, filter: Callable[[str, Any], bool] | None = None, dict_factory: Callable[..., 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 (key, value) pair.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) 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, str | int | float]) None [source]#
Add [ name, value ] attribute to list. Init attrs if necessary.
- attrSet(name: str, value: str | int | float) None [source]#
Set name attribute to value. Override old value if exists.
- attrs: dict[str, str | int | float]#
HTML attributes. Note this differs from the upstream “list of lists” format, although than an instance can still be initialised with this format.
- block: bool = False#
True for block-level tokens, false for inline tokens. Used in renderer to calculate line breaks
If true, ignore this element when rendering. Used for tight lists to hide paragraphs.
- info: str = ''#
Additional information: - Info string for “fence” tokens - The value “auto” for autolink “link_open” and “link_close” tokens - The string value of the item marker for ordered-list “list_item_open” tokens