Skip to main content

hypo/
macro.rs

1#[doc(hidden)]
2#[macro_export]
3macro_rules! render {
4    ($open:expr, $($close:expr)? => ($key:ident = $value:expr$(, $($tt:tt)*)?) -> ($($attrs:tt)*)) => {
5        $crate::render!($open, $($close)* => ($($($tt)*)*) -> (($crate::key!($key), $value, $($attrs)*)))
6    };
7    ($open:expr, $close:expr => ($($child:expr),*$(,)?) -> ($($attrs:tt)*)) => {
8        ($open, $crate::Attrs($($attrs)*), ($($child),*), $close)
9    };
10    ($open:expr, => () -> ($($attrs:tt)*)) => {
11        ($open, $crate::Attrs($($attrs)*))
12    };
13}
14
15#[doc(hidden)]
16#[macro_export]
17#[cfg(not(feature = "kebab"))]
18macro_rules! key {
19    ($key:ident) => {
20        stringify!($key)
21    };
22}
23
24#[doc(hidden)]
25#[macro_export]
26#[cfg(feature = "kebab")]
27macro_rules! key {
28    ($key:ident) => {
29        $crate::const_str::replace!(
30            $crate::const_str::replace!(stringify!($key), "r#", ""),
31            "_",
32            "-"
33        )
34    };
35}
36
37#[macro_export]
38/// renders arbitrary element
39macro_rules! element {
40    ($name:expr, $($tt:tt)*) => {
41        $crate::render!($crate::Raw(concat!('<', $name)), $crate::Raw(concat!("</", $name, '>')) => ($($tt)*) -> (()));
42    };
43    ($name:expr => void, $($tt:tt)*) => {
44        $crate::render!($crate::Raw(concat!('<', $name)), => ($($tt)*) -> (()));
45    };
46}
47
48macro_rules! elements {
49    ($dol:tt, $($name:ident $(@$tag:tt)? $doc:literal,)+) => {
50        $(
51            #[doc = $doc]
52            #[macro_export]
53            macro_rules! $name {
54                ($dol($doltt:tt)*) => {
55                    $crate::element!(stringify!($name)$(=> $tag)*, $dol($doltt)*)
56                };
57            }
58        )*
59    };
60}
61
62elements!($, // https://html.spec.whatwg.org/multipage/indices.html
63    a "Hyperlink",
64    abbr "Abbreviation",
65    address "Contact information for a page or article element",
66    area @void "Hyperlink or dead area on an image map",
67    article "Self-contained syndicatable or reusable composition",
68    aside "Sidebar for tangentially related content",
69    audio "Audio player",
70    b "Keywords",
71    base @void "Base URL and default target navigable for hyperlinks and forms",
72    bdi "Text directionality isolation",
73    bdo "Text directionality formatting",
74    blockquote "A section quoted from another source",
75    body "Document body",
76    br @void "Line break, e.g. in poem or postal address",
77    button "Button control",
78    canvas "Scriptable bitmap canvas",
79    caption "Table caption",
80    cite "Title of a work",
81    code "Computer code",
82    col "Table column",
83    colgroup "Group of columns in a table",
84    data "Machine-readable equivalent",
85    datalist "Container for options for combo box control",
86    dd "Content for corresponding dt element(s)",
87    del "A removal from the document",
88    details "Disclosure control for hiding details",
89    dfn "Defining instance",
90    dialog "Dialog box or window",
91    div "Generic flow container, or container for name-value groups in dl elements",
92    dl "Association list consisting of zero or more name-value groups",
93    dt "Legend for corresponding dd element(s)",
94    em "Stress emphasis",
95    embed @void "Plugin",
96    fieldset "Group of form controls",
97    figcaption "Caption for figure",
98    figure "Figure with optional caption",
99    footer "Footer for a page or section",
100    form "User-submittable form",
101    h1 "Heading 1",
102    h2 "Heading 2",
103    h3 "Heading 3",
104    h4 "Heading 4",
105    h5 "Heading 5",
106    h6 "Heading 6",
107    head "Container for document metadata",
108    header "Introductory or navigational aids for a page or section",
109    hgroup "Heading container",
110    hr @void "Thematic break",
111    html "Root element",
112    i "Alternate voice",
113    iframe "Child navigable",
114    img @void "Image",
115    input @void "Form control",
116    ins "An addition to the document",
117    kbd "User input",
118    label "Caption for a form control",
119    legend "Caption for fieldset",
120    li "List item",
121    link @void "Link metadata",
122    main "Container for the dominant contents of the document",
123    map "Image map",
124    mark "Highlight",
125    math "mathml root",
126    menu "Menu of commands",
127    meta @void "Text metadata",
128    meter "Gauge",
129    nav "Section with navigational links",
130    noscript "Fallback content for script",
131    object "Image, child navigable, or plugin",
132    ol "Ordered list",
133    optgroup "Group of options in a list box",
134    option "Option in a list box or combo box control",
135    output "Calculated output value",
136    p "Paragraph",
137    picture "Image",
138    pre "Block of preformatted text",
139    progress "Progress bar",
140    q "Quotation",
141    rp "Parenthesis for ruby annotation text",
142    rt "Ruby annotation text",
143    ruby "Ruby annotation(s)",
144    s "Inaccurate text",
145    samp "Computer output",
146    script "Embedded script",
147    search "Container for search controls",
148    section "Generic document or application section",
149    select "List box control",
150    selectedcontent "Mirrors content from an option",
151    slot "Shadow tree slot",
152    small "Side comment",
153    source @void "Image source for img or media source for video or audio",
154    span "Generic phrasing container",
155    strong "Importance",
156    style "Embedded styling information",
157    sub "Subscript",
158    summary "Caption for details",
159    sup "Superscript",
160    svg "svg root",
161    table "Table",
162    tbody "Group of rows in a table",
163    td "Table cell",
164    template "Template",
165    textarea "Multiline text controls",
166    tfoot "Group of footer rows in a table",
167    th "Table header cell",
168    thead "Group of heading rows in a table",
169    time "Machine-readable equivalent of date- or time-related data",
170    title "Document title",
171    tr "Table row",
172    track @void "Timed text track",
173    u "Unarticulated annotation",
174    ul "List",
175    var "Variable",
176    video "Video player",
177    wbr @void "Line breaking opportunity",
178);