Added all current html tags to dynatos_html::html.

Tags in `dynatos_html::html` now use `createElementNS` with the html namespace.
This commit is contained in:
Filipe Rodrigues 2024-02-16 12:53:31 +00:00
parent da19e1c801
commit 033355dad4
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU

View File

@ -3,6 +3,9 @@
// Imports
use {wasm_bindgen::JsValue, web_sys::Element};
/// Html namespace
const HTML_NAMESPACE: &str = "http://www.w3.org/1999/xhtml";
/// Expands to `stringify!($el_name)`, if present, otherwise to `$fn_name`
macro el_name {
($fn_name:ident, $el_name:literal) => {
@ -24,24 +27,146 @@ macro decl_elements(
let document = window.document().expect("Unable to get document");
let el_name = el_name!($fn_name $(, $el_name)?);
document.create_element( el_name )
document.create_element_ns(Some(HTML_NAMESPACE), el_name)
.unwrap_or_else(|err| self::on_create_fail(err, el_name))
}
)*
}
/// Function called when `document.create_element` fails
/// Function called when creating an element fails
fn on_create_fail(err: JsValue, el_name: &str) -> ! {
panic!("Unable to create element {el_name:?}: {err:?}");
panic!("Unable to create element {el_name:?} on namespace {HTML_NAMESPACE:?}: {err:?}");
}
decl_elements! {
a,
abbr,
acronym,
address,
area,
article,
aside,
audio,
b,
base,
bdi,
bdo,
big,
blockquote,
body,
br,
button,
canvas,
caption,
center,
cite,
code,
col,
colgroup,
content,
data,
datalist,
dd,
del,
details,
dfn,
dialog,
dir,
div,
dl,
dt,
em,
embed,
fieldset,
figcaption,
figure,
font,
footer,
form,
frame,
frameset,
h1,
head,
header,
hgroup,
hr,
html,
i,
iframe,
image,
img,
input,
ins,
kbd,
label,
legend,
li,
link,
main,
map,
mark,
marquee,
menu,
menuitem,
meta,
meter,
nav,
nobr,
noembed,
noframes,
noscript,
object,
ol,
optgroup,
option,
output,
p,
param,
picture,
plaintext,
portal,
pre,
progress,
q,
rb,
rp,
rt,
rtc,
ruby,
s,
samp,
script,
search,
section,
select,
shadow,
slot,
small,
source,
span,
strike,
strong,
style,
sub,
summary,
sup,
table,
tbody,
td,
template,
textarea,
tfoot,
th,
thead,
time,
title,
tr,
track,
tt,
u,
ul,
var,
video,
wbr,
xmp,
}