MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / to_tokens

Method to_tokens

markdown_it/tree.py:90–108  ·  view source on GitHub ↗

Recover the linear token stream.

(self: _NodeType)

Source from the content-addressed store, hash-verified

88 return self.children[item]
89
90 def to_tokens(self: _NodeType) -> list[Token]:
91 """Recover the linear token stream."""
92
93 def recursive_collect_tokens(node: _NodeType, token_list: list[Token]) -> None:
94 if node.type == "root":
95 for child in node.children:
96 recursive_collect_tokens(child, token_list)
97 elif node.token:
98 token_list.append(node.token)
99 else:
100 assert node.nester_tokens
101 token_list.append(node.nester_tokens.opening)
102 for child in node.children:
103 recursive_collect_tokens(child, token_list)
104 token_list.append(node.nester_tokens.closing)
105
106 tokens: list[Token] = []
107 recursive_collect_tokens(self, tokens)
108 return tokens
109
110 @property
111 def children(self: _NodeType) -> list[_NodeType]:

Callers 1

Calls

no outgoing calls

Tested by 1