From c352c80c9645bd333f630a28dceda2e9035117fc Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Tue, 27 Oct 2026 02:11:32 +0100 Subject: [PATCH] Books: save a plain page as a string, as ComponentSerialization does Pages kept as components for their click events wrote a plain text page as {text:"p"}; vanilla's codec writes a component with no style or siblings as its string (the hotbar harness). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/item_data.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/item_data.rs b/crates/horizon-client/src/item_data.rs index 856eb2af3..68cb6e299 100644 --- a/crates/horizon-client/src/item_data.rs +++ b/crates/horizon-client/src/item_data.rs @@ -296,6 +296,21 @@ fn read_levels(t: Option<&Tag>) -> Levels { } /// A text component as stored by vanilla: a plain string or `{"text": ...}`. /// A `Filterable`: the value itself or `{raw: value}`. +/// `ComponentSerialization.CODEC`'s short form: a plain text component with +/// no style and no siblings is written as its string. +fn plain_component(t: &Tag) -> Tag { + if let Tag::Compound(c) = t + && let Some(text @ Tag::String(_)) = c.get(&"text".into()) + && c.iter().all(|(k, v)| { + k.to_string_lossy() == "text" + || (k.to_string_lossy() == "type" + && matches!(v, Tag::String(s) if s.to_string_lossy() == "text")) + }) + { + return text.clone(); + } + t.clone() +} fn filterable_text(t: &Tag) -> Option { match t.get("raw") { Some(raw) => read_text(raw), @@ -716,7 +731,7 @@ pub fn decode_components(components: Option<&Tag>) -> (u32, Option pages .iter() - .map(|p| p.get("raw").unwrap_or(p).clone()) + .map(|p| plain_component(p.get("raw").unwrap_or(p))) .collect(), _ => Vec::new(), },