@difizen/libro-common 0.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/es/array.d.ts +368 -0
- package/es/array.d.ts.map +1 -0
- package/es/array.js +577 -0
- package/es/display-wrapper.d.ts +6 -0
- package/es/display-wrapper.d.ts.map +1 -0
- package/es/display-wrapper.js +12 -0
- package/es/index.d.ts +11 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +10 -0
- package/es/iter.d.ts +147 -0
- package/es/iter.d.ts.map +1 -0
- package/es/iter.js +162 -0
- package/es/json.d.ts +126 -0
- package/es/json.d.ts.map +1 -0
- package/es/json.js +274 -0
- package/es/path.d.ts +97 -0
- package/es/path.d.ts.map +1 -0
- package/es/path.js +60 -0
- package/es/polling/index.d.ts +3 -0
- package/es/polling/index.d.ts.map +1 -0
- package/es/polling/index.js +2 -0
- package/es/polling/poll.d.ts +193 -0
- package/es/polling/poll.d.ts.map +1 -0
- package/es/polling/poll.js +501 -0
- package/es/polling/protocol.d.ts +120 -0
- package/es/polling/protocol.d.ts.map +1 -0
- package/es/polling/protocol.js +13 -0
- package/es/posix.d.ts +2 -0
- package/es/posix.d.ts.map +1 -0
- package/es/posix.js +71 -0
- package/es/protocol/cell-protocol.d.ts +181 -0
- package/es/protocol/cell-protocol.d.ts.map +1 -0
- package/es/protocol/cell-protocol.js +1 -0
- package/es/protocol/index.d.ts +4 -0
- package/es/protocol/index.d.ts.map +1 -0
- package/es/protocol/index.js +3 -0
- package/es/protocol/notebook-protocol.d.ts +63 -0
- package/es/protocol/notebook-protocol.d.ts.map +1 -0
- package/es/protocol/notebook-protocol.js +41 -0
- package/es/protocol/output-protocol.d.ts +125 -0
- package/es/protocol/output-protocol.d.ts.map +1 -0
- package/es/protocol/output-protocol.js +1 -0
- package/es/sanitizer.d.ts +44 -0
- package/es/sanitizer.d.ts.map +1 -0
- package/es/sanitizer.js +659 -0
- package/es/url.d.ts +98 -0
- package/es/url.d.ts.map +1 -0
- package/es/url.js +134 -0
- package/es/utils.d.ts +57 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +124 -0
- package/package.json +62 -0
- package/src/array.ts +608 -0
- package/src/display-wrapper.tsx +11 -0
- package/src/index.ts +10 -0
- package/src/iter.ts +199 -0
- package/src/json.ts +321 -0
- package/src/path.ts +138 -0
- package/src/polling/index.ts +2 -0
- package/src/polling/poll.ts +508 -0
- package/src/polling/protocol.ts +145 -0
- package/src/posix.ts +75 -0
- package/src/protocol/cell-protocol.ts +215 -0
- package/src/protocol/index.ts +3 -0
- package/src/protocol/notebook-protocol.ts +73 -0
- package/src/protocol/output-protocol.ts +162 -0
- package/src/sanitizer.ts +944 -0
- package/src/url.ts +157 -0
- package/src/utils.ts +145 -0
package/src/sanitizer.ts
ADDED
|
@@ -0,0 +1,944 @@
|
|
|
1
|
+
import sanitize from 'sanitize-html';
|
|
2
|
+
|
|
3
|
+
class CssProp {
|
|
4
|
+
static reg(r: string): RegExp {
|
|
5
|
+
return new RegExp('^' + r + '$', 'i');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Numeric base expressions used to help build more complex regular expressions
|
|
10
|
+
*/
|
|
11
|
+
private static readonly N = {
|
|
12
|
+
integer: `[+-]?[0-9]+`,
|
|
13
|
+
integer_pos: `[+]?[0-9]+`,
|
|
14
|
+
integer_zero_ff: `([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])`,
|
|
15
|
+
number: `[+-]?([0-9]*[.])?[0-9]+(e-?[0-9]*)?`,
|
|
16
|
+
number_pos: `[+]?([0-9]*[.])?[0-9]+(e-?[0-9]*)?`,
|
|
17
|
+
number_zero_hundred: `[+]?(([0-9]|[1-9][0-9])([.][0-9]+)?|100)`,
|
|
18
|
+
number_zero_one: `[+]?(1([.][0]+)?|0?([.][0-9]+)?)`,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Base expressions of common CSS syntax elements
|
|
23
|
+
*/
|
|
24
|
+
private static readonly B = {
|
|
25
|
+
angle: `(${CssProp.N.number}(deg|rad|grad|turn)|0)`,
|
|
26
|
+
frequency: `${CssProp.N.number}(Hz|kHz)`,
|
|
27
|
+
ident: String.raw`-?([_a-z]|[\xA0-\xFF]|\\[0-9a-f]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-f])([_a-z0-9-]|[\xA0-\xFF]|\\[0-9a-f]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-f])*`,
|
|
28
|
+
len_or_perc: `(0|${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc|%))`,
|
|
29
|
+
length: `(${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc)|0)`,
|
|
30
|
+
length_pos: `(${CssProp.N.number_pos}(px|em|rem|ex|in|cm|mm|pt|pc)|0)`,
|
|
31
|
+
percentage: `${CssProp.N.number}%`,
|
|
32
|
+
percentage_pos: `${CssProp.N.number_pos}%`,
|
|
33
|
+
percentage_zero_hundred: `${CssProp.N.number_zero_hundred}%`,
|
|
34
|
+
string: String.raw`(\"([^\n\r\f\\"]|\\\n|\r\n|\r|\f|\\[0-9a-f]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-f])*\")|(\'([^\n\r\f\\']|\\\n|\r\n|\r|\f|\\[0-9a-f]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-f])*\')`,
|
|
35
|
+
time: `${CssProp.N.number}(s|ms)`,
|
|
36
|
+
url: `url\\(.*?\\)`,
|
|
37
|
+
z_index: `[+-]?[0-9]{1,7}`,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* Atomic (i.e. not dependant on other regular expressions) sub RegEx segments
|
|
42
|
+
*/
|
|
43
|
+
private static readonly A = {
|
|
44
|
+
absolute_size: `xx-small|x-small|small|medium|large|x-large|xx-large`,
|
|
45
|
+
attachment: `scroll|fixed|local`,
|
|
46
|
+
bg_origin: `border-box|padding-box|content-box`,
|
|
47
|
+
border_style: `none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset`,
|
|
48
|
+
box: `border-box|padding-box|content-box`,
|
|
49
|
+
display_inside: `auto|block|table|flex|grid`,
|
|
50
|
+
display_outside: `block-level|inline-level|none|table-row-group|table-header-group|table-footer-group|table-row|table-cell|table-column-group|table-column|table-caption`,
|
|
51
|
+
ending_shape: `circle|ellipse`,
|
|
52
|
+
generic_family: `serif|sans-serif|cursive|fantasy|monospace`,
|
|
53
|
+
generic_voice: `male|female|child`,
|
|
54
|
+
relative_size: `smaller|larger`,
|
|
55
|
+
repeat_style: `repeat-x|repeat-y|((?:repeat|space|round|no-repeat)(?:\\s*(?:repeat|space|round|no-repeat))?)`,
|
|
56
|
+
side_or_corner: `(left|right)?\\s*(top|bottom)?`,
|
|
57
|
+
single_animation_direction: `normal|reverse|alternate|alternate-reverse`,
|
|
58
|
+
single_animation_fill_mode: `none|forwards|backwards|both`,
|
|
59
|
+
single_animation_play_state: `running|paused`,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* Color definition sub expressions
|
|
64
|
+
*/
|
|
65
|
+
private static readonly _COLOR = {
|
|
66
|
+
hex: `\\#(0x)?[0-9a-f]+`,
|
|
67
|
+
name: `aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|transparent|violet|wheat|white|whitesmoke|yellow|yellowgreen`,
|
|
68
|
+
rgb: String.raw`rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)`,
|
|
69
|
+
rgba: String.raw`rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(${CssProp.N.integer_zero_ff}|${CssProp.N.number_zero_one}|${CssProp.B.percentage_zero_hundred})\s*\)`,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
* Compound (i.e. dependant on other (sub) regular expressions) sub RegEx segments
|
|
74
|
+
*/
|
|
75
|
+
private static readonly _C = {
|
|
76
|
+
alpha: `${CssProp.N.integer_zero_ff}|${CssProp.N.number_zero_one}|${CssProp.B.percentage_zero_hundred}`,
|
|
77
|
+
alphavalue: CssProp.N.number_zero_one,
|
|
78
|
+
bg_position: `((${CssProp.B.len_or_perc}|left|center|right|top|bottom)\\s*){1,4}`,
|
|
79
|
+
bg_size: `(${CssProp.B.length_pos}|${CssProp.B.percentage}|auto){1,2}|cover|contain`,
|
|
80
|
+
border_width: `thin|medium|thick|${CssProp.B.length}`,
|
|
81
|
+
bottom: `${CssProp.B.length}|auto`,
|
|
82
|
+
color: `${CssProp._COLOR.hex}|${CssProp._COLOR.rgb}|${CssProp._COLOR.rgba}|${CssProp._COLOR.name}`,
|
|
83
|
+
color_stop_length: `(${CssProp.B.len_or_perc}\\s*){1,2}`,
|
|
84
|
+
linear_color_hint: `${CssProp.B.len_or_perc}`,
|
|
85
|
+
family_name: `${CssProp.B.string}|(${CssProp.B.ident}\\s*)+`,
|
|
86
|
+
image_decl: CssProp.B.url,
|
|
87
|
+
left: `${CssProp.B.length}|auto`,
|
|
88
|
+
loose_quotable_words: `(${CssProp.B.ident})+`,
|
|
89
|
+
margin_width: `${CssProp.B.len_or_perc}|auto`,
|
|
90
|
+
padding_width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}`,
|
|
91
|
+
page_url: CssProp.B.url,
|
|
92
|
+
position: `((${CssProp.B.len_or_perc}|left|center|right|top|bottom)\\s*){1,4}`,
|
|
93
|
+
right: `${CssProp.B.length}|auto`,
|
|
94
|
+
shadow: '',
|
|
95
|
+
size: `closest-side|farthest-side|closest-corner|farthest-corner|${CssProp.B.length}|(${CssProp.B.len_or_perc})\\s+(${CssProp.B.len_or_perc})`,
|
|
96
|
+
top: `${CssProp.B.length}|auto`,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
private static readonly _C1 = {
|
|
100
|
+
image_list: `image\\(\\s*(${CssProp.B.url})*\\s*(${CssProp.B.url}|${CssProp._C.color})\\s*\\)`,
|
|
101
|
+
linear_color_stop: `(${CssProp._C.color})(\\s*${CssProp._C.color_stop_length})?`,
|
|
102
|
+
// eslint-disable-next-line no-useless-escape
|
|
103
|
+
shadow: `((${CssProp._C.color})\\s+((${CssProp.B.length})\\s*){2,4}(\s+inset)?)|((inset\\s+)?((${CssProp.B.length})\\s*){2,4}\\s*(${CssProp._C.color})?)`,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
private static readonly _C2 = {
|
|
107
|
+
color_stop_list: `((${CssProp._C1.linear_color_stop})(\\s*(${CssProp._C.linear_color_hint}))?\\s*,\\s*)+(${CssProp._C1.linear_color_stop})`,
|
|
108
|
+
shape: `rect\\(\\s*(${CssProp._C.top})\\s*,\\s*(${CssProp._C.right})\\s*,\\s*(${CssProp._C.bottom})\\s*,\\s*(${CssProp._C.left})\\s*\\)`,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
private static readonly _C3 = {
|
|
112
|
+
linear_gradient: `linear-gradient\\((((${CssProp.B.angle})|to\\s+(${CssProp.A.side_or_corner}))\\s*,\\s*)?\\s*(${CssProp._C2.color_stop_list})\\s*\\)`,
|
|
113
|
+
radial_gradient: `radial-gradient\\(((((${CssProp.A.ending_shape})|(${CssProp._C.size}))\\s*)*\\s*(at\\s+${CssProp._C.position})?\\s*,\\s*)?\\s*(${CssProp._C2.color_stop_list})\\s*\\)`,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
private static readonly _C4 = {
|
|
117
|
+
image: `${CssProp.B.url}|${CssProp._C3.linear_gradient}|${CssProp._C3.radial_gradient}|${CssProp._C1.image_list}`,
|
|
118
|
+
bg_image: `(${CssProp.B.url}|${CssProp._C3.linear_gradient}|${CssProp._C3.radial_gradient}|${CssProp._C1.image_list})|none`,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
private static readonly C = {
|
|
122
|
+
...CssProp._C,
|
|
123
|
+
...CssProp._C1,
|
|
124
|
+
...CssProp._C2,
|
|
125
|
+
...CssProp._C3,
|
|
126
|
+
...CssProp._C4,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/*
|
|
130
|
+
* Property value regular expressions not dependant on other sub expressions
|
|
131
|
+
*/
|
|
132
|
+
private static readonly AP = {
|
|
133
|
+
border_collapse: `collapse|separate`,
|
|
134
|
+
box: `normal|none|contents`,
|
|
135
|
+
box_sizing: `content-box|padding-box|border-box`,
|
|
136
|
+
caption_side: `top|bottom`,
|
|
137
|
+
clear: `none|left|right|both`,
|
|
138
|
+
direction: `ltr|rtl`,
|
|
139
|
+
empty_cells: `show|hide`,
|
|
140
|
+
float: `left|right|none`,
|
|
141
|
+
font_stretch: `normal|wider|narrower|ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded`,
|
|
142
|
+
font_style: `normal|italic|oblique`,
|
|
143
|
+
font_variant: `normal|small-caps`,
|
|
144
|
+
font_weight: `normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900`,
|
|
145
|
+
list_style_position: `inside|outside`,
|
|
146
|
+
list_style_type: `disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-greek|lower-latin|upper-latin|armenian|georgian|lower-alpha|upper-alpha|none`,
|
|
147
|
+
overflow: `visible|hidden|scroll|auto`,
|
|
148
|
+
overflow_wrap: `normal|break-word`,
|
|
149
|
+
overflow_x: `visible|hidden|scroll|auto|no-display|no-content`,
|
|
150
|
+
page_break_after: `auto|always|avoid|left|right`,
|
|
151
|
+
page_break_before: `auto|always|avoid|left|right`,
|
|
152
|
+
page_break_inside: `avoid|auto`,
|
|
153
|
+
position: `static|relative|absolute`,
|
|
154
|
+
resize: `none|both|horizontal|vertical`,
|
|
155
|
+
speak: `normal|none|spell-out`,
|
|
156
|
+
speak_header: `once|always`,
|
|
157
|
+
speak_numeral: `digits|continuous`,
|
|
158
|
+
speak_punctuation: `code|none`,
|
|
159
|
+
table_layout: `auto|fixed`,
|
|
160
|
+
text_align: `left|right|center|justify`,
|
|
161
|
+
text_decoration: `none|((underline|overline|line-through|blink)\\s*)+`,
|
|
162
|
+
text_transform: `capitalize|uppercase|lowercase|none`,
|
|
163
|
+
text_wrap: `normal|unrestricted|none|suppress`,
|
|
164
|
+
unicode_bidi: `normal|embed|bidi-override`,
|
|
165
|
+
visibility: `visible|hidden|collapse`,
|
|
166
|
+
white_space: `normal|pre|nowrap|pre-wrap|pre-line`,
|
|
167
|
+
word_break: `normal|keep-all|break-all`,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/*
|
|
171
|
+
* Compound propertiy value regular expressions (i.e. dependant on other sub expressions)
|
|
172
|
+
*/
|
|
173
|
+
private static readonly _CP = {
|
|
174
|
+
background_attachment: `${CssProp.A.attachment}(,\\s*${CssProp.A.attachment})*`,
|
|
175
|
+
background_color: CssProp.C.color,
|
|
176
|
+
background_origin: `${CssProp.A.box}(,\\s*${CssProp.A.box})*`,
|
|
177
|
+
background_repeat: `${CssProp.A.repeat_style}(,\\s*${CssProp.A.repeat_style})*`,
|
|
178
|
+
border: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
|
|
179
|
+
border_radius: `((${CssProp.B.len_or_perc})\\s*){1,4}(\\/\\s*((${CssProp.B.len_or_perc})\\s*){1,4})?`,
|
|
180
|
+
border_spacing: `${CssProp.B.length}\\s*(${CssProp.B.length})?`,
|
|
181
|
+
border_top_color: CssProp.C.color,
|
|
182
|
+
border_top_style: CssProp.A.border_style,
|
|
183
|
+
border_width: `((${CssProp.C.border_width})\\s*){1,4}`,
|
|
184
|
+
color: CssProp.C.color,
|
|
185
|
+
cursor: `(${CssProp.B.url}(\\s*,\\s*)?)*(auto|crosshair|default|pointer|move|e-resize|ne-resize|nw-resize|n-resize|se-resize|sw-resize|s-resize|w-resize|text|wait|help|progress|all-scroll|col-resize|hand|no-drop|not-allowed|row-resize|vertical-text)`,
|
|
186
|
+
display: `inline|block|list-item|run-in|inline-list-item|inline-block|table|inline-table|table-cell|table-caption|flex|inline-flex|grid|inline-grid|${CssProp.A.display_inside}|${CssProp.A.display_outside}|inherit|inline-box|inline-stack`,
|
|
187
|
+
display_outside: CssProp.A.display_outside,
|
|
188
|
+
elevation: `${CssProp.B.angle}|below|level|above|higher|lower`,
|
|
189
|
+
font_family: `(${CssProp.C.family_name}|${CssProp.A.generic_family})(,\\s*(${CssProp.C.family_name}|${CssProp.A.generic_family}))*`,
|
|
190
|
+
height: `${CssProp.B.length}|${CssProp.B.percentage}|auto`,
|
|
191
|
+
letter_spacing: `normal|${CssProp.B.length}`,
|
|
192
|
+
list_style_image: `${CssProp.C.image}|none`,
|
|
193
|
+
margin_right: CssProp.C.margin_width,
|
|
194
|
+
max_height: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|none|auto`,
|
|
195
|
+
min_height: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|auto`,
|
|
196
|
+
opacity: CssProp.C.alphavalue,
|
|
197
|
+
outline_color: `${CssProp.C.color}|invert`,
|
|
198
|
+
outline_width: CssProp.C.border_width,
|
|
199
|
+
padding: `((${CssProp.C.padding_width})\\s*){1,4}`,
|
|
200
|
+
padding_top: CssProp.C.padding_width,
|
|
201
|
+
pitch_range: CssProp.N.number,
|
|
202
|
+
right: `${CssProp.B.length}|${CssProp.B.percentage}|auto`,
|
|
203
|
+
stress: CssProp.N.number,
|
|
204
|
+
text_indent: `${CssProp.B.length}|${CssProp.B.percentage}`,
|
|
205
|
+
text_shadow: `none|${CssProp.C.shadow}(,\\s*(${CssProp.C.shadow}))*`,
|
|
206
|
+
volume: `${CssProp.N.number_pos}|${CssProp.B.percentage_pos}|silent|x-soft|soft|medium|loud|x-loud`,
|
|
207
|
+
word_wrap: CssProp.AP.overflow_wrap,
|
|
208
|
+
zoom: `normal|${CssProp.N.number_pos}|${CssProp.B.percentage_pos}`,
|
|
209
|
+
backface_visibility: CssProp.AP.visibility,
|
|
210
|
+
background_clip: `${CssProp.A.box}(,\\s*(${CssProp.A.box}))*`,
|
|
211
|
+
background_position: `${CssProp.C.bg_position}(,\\s*(${CssProp.C.bg_position}))*`,
|
|
212
|
+
border_bottom_color: CssProp.C.color,
|
|
213
|
+
border_bottom_style: CssProp.A.border_style,
|
|
214
|
+
border_color: `((${CssProp.C.color})\\s*){1,4}`,
|
|
215
|
+
border_left_color: CssProp.C.color,
|
|
216
|
+
border_right_color: CssProp.C.color,
|
|
217
|
+
border_style: `((${CssProp.A.border_style})\\s*){1,4}`,
|
|
218
|
+
border_top_left_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
|
|
219
|
+
border_top_width: CssProp.C.border_width,
|
|
220
|
+
box_shadow: `none|${CssProp.C.shadow}(,\\s*(${CssProp.C.shadow}))*`,
|
|
221
|
+
clip: `${CssProp.C.shape}|auto`,
|
|
222
|
+
display_inside: CssProp.A.display_inside,
|
|
223
|
+
font_size: `${CssProp.A.absolute_size}|${CssProp.A.relative_size}|${CssProp.B.length_pos}|${CssProp.B.percentage_pos}`,
|
|
224
|
+
line_height: `normal|${CssProp.N.number_pos}|${CssProp.B.length_pos}|${CssProp.B.percentage_pos}`,
|
|
225
|
+
margin_left: CssProp.C.margin_width,
|
|
226
|
+
max_width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|none|auto`,
|
|
227
|
+
outline_style: CssProp.A.border_style,
|
|
228
|
+
padding_bottom: CssProp.C.padding_width,
|
|
229
|
+
padding_right: CssProp.C.padding_width,
|
|
230
|
+
perspective: `none|${CssProp.B.length}`,
|
|
231
|
+
richness: CssProp.N.number,
|
|
232
|
+
text_overflow: `((clip|ellipsis|${CssProp.B.string})\\s*){1,2}`,
|
|
233
|
+
top: `${CssProp.B.length}|${CssProp.B.percentage}|auto`,
|
|
234
|
+
width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|auto`,
|
|
235
|
+
z_index: `auto|${CssProp.B.z_index}`,
|
|
236
|
+
// Simplified background
|
|
237
|
+
background: `(((${CssProp.C.bg_position}\\s*(\\/\\s*${CssProp.C.bg_size})?)|(${CssProp.A.repeat_style})|(${CssProp.A.attachment})|(${CssProp.A.bg_origin})|(${CssProp.C.bg_image})|(${CssProp.C.color}))\\s*)+`,
|
|
238
|
+
background_size: `${CssProp.C.bg_size}(,\\s*${CssProp.C.bg_size})*`,
|
|
239
|
+
border_bottom_left_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
|
|
240
|
+
border_bottom_width: CssProp.C.border_width,
|
|
241
|
+
border_left_style: CssProp.A.border_style,
|
|
242
|
+
border_right_style: CssProp.A.border_style,
|
|
243
|
+
border_top: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
|
|
244
|
+
bottom: `${CssProp.B.len_or_perc}|auto`,
|
|
245
|
+
list_style: `((${CssProp.AP.list_style_type}|${CssProp.AP.list_style_position}|${CssProp.C.image}|none})\\s*){1,3}`,
|
|
246
|
+
margin_top: CssProp.C.margin_width,
|
|
247
|
+
outline: `((${CssProp.C.color}|invert|${CssProp.A.border_style}|${CssProp.C.border_width})\\s*){1,3}`,
|
|
248
|
+
overflow_y: CssProp.AP.overflow_x,
|
|
249
|
+
pitch: `${CssProp.B.frequency}|x-low|low|medium|high|x-high`,
|
|
250
|
+
vertical_align: `baseline|sub|super|top|text-top|middle|bottom|text-bottom|${CssProp.B.len_or_perc}`,
|
|
251
|
+
word_spacing: `normal|${CssProp.B.length}`,
|
|
252
|
+
background_image: `${CssProp.C.bg_image}(,\\s*${CssProp.C.bg_image})*`,
|
|
253
|
+
border_bottom_right_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
|
|
254
|
+
border_left_width: CssProp.C.border_width,
|
|
255
|
+
border_right_width: CssProp.C.border_width,
|
|
256
|
+
left: `${CssProp.B.len_or_perc}|auto`,
|
|
257
|
+
margin_bottom: CssProp.C.margin_width,
|
|
258
|
+
pause_after: `${CssProp.B.time}|${CssProp.B.percentage}`,
|
|
259
|
+
speech_rate: `${CssProp.N.number}|x-slow|slow|medium|fast|x-fast|faster|slower`,
|
|
260
|
+
transition_duration: `${CssProp.B.time}(,\\s*${CssProp.B.time})*`,
|
|
261
|
+
border_bottom: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
|
|
262
|
+
border_right: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
|
|
263
|
+
margin: `((${CssProp.C.margin_width})\\s*){1,4}`,
|
|
264
|
+
padding_left: CssProp.C.padding_width,
|
|
265
|
+
border_left: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
|
|
266
|
+
quotes: `(${CssProp.B.string}\\s*${CssProp.B.string})+|none`,
|
|
267
|
+
border_top_right_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
|
|
268
|
+
min_width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|auto`,
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
private static readonly _CP1 = {
|
|
272
|
+
font: `(((((${CssProp.AP.font_style}|${CssProp.AP.font_variant}|${CssProp.AP.font_weight})\\s*){1,3})?\\s*(${CssProp._CP.font_size})\\s*(\\/\\s*(${CssProp._CP.line_height}))?\\s+(${CssProp._CP.font_family}))|caption|icon|menu|message-box|small-caption|status-bar)`,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
private static readonly CP = { ...CssProp._CP, ...CssProp._CP1 };
|
|
276
|
+
|
|
277
|
+
// CSS Property value validation regular expressions for use with sanitize-html
|
|
278
|
+
|
|
279
|
+
static BORDER_COLLAPSE = CssProp.reg(CssProp.AP.border_collapse);
|
|
280
|
+
static BOX = CssProp.reg(CssProp.AP.box);
|
|
281
|
+
static BOX_SIZING = CssProp.reg(CssProp.AP.box_sizing);
|
|
282
|
+
static CAPTION_SIDE = CssProp.reg(CssProp.AP.caption_side);
|
|
283
|
+
static CLEAR = CssProp.reg(CssProp.AP.clear);
|
|
284
|
+
static DIRECTION = CssProp.reg(CssProp.AP.direction);
|
|
285
|
+
static EMPTY_CELLS = CssProp.reg(CssProp.AP.empty_cells);
|
|
286
|
+
static FLOAT = CssProp.reg(CssProp.AP.float);
|
|
287
|
+
static FONT_STRETCH = CssProp.reg(CssProp.AP.font_stretch);
|
|
288
|
+
static FONT_STYLE = CssProp.reg(CssProp.AP.font_style);
|
|
289
|
+
static FONT_VARIANT = CssProp.reg(CssProp.AP.font_variant);
|
|
290
|
+
static FONT_WEIGHT = CssProp.reg(CssProp.AP.font_weight);
|
|
291
|
+
static LIST_STYLE_POSITION = CssProp.reg(CssProp.AP.list_style_position);
|
|
292
|
+
static LIST_STYLE_TYPE = CssProp.reg(CssProp.AP.list_style_type);
|
|
293
|
+
static OVERFLOW = CssProp.reg(CssProp.AP.overflow);
|
|
294
|
+
static OVERFLOW_WRAP = CssProp.reg(CssProp.AP.overflow_wrap);
|
|
295
|
+
static OVERFLOW_X = CssProp.reg(CssProp.AP.overflow_x);
|
|
296
|
+
static PAGE_BREAK_AFTER = CssProp.reg(CssProp.AP.page_break_after);
|
|
297
|
+
static PAGE_BREAK_BEFORE = CssProp.reg(CssProp.AP.page_break_before);
|
|
298
|
+
static PAGE_BREAK_INSIDE = CssProp.reg(CssProp.AP.page_break_inside);
|
|
299
|
+
static POSITION = CssProp.reg(CssProp.AP.position);
|
|
300
|
+
static RESIZE = CssProp.reg(CssProp.AP.resize);
|
|
301
|
+
static SPEAK = CssProp.reg(CssProp.AP.speak);
|
|
302
|
+
static SPEAK_HEADER = CssProp.reg(CssProp.AP.speak_header);
|
|
303
|
+
static SPEAK_NUMERAL = CssProp.reg(CssProp.AP.speak_numeral);
|
|
304
|
+
static SPEAK_PUNCTUATION = CssProp.reg(CssProp.AP.speak_punctuation);
|
|
305
|
+
static TABLE_LAYOUT = CssProp.reg(CssProp.AP.table_layout);
|
|
306
|
+
static TEXT_ALIGN = CssProp.reg(CssProp.AP.text_align);
|
|
307
|
+
static TEXT_DECORATION = CssProp.reg(CssProp.AP.text_decoration);
|
|
308
|
+
static TEXT_TRANSFORM = CssProp.reg(CssProp.AP.text_transform);
|
|
309
|
+
static TEXT_WRAP = CssProp.reg(CssProp.AP.text_wrap);
|
|
310
|
+
static UNICODE_BIDI = CssProp.reg(CssProp.AP.unicode_bidi);
|
|
311
|
+
static VISIBILITY = CssProp.reg(CssProp.AP.visibility);
|
|
312
|
+
static WHITE_SPACE = CssProp.reg(CssProp.AP.white_space);
|
|
313
|
+
static WORD_BREAK = CssProp.reg(CssProp.AP.word_break);
|
|
314
|
+
|
|
315
|
+
static BACKGROUND_ATTACHMENT = CssProp.reg(CssProp.CP.background_attachment);
|
|
316
|
+
static BACKGROUND_COLOR = CssProp.reg(CssProp.CP.background_color);
|
|
317
|
+
static BACKGROUND_ORIGIN = CssProp.reg(CssProp.CP.background_origin);
|
|
318
|
+
static BACKGROUND_REPEAT = CssProp.reg(CssProp.CP.background_repeat);
|
|
319
|
+
static BORDER = CssProp.reg(CssProp.CP.border);
|
|
320
|
+
static BORDER_RADIUS = CssProp.reg(CssProp.CP.border_radius);
|
|
321
|
+
static BORDER_SPACING = CssProp.reg(CssProp.CP.border_spacing);
|
|
322
|
+
static BORDER_TOP_COLOR = CssProp.reg(CssProp.CP.border_top_color);
|
|
323
|
+
static BORDER_TOP_STYLE = CssProp.reg(CssProp.CP.border_top_style);
|
|
324
|
+
static BORDER_WIDTH = CssProp.reg(CssProp.CP.border_width);
|
|
325
|
+
static COLOR = CssProp.reg(CssProp.CP.color);
|
|
326
|
+
static CURSOR = CssProp.reg(CssProp.CP.cursor);
|
|
327
|
+
static DISPLAY = CssProp.reg(CssProp.CP.display);
|
|
328
|
+
static DISPLAY_OUTSIDE = CssProp.reg(CssProp.CP.display_outside);
|
|
329
|
+
static ELEVATION = CssProp.reg(CssProp.CP.elevation);
|
|
330
|
+
static FONT_FAMILY = CssProp.reg(CssProp.CP.font_family);
|
|
331
|
+
static HEIGHT = CssProp.reg(CssProp.CP.height);
|
|
332
|
+
static LETTER_SPACING = CssProp.reg(CssProp.CP.letter_spacing);
|
|
333
|
+
static LIST_STYLE_IMAGE = CssProp.reg(CssProp.CP.list_style_image);
|
|
334
|
+
static MARGIN_RIGHT = CssProp.reg(CssProp.CP.margin_right);
|
|
335
|
+
static MAX_HEIGHT = CssProp.reg(CssProp.CP.max_height);
|
|
336
|
+
static MIN_HEIGHT = CssProp.reg(CssProp.CP.min_height);
|
|
337
|
+
static OPACITY = CssProp.reg(CssProp.CP.opacity);
|
|
338
|
+
static OUTLINE_COLOR = CssProp.reg(CssProp.CP.outline_color);
|
|
339
|
+
static OUTLINE_WIDTH = CssProp.reg(CssProp.CP.outline_width);
|
|
340
|
+
static PADDING = CssProp.reg(CssProp.CP.padding);
|
|
341
|
+
static PADDING_TOP = CssProp.reg(CssProp.CP.padding_top);
|
|
342
|
+
static PITCH_RANGE = CssProp.reg(CssProp.CP.pitch_range);
|
|
343
|
+
static RIGHT = CssProp.reg(CssProp.CP.right);
|
|
344
|
+
static STRESS = CssProp.reg(CssProp.CP.stress);
|
|
345
|
+
static TEXT_INDENT = CssProp.reg(CssProp.CP.text_indent);
|
|
346
|
+
static TEXT_SHADOW = CssProp.reg(CssProp.CP.text_shadow);
|
|
347
|
+
static VOLUME = CssProp.reg(CssProp.CP.volume);
|
|
348
|
+
static WORD_WRAP = CssProp.reg(CssProp.CP.word_wrap);
|
|
349
|
+
static ZOOM = CssProp.reg(CssProp.CP.zoom);
|
|
350
|
+
static BACKFACE_VISIBILITY = CssProp.reg(CssProp.CP.backface_visibility);
|
|
351
|
+
static BACKGROUND_CLIP = CssProp.reg(CssProp.CP.background_clip);
|
|
352
|
+
static BACKGROUND_POSITION = CssProp.reg(CssProp.CP.background_position);
|
|
353
|
+
static BORDER_BOTTOM_COLOR = CssProp.reg(CssProp.CP.border_bottom_color);
|
|
354
|
+
static BORDER_BOTTOM_STYLE = CssProp.reg(CssProp.CP.border_bottom_style);
|
|
355
|
+
static BORDER_COLOR = CssProp.reg(CssProp.CP.border_color);
|
|
356
|
+
static BORDER_LEFT_COLOR = CssProp.reg(CssProp.CP.border_left_color);
|
|
357
|
+
static BORDER_RIGHT_COLOR = CssProp.reg(CssProp.CP.border_right_color);
|
|
358
|
+
static BORDER_STYLE = CssProp.reg(CssProp.CP.border_style);
|
|
359
|
+
static BORDER_TOP_LEFT_RADIUS = CssProp.reg(CssProp.CP.border_top_left_radius);
|
|
360
|
+
static BORDER_TOP_WIDTH = CssProp.reg(CssProp.CP.border_top_width);
|
|
361
|
+
static BOX_SHADOW = CssProp.reg(CssProp.CP.box_shadow);
|
|
362
|
+
static CLIP = CssProp.reg(CssProp.CP.clip);
|
|
363
|
+
static DISPLAY_INSIDE = CssProp.reg(CssProp.CP.display_inside);
|
|
364
|
+
static FONT_SIZE = CssProp.reg(CssProp.CP.font_size);
|
|
365
|
+
static LINE_HEIGHT = CssProp.reg(CssProp.CP.line_height);
|
|
366
|
+
static MARGIN_LEFT = CssProp.reg(CssProp.CP.margin_left);
|
|
367
|
+
static MAX_WIDTH = CssProp.reg(CssProp.CP.max_width);
|
|
368
|
+
static OUTLINE_STYLE = CssProp.reg(CssProp.CP.outline_style);
|
|
369
|
+
static PADDING_BOTTOM = CssProp.reg(CssProp.CP.padding_bottom);
|
|
370
|
+
static PADDING_RIGHT = CssProp.reg(CssProp.CP.padding_right);
|
|
371
|
+
static PERSPECTIVE = CssProp.reg(CssProp.CP.perspective);
|
|
372
|
+
static RICHNESS = CssProp.reg(CssProp.CP.richness);
|
|
373
|
+
static TEXT_OVERFLOW = CssProp.reg(CssProp.CP.text_overflow);
|
|
374
|
+
static TOP = CssProp.reg(CssProp.CP.top);
|
|
375
|
+
static WIDTH = CssProp.reg(CssProp.CP.width);
|
|
376
|
+
static Z_INDEX = CssProp.reg(CssProp.CP.z_index);
|
|
377
|
+
static BACKGROUND = CssProp.reg(CssProp.CP.background);
|
|
378
|
+
static BACKGROUND_SIZE = CssProp.reg(CssProp.CP.background_size);
|
|
379
|
+
static BORDER_BOTTOM_LEFT_RADIUS = CssProp.reg(CssProp.CP.border_bottom_left_radius);
|
|
380
|
+
static BORDER_BOTTOM_WIDTH = CssProp.reg(CssProp.CP.border_bottom_width);
|
|
381
|
+
static BORDER_LEFT_STYLE = CssProp.reg(CssProp.CP.border_left_style);
|
|
382
|
+
static BORDER_RIGHT_STYLE = CssProp.reg(CssProp.CP.border_right_style);
|
|
383
|
+
static BORDER_TOP = CssProp.reg(CssProp.CP.border_top);
|
|
384
|
+
static BOTTOM = CssProp.reg(CssProp.CP.bottom);
|
|
385
|
+
static LIST_STYLE = CssProp.reg(CssProp.CP.list_style);
|
|
386
|
+
static MARGIN_TOP = CssProp.reg(CssProp.CP.margin_top);
|
|
387
|
+
static OUTLINE = CssProp.reg(CssProp.CP.outline);
|
|
388
|
+
static OVERFLOW_Y = CssProp.reg(CssProp.CP.overflow_y);
|
|
389
|
+
static PITCH = CssProp.reg(CssProp.CP.pitch);
|
|
390
|
+
static VERTICAL_ALIGN = CssProp.reg(CssProp.CP.vertical_align);
|
|
391
|
+
static WORD_SPACING = CssProp.reg(CssProp.CP.word_spacing);
|
|
392
|
+
static BACKGROUND_IMAGE = CssProp.reg(CssProp.CP.background_image);
|
|
393
|
+
static BORDER_BOTTOM_RIGHT_RADIUS = CssProp.reg(
|
|
394
|
+
CssProp.CP.border_bottom_right_radius,
|
|
395
|
+
);
|
|
396
|
+
static BORDER_LEFT_WIDTH = CssProp.reg(CssProp.CP.border_left_width);
|
|
397
|
+
static BORDER_RIGHT_WIDTH = CssProp.reg(CssProp.CP.border_right_width);
|
|
398
|
+
static LEFT = CssProp.reg(CssProp.CP.left);
|
|
399
|
+
static MARGIN_BOTTOM = CssProp.reg(CssProp.CP.margin_bottom);
|
|
400
|
+
static PAUSE_AFTER = CssProp.reg(CssProp.CP.pause_after);
|
|
401
|
+
static SPEECH_RATE = CssProp.reg(CssProp.CP.speech_rate);
|
|
402
|
+
static TRANSITION_DURATION = CssProp.reg(CssProp.CP.transition_duration);
|
|
403
|
+
static BORDER_BOTTOM = CssProp.reg(CssProp.CP.border_bottom);
|
|
404
|
+
static BORDER_RIGHT = CssProp.reg(CssProp.CP.border_right);
|
|
405
|
+
static MARGIN = CssProp.reg(CssProp.CP.margin);
|
|
406
|
+
static PADDING_LEFT = CssProp.reg(CssProp.CP.padding_left);
|
|
407
|
+
static BORDER_LEFT = CssProp.reg(CssProp.CP.border_left);
|
|
408
|
+
static FONT = CssProp.reg(CssProp.CP.font);
|
|
409
|
+
static QUOTES = CssProp.reg(CssProp.CP.quotes);
|
|
410
|
+
static BORDER_TOP_RIGHT_RADIUS = CssProp.reg(CssProp.CP.border_top_right_radius);
|
|
411
|
+
static MIN_WIDTH = CssProp.reg(CssProp.CP.min_width);
|
|
412
|
+
}
|
|
413
|
+
export interface ISanitizerOptions {
|
|
414
|
+
/**
|
|
415
|
+
* The allowed tags.
|
|
416
|
+
*/
|
|
417
|
+
allowedTags?: string[];
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* The allowed attributes for a given tag.
|
|
421
|
+
*/
|
|
422
|
+
allowedAttributes?: Record<string, string[]>;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* The allowed style values for a given tag.
|
|
426
|
+
*/
|
|
427
|
+
allowedStyles?: Record<string, Record<string, RegExp[]>>;
|
|
428
|
+
}
|
|
429
|
+
export interface ISanitizer {
|
|
430
|
+
/**
|
|
431
|
+
* Sanitize an HTML string.
|
|
432
|
+
*
|
|
433
|
+
* @param dirty - The dirty text.
|
|
434
|
+
*
|
|
435
|
+
* @param options - The optional sanitization options.
|
|
436
|
+
*
|
|
437
|
+
* @returns The sanitized string.
|
|
438
|
+
*/
|
|
439
|
+
sanitize: (dirty: string, options?: ISanitizerOptions) => string;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* A class to sanitize HTML strings.
|
|
444
|
+
*/
|
|
445
|
+
export class Sanitizer implements ISanitizer {
|
|
446
|
+
/**
|
|
447
|
+
* Sanitize an HTML string.
|
|
448
|
+
*
|
|
449
|
+
* @param dirty - The dirty text.
|
|
450
|
+
*
|
|
451
|
+
* @param options - The optional sanitization options.
|
|
452
|
+
*
|
|
453
|
+
* @returns The sanitized string.
|
|
454
|
+
*/
|
|
455
|
+
sanitize(dirty: string, options?: ISanitizerOptions): string {
|
|
456
|
+
return sanitize(dirty, { ...this._options, ...(options || {}) });
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
private _options: sanitize.IOptions = {
|
|
460
|
+
// HTML tags that are allowed to be used. Tags were extracted from Google Caja
|
|
461
|
+
allowedTags: [
|
|
462
|
+
'a',
|
|
463
|
+
'abbr',
|
|
464
|
+
'acronym',
|
|
465
|
+
'address',
|
|
466
|
+
'area',
|
|
467
|
+
'article',
|
|
468
|
+
'aside',
|
|
469
|
+
'audio',
|
|
470
|
+
'b',
|
|
471
|
+
'bdi',
|
|
472
|
+
'bdo',
|
|
473
|
+
'big',
|
|
474
|
+
'blockquote',
|
|
475
|
+
'br',
|
|
476
|
+
'button',
|
|
477
|
+
'canvas',
|
|
478
|
+
'caption',
|
|
479
|
+
'center',
|
|
480
|
+
'cite',
|
|
481
|
+
'code',
|
|
482
|
+
'col',
|
|
483
|
+
'colgroup',
|
|
484
|
+
'colspan',
|
|
485
|
+
'command',
|
|
486
|
+
'data',
|
|
487
|
+
'datalist',
|
|
488
|
+
'dd',
|
|
489
|
+
'del',
|
|
490
|
+
'details',
|
|
491
|
+
'dfn',
|
|
492
|
+
'dir',
|
|
493
|
+
'div',
|
|
494
|
+
'dl',
|
|
495
|
+
'dt',
|
|
496
|
+
'em',
|
|
497
|
+
'fieldset',
|
|
498
|
+
'figcaption',
|
|
499
|
+
'figure',
|
|
500
|
+
'font',
|
|
501
|
+
'footer',
|
|
502
|
+
'form',
|
|
503
|
+
'h1',
|
|
504
|
+
'h2',
|
|
505
|
+
'h3',
|
|
506
|
+
'h4',
|
|
507
|
+
'h5',
|
|
508
|
+
'h6',
|
|
509
|
+
'header',
|
|
510
|
+
'hgroup',
|
|
511
|
+
'hr',
|
|
512
|
+
'i',
|
|
513
|
+
// 'iframe' is allowed by Google Caja, but disallowed by default by sanitize-html
|
|
514
|
+
// , 'iframe'
|
|
515
|
+
'img',
|
|
516
|
+
'input',
|
|
517
|
+
'ins',
|
|
518
|
+
'kbd',
|
|
519
|
+
'label',
|
|
520
|
+
'legend',
|
|
521
|
+
'li',
|
|
522
|
+
'map',
|
|
523
|
+
'mark',
|
|
524
|
+
'menu',
|
|
525
|
+
'meter',
|
|
526
|
+
'nav',
|
|
527
|
+
'nobr',
|
|
528
|
+
'ol',
|
|
529
|
+
'optgroup',
|
|
530
|
+
'option',
|
|
531
|
+
'output',
|
|
532
|
+
'p',
|
|
533
|
+
'pre',
|
|
534
|
+
'progress',
|
|
535
|
+
'q',
|
|
536
|
+
'rowspan',
|
|
537
|
+
's',
|
|
538
|
+
'samp',
|
|
539
|
+
'section',
|
|
540
|
+
'select',
|
|
541
|
+
'small',
|
|
542
|
+
'source',
|
|
543
|
+
'span',
|
|
544
|
+
'strike',
|
|
545
|
+
'strong',
|
|
546
|
+
'sub',
|
|
547
|
+
'summary',
|
|
548
|
+
'sup',
|
|
549
|
+
'table',
|
|
550
|
+
'tbody',
|
|
551
|
+
'td',
|
|
552
|
+
'textarea',
|
|
553
|
+
'tfoot',
|
|
554
|
+
'th',
|
|
555
|
+
'thead',
|
|
556
|
+
'time',
|
|
557
|
+
'tr',
|
|
558
|
+
'track',
|
|
559
|
+
'tt',
|
|
560
|
+
'u',
|
|
561
|
+
'ul',
|
|
562
|
+
'var',
|
|
563
|
+
'video',
|
|
564
|
+
'wbr',
|
|
565
|
+
],
|
|
566
|
+
// Attributes that HTML tags are allowed to have, extracted from Google Caja.
|
|
567
|
+
// See https://github.com/jupyterlab/jupyterlab/issues/1812#issuecomment-285848435
|
|
568
|
+
allowedAttributes: {
|
|
569
|
+
'*': [
|
|
570
|
+
'class',
|
|
571
|
+
'dir',
|
|
572
|
+
'draggable',
|
|
573
|
+
'hidden',
|
|
574
|
+
'id',
|
|
575
|
+
'inert',
|
|
576
|
+
'itemprop',
|
|
577
|
+
'itemref',
|
|
578
|
+
'itemscope',
|
|
579
|
+
'lang',
|
|
580
|
+
'spellcheck',
|
|
581
|
+
'style',
|
|
582
|
+
'title',
|
|
583
|
+
'translate',
|
|
584
|
+
],
|
|
585
|
+
// 'rel' and 'target' were *not* allowed by Google Caja
|
|
586
|
+
a: [
|
|
587
|
+
'accesskey',
|
|
588
|
+
'coords',
|
|
589
|
+
'href',
|
|
590
|
+
'hreflang',
|
|
591
|
+
'name',
|
|
592
|
+
'rel',
|
|
593
|
+
'shape',
|
|
594
|
+
'tabindex',
|
|
595
|
+
'target',
|
|
596
|
+
'type',
|
|
597
|
+
],
|
|
598
|
+
area: ['accesskey', 'alt', 'coords', 'href', 'nohref', 'shape', 'tabindex'],
|
|
599
|
+
// 'autoplay' was *not* allowed by Google Caja
|
|
600
|
+
audio: ['autoplay', 'controls', 'loop', 'mediagroup', 'muted', 'preload', 'src'],
|
|
601
|
+
bdo: ['dir'],
|
|
602
|
+
blockquote: ['cite'],
|
|
603
|
+
br: ['clear'],
|
|
604
|
+
button: [
|
|
605
|
+
'accesskey',
|
|
606
|
+
'data-commandlinker-args',
|
|
607
|
+
'data-commandlinker-command',
|
|
608
|
+
'disabled',
|
|
609
|
+
'name',
|
|
610
|
+
'tabindex',
|
|
611
|
+
'type',
|
|
612
|
+
'value',
|
|
613
|
+
],
|
|
614
|
+
canvas: ['height', 'width'],
|
|
615
|
+
caption: ['align'],
|
|
616
|
+
col: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
|
|
617
|
+
colgroup: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
|
|
618
|
+
command: [
|
|
619
|
+
'checked',
|
|
620
|
+
'command',
|
|
621
|
+
'disabled',
|
|
622
|
+
'icon',
|
|
623
|
+
'label',
|
|
624
|
+
'radiogroup',
|
|
625
|
+
'type',
|
|
626
|
+
],
|
|
627
|
+
data: ['value'],
|
|
628
|
+
del: ['cite', 'datetime'],
|
|
629
|
+
details: ['open'],
|
|
630
|
+
dir: ['compact'],
|
|
631
|
+
div: ['align'],
|
|
632
|
+
dl: ['compact'],
|
|
633
|
+
fieldset: ['disabled'],
|
|
634
|
+
font: ['color', 'face', 'size'],
|
|
635
|
+
form: ['accept', 'autocomplete', 'enctype', 'method', 'name', 'novalidate'],
|
|
636
|
+
h1: ['align'],
|
|
637
|
+
h2: ['align'],
|
|
638
|
+
h3: ['align'],
|
|
639
|
+
h4: ['align'],
|
|
640
|
+
h5: ['align'],
|
|
641
|
+
h6: ['align'],
|
|
642
|
+
hr: ['align', 'noshade', 'size', 'width'],
|
|
643
|
+
iframe: [
|
|
644
|
+
'align',
|
|
645
|
+
'frameborder',
|
|
646
|
+
'height',
|
|
647
|
+
'marginheight',
|
|
648
|
+
'marginwidth',
|
|
649
|
+
'width',
|
|
650
|
+
],
|
|
651
|
+
img: [
|
|
652
|
+
'align',
|
|
653
|
+
'alt',
|
|
654
|
+
'border',
|
|
655
|
+
'height',
|
|
656
|
+
'hspace',
|
|
657
|
+
'ismap',
|
|
658
|
+
'name',
|
|
659
|
+
'src',
|
|
660
|
+
'usemap',
|
|
661
|
+
'vspace',
|
|
662
|
+
'width',
|
|
663
|
+
],
|
|
664
|
+
input: [
|
|
665
|
+
'accept',
|
|
666
|
+
'accesskey',
|
|
667
|
+
'align',
|
|
668
|
+
'alt',
|
|
669
|
+
'autocomplete',
|
|
670
|
+
'checked',
|
|
671
|
+
'disabled',
|
|
672
|
+
'inputmode',
|
|
673
|
+
'ismap',
|
|
674
|
+
'list',
|
|
675
|
+
'max',
|
|
676
|
+
'maxlength',
|
|
677
|
+
'min',
|
|
678
|
+
'multiple',
|
|
679
|
+
'name',
|
|
680
|
+
'placeholder',
|
|
681
|
+
'readonly',
|
|
682
|
+
'required',
|
|
683
|
+
'size',
|
|
684
|
+
'src',
|
|
685
|
+
'step',
|
|
686
|
+
'tabindex',
|
|
687
|
+
'type',
|
|
688
|
+
'usemap',
|
|
689
|
+
'value',
|
|
690
|
+
],
|
|
691
|
+
ins: ['cite', 'datetime'],
|
|
692
|
+
label: ['accesskey', 'for'],
|
|
693
|
+
legend: ['accesskey', 'align'],
|
|
694
|
+
li: ['type', 'value'],
|
|
695
|
+
map: ['name'],
|
|
696
|
+
menu: ['compact', 'label', 'type'],
|
|
697
|
+
meter: ['high', 'low', 'max', 'min', 'value'],
|
|
698
|
+
ol: ['compact', 'reversed', 'start', 'type'],
|
|
699
|
+
optgroup: ['disabled', 'label'],
|
|
700
|
+
option: ['disabled', 'label', 'selected', 'value'],
|
|
701
|
+
output: ['for', 'name'],
|
|
702
|
+
p: ['align'],
|
|
703
|
+
pre: ['width'],
|
|
704
|
+
progress: ['max', 'min', 'value'],
|
|
705
|
+
q: ['cite'],
|
|
706
|
+
select: [
|
|
707
|
+
'autocomplete',
|
|
708
|
+
'disabled',
|
|
709
|
+
'multiple',
|
|
710
|
+
'name',
|
|
711
|
+
'required',
|
|
712
|
+
'size',
|
|
713
|
+
'tabindex',
|
|
714
|
+
],
|
|
715
|
+
source: ['type'],
|
|
716
|
+
table: [
|
|
717
|
+
'align',
|
|
718
|
+
'bgcolor',
|
|
719
|
+
'border',
|
|
720
|
+
'cellpadding',
|
|
721
|
+
'cellspacing',
|
|
722
|
+
'frame',
|
|
723
|
+
'rules',
|
|
724
|
+
'summary',
|
|
725
|
+
'width',
|
|
726
|
+
],
|
|
727
|
+
tbody: ['align', 'char', 'charoff', 'valign'],
|
|
728
|
+
td: [
|
|
729
|
+
'abbr',
|
|
730
|
+
'align',
|
|
731
|
+
'axis',
|
|
732
|
+
'bgcolor',
|
|
733
|
+
'char',
|
|
734
|
+
'charoff',
|
|
735
|
+
'colspan',
|
|
736
|
+
'headers',
|
|
737
|
+
'height',
|
|
738
|
+
'nowrap',
|
|
739
|
+
'rowspan',
|
|
740
|
+
'scope',
|
|
741
|
+
'valign',
|
|
742
|
+
'width',
|
|
743
|
+
],
|
|
744
|
+
textarea: [
|
|
745
|
+
'accesskey',
|
|
746
|
+
'autocomplete',
|
|
747
|
+
'cols',
|
|
748
|
+
'disabled',
|
|
749
|
+
'inputmode',
|
|
750
|
+
'name',
|
|
751
|
+
'placeholder',
|
|
752
|
+
'readonly',
|
|
753
|
+
'required',
|
|
754
|
+
'rows',
|
|
755
|
+
'tabindex',
|
|
756
|
+
'wrap',
|
|
757
|
+
],
|
|
758
|
+
tfoot: ['align', 'char', 'charoff', 'valign'],
|
|
759
|
+
th: [
|
|
760
|
+
'abbr',
|
|
761
|
+
'align',
|
|
762
|
+
'axis',
|
|
763
|
+
'bgcolor',
|
|
764
|
+
'char',
|
|
765
|
+
'charoff',
|
|
766
|
+
'colspan',
|
|
767
|
+
'headers',
|
|
768
|
+
'height',
|
|
769
|
+
'nowrap',
|
|
770
|
+
'rowspan',
|
|
771
|
+
'scope',
|
|
772
|
+
'valign',
|
|
773
|
+
'width',
|
|
774
|
+
],
|
|
775
|
+
thead: ['align', 'char', 'charoff', 'valign'],
|
|
776
|
+
tr: ['align', 'bgcolor', 'char', 'charoff', 'valign'],
|
|
777
|
+
track: ['default', 'kind', 'label', 'srclang'],
|
|
778
|
+
ul: ['compact', 'type'],
|
|
779
|
+
video: [
|
|
780
|
+
'autoplay',
|
|
781
|
+
'controls',
|
|
782
|
+
'height',
|
|
783
|
+
'loop',
|
|
784
|
+
'mediagroup',
|
|
785
|
+
'muted',
|
|
786
|
+
'poster',
|
|
787
|
+
'preload',
|
|
788
|
+
'src',
|
|
789
|
+
'width',
|
|
790
|
+
],
|
|
791
|
+
},
|
|
792
|
+
// Inline CSS styles that HTML tags may have (and their allowed values)
|
|
793
|
+
allowedStyles: {
|
|
794
|
+
// To simplify the data, all styles are allowed on all tags that allow the style attribute
|
|
795
|
+
'*': {
|
|
796
|
+
'backface-visibility': [CssProp.BACKFACE_VISIBILITY],
|
|
797
|
+
background: [CssProp.BACKGROUND],
|
|
798
|
+
'background-attachment': [CssProp.BACKGROUND_ATTACHMENT],
|
|
799
|
+
'background-clip': [CssProp.BACKGROUND_CLIP],
|
|
800
|
+
'background-color': [CssProp.BACKGROUND_COLOR],
|
|
801
|
+
'background-image': [CssProp.BACKGROUND_IMAGE],
|
|
802
|
+
'background-origin': [CssProp.BACKGROUND_ORIGIN],
|
|
803
|
+
'background-position': [CssProp.BACKGROUND_POSITION],
|
|
804
|
+
'background-repeat': [CssProp.BACKGROUND_REPEAT],
|
|
805
|
+
'background-size': [CssProp.BACKGROUND_SIZE],
|
|
806
|
+
border: [CssProp.BORDER],
|
|
807
|
+
'border-bottom': [CssProp.BORDER_BOTTOM],
|
|
808
|
+
'border-bottom-color': [CssProp.BORDER_BOTTOM_COLOR],
|
|
809
|
+
'border-bottom-left-radius': [CssProp.BORDER_BOTTOM_LEFT_RADIUS],
|
|
810
|
+
'border-bottom-right-radius': [CssProp.BORDER_BOTTOM_RIGHT_RADIUS],
|
|
811
|
+
'border-bottom-style': [CssProp.BORDER_BOTTOM_STYLE],
|
|
812
|
+
'border-bottom-width': [CssProp.BORDER_BOTTOM_WIDTH],
|
|
813
|
+
'border-collapse': [CssProp.BORDER_COLLAPSE],
|
|
814
|
+
'border-color': [CssProp.BORDER_COLOR],
|
|
815
|
+
'border-left': [CssProp.BORDER_LEFT],
|
|
816
|
+
'border-left-color': [CssProp.BORDER_LEFT_COLOR],
|
|
817
|
+
'border-left-style': [CssProp.BORDER_LEFT_STYLE],
|
|
818
|
+
'border-left-width': [CssProp.BORDER_LEFT_WIDTH],
|
|
819
|
+
'border-radius': [CssProp.BORDER_RADIUS],
|
|
820
|
+
'border-right': [CssProp.BORDER_RIGHT],
|
|
821
|
+
'border-right-color': [CssProp.BORDER_RIGHT_COLOR],
|
|
822
|
+
'border-right-style': [CssProp.BORDER_RIGHT_STYLE],
|
|
823
|
+
'border-right-width': [CssProp.BORDER_RIGHT_WIDTH],
|
|
824
|
+
'border-spacing': [CssProp.BORDER_SPACING],
|
|
825
|
+
'border-style': [CssProp.BORDER_STYLE],
|
|
826
|
+
'border-top': [CssProp.BORDER_TOP],
|
|
827
|
+
'border-top-color': [CssProp.BORDER_TOP_COLOR],
|
|
828
|
+
'border-top-left-radius': [CssProp.BORDER_TOP_LEFT_RADIUS],
|
|
829
|
+
'border-top-right-radius': [CssProp.BORDER_TOP_RIGHT_RADIUS],
|
|
830
|
+
'border-top-style': [CssProp.BORDER_TOP_STYLE],
|
|
831
|
+
'border-top-width': [CssProp.BORDER_TOP_WIDTH],
|
|
832
|
+
'border-width': [CssProp.BORDER_WIDTH],
|
|
833
|
+
bottom: [CssProp.BOTTOM],
|
|
834
|
+
box: [CssProp.BOX],
|
|
835
|
+
'box-shadow': [CssProp.BOX_SHADOW],
|
|
836
|
+
'box-sizing': [CssProp.BOX_SIZING],
|
|
837
|
+
'caption-side': [CssProp.CAPTION_SIDE],
|
|
838
|
+
clear: [CssProp.CLEAR],
|
|
839
|
+
clip: [CssProp.CLIP],
|
|
840
|
+
color: [CssProp.COLOR],
|
|
841
|
+
cursor: [CssProp.CURSOR],
|
|
842
|
+
direction: [CssProp.DIRECTION],
|
|
843
|
+
display: [CssProp.DISPLAY],
|
|
844
|
+
'display-inside': [CssProp.DISPLAY_INSIDE],
|
|
845
|
+
'display-outside': [CssProp.DISPLAY_OUTSIDE],
|
|
846
|
+
elevation: [CssProp.ELEVATION],
|
|
847
|
+
'empty-cells': [CssProp.EMPTY_CELLS],
|
|
848
|
+
float: [CssProp.FLOAT],
|
|
849
|
+
font: [CssProp.FONT],
|
|
850
|
+
'font-family': [CssProp.FONT_FAMILY],
|
|
851
|
+
'font-size': [CssProp.FONT_SIZE],
|
|
852
|
+
'font-stretch': [CssProp.FONT_STRETCH],
|
|
853
|
+
'font-style': [CssProp.FONT_STYLE],
|
|
854
|
+
'font-variant': [CssProp.FONT_VARIANT],
|
|
855
|
+
'font-weight': [CssProp.FONT_WEIGHT],
|
|
856
|
+
height: [CssProp.HEIGHT],
|
|
857
|
+
left: [CssProp.LEFT],
|
|
858
|
+
'letter-spacing': [CssProp.LETTER_SPACING],
|
|
859
|
+
'line-height': [CssProp.LINE_HEIGHT],
|
|
860
|
+
'list-style': [CssProp.LIST_STYLE],
|
|
861
|
+
'list-style-image': [CssProp.LIST_STYLE_IMAGE],
|
|
862
|
+
'list-style-position': [CssProp.LIST_STYLE_POSITION],
|
|
863
|
+
'list-style-type': [CssProp.LIST_STYLE_TYPE],
|
|
864
|
+
margin: [CssProp.MARGIN],
|
|
865
|
+
'margin-bottom': [CssProp.MARGIN_BOTTOM],
|
|
866
|
+
'margin-left': [CssProp.MARGIN_LEFT],
|
|
867
|
+
'margin-right': [CssProp.MARGIN_RIGHT],
|
|
868
|
+
'margin-top': [CssProp.MARGIN_TOP],
|
|
869
|
+
'max-height': [CssProp.MAX_HEIGHT],
|
|
870
|
+
'max-width': [CssProp.MAX_WIDTH],
|
|
871
|
+
'min-height': [CssProp.MIN_HEIGHT],
|
|
872
|
+
'min-width': [CssProp.MIN_WIDTH],
|
|
873
|
+
opacity: [CssProp.OPACITY],
|
|
874
|
+
outline: [CssProp.OUTLINE],
|
|
875
|
+
'outline-color': [CssProp.OUTLINE_COLOR],
|
|
876
|
+
'outline-style': [CssProp.OUTLINE_STYLE],
|
|
877
|
+
'outline-width': [CssProp.OUTLINE_WIDTH],
|
|
878
|
+
overflow: [CssProp.OVERFLOW],
|
|
879
|
+
'overflow-wrap': [CssProp.OVERFLOW_WRAP],
|
|
880
|
+
'overflow-x': [CssProp.OVERFLOW_X],
|
|
881
|
+
'overflow-y': [CssProp.OVERFLOW_Y],
|
|
882
|
+
padding: [CssProp.PADDING],
|
|
883
|
+
'padding-bottom': [CssProp.PADDING_BOTTOM],
|
|
884
|
+
'padding-left': [CssProp.PADDING_LEFT],
|
|
885
|
+
'padding-right': [CssProp.PADDING_RIGHT],
|
|
886
|
+
'padding-top': [CssProp.PADDING_TOP],
|
|
887
|
+
'page-break-after': [CssProp.PAGE_BREAK_AFTER],
|
|
888
|
+
'page-break-before': [CssProp.PAGE_BREAK_BEFORE],
|
|
889
|
+
'page-break-inside': [CssProp.PAGE_BREAK_INSIDE],
|
|
890
|
+
'pause-after': [CssProp.PAUSE_AFTER],
|
|
891
|
+
perspective: [CssProp.PERSPECTIVE],
|
|
892
|
+
pitch: [CssProp.PITCH],
|
|
893
|
+
'pitch-range': [CssProp.PITCH_RANGE],
|
|
894
|
+
position: [CssProp.POSITION],
|
|
895
|
+
quotes: [CssProp.QUOTES],
|
|
896
|
+
resize: [CssProp.RESIZE],
|
|
897
|
+
richness: [CssProp.RICHNESS],
|
|
898
|
+
right: [CssProp.RIGHT],
|
|
899
|
+
speak: [CssProp.SPEAK],
|
|
900
|
+
'speak-header': [CssProp.SPEAK_HEADER],
|
|
901
|
+
'speak-numeral': [CssProp.SPEAK_NUMERAL],
|
|
902
|
+
'speak-punctuation': [CssProp.SPEAK_PUNCTUATION],
|
|
903
|
+
'speech-rate': [CssProp.SPEECH_RATE],
|
|
904
|
+
stress: [CssProp.STRESS],
|
|
905
|
+
'table-layout': [CssProp.TABLE_LAYOUT],
|
|
906
|
+
'text-align': [CssProp.TEXT_ALIGN],
|
|
907
|
+
'text-decoration': [CssProp.TEXT_DECORATION],
|
|
908
|
+
'text-indent': [CssProp.TEXT_INDENT],
|
|
909
|
+
'text-overflow': [CssProp.TEXT_OVERFLOW],
|
|
910
|
+
'text-shadow': [CssProp.TEXT_SHADOW],
|
|
911
|
+
'text-transform': [CssProp.TEXT_TRANSFORM],
|
|
912
|
+
'text-wrap': [CssProp.TEXT_WRAP],
|
|
913
|
+
top: [CssProp.TOP],
|
|
914
|
+
'unicode-bidi': [CssProp.UNICODE_BIDI],
|
|
915
|
+
'vertical-align': [CssProp.VERTICAL_ALIGN],
|
|
916
|
+
visibility: [CssProp.VISIBILITY],
|
|
917
|
+
volume: [CssProp.VOLUME],
|
|
918
|
+
'white-space': [CssProp.WHITE_SPACE],
|
|
919
|
+
width: [CssProp.WIDTH],
|
|
920
|
+
'word-break': [CssProp.WORD_BREAK],
|
|
921
|
+
'word-spacing': [CssProp.WORD_SPACING],
|
|
922
|
+
'word-wrap': [CssProp.WORD_WRAP],
|
|
923
|
+
'z-index': [CssProp.Z_INDEX],
|
|
924
|
+
zoom: [CssProp.ZOOM],
|
|
925
|
+
},
|
|
926
|
+
},
|
|
927
|
+
transformTags: {
|
|
928
|
+
// Set the "rel" attribute for <a> tags to "nofollow".
|
|
929
|
+
a: sanitize.simpleTransform('a', { rel: 'nofollow' }),
|
|
930
|
+
// Set the "disabled" attribute for <input> tags.
|
|
931
|
+
input: sanitize.simpleTransform('input', { disabled: 'disabled' }),
|
|
932
|
+
},
|
|
933
|
+
allowedSchemesByTag: {
|
|
934
|
+
// Allow 'attachment:' img src (used for markdown cell attachments).
|
|
935
|
+
img: sanitize.defaults.allowedSchemes.concat(['attachment']),
|
|
936
|
+
},
|
|
937
|
+
// Override of the default option, so we can skip 'src' attribute validation.
|
|
938
|
+
// 'src' Attributes are validated to be URIs, which does not allow for embedded (image) data.
|
|
939
|
+
// Since embedded data is no longer deemed to be a threat, validation can be skipped.
|
|
940
|
+
// See https://github.com/jupyterlab/jupyterlab/issues/5183
|
|
941
|
+
allowedSchemesAppliedToAttributes: ['href', 'cite'],
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
export const defaultSanitizer: ISanitizer = new Sanitizer();
|