This library is based on the sources and definitions of yattag with the fondamental difference that BeautifulSoup is used as the html renderer.
* At this time, only SimpleDoc has been converted, Doc class is work in progress. *
- The SimpleDoc/Doc object contains a BeautifulSoup intance in the soup attribute
- asis() and ttls() functions added to SimpleDoc
( tutorial for both libraries: yattag.org and BS4)
- No support for custom indentation (indent)
- stag_end option is not available
Nested html tags, no need to close tags, same as yattag.
from bs4tag import Doc
doc, tag, text = Doc().tagtext()
with tag('html'):
with tag('body', id = 'hello'):
with tag('h1'):
text('Hello world!')
print(doc.getvalue())
Insert bs4tag document into a BeautifulSoup instance.
def body_text():
doc, tag, text = SimpleDoc().tagtext()
with tag('h1'):
text('Hello world!')
return doc.soup
doc, tag, text = SimpleDoc().tagtext()
with tag('html'):
with tag('body', id='hello'):
pass
doc.soup.find(id='hello').append(body_text())
print(doc.getvalue())
# <html><body id="hello"><h1>Hello world!</h1></body></html>
pip3 install bs4tag
This library is compatible with the tutorial on yattag.org
GitHub repo: https://github.com/ceprio/bs4tag Derived from: https://github.com/leforestier/yattag