我yattag用来生成 HTML:
doc, tag, text = Doc().tagtext()
with tag("p"):
text("My paragraph.")
虽然它工作得很好,但当我查看 HTML 源代码时,它全部出现在一行中。是否有某种开关或其他技巧可以使yattag创建更具可读性的源?
我yattag用来生成 HTML:
doc, tag, text = Doc().tagtext()
with tag("p"):
text("My paragraph.")
虽然它工作得很好,但当我查看 HTML 源代码时,它全部出现在一行中。是否有某种开关或其他技巧可以使yattag创建更具可读性的源?
使用该indent功能。
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>