mirror of
https://github.com/storytold/wordcraft.git
synced 2026-10-29 04:47:10 -06:00
Keep a single leading space in HTML export paragraphs (#3102)
Found while testing crates/formats/src/html.rs (export, around line 1744; paragraph text writer) Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
517ba09250
commit
74ab8d2819
@@ -1474,9 +1474,9 @@ fn align_css(a: Option<Align>) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
fn text_html(t: &str) -> String {
|
||||
fn text_html(t: &str, at_start: bool) -> String {
|
||||
let mut o = String::new();
|
||||
let mut prev_space = false;
|
||||
let mut prev_space = at_start;
|
||||
for c in t.chars() {
|
||||
match c {
|
||||
'\n' => {
|
||||
@@ -1547,8 +1547,9 @@ pub fn inlines_html(inlines: &[Inline]) -> String {
|
||||
open.push_str(&format!("<span style=\"{}\">", css.join(";")));
|
||||
close.push("</span>");
|
||||
}
|
||||
let at_start = o.is_empty();
|
||||
o.push_str(&open);
|
||||
o.push_str(&text_html(t));
|
||||
o.push_str(&text_html(t, at_start));
|
||||
for c in close.iter().rev() {
|
||||
o.push_str(c);
|
||||
}
|
||||
@@ -2036,4 +2037,13 @@ mod tests {
|
||||
};
|
||||
assert_eq!(p.text(), "World");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_space_survives_round_trip() {
|
||||
let doc = Document::from_text(" lead");
|
||||
let html = export(&doc);
|
||||
assert!(!html.contains("<p> lead"), "{html}");
|
||||
let back = import(&html);
|
||||
assert_eq!(back.plain_text(Default::default()).replace('\u{a0}', " "), " lead");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user