Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
<div class="light bold"></div>

Empty Elements

Some elements (e.g., <br>) do not have children and only an opening tag:

...

However, it is sometimes necessary to dump raw, prepared content into the tree that will be rendered as is. This is done using Raw.

Code Block
tb = Html5TreeBuilder()
doc = tb.html()
doc.add(Raw("<data>raw</data>"), "<data>processed</data>")

...

Code Block
languagepy
data = [("Mark", 25), ("Lucy", 23), ("Joe", 32), ("Jane", 41)]
table = tb.table()
table.add(tb.tr(tb.th("Name"), tb.th("Age")))
table.add([tb.tr[(tb.td(name), tb.td(age)) for name, age in data.items()])

...