Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👌 Show text of text_special in tree.pretty #282

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion markdown_it/tree.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<root>
<paragraph>
<inline>
<text>
foo
<text_special>
©
<text>
bar
<text_special>
(