#![deny(missing_docs)]
extern crate proc_macro;
use node::{Element, Node};
use proc_macro::TokenStream;
mod build;
mod node;
macro_rules! declare_tag {
($(#[$attr:meta])* $name:ident, $elem:expr) => {
$(#[$attr])*
#[proc_macro]
pub fn $name(stream: TokenStream) -> TokenStream {
Node::generate($elem, stream.into()).into()
}
};
}
macro_rules! declare_tags {
($type:ident, [$list:ident, $count:literal], [$($(#[$attr:meta])* $name:ident),*]) => {
const $list: [&str; $count] = [$(stringify!($name)),*];
$(
declare_tag!(
$(#[$attr])*
#[doc = concat!("[`<", stringify!($name), ">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/", stringify!($name), ") element.")]
#[doc = ""]
#[doc = include_str!(concat!("../docs/", stringify!($name), ".md"))]
$name,
Element::$type(stringify!($name))
);
)*
};
}
declare_tags![
normal,
[KNOWN_NORMAL_TAGS, 101],
[
a, abbr, address, article, aside, audio, b, bdi, bdo, blockquote, body, button, canvas,
caption, cite, code, colgroup, data, datalist, dd, del, details, dfn, dialog, div, dl, dt,
em, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, head, header,
hgroup, html, i, iframe, ins, kbd, label, legend, li, main, map, mark, menu, menuitem,
meter, nav, noscript, object, ol, optgroup, option, output, p, picture, pre, progress, q,
rb, rp, rt, rtc, ruby, s, samp, script, section, select, slot, small, span, strong, style,
sub, summary, sup, table, tbody, td, template, textarea, tfoot, th, thead, time, title, tr,
u, ul, var, video
]
];
declare_tags![
void,
[KNOWN_VOID_TAGS, 14],
[area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr]
];
declare_tag!(
frag,
Element::frag()
);
fn get_element(tag: &str) -> Option<Element> {
if KNOWN_NORMAL_TAGS.contains(&tag) {
return Some(Element::normal(tag));
}
if KNOWN_VOID_TAGS.contains(&tag) {
return Some(Element::void(tag));
}
if tag == "frag" {
return Some(Element::frag());
}
None
}