// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use super::prelude::*;
/// Removes invalid FuncIRI links.
///
/// `svgdom` will store unresolved links as strings.
/// So we have to remove attributes that should be FuncIRI and not string.
pub fn rm_invalid_links(doc: &mut Document) {
for mut node in doc.root().descendants() {
if !is_valid_func_link(&node, AId::ClipPath) {
node.remove_attribute(AId::ClipPath);
}
if !is_valid_func_link(&node, AId::Mask) {
node.remove_attribute(AId::Mask);
}
}
// Unlike `clip-path` and `mask`, when `filter` is invalid
// than the whole element should be removed.
let root = doc.root().clone();
doc.drain(root, |n| !is_valid_func_link(n, AId::Filter));
}
fn is_valid_func_link(node: &Node, aid: AId) -> bool {
match node.attributes().get_value(aid) {
Some(AValue::FuncLink(_)) | None => true,
_ => false,
}
}