Skip to content

Commit

Permalink
silenced non-normalised element name warnings for SVG elements
Browse files Browse the repository at this point in the history
  • Loading branch information
its-the-shrimp committed Nov 30, 2024
1 parent 84b7548 commit 420392b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
43 changes: 41 additions & 2 deletions packages/yew-macro/src/html_tree/html_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,45 @@ use crate::props::{ElementProps, Prop, PropDirective};
use crate::stringify::{Stringify, Value};
use crate::{is_ide_completion, non_capitalized_ascii, Peek, PeekValue};

fn is_normalised_element_name(name: &str) -> bool {
match name {
| "animateMotion"
| "animateTransform"
| "clipPath"
| "feBlend"
| "feColorMatrix"
| "feComponentTransfer"
| "feComposite"
| "feConvolveMatrix"
| "feDiffuseLighting"
| "feDisplacementMap"
| "feDistantLight"
| "feDropShadow"
| "feFlood"
| "feFuncA"
| "feFuncB"
| "feFuncG"
| "feFuncR"
| "feGaussianBlur"
| "feImage"
| "feMerge"
| "feMergeNode"
| "feMorphology"
| "feOffset"
| "fePointLight"
| "feSpecularLighting"
| "feSpotLight"
| "feTile"
| "feTurbulence"
| "foreignObject"
| "glyphRef"
| "linearGradient"
| "radialGradient"
| "textPath" => true,
_ => name.chars().all(|c| c.is_ascii_lowercase()),
}
}

pub struct HtmlElement {
pub name: TagName,
pub props: ElementProps,
Expand Down Expand Up @@ -310,9 +349,9 @@ impl ToTokens for HtmlElement {
TagName::Lit(dashedname) => {
let name_span = dashedname.span();
let name = dashedname.to_ascii_lowercase_string();
if name != dashedname.to_string() {
if !is_normalised_element_name(&dashedname.to_string()) {
emit_warning!(
dashedname.span(),
name_span.clone(),
format!(
"The tag '{dashedname}' is not matching its normalized form '{name}'. If you want \
to keep this form, change this to a dynamic tag `@{{\"{dashedname}\"}}`."
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-macro/tests/html_macro_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn dynamic_tags_catch_non_ascii() {
#[test]
fn html_nested_macro_on_html_element() {
let _node = html_nested! {
<div/>
<feBlend/>
};
let _node = html_nested! {
<input/>
Expand Down

0 comments on commit 420392b

Please sign in to comment.