From 8691c11933ef42ab9eef4d74d3f46e263ea77697 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 5 Sep 2025 16:43:57 -0700 Subject: [PATCH] template_parser: Check for invalid combinations of HTML elements. Signed-off-by: Anders Kaseorg --- tools/lib/html_elements.py | 191 +++++++++++++++++++++++++++++++++++ tools/lib/template_parser.py | 76 +++++++------- 2 files changed, 232 insertions(+), 35 deletions(-) create mode 100644 tools/lib/html_elements.py diff --git a/tools/lib/html_elements.py b/tools/lib/html_elements.py new file mode 100644 index 0000000000..563cb584b1 --- /dev/null +++ b/tools/lib/html_elements.py @@ -0,0 +1,191 @@ +from collections.abc import Iterator + +VALID_HTML_CONTEXTS: dict[tuple[str, str], str] = { + # https://html.spec.whatwg.org/multipage/indices.html#elements-3 + ("a", "phrasing"): "transparent", + ("abbr", "phrasing"): "phrasing", + ("address", "flow"): "flow", + ("area", "phrasing"): "void", + ("article", "flow"): "flow", + ("aside", "flow"): "flow", + ("audio", "phrasing"): "