mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-12 18:15:49 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6945bc1877
commit
8b85809a0a
@@ -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();
|
||||
|
||||
@@ -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#"<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><g id="grp" class="wrap big"><rect id="r" class="hero hero cls-7" width="20" height="20" fill="red"/><circle id="c" r="5" fill="blue"/></g></svg>"#;
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user