MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / pretty

Method pretty

markdown_it/tree.py:222–242  ·  view source on GitHub ↗

Create an XML style string of the tree.

(
        self, *, indent: int = 2, show_text: bool = False, _current: int = 0
    )

Source from the content-addressed store, hash-verified

220 self._add_child(nested_tokens)
221
222 def pretty(
223 self, *, indent: int = 2, show_text: bool = False, _current: int = 0
224 ) -> str:
225 """Create an XML style string of the tree."""
226 prefix = " " * _current
227 text = prefix + f"<{self.type}"
228 if not self.is_root and self.attrs:
229 text += " " + " ".join(f"{k}={v!r}" for k, v in self.attrs.items())
230 text += ">"
231 if (
232 show_text
233 and not self.is_root
234 and self.type in ("text", "text_special")
235 and self.content
236 ):
237 text += "\n" + textwrap.indent(self.content, prefix + " " * indent)
238 for child in self.children:
239 text += "\n" + child.pretty(
240 indent=indent, show_text=show_text, _current=_current + indent
241 )
242 return text
243
244 def walk(
245 self: _NodeType, *, include_self: bool = True

Callers 2

test_prettyFunction · 0.95
test_pretty_text_specialFunction · 0.95

Calls

no outgoing calls

Tested by 2

test_prettyFunction · 0.76
test_pretty_text_specialFunction · 0.76