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)[源代码]

基类: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][源代码]

Get the value of attribute name, or null if it does not exist.

children: List[Union[markdown_it.token.Token, markdown_it.token.NestedTokens]]
closing: markdown_it.token.Token
opening: markdown_it.token.Token
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)[源代码]

基类: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][源代码]

Return the token as a dictionary.

参数
  • 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][源代码]

Get the value of attribute name, or null if it does not exist.

attrIndex(name: str) int[源代码]
attrItems() List[Tuple[str, Union[str, int, float]]][源代码]

Get (key, value) list of attrs.

attrJoin(name: str, value: str) None[源代码]

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[源代码]

Add [ name, value ] attribute to list. Init attrs if necessary.

attrSet(name: str, value: Union[str, int, float]) None[源代码]

Set name attribute to value. Override old value if exists.

attrs: Dict[str, Union[str, int, float]]
block: bool
children: Optional[List[markdown_it.token.Token]]
content: str
copy() markdown_it.token.Token[源代码]

Return a shallow copy of the instance.

classmethod from_dict(dct: MutableMapping[str, Any]) markdown_it.token.Token[源代码]

Convert a dict to a Token.

hidden: bool
info: str
level: int
map: Optional[List[int]]
markup: str
meta: dict
nesting: int
tag: str
type: str
markdown_it.token.convert_attrs(value: Any) Any[源代码]

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]][源代码]

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)