use crate::widgets::markdown_widget::foundation::elements::{ElementKind, MarkdownElement};
use crate::widgets::markdown_widget::state::CollapseState;
pub fn should_render_line(
element: &MarkdownElement,
_idx: usize,
collapse: &CollapseState,
) -> bool {
if let ElementKind::Heading { section_id, .. } = &element.kind {
if let Some((_, Some(parent))) = collapse.get_hierarchy(*section_id) {
if collapse.is_section_collapsed(parent) {
return false;
}
}
return true;
}
if matches!(element.kind, ElementKind::Frontmatter { .. }) {
return true;
}
if matches!(element.kind, ElementKind::FrontmatterStart { .. }) {
return true;
}
if matches!(
element.kind,
ElementKind::FrontmatterField { .. } | ElementKind::FrontmatterEnd
) {
if collapse.is_section_collapsed(0) {
return false;
}
return true;
}
if let Some(section_id) = element.section_id {
if collapse.is_section_collapsed(section_id) {
return false;
}
}
true
}