Message413473
[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 |
|
Date |
User |
Action |
Args |
2022-02-18 10:23:19 | jnns | set | recipients:
+ jnns |
2022-02-18 10:23:19 | jnns | set | messageid: <1645179799.58.0.92424391054.issue46786@roundup.psfhosted.org> |
2022-02-18 10:23:19 | jnns | link | issue46786 messages |
2022-02-18 10:23:19 | jnns | create | |
|