//! Small read helpers shared by the readers. use loro::{LoroDoc, LoroValue}; pub fn value_str(v: &LoroValue) -> Option { v.as_string().map(|s| s.as_str().to_owned()) } /// Plain text of the first non-empty block, trimmed, max 80 chars. "Untitled" if empty. pub fn title(doc: &LoroDoc) -> String { title_from(&crate::flat::first_text(doc)) } /// A title from a block's plain text, as [`title`] makes it. pub fn title_from(raw: &str) -> String { let collapsed = raw.split_whitespace().collect::>().join(" "); let truncated: String = collapsed.chars().take(80).collect(); let trimmed = truncated.trim_end(); if trimmed.is_empty() { "Untitled".to_string() } else { trimmed.to_string() } }