Skip to content

Commit

Permalink
馃憣 Show text of text_special in tree.pretty (#282)
Browse files Browse the repository at this point in the history
Provides a demonstration of how the new `text_special` token parsing works
  • Loading branch information
chrisjsewell committed Jun 2, 2023
1 parent dd51f62 commit 64965cf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion markdown_it/tree.py
Expand Up @@ -229,7 +229,12 @@ def pretty(
if not self.is_root and self.attrs:
text += " " + " ".join(f"{k}={v!r}" for k, v in self.attrs.items())
text += ">"
if show_text and not self.is_root and self.type == "text" and self.content:
if (
show_text
and not self.is_root
and self.type in ("text", "text_special")
and self.content
):
text += "\n" + textwrap.indent(self.content, prefix + " " * indent)
for child in self.children:
text += "\n" + child.pretty(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_tree.py
Expand Up @@ -76,6 +76,13 @@ def test_pretty(file_regression):
file_regression.check(node.pretty(indent=2, show_text=True), extension=".xml")


def test_pretty_text_special(file_regression):
md = MarkdownIt()
md.disable("text_join")
tree = SyntaxTreeNode(md.parse("foo © bar \\("))
file_regression.check(tree.pretty(show_text=True), extension=".xml")


def test_walk():
tokens = MarkdownIt().parse(EXAMPLE_MARKDOWN)
tree = SyntaxTreeNode(tokens)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_tree/test_pretty_text_special.xml
@@ -0,0 +1,11 @@
<root>
<paragraph>
<inline>
<text>
foo
<text_special>
<text>
bar
<text_special>
(

0 comments on commit 64965cf

Please sign in to comment.