use crate::dom::{Element, HTML_NAMESPACE, Node, TreeRelation};
use crate::style::{Display, ListStylePosition, ListStyleType, Style};
pub(super) const DEFAULT_SUMMARY: &str = "Details";
fn is_details(element: Element<'_>) -> bool {
element.namespace() == HTML_NAMESPACE && element.name() == "details"
}
pub(super) fn summary(details: Element<'_>) -> Option<Node<'_>> {
if !is_details(details) {
return None;
}
details
.children(TreeRelation::Formatting)
.find(|child| child.namespace() == HTML_NAMESPACE && child.name() == "summary")
.map(Element::as_node)
}
pub(super) fn renders_child(parent: Element<'_>, node: Node<'_>) -> bool {
if !is_details(parent) {
return true;
}
parent.attr("open").is_some() && summary(parent) != Some(node)
}
pub(super) fn default_summary_style(details: Element<'_>, style: &Style) -> Option<Style> {
if !is_details(details) || summary(details).is_some() {
return None;
}
let mut summary = style.anonymous(Display::ListItem);
summary.list_style_type = ListStyleType::disclosure(details.attr("open").is_some());
summary.list_style_position = ListStylePosition::Inside;
Some(summary)
}