//! Inline marks of a LoroText run, shared by the readers and the writer. use std::collections::HashMap; use std::hash::BuildHasher; use loro::LoroValue; use crate::tree::value_str; /// The marks on one run of text. `link` holds `(href, title)`. #[derive(PartialEq, Clone, Default, Debug)] pub struct Marks { pub strong: bool, pub em: bool, pub code: bool, pub link: Option<(String, Option)>, } impl Marks { /// Reads the marks from the attributes of a rich-text delta. A mark counts as on /// unless its value is null or absent. pub fn from_attrs(attrs: &HashMap) -> Marks { let on = |k: &str| attrs.get(k).is_some_and(|v| !matches!(v, LoroValue::Null)); let link = attrs.get("link").map(|v| { let href = v.get_by_key("href").and_then(value_str).unwrap_or_default(); let title = v .get_by_key("title") .and_then(value_str) .filter(|t| !t.is_empty()); (href, title) }); Marks { strong: on("strong"), em: on("em"), code: on("code"), link, } } }