Return (tag, attrs dict, text) for each start tag; HTMLParser decodes entities.
(fragment: str)
| 1697 | |
| 1698 | |
| 1699 | def _parse_html_fragment(fragment: str) -> list: |
| 1700 | """Return (tag, attrs dict, text) for each start tag; HTMLParser decodes entities.""" |
| 1701 | from html.parser import HTMLParser |
| 1702 | tags: list = [] |
| 1703 | open_: list = [] |
| 1704 | |
| 1705 | class _P(HTMLParser): |
| 1706 | def handle_starttag(self, tag, attrs): |
| 1707 | tags.append([tag, dict(attrs), ""]) |
| 1708 | open_.append(tags[-1]) |
| 1709 | |
| 1710 | def handle_endtag(self, tag): |
| 1711 | if open_: |
| 1712 | open_.pop() |
| 1713 | |
| 1714 | def handle_data(self, data): |
| 1715 | if open_: |
| 1716 | open_[-1][2] += data |
| 1717 | |
| 1718 | _P(convert_charrefs=True).feed(fragment) |
| 1719 | return tags |
| 1720 | |
| 1721 | |
| 1722 | def test_to_html_legend_label_escaped_once_without_title(tmp_path): |
no test coverage detected