🐛 Fix parsing text spaces

This commit is contained in:
Elena Torro 2025-05-09 11:23:00 +02:00
parent 23bde76192
commit 59982c9056
2 changed files with 6 additions and 5 deletions

View file

@ -10,8 +10,7 @@
[app.render-wasm.helpers :as h]
[app.render-wasm.mem :as mem]
[app.render-wasm.serializers :as sr]
[app.render-wasm.wasm :as wasm]
[clojure.string :as str]))
[app.render-wasm.wasm :as wasm]))
(defn utf8->buffer [text]
(let [encoder (js/TextEncoder.)]
@ -21,8 +20,7 @@
;; buffer has the following format:
;; [<num-leaves> <paragraph_attributes> <leaves_attributes> <text>]
[leaves paragraph text]
(let [leaves (filter #(not (str/blank? (:text %))) leaves)
num-leaves (count leaves)
(let [num-leaves (count leaves)
paragraph-attr-size 48
leaf-attr-size 52
metadata-size (+ 1 paragraph-attr-size (* num-leaves leaf-attr-size))

View file

@ -451,8 +451,11 @@ impl RawTextData {
}
let text_utf8 = buffer[offset..text_end].to_vec();
let text = String::from_utf8(text_utf8).expect("Invalid UTF-8 text");
if text_utf8.is_empty() {
return (String::new(), text_end);
}
let text = String::from_utf8_lossy(&text_utf8).to_string();
(text, text_end)
}
}