1// Copyright 2014-2017 The html5ever Project Developers. See the
2// COPYRIGHT file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10//! Various sets of HTML tag names, and macros for declaring them.
11
12use crate::ExpandedName;
13use markup5ever::{expanded_name, local_name, namespace_url, ns};
14
15macro_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
22macro_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
33macro_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)]
48pub(crate) fn empty_set(_: ExpandedName) -> bool {
49 false
50}
51#[inline(always)]
52pub(crate) fn full_set(_: ExpandedName) -> bool {
53 true
54}
55
56declare_tag_set!(pub html_default_scope =
57 "applet" "caption" "html" "table" "td" "th" "marquee" "object" "template");
58
59#[inline(always)]
60pub(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
66declare_tag_set!(pub list_item_scope = [default_scope] + "ol" "ul");
67declare_tag_set!(pub button_scope = [default_scope] + "button");
68declare_tag_set!(pub table_scope = "html" "table" "template");
69declare_tag_set!(pub select_scope = [full_set] - "optgroup" "option");
70
71declare_tag_set!(pub table_body_context = "tbody" "tfoot" "thead" "template" "html");
72declare_tag_set!(pub table_row_context = "tr" "template" "html");
73declare_tag_set!(pub td_th = "td" "th");
74
75declare_tag_set!(pub cursory_implied_end =
76 "dd" "dt" "li" "option" "optgroup" "p" "rb" "rp" "rt" "rtc");
77
78declare_tag_set!(pub thorough_implied_end = [cursory_implied_end]
79 + "caption" "colgroup" "tbody" "td" "tfoot" "th" "thead" "tr");
80
81declare_tag_set!(pub heading_tag = "h1" "h2" "h3" "h4" "h5" "h6");
82
83declare_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//ยง END
93
94pub(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/// https://html.spec.whatwg.org/multipage/#html-integration-point
106pub(crate) fn svg_html_integration_point(p: ExpandedName) -> bool {
107 // annotation-xml are handle in another place
108 matches!(
109 p,
110 expanded_name!(svg "foreignObject")
111 | expanded_name!(svg "desc")
112 | expanded_name!(svg "title")
113 )
114}
115