Tea
" "Steeping green tea for three minutes draws out its flavor without turning it bitter.
###################
Exporting to text
###################
Once you have the node you want, :meth:`~turbohtml.Node.to_markdown` turns it into `GitHub-Flavored Markdown
Steep green tea for 3 minutes. Steeping green tea for three minutes draws out its flavor without turning it bitter.Tea
Tea
"
"
`` -- set ``xml`` on the :class:`~turbohtml.clean.Policy` and the cleaned tree serializes as well-formed XML,
every empty element self-closed:
.. testcode::
from turbohtml.clean import sanitize, Policy
print(sanitize("
one
two
one
two
Hi
********************** Emit well-formed XML ********************** To hand the tree to an XML toolchain instead of a browser, set ``xml=True`` on the :class:`~turbohtml.Html` config. Every empty element self-closes, foreign SVG and MathML subtrees carry their namespace declarations, and text and attribute values follow the XML escaping rules, so the output parses with any XML reader: .. testcode:: from turbohtml import Html doc = turbohtml.parse("a & b
a & b
hi & bye
hi & bye
hi & bye
Steep the tea.
", source_locations=True) doc.find("b").attrs["data-term"] = "1" print(doc.find("p").to_source()) .. testoutput::Steep the tea.
The single-quoted ``class`` and the unchanged text stay exactly as written; only the edited ```` tag rebuilds. That is the whole tree API. Head to the :doc:`/how-to/index` guides for task-focused recipes, the :doc:`/migration/index` guide if you are coming from another HTML library, or the :doc:`/reference` for the exact signatures.