From 8b85809a0a56838d6a15d740de8b1ec037fa72f1 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sun, 8 Nov 2026 06:21:44 +0100 Subject: [PATCH] Write imported classes in the SVG Tiny 1.2 profile too SVG Tiny 1.2 lists class among its core attributes, so the Tiny export no longer drops an object's own classes. Co-Authored-By: Claude Opus 5.5 --- crates/svg/src/export/output.rs | 3 ++- crates/svg/tests/classes.rs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/svg/src/export/output.rs b/crates/svg/src/export/output.rs index 6086dcc47..fb06f8005 100644 --- a/crates/svg/src/export/output.rs +++ b/crates/svg/src/export/output.rs @@ -211,7 +211,8 @@ impl Writer<'_> { .map(String::as_str) .filter(|c| !c.is_empty() && !c.chars().any(|ch| ch.is_control() || matches!(ch, '\u{fffe}' | '\u{ffff}'))) .collect(); - if !classes.is_empty() && !self.tiny() { + // SVG Tiny 1.2 has `class` among its core attributes, so every profile writes them. + if !classes.is_empty() { out.push_str(&format!(" class=\"{}\"", xml_attr_escape(&classes.join(" ")))); } let mut keys = HashSet::new(); diff --git a/crates/svg/tests/classes.rs b/crates/svg/tests/classes.rs index 88be96429..b3ae4622e 100644 --- a/crates/svg/tests/classes.rs +++ b/crates/svg/tests/classes.rs @@ -1,7 +1,7 @@ //! CSS classes on imported elements come back on export, beside the generated `cls-N` classes. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] use usvg::roxmltree; -use vectorcraft_svg::{ExportOptions, Styling, export, import}; +use vectorcraft_svg::{ExportOptions, Profile, Styling, export, import}; const SRC: &str = r#""#; @@ -36,3 +36,10 @@ fn class_names_with_colons_slashes_and_no_break_spaces_are_kept() { let out = export(&import(src).unwrap(), &ExportOptions::default()); assert_eq!(class_of(&out, "r").as_deref(), Some("hover:bg-blue w-1/2 a\u{a0}b")); } + +#[test] +fn the_tiny_profile_keeps_imported_classes() { + let out = export(&import(SRC).unwrap(), &ExportOptions { profile: Profile::Tiny12, ..ExportOptions::default() }); + assert_eq!(class_of(&out, "grp").as_deref(), Some("wrap big"), "{out}"); + assert_eq!(class_of(&out, "r").as_deref(), Some("hero"), "{out}"); +}