use alloc::string::String;
use crate::serialize::is_space;
use crate::tree::{Dom, NodeRef};
mod links;
mod meta;
mod readable;
mod table;
pub use links::{Link, Resource};
pub use meta::Metadata;
pub use table::to_csv;
pub(crate) fn document_order(dom: &Dom) -> impl Iterator<Item = NodeRef<'_>> {
dom.roots()
.flat_map(|root| core::iter::once(root).chain(root.descendants()))
}
pub(crate) fn collapse(text: &str) -> String {
let mut out = String::with_capacity(text.len());
for word in text.split(is_space).filter(|w| !w.is_empty()) {
if !out.is_empty() {
out.push(' ');
}
out.push_str(word);
}
out
}
pub(crate) fn has_token(list: &str, token: &str) -> bool {
list.split(is_space).any(|t| t.eq_ignore_ascii_case(token))
}
pub(crate) fn non_empty(value: &str) -> Option<&str> {
let value = value.trim_matches(is_space);
(!value.is_empty()).then_some(value)
}