From 124da6c73591d60f5d14839e9e10c7bc52f5fbe5 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Thu, 25 Feb 2021 23:03:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Make=20`SyntaxTreeNod?= =?UTF-8?q?e`=20subclassable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- markdown_it/tree.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/markdown_it/tree.py b/markdown_it/tree.py index 62d16c79..c0036139 100644 --- a/markdown_it/tree.py +++ b/markdown_it/tree.py @@ -44,13 +44,13 @@ def __init__(self) -> None: # children (i.e. inline or img) self.children: List["SyntaxTreeNode"] = [] - @staticmethod - def from_tokens(tokens: Sequence[Token]) -> "SyntaxTreeNode": + @classmethod + def from_tokens(cls, tokens: Sequence[Token]) -> "SyntaxTreeNode": """Instantiate a `SyntaxTreeNode` from a token stream. This is the standard method for instantiating `SyntaxTreeNode`. """ - root = SyntaxTreeNode() + root = cls() root._set_children_from_tokens(tokens) return root @@ -143,7 +143,7 @@ def _make_child( """Make and return a child node for `self`.""" if token and nester_tokens or not token and not nester_tokens: raise ValueError("must specify either `token` or `nester_tokens`") - child = SyntaxTreeNode() + child = type(self)() if token: child.token = token else: