New submission from jnns <[email protected]>:
[According to the WHATWG][1], the elements `area`, `base`, `br`, `col`,
`embed`, `hr`, `img`, `input`, `link`, `meta`, `param`, `source`, `track`,
`wbr` are *void elements* that don't need and therefore shouldn't have a
closing tag.
The source view of Firefox 96 shows a warning about an unexpected closing tag
[1].
In Python 3.10.2 `xml.etree` seems to correctly recognize most of them as such
and doesn't generate closing tags when using the `.tostring()` method. A few
elements are serialized with a closing tag (`<embed></embed>` for example).
```python
from xml.etree import ElementTree as etree
void_elements = [
"area", "base","br", "col", "embed", "hr", "img",
"input", "link", "meta", "param", "source", "track", "wbr"
]
for el in void_elements:
el = etree.Element(el)
print(etree.tostring(el, method="html", encoding="unicode"))
```
```html
<area>
<base>
<br>
<col>
<embed></embed>
<hr>
<img>
<input>
<link>
<meta>
<param>
<source></source>
<track></track>
<wbr></wbr>
```
HTML_EMPTY in Lib/xml/etree/ElementTree.py only contains the following entries:
"area", "base", "basefont", "br", "col", "frame", "hr", "img", "input",
"isindex", "link", "meta", "param"
I suppose "embed", "source", "track" and "wbr" should be added to that list.
[1]: https://html.spec.whatwg.org/multipage/syntax.html#void-elements
[2]: https://i.stack.imgur.com/rBTHw.png
----------
components: XML
messages: 413473
nosy: jnns
priority: normal
severity: normal
status: open
title: embed, source, track, wbr HTML elements not considered empty
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46786>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com