| 20 | |
| 21 | @dc.dataclass(slots=True) |
| 22 | class Token: |
| 23 | type: str |
| 24 | """Type of the token (string, e.g. "paragraph_open")""" |
| 25 | |
| 26 | tag: str |
| 27 | """HTML tag name, e.g. 'p'""" |
| 28 | |
| 29 | nesting: Literal[-1, 0, 1] |
| 30 | """Level change (number in {-1, 0, 1} set), where: |
| 31 | - `1` means the tag is opening |
| 32 | - `0` means the tag is self-closing |
| 33 | - `-1` means the tag is closing |
| 34 | """ |
| 35 | |
| 36 | attrs: dict[str, str | int | float] = dc.field(default_factory=dict) |
| 37 | """HTML attributes. |
| 38 | Note this differs from the upstream "list of lists" format, |
| 39 | although than an instance can still be initialised with this format. |
| 40 | """ |
| 41 | |
| 42 | map: list[int] | None = None |
| 43 | """Source map info. Format: `[ line_begin, line_end ]`""" |
| 44 | |
| 45 | level: int = 0 |
| 46 | """Nesting level, the same as `state.level`""" |
| 47 | |
| 48 | children: list[Token] | None = None |
| 49 | """Array of child nodes (inline and img tokens).""" |
| 50 | |
| 51 | content: str = "" |
| 52 | """Inner content, in the case of a self-closing tag (code, html, fence, etc.),""" |
| 53 | |
| 54 | markup: str = "" |
| 55 | """'*' or '_' for emphasis, fence string for fence, etc.""" |
| 56 | |
| 57 | info: str = "" |
| 58 | """Additional information: |
| 59 | - Info string for "fence" tokens |
| 60 | - The value "auto" for autolink "link_open" and "link_close" tokens |
| 61 | - The string value of the item marker for ordered-list "list_item_open" tokens |
| 62 | """ |
| 63 | |
| 64 | meta: dict[Any, Any] = dc.field(default_factory=dict) |
| 65 | """A place for plugins to store any arbitrary data""" |
| 66 | |
| 67 | block: bool = False |
| 68 | """True for block-level tokens, false for inline tokens. |
| 69 | Used in renderer to calculate line breaks |
| 70 | """ |
| 71 | |
| 72 | hidden: bool = False |
| 73 | """If true, ignore this element when rendering. |
| 74 | Used for tight lists to hide paragraphs. |
| 75 | """ |
| 76 | |
| 77 | def __post_init__(self) -> None: |
| 78 | self.attrs = convert_attrs(self.attrs) |
| 79 |
no outgoing calls
searching dependent graphs…