Skip to main content

lignin_schema/
lib.rs

1#![forbid(unsafe_code)]
2#![no_std]
3#![doc(html_root_url = "https://docs.rs/lignin-schema/0.0.4")]
4#![warn(clippy::pedantic)]
5
6use heck_but_macros::stringify_SHOUTY_SNEK_CASE;
7pub use lignin;
8
9#[cfg(doctest)]
10pub mod readme {
11	doc_comment::doctest!("../README.md");
12}
13
14macro_rules! element {
15	($name:ident) => {
16		#[inline(always)]
17		#[must_use]
18		pub fn $name<'a>(
19			attributes: &'a [lignin::Attribute<'a>],
20			content: &'a [lignin::Node<'a>],
21			event_bindings: &'a [lignin::EventBinding<'a>],
22		) -> lignin::Element<'a> {
23			lignin::Element {
24				name: stringify_SHOUTY_SNEK_CASE!($name),
25				attributes,
26				content,
27				event_bindings,
28			}
29		}
30	};
31}
32
33macro_rules! void_element {
34	($name:ident) => {
35		#[inline(always)]
36		#[must_use]
37		pub fn $name<'a>(
38			attributes: &'a [lignin::Attribute<'a>],
39			_: &'a [lignin::Node<'a>; 0],
40			event_bindings: &'a [lignin::EventBinding<'a>],
41		) -> lignin::Element<'a> {
42			lignin::Element {
43				name: stringify_SHOUTY_SNEK_CASE!($name),
44				attributes,
45				content: &[],
46				event_bindings,
47			}
48		}
49	};
50}
51
52macro_rules! elements {
53    ($($name:ident),+) => {
54        $(element!($name);)+
55    };
56}
57
58macro_rules! void_elements {
59    ($($name:ident),+) => {
60        $(void_element!($name);)+
61    };
62}
63
64//SEE: https://developer.mozilla.org/en-US/docs/Web/HTML/Element
65// Main root
66elements!(html);
67// Document metadata
68elements!(head, style, title);
69void_elements!(base, link, meta);
70// Sectioning root
71elements!(body);
72// Content sectioning
73elements!(
74	address, article, aside, footer, header, h1, h2, h3, h4, h5, h6, hgroup, main, nav, section
75);
76// Text content
77elements!(blockquote, dd, div, dl, dt, figcaption, figure, hr, li, /*main,*/ ol, p, pre, ul);
78// Inline text semantics
79elements!(
80	a, abbr, b, bdi, bdo, cite, code, data, dfn, em, i, kbd, mark, q, rb, rp, rt, rtc, ruby, s,
81	samp, small, span, strong, sub, sup, time, u, var
82);
83void_elements!(br, wbr);
84// Image and multimedia
85elements!(audio, map, video);
86void_elements!(area, img, track);
87// Embedded content
88elements!(iframe, object, picture);
89void_elements!(embed, param, source);
90// Scripting
91elements!(canvas, noscript, script);
92// Demarcating edits
93elements!(del, ins);
94// Table content
95elements!(caption, colgroup, table, tbody, td, tfoot, th, thead, tr);
96void_elements!(col);
97// Forms
98elements!(
99	button, datalist, fieldset, form, label, legend, meter, optgroup, option, progress, select,
100	textarea
101);
102void_elements!(input);
103// Interactive elements
104elements!(details, dialog, menu, summary);
105// Web components
106elements!(slot, template);
107
108#[deprecated = "To quote MDN: Warning: \"These are old HTML elements which are deprecated and should not be used. You should never use them in new projects, and should replace them in old projects as soon as you can. They are listed here for informational purposes only.\""]
109/// Don't actually use these. They're broken or could break at a moment's notice (or without notice, for that matter...).
110pub mod deprecated {
111	use super::stringify_SHOUTY_SNEK_CASE;
112	elements!(
113		acronym, applet, big, blink, center, content, dir, element, font, frameset, listing,
114		marquee, multicol, nobr, noembed, noframes, plaintext, shadow, strike, tt, xmp
115	);
116	void_elements!(
117		basefont, bgsound, command, frame,
118		image, // The spec doesn't actually say whether this allows content.
119		isindex, keygen, menuitem, nextid, spacer
120	);
121}