To support both a JPEG and WEBP compressed image, I'd like to include the following HTML code in a web page:
<picture>
<source srcset="img/awesomeWebPImage.webp" type="image/webp">
<source srcset="img/creakyOldJPEG.jpg" type="image/jpeg">
<img src="img/creakyOldJPEG.jpg" alt="Alt Text!">
</picture>
I've been using Python Dominate and it has generally worked well for me. But the Picture and Source tags I think are not supported by Dominate. I could add the HTML as a raw() Dominate tag, but was wondering if there was a way to get Dominate to recognize these tags.
p = picture()
with p:
source(srcset=image.split('.')[0]+'.webp', type="image/webp")
source(srcset=image, type="image/jpeg")
img(src=image, alt=imagealt)
I am seeing this kind of error:
p = picture()
NameError: global name 'picture' is not defined
Dominate is used to generate HTML(5) documents.
The list of elements are defined in the
tags.py
file, see the repository in GitHub: https://github.com/Knio/dominate/blob/master/dominate/tags.py.But,
picture
is not a standard tag.You may look at the lxml library which contains a
ElementMaker
similar to Dominate to build XML tree easily. See the E-Factory.For instance: