MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _parse_html_fragment

Function _parse_html_fragment

tests/test_export.py:1699–1719  ·  view source on GitHub ↗

Return (tag, attrs dict, text) for each start tag; HTMLParser decodes entities.

(fragment: str)

Source from the content-addressed store, hash-verified

1697
1698
1699def _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
1722def test_to_html_legend_label_escaped_once_without_title(tmp_path):

Calls 1

_PClass · 0.85

Tested by

no test coverage detected