@@ -157,67 +157,3 @@ def from_dict(cls, dct: MutableMapping[str, Any]) -> Token:
157157 if token .children :
158158 token .children = [cls .from_dict (c ) for c in token .children ] # type: ignore[arg-type]
159159 return token
160-
161-
162- @attr .s (slots = True )
163- class NestedTokens :
164- """A class that closely resembles a Token,
165- but for a an opening/closing Token pair, and their containing children.
166- """
167-
168- opening : Token = attr .ib ()
169- closing : Token = attr .ib ()
170- children : list [Token | NestedTokens ] = attr .ib (factory = list )
171-
172- def __getattr__ (self , name ):
173- return getattr (self .opening , name )
174-
175- def attrGet (self , name : str ) -> None | str | int | float :
176- """Get the value of attribute `name`, or null if it does not exist."""
177- return self .opening .attrGet (name )
178-
179-
180- def nest_tokens (tokens : list [Token ]) -> list [Token | NestedTokens ]:
181- """Convert the token stream to a list of tokens and nested tokens.
182-
183- ``NestedTokens`` contain the open and close tokens and a list of children
184- of all tokens in between (recursively nested)
185- """
186- warnings .warn (
187- "`markdown_it.token.nest_tokens` and `markdown_it.token.NestedTokens`"
188- " are deprecated. Please migrate to `markdown_it.tree.SyntaxTreeNode`" ,
189- DeprecationWarning ,
190- )
191-
192- output : list [Token | NestedTokens ] = []
193-
194- tokens = list (reversed (tokens ))
195- while tokens :
196- token = tokens .pop ()
197-
198- if token .nesting == 0 :
199- token = token .copy ()
200- output .append (token )
201- if token .children :
202- # Ignore type checkers because `nest_tokens` doesn't respect
203- # typing of `Token.children`. We add `NestedTokens` into a
204- # `list[Token]` here.
205- token .children = nest_tokens (token .children ) # type: ignore
206- continue
207-
208- assert token .nesting == 1 , token .nesting
209-
210- nested_tokens = [token ]
211- nesting = 1
212- while tokens and nesting != 0 :
213- token = tokens .pop ()
214- nested_tokens .append (token )
215- nesting += token .nesting
216- if nesting != 0 :
217- raise ValueError (f"unclosed tokens starting { nested_tokens [0 ]} " )
218-
219- child = NestedTokens (nested_tokens [0 ], nested_tokens [- 1 ])
220- output .append (child )
221- child .children = nest_tokens (nested_tokens [1 :- 1 ])
222-
223- return output
0 commit comments