pub(super) use crate::converter::main_helpers::tag_name_eq;
pub(super) use crate::converter::utility::content::normalized_tag_name;
#[allow(clippy::trivially_copy_pass_by_ref)]
pub(super) fn is_tag_name(
node_handle: &crate::dom::NodeHandle,
parser: &crate::dom::Parser,
dom_ctx: &super::super::super::DomContext,
name: &str,
) -> bool {
if let Some(info) = dom_ctx.tag_info(node_handle.get_inner(), parser) {
return info.name == name;
}
matches!(
node_handle.get(parser),
Some(crate::dom::Node::Tag(tag)) if tag_name_eq(tag.name().as_utf8_str(), name)
)
}
#[allow(clippy::trivially_copy_pass_by_ref)]
pub(super) fn is_or_contains_table(
node_handle: &crate::dom::NodeHandle,
parser: &crate::dom::Parser,
dom_ctx: &super::super::super::DomContext,
) -> bool {
let mut work = vec![*node_handle];
while let Some(handle) = work.pop() {
if is_tag_name(&handle, parser, dom_ctx, "table") {
return true;
}
let Some(crate::dom::Node::Tag(tag)) = handle.get(parser) else {
continue;
};
if let Some(children) = dom_ctx.children_of(handle.get_inner()) {
work.extend(children.iter().copied());
} else {
work.extend(tag.children().top().iter().copied());
}
}
false
}