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