Coverage for phml\transform\sanitize\schema.py: 100%
9 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 13:16 -0600
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 13:16 -0600
1"""Defines the schema on how to sanitize the phml ast."""
2from dataclasses import dataclass, field
5@dataclass
6class Schema:
7 """Dataclass of information on how to sanatize a phml tree.
9 `strip (list[str])`: The elements to strip from the tree.
10 `protocols (dict[str, list])`: Collection of element name and allowed protocal value list
11 `tag_names (list[str])`: List of allowed tag names.
12 `attributes (dict[str, list[str | list[str]]])`: Collection of element name and allowed property
13 names.
14 `required (dict[str, str | list[str]])`: Collection of element names and their required
15 properties and required property values.
16 """
18 strip: list[str] = field(default_factory=lambda: ['script'])
19 ancestors: dict[str, list] = field(
20 default_factory=lambda: {
21 "tbody": ['table'],
22 "tfoot": ['table'],
23 "thead": ['table'],
24 "td": ['table'],
25 "th": ['table'],
26 "tr": ['table'],
27 }
28 )
29 protocols: dict[str, list] = field(
30 default_factory=lambda: {
31 "href": ['http', 'https', 'mailto', 'xmpp', 'irc', 'ircs'],
32 "cite": ['http', 'https'],
33 "src": ['http', 'https'],
34 "longDesc": ['http', 'https'],
35 }
36 )
37 tag_names: list[str] = field(
38 default_factory=lambda: [
39 'h1',
40 'h2',
41 'h3',
42 'h4',
43 'h5',
44 'h6',
45 'br',
46 'b',
47 'i',
48 'strong',
49 'em',
50 'a',
51 'pre',
52 'code',
53 'img',
54 'tt',
55 'div',
56 'ins',
57 'del',
58 'sup',
59 'sub',
60 'p',
61 'ol',
62 'ul',
63 'table',
64 'thead',
65 'tbody',
66 'tfoot',
67 'blockquote',
68 'dl',
69 'dt',
70 'dd',
71 'kbd',
72 'q',
73 'samp',
74 'var',
75 'hr',
76 'ruby',
77 'rt',
78 'rp',
79 'li',
80 'tr',
81 'td',
82 'th',
83 's',
84 'strike',
85 'summary',
86 'details',
87 'caption',
88 'figure',
89 'figcaption',
90 'abbr',
91 'bdo',
92 'cite',
93 'dfn',
94 'mark',
95 'small',
96 'span',
97 'time',
98 'wbr',
99 'input',
100 ]
101 )
102 attributes: dict[str, list[str | list[str]]] = field(
103 default_factory=lambda: {
104 "a": ['href'],
105 "img": ['src', 'longDesc'],
106 "input": [['type', 'checkbox'], ['disabled', True]],
107 "li": [['class', 'task-list-item']],
108 "div": ['itemScope', 'itemType'],
109 "blockquote": ['cite'],
110 "del": ['cite'],
111 "ins": ['cite'],
112 "q": ['cite'],
113 '*': [
114 'abbr',
115 'accept',
116 'acceptCharset',
117 'accessKey',
118 'action',
119 'align',
120 'alt',
121 'ariaDescribedBy',
122 'ariaHidden',
123 'ariaLabel',
124 'ariaLabelledBy',
125 'axis',
126 'border',
127 'cellPadding',
128 'cellSpacing',
129 'char',
130 'charOff',
131 'charSet',
132 'checked',
133 'clear',
134 'cols',
135 'colSpan',
136 'color',
137 'compact',
138 'coords',
139 'dateTime',
140 'dir',
141 'disabled',
142 'encType',
143 'htmlFor',
144 'frame',
145 'headers',
146 'height',
147 'hrefLang',
148 'hSpace',
149 'isMap',
150 'id',
151 'label',
152 'lang',
153 'maxLength',
154 'media',
155 'method',
156 'multiple',
157 'name',
158 'noHref',
159 'noShade',
160 'noWrap',
161 'open',
162 'prompt',
163 'readOnly',
164 'rel',
165 'rev',
166 'rows',
167 'rowSpan',
168 'rules',
169 'scope',
170 'selected',
171 'shape',
172 'size',
173 'span',
174 'start',
175 'summary',
176 'tabIndex',
177 'target',
178 'title',
179 'type',
180 'useMap',
181 'vAlign',
182 'value',
183 'vSpace',
184 'width',
185 'itemProp',
186 ],
187 }
188 )
189 required: dict[str, str | list[str]] = field(
190 default_factory=lambda: {
191 "input": {
192 "type": 'checkbox',
193 "disabled": True,
194 }
195 }
196 )