'Wd,dZddlmZddlmZmZddlZddlmZm Z m Z m Z ddl m Z Gdd e Ze d d ZGd d ZddZy)zyA tree representation of a linear markdown-it token stream. This module is not part of upstream JavaScript markdown-it. ) annotations) GeneratorSequenceN)Any NamedTupleTypeVaroverload)Tokenc"eZdZUded<ded<y) _NesterTokensr openingclosingN)__name__ __module__ __qualname____annotations__2/usr/lib/python3/dist-packages/markdown_it/tree.pyr r s N Nrr _NodeTypeSyntaxTreeNode)boundcXeZdZdZ d*dd d+dZd,dZed-dZed.dZd/dZd0d Ze d1d Z e jd2d Z e d3d Z e jd4d Z e d5dZ e d5dZe d6dZe d,dZe d3dZe d3dZ d7dZd7dZdddd d8dZdd d9dZd:dZe d,dZe d;dZdd"Ze d,d#Ze d,d$Ze d,d%Ze d?d&Z e d5d'Z!e d5d(Z"y))@raeA Markdown syntax tree node. A class that can be used to construct a tree representation of a linear `markdown-it-py` token stream. Each node in the tree represents either: - root of the Markdown document - a single unnested `Token` - a `Token` "_open" and "_close" token pair, and the tokens nested in between T create_rootcd|_d|_d|_g|_|r|j |y|s t dt |dk(rL|d}|jr t d||_|jr|j |jyyt|d|d|_|j |ddy)zInitialize a `SyntaxTreeNode` from a token stream. If `create_root` is True, create a root node for the document. NzGCan only create root from empty token sequence. Set `create_root=True`.r rz;Unequal nesting level at the start and end of token stream.) token nester_tokens_parent _children_set_children_from_tokens ValueErrorlennestingchildrenr )selftokensr inline_tokens r__init__zSyntaxTreeNode.__init__#s$( 48! %'   * *6 2 + [A !!9L## Q&DJ$$..|/D/DE%"/vay&*!ED   * *6!B< 8rcLt|jd|jdS)N())typerr(s r__repr__zSyntaxTreeNode.__repr__Ms$t*%%&a {!44rcyNrr(items r __getitem__zSyntaxTreeNode.__getitem__P rcyr3rr4s rr6zSyntaxTreeNode.__getitem__Tr7rc |j|Sr3)r'r4s rr6zSyntaxTreeNode.__getitem__Xs}}T""rc*dfd g}|||S)z Recover the linear token stream.c|jdk(r|jD] }|| y|jr|j|jy|jsJ|j|jj |jD] }|| |j|jj y)Nroot)r/r'rappendr rr)node token_listchildrecursive_collect_tokenss rrAz:SyntaxTreeNode.to_tokens..recursive_collect_tokens^syyF"!]]@E,UJ?@!!$**-))))!!$"4"4"<"<=!]]@E,UJ?@!!$"4"4"<"<=r)r>rr? list[Token]returnNoner)r(r)rAs @r to_tokenszSyntaxTreeNode.to_tokens[s >! v. rc|jSr3r"r0s rr'zSyntaxTreeNode.childrenos ~~rc||_yr3rGr(values rr'zSyntaxTreeNode.childrenss rc|jSr3r!r0s rparentzSyntaxTreeNode.parentws ||rc||_yr3rLrIs rrMzSyntaxTreeNode.parent{s  rc8|jxs |j S)z Is the node a special root node?)rr r0s ris_rootzSyntaxTreeNode.is_rootsJJ4$"4"455rc,t|jS)zIs this node nested?. Returns `True` if the node represents a `Token` pair and tokens in the sequence between them, where `Token.nesting` of the first `Token` in the pair is 1 and nesting of the other `Token` is -1. )boolr r0s r is_nestedzSyntaxTreeNode.is_nestedsD&&''rcL|js|gS|jjS)z]Get siblings of the node. Gets the whole group of siblings, including self. )rMr'r0s rsiblingszSyntaxTreeNode.siblingss" {{6M{{###rc|jry|jr|jjS|jsJt |jj jdS)aGet a string type of the represented syntax. - "root" for root nodes - `Token.type` if the node represents an unnested token - `Token.type` of the opening token, with "_open" suffix stripped, if the node represents a nester token pair r<_open)rPrr/r _removesuffixrr0s rr/zSyntaxTreeNode.typesQ << ::::?? "!!!!T//77<C . .==a0 0rcn|jj|}|dz dk\r|j|dz Sy)zqGet the previous node in the sequence of siblings. Returns `None` if this is the first sibling. r rN)rUrZr[s rprevious_siblingzSyntaxTreeNode.previous_siblings: ]]((. >Q ==a0 0rcnt||d}||_|jj|y)zMake a child node for `self`.FrN)r/rMr'r=)r(r)r@s r _add_childzSyntaxTreeNode._add_childs/ T 6u5  U#rctt|}|r|j}|js|j |g1|jdk7r t d|g}d}|r7|r5|j}|j |||jz }|r|r5|rt d|d|j ||ryy)zgConvert the token stream to a tree structure and set the resulting nodes as children of `self`.r zInvalid token nestingzunclosed tokens starting rN)listreversedpopr&rar$r=)r(r)reversed_tokensr nested_tokensr&s rr#z(SyntaxTreeNode._set_children_from_tokenssx/0#'')E==(}}! !899"GMG!g'++-$$U+5==("g #<]1=Mz(SyntaxTreeNode.pretty..s"ODAqaS!<"Os>)text text_special ri) r/rPattrsjoinitemscontenttextwraprjr'pretty)r(rjrkrlprefixrwr@s rrzSyntaxTreeNode.prettysx!DII;'|| C#(("ODJJrsK#/55J K'7 8 x.x.v r