Skip to content

Commit c1148b8

Browse files
committed
Minor API improvement
1 parent 49b3aaa commit c1148b8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

markdown_it/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def __init__(
5353
if options:
5454
self.set(options)
5555

56+
def __repr__(self):
57+
return f"{self.__class__.__module__}.{self.__class__.__name__}()"
58+
5659
def __getitem__(self, name):
5760
return {
5861
"inline": self.inline,

markdown_it/token.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def attrJoin(self, name, value):
7979
else:
8080
self.attrs[idx][1] = self.attrs[idx][1] + " " + value
8181

82+
def copy(self):
83+
"""Return a shallow copy of the instance."""
84+
return attr.evolve(self)
85+
8286
def as_dict(self, children=True, filter=None, dict_factory=dict):
8387
"""Return the token as a dict.
8488
@@ -128,6 +132,7 @@ def nest_tokens(tokens: List[Token]) -> List[Union[Token, NestedTokens]]:
128132
token = tokens.pop()
129133

130134
if token.nesting == 0:
135+
token = token.copy()
131136
output.append(token)
132137
if token.children:
133138
token.children = nest_tokens(token.children)

0 commit comments

Comments
 (0)