PSD export: a CR LF in an HTML Text slice's type is one line break

A type object whose text ends its lines with CR LF no longer writes two <br> tags for each line ending in its HTML Text slice's cell text.
This commit is contained in:
dotCooCoo
2026-11-15 18:11:50 -08:00
parent dea17e5446
commit 5163f9a9b9
2 changed files with 16 additions and 1 deletions
+2 -1
View File
@@ -541,10 +541,11 @@ fn background(o: &SliceOptions) -> [u8; 4] {
}
/// The text of type object `n` as the HTML an HTML Text slice shows: `&`, `<` and `>` escaped, a
/// line break as `<br>`. Empty for anything but type.
/// line break as `<br>` (CR LF is one break). Empty for anything but type.
fn html_text(n: &Node) -> String {
let NodeKind::Text(t) = &n.kind else { return String::new() };
t.plain_text()
.replace("\r\n", "\n")
.split(['\n', '\r', '\u{2029}'])
.map(|l| l.replace('&', "&amp;").replace('<', "&lt;").replace('>', "&gt;"))
.collect::<Vec<_>>()
+14
View File
@@ -452,6 +452,20 @@ fn slices_are_cut_to_the_exported_region_in_its_pixels() {
assert!(slices_of(&file).is_none());
}
#[test]
fn an_html_text_slice_writes_one_break_for_each_line_ending() {
use vectorcraft_doc::{CharStyle, NodeKind, TextObject};
use vectorcraft_geom::Point;
let mut d = DocBuilder::new(100.0, 60.0).build();
let t = TextObject::point(Point::new(10.0, 30.0), "A\r\nB\rC\nD\u{2029}E", CharStyle { size: 12.0, ..CharStyle::default() });
let mut n = Node::new(d.alloc_id(), NodeKind::Text(Box::new(t)));
n.extras_mut().slice = Some(Box::new(SliceOptions { kind: SliceKind::HtmlText, ..SliceOptions::default() }));
let l = d.layers[0].id;
d.insert(Some(l), 0, n).unwrap();
let res = slices_of(&export(&d, &opts(PsdOptions::default()))).unwrap();
assert_eq!(res.slices[0].cell_text, "A<br>B<br>C<br>D<br>E");
}
#[test]
fn slice_ids_count_from_1_and_the_limits_are_errors() {
let mut doc = doc();