Skip to content

Commit 034a22c

Browse files
authored
Merge pull request #25 from rocal-dev/fix/void-tag
Fix close void tag
2 parents faafb4d + 8b63438 commit 034a22c

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rocal_ui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rocal-ui"
3-
version = "0.1.10"
3+
version = "0.1.11"
44
edition = "2021"
55

66
authors = ["Yoshiki Sashiyama <yoshi@rocal.dev>"]

rocal_ui/src/html/to_tokens.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ impl Html {
8383
};
8484
}
8585

86-
out.push(quote! {
87-
html.push_str(">");
88-
});
86+
if element.is_void() {
87+
out.push(quote! {
88+
html.push_str(" />");
89+
});
90+
} else {
91+
out.push(quote! {
92+
html.push_str(">");
93+
});
94+
}
8995
}
9096

9197
if !element.is_void() {

rocal_ui/tests/test_html_to_tokens.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,23 @@ mod tests {
147147
assert!(out.contains("async"));
148148
assert!(out.contains("defer"));
149149
}
150+
151+
#[test]
152+
fn svg_image() {
153+
let out = gen(quote! {
154+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
155+
<path d="m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72"/>
156+
<path d="m14 7 3 3"/>
157+
<path d="M5 6v4"/>
158+
<path d="M19 14v4"/>
159+
<path d="M10 2v2"/>
160+
<path d="M7 8H3"/>
161+
<path d="M21 16h-4"/>
162+
<path d="M11 3H9"/>
163+
</svg>
164+
});
165+
166+
assert!(out.contains("svg"));
167+
assert!(out.contains("path"));
168+
}
150169
}

0 commit comments

Comments
 (0)