html_validation/
svg_namespace.rs

1use lazy_static::lazy_static;
2use std::collections::HashMap;
3
4lazy_static! {
5    // list of svg elements
6    //  https://developer.mozilla.org/en-US/docs/Web/SVG/Element
7    //  a hashmap of `(tag, is_self_closing)`
8    static ref SVG_NAMESPACED_TAGS: HashMap<&'static str, bool> = [
9        // TODO: can cause conflict with html `a`
10        //("a", true),
11        ("animate", true),
12        ("animateMotion", false),
13        ("animateTransform", true),
14        ("circle", true),
15        ("clipPath",false),
16        // TODO: blocked with [issue](https://github.com/chinedufn/percy/issues/106)
17        //("color-profile",),
18        ("defs", false),
19        ("desc", false),
20        ("discard", true),
21        ("ellipse",true),
22        ("feBlend", true),
23        ("feColorMatrix", true),
24        ("feComponentTransfer", false),
25        ("feComposite", true),
26        ("feConvolveMatrix", true),
27        ("feDiffuseLighting", false),
28        ("feDisplacementMap", true),
29        ("feDistantLight", true),
30        ("feDropShadow", true),
31        ("feFlood", true),
32        ("feFuncA", true),
33        ("feFuncB", true),
34        ("feFuncG", true),
35        ("feFuncR", true),
36        ("feGaussianBlur", true),
37        ("feImage", true),
38        ("feMerge", false),
39        ("feMergeNode", true),
40        ("feMorphology", true),
41        ("feOffset", true),
42        ("fePointLight", true),
43        ("feSpecularLighting", false),
44        ("feSpotLight", true),
45        ("feTile", true),
46        ("feTurbulence", true),
47        ("filter", false),
48        ("foreignObject", false),
49        ("g",false),
50        ("hatch", false),
51        ("hatchpath", true),
52        ("image", true),
53        ("line", true),
54        ("linearGradient", false),
55        ("marker", false),
56        ("mask", false),
57        // TODO: undocumented
58        //("mesh",),
59        // TODO: undocumented
60        //("meshgradient",),
61        // TODO: undocumented
62        //("meshpatch",),
63        // TODO: undocumented
64        //("meshrow",),
65        ("metadata", false),
66        ("mpath", true),
67        ("path", true),
68        ("pattern", false),
69        ("polygon", true),
70        ("polyline", true),
71        ("radialGradient", false),
72        ("rect", true),
73        // TODO: can cause conflict with html `script` tag
74        //("script", false),
75        ("set", true),
76        ("solidcolor", true),
77        ("stop", true),
78        // TODO: can cause conflict with html `style` tag
79        //("style", false),
80        ("svg", false),
81        ("switch", false),
82        ("symbol", false),
83        ("text", false),
84        ("textPath", false),
85        // TODO: can cause conflict with html `title` tag
86        //("title", false),
87        ("tspan", false),
88        // TODO: undocumented
89        //("unknown",),
90        ("use", true),
91        ("view", true),
92    ]
93    .iter()
94    .cloned()
95    .collect();
96}
97/// Whether or not this tag is part svg elements
98/// ```
99/// use html_validation::is_svg_namespace;
100///
101/// assert_eq!(is_svg_namespace("svg"), true);
102///
103/// assert_eq!(is_svg_namespace("circle"), true);
104///
105/// assert_eq!(is_svg_namespace("div"), false);
106/// ```
107pub fn is_svg_namespace(tag: &str) -> bool {
108    SVG_NAMESPACED_TAGS.contains_key(tag)
109}
110
111/// Whether or not this svg tag is self closing
112pub(crate) fn is_self_closing_svg_tag(tag: &str) -> bool {
113    SVG_NAMESPACED_TAGS.get(tag).map(|v| *v).unwrap_or(false)
114}