Skip to content

Commit 261dc90

Browse files
authored
👌 IMPROVE: Make SyntaxTreeNode subclassable (#130)
1 parent 888636c commit 261dc90

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

markdown_it/tree.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ def __init__(self) -> None:
4444
# children (i.e. inline or img)
4545
self.children: List["SyntaxTreeNode"] = []
4646

47-
@staticmethod
48-
def from_tokens(tokens: Sequence[Token]) -> "SyntaxTreeNode":
47+
@classmethod
48+
def from_tokens(cls, tokens: Sequence[Token]) -> "SyntaxTreeNode":
4949
"""Instantiate a `SyntaxTreeNode` from a token stream.
5050
5151
This is the standard method for instantiating `SyntaxTreeNode`.
5252
"""
53-
root = SyntaxTreeNode()
53+
root = cls()
5454
root._set_children_from_tokens(tokens)
5555
return root
5656

@@ -143,7 +143,7 @@ def _make_child(
143143
"""Make and return a child node for `self`."""
144144
if token and nester_tokens or not token and not nester_tokens:
145145
raise ValueError("must specify either `token` or `nester_tokens`")
146-
child = SyntaxTreeNode()
146+
child = type(self)()
147147
if token:
148148
child.token = token
149149
else:

0 commit comments

Comments
 (0)