Skip to content

Commit 64965cf

Browse files
authored
👌 Show text of text_special in tree.pretty (#282)
Provides a demonstration of how the new `text_special` token parsing works
1 parent dd51f62 commit 64965cf

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

markdown_it/tree.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,12 @@ def pretty(
229229
if not self.is_root and self.attrs:
230230
text += " " + " ".join(f"{k}={v!r}" for k, v in self.attrs.items())
231231
text += ">"
232-
if show_text and not self.is_root and self.type == "text" and self.content:
232+
if (
233+
show_text
234+
and not self.is_root
235+
and self.type in ("text", "text_special")
236+
and self.content
237+
):
233238
text += "\n" + textwrap.indent(self.content, prefix + " " * indent)
234239
for child in self.children:
235240
text += "\n" + child.pretty(

tests/test_tree.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ def test_pretty(file_regression):
7676
file_regression.check(node.pretty(indent=2, show_text=True), extension=".xml")
7777

7878

79+
def test_pretty_text_special(file_regression):
80+
md = MarkdownIt()
81+
md.disable("text_join")
82+
tree = SyntaxTreeNode(md.parse("foo © bar \\("))
83+
file_regression.check(tree.pretty(show_text=True), extension=".xml")
84+
85+
7986
def test_walk():
8087
tokens = MarkdownIt().parse(EXAMPLE_MARKDOWN)
8188
tree = SyntaxTreeNode(tokens)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<root>
2+
<paragraph>
3+
<inline>
4+
<text>
5+
foo
6+
<text_special>
7+
©
8+
<text>
9+
bar
10+
<text_special>
11+
(

0 commit comments

Comments
 (0)