A simple HTML writer
Project description
html-writer
A simple html writer for python.
Description
You can write raw html with 'with' statements like:
html = Html()
with html.tag('div'):
with html.tag('p') as h:
h += 'Hello world!'
# Here html has '<div><p>Hello world!</p></div>'
'with' syntax also serves human-readable indentation:
html = Html()
with html.tag('div'):
with html.tag('p') as h:
h += 'Hello world!'
# Here html really has
# <div>
# <p>
# Hello world!
# </p>
# </div>
Installation
pip install html_writer
Example
from html_writer import Html
import datetime
head = Html()
head.self_close_tag('meta', attributes=dict(charset='utf-8'))
body = Html()
with body.tag('div'):
with body.tag('p') as h:
h += 'Hello World!'
with body.tag('dl'):
body.tag_with_content('Today', name='dt')
with body.tag('dt') as h:
h += datetime.datetime.now().strftime('%y/%m/%d %H:%M:%S')
print(Html.html_template(head, body).to_raw_html(indent_size=2))
Requirements
- Python >= 3.7.0
Frequently Asked Questions
Q. Isn't it reinventing the wheel? :) :) :)
A. Enjoy coding!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
html_writer-1.1.1.tar.gz
(6.8 kB
view hashes)
Built Distribution
Close
Hashes for html_writer-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16fc5d4337d6a22de33abf6f2e0e2061a2415caa61bf2f77a12f58f41981bfbb |
|
MD5 | 9825bfda254614fb1be6807f1608c088 |
|
BLAKE2b-256 | a0253f2645a949a0cb8c385fcd5a5596e3b6a9b637c8b72f56ee73e99adc550c |