I'm using yattag
to generate HTML:
doc, tag, text = Doc().tagtext()
with tag("p"):
text("My paragraph.")
While it works well enough, when I look at the HTML source it comes out all on one line. Is there some kind of switch or other trick that makes yattag
create more readable source?
Use the indent
function.
from yattag import Doc, indent
doc, tag, text = Doc().tagtext()
with tag("p"):
text("My paragraph.")
print(indent(doc.getvalue())) # will indent the tags but not the text directly contained between <tag> and </tag>
print(indent(doc.getvalue(), indent_text = True)) # will also indent the text directly contained between <tag> and </tag>