Files
faunosteo/crates/core/src/anatomy/svg/mod.rs
T
bchanot cf37aa265a feat(anatomy): V1-2.2 classify and clean drawings before upload
The sanitiser walk names removals that carried active or external
content; clean_svg answers clean, cleanable or rejected, the cleaned
text reading back with no removal. Committed cairo and ImageMagick
exports; the owner's editor exports go under exports/owner.
2026-10-29 13:14:22 +01:00

31 lines
1.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! SVG text → bounded, sanitised tree → text (plan R3 C2–C4). One reader for every SVG the
//! product draws: the sheet drawings now, the branding and Step 13 uploads later.
pub mod clean;
pub mod number;
pub mod prescan;
pub mod refs;
pub mod sanitize;
pub mod serialize;
pub mod tree;
pub use sanitize::Sanitized;
pub use tree::{Element, Node, SvgRejection};
/// Bounds, parses, sanitises and checks the references of an SVG text.
pub fn read_svg(text: &str) -> Result<Sanitized, SvgRejection> {
let root = tree::parse_svg(text)?;
let sanitized = sanitize::sanitize(root)?;
refs::check_references(&sanitized.root)?;
Ok(sanitized)
}
/// `read_svg` as the cleaning reads a file picked for upload: an oversized `title` or `desc`
/// is a removal, not a refusal (`sanitize::sanitize_for_cleaning`).
pub fn read_svg_for_cleaning(text: &str) -> Result<Sanitized, SvgRejection> {
let root = tree::parse_svg(text)?;
let sanitized = sanitize::sanitize_for_cleaning(root)?;
refs::check_references(&sanitized.root)?;
Ok(sanitized)
}