use mant_ast::Inline;
pub(crate) fn plain_text(nodes: &[Inline]) -> String {
let mut output = String::new();
for node in nodes {
match node {
Inline::Text { value } | Inline::Code { value } => output.push_str(value),
Inline::Strong { children }
| Inline::Emphasis { children }
| Inline::ExternalLink { children, .. }
| Inline::EmailLink { children, .. }
| Inline::ManualReference { children, .. }
| Inline::SectionReference { children, .. } => output.push_str(&plain_text(children)),
Inline::Anchor { .. } => {}
Inline::LineBreak => output.push('\n'),
}
}
output
}
pub(crate) const DEFAULT_INLINE_TERM_MAX_WIDTH: usize = 6;
pub(crate) fn terms_fit_inline(terms: &[Vec<Inline>], max_width: usize) -> bool {
let width = terms
.iter()
.map(|term| plain_text(term))
.collect::<Vec<_>>()
.join(", ")
.trim()
.chars()
.count();
(1..=max_width).contains(&width)
}