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.
31 lines
1.0 KiB
Rust
31 lines
1.0 KiB
Rust
//! 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)
|
||
}
|