| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
use crate::ExpandedName; |
| 13 |
use markup5ever::{expanded_name, local_name, ns}; |
| 14 |
|
| 15 |
macro_rules! declare_tag_set_impl ( ($param:ident, $b:ident, $supr:ident, $($tag:tt)+) => ( |
| 16 |
match $param { |
| 17 |
$( expanded_name!(html $tag) => $b, )+ |
| 18 |
p => $supr(p), |
| 19 |
} |
| 20 |
)); |
| 21 |
|
| 22 |
macro_rules! declare_tag_set_body ( |
| 23 |
($param:ident = [$supr:ident] - $($tag:tt)+) |
| 24 |
=> ( declare_tag_set_impl!($param, false, $supr, $($tag)+) ); |
| 25 |
|
| 26 |
($param:ident = [$supr:ident] + $($tag:tt)+) |
| 27 |
=> ( declare_tag_set_impl!($param, true, $supr, $($tag)+) ); |
| 28 |
|
| 29 |
($param:ident = $($tag:tt)+) |
| 30 |
=> ( declare_tag_set_impl!($param, true, empty_set, $($tag)+) ); |
| 31 |
); |
| 32 |
|
| 33 |
macro_rules! declare_tag_set ( |
| 34 |
(pub $name:ident = $($toks:tt)+) => ( |
| 35 |
pub(crate) fn $name(p: crate::ExpandedName) -> bool { |
| 36 |
declare_tag_set_body!(p = $($toks)+) |
| 37 |
} |
| 38 |
); |
| 39 |
|
| 40 |
($name:ident = $($toks:tt)+) => ( |
| 41 |
fn $name(p: crate::ExpandedName) -> bool { |
| 42 |
declare_tag_set_body!(p = $($toks)+) |
| 43 |
} |
| 44 |
); |
| 45 |
); |
| 46 |
|
| 47 |
#[inline(always)] |
| 48 |
pub(crate) fn empty_set(_: ExpandedName) -> bool { |
| 49 |
false |
| 50 |
} |
| 51 |
#[inline(always)] |
| 52 |
pub(crate) fn full_set(_: ExpandedName) -> bool { |
| 53 |
true |
| 54 |
} |
| 55 |
|
| 56 |
declare_tag_set!(pub html_default_scope = |
| 57 |
"applet" "caption" "html" "table" "td" "th" "marquee" "object" "template"); |
| 58 |
|
| 59 |
#[inline(always)] |
| 60 |
pub(crate) fn default_scope(name: ExpandedName) -> bool { |
| 61 |
html_default_scope(name) |
| 62 |
|| mathml_text_integration_point(name) |
| 63 |
|| svg_html_integration_point(name) |
| 64 |
} |
| 65 |
|
| 66 |
declare_tag_set!(pub list_item_scope = [default_scope] + "ol" "ul"); |
| 67 |
declare_tag_set!(pub button_scope = [default_scope] + "button"); |
| 68 |
declare_tag_set!(pub table_scope = "html" "table" "template"); |
| 69 |
declare_tag_set!(pub select_scope = [full_set] - "optgroup" "option"); |
| 70 |
|
| 71 |
declare_tag_set!(pub table_body_context = "tbody" "tfoot" "thead" "template" "html"); |
| 72 |
declare_tag_set!(pub table_row_context = "tr" "template" "html"); |
| 73 |
declare_tag_set!(pub td_th = "td" "th"); |
| 74 |
|
| 75 |
declare_tag_set!(pub cursory_implied_end = |
| 76 |
"dd" "dt" "li" "option" "optgroup" "p" "rb" "rp" "rt" "rtc"); |
| 77 |
|
| 78 |
declare_tag_set!(pub thorough_implied_end = [cursory_implied_end] |
| 79 |
+ "caption" "colgroup" "tbody" "td" "tfoot" "th" "thead" "tr"); |
| 80 |
|
| 81 |
declare_tag_set!(pub heading_tag = "h1" "h2" "h3" "h4" "h5" "h6"); |
| 82 |
|
| 83 |
declare_tag_set!(pub special_tag = |
| 84 |
"address" "applet" "area" "article" "aside" "base" "basefont" "bgsound" "blockquote" "body" |
| 85 |
"br" "button" "caption" "center" "col" "colgroup" "dd" "details" "dir" "div" "dl" "dt" "embed" |
| 86 |
"fieldset" "figcaption" "figure" "footer" "form" "frame" "frameset" "h1" "h2" "h3" "h4" "h5" |
| 87 |
"h6" "head" "header" "hgroup" "hr" "html" "iframe" "img" "input" "isindex" "li" "link" |
| 88 |
"listing" "main" "marquee" "menu" "meta" "nav" "noembed" "noframes" "noscript" |
| 89 |
"object" "ol" "p" "param" "plaintext" "pre" "script" "section" "select" "source" "style" |
| 90 |
"summary" "table" "tbody" "td" "template" "textarea" "tfoot" "th" "thead" "title" "tr" "track" |
| 91 |
"ul" "wbr" "xmp"); |
| 92 |
D |
| 93 |
|
| 94 |
pub(crate) fn mathml_text_integration_point(p: ExpandedName) -> bool { |
| 95 |
matches!( |
| 96 |
p, |
| 97 |
expanded_name!(mathml "mi") |
| 98 |
| expanded_name!(mathml "mo") |
| 99 |
| expanded_name!(mathml "mn") |
| 100 |
| expanded_name!(mathml "ms") |
| 101 |
| expanded_name!(mathml "mtext") |
| 102 |
) |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
pub(crate) fn svg_html_integration_point(p: ExpandedName) -> bool { |
| 107 |
|
| 108 |
matches!( |
| 109 |
p, |
| 110 |
expanded_name!(svg "foreignObject") |
| 111 |
| expanded_name!(svg "desc") |
| 112 |
| expanded_name!(svg "title") |
| 113 |
) |
| 114 |
} |