fix: Filter out script/style tags during DOM tree build
Some checks are pending
Build and Release / build (linux, ubuntu-latest) (push) Waiting to run
Build and Release / build (macos, macos-latest) (push) Waiting to run
Build and Release / release (push) Blocked by required conditions

Previously, script and style tags were only filtered during render,
but their text content (JavaScript code) was still in the DOM tree.
Now we skip these tags entirely during DOM tree construction,
resulting in much cleaner output for modern websites.
This commit is contained in:
m1ngsama 2025-12-27 18:24:23 +08:00
parent 8d56a7b67b
commit 7ac0fc1c91

View file

@ -178,6 +178,12 @@ std::unique_ptr<DomNode> DomTreeBuilder::convert_node(
node->tag_name = gumbo_normalized_tagname(element.tag); node->tag_name = gumbo_normalized_tagname(element.tag);
node->element_type = map_gumbo_tag_to_element_type(element.tag); node->element_type = map_gumbo_tag_to_element_type(element.tag);
// 跳过 script、style 等不需要渲染的标签(包括其所有子节点)
if (element.tag == GUMBO_TAG_SCRIPT || element.tag == GUMBO_TAG_STYLE ||
element.tag == GUMBO_TAG_NOSCRIPT || element.tag == GUMBO_TAG_TEMPLATE) {
return nullptr;
}
// Assign current form ID to children // Assign current form ID to children
node->form_id = g_current_form_id; node->form_id = g_current_form_id;