forge
Explore
Log in

Don't you dare go Hollow

project_note

Clone
★ 0

0 watching0 forksRust3.6 MiBc49f5e7Tahinli1 month ago2 commits

tree.rs24 lines, 753 bytesHistoryRawDownload
1//! Small read helpers shared by the readers.
2
3use loro::{LoroDoc, LoroValue};
4
5pub fn value_str(v: &LoroValue) -> Option<String> {
6 v.as_string().map(|s| s.as_str().to_owned())
7}
8
9/// Plain text of the first non-empty block, trimmed, max 80 chars. "Untitled" if empty.
10pub fn title(doc: &LoroDoc) -> String {
11 title_from(&crate::flat::first_text(doc))
12}
13
14/// A title from a block's plain text, as [`title`] makes it.
15pub fn title_from(raw: &str) -> String {
16 let collapsed = raw.split_whitespace().collect::<Vec<_>>().join(" ");
17 let truncated: String = collapsed.chars().take(80).collect();
18 let trimmed = truncated.trim_end();
19 if trimmed.is_empty() {
20 "Untitled".to_string()
21 } else {
22 trimmed.to_string()
23 }
24}