@jupyterlab/apputils 4.7.5 → 4.7.7
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/lib/dialog.js +54 -14
- package/lib/dialog.js.map +1 -1
- package/lib/sanitizer.d.ts +5 -0
- package/lib/sanitizer.js +205 -121
- package/lib/sanitizer.js.map +1 -1
- package/lib/thememanager.js +7 -2
- package/lib/thememanager.js.map +1 -1
- package/lib/toolbar/factory.js +9 -1
- package/lib/toolbar/factory.js.map +1 -1
- package/package.json +12 -12
- package/src/dialog.tsx +63 -19
- package/src/sanitizer.ts +227 -122
- package/src/thememanager.ts +7 -2
- package/src/toolbar/factory.ts +9 -1
package/lib/sanitizer.js
CHANGED
|
@@ -13,72 +13,101 @@ import sanitize from 'sanitize-html';
|
|
|
13
13
|
*/
|
|
14
14
|
class CssProp {
|
|
15
15
|
static reg(r) {
|
|
16
|
-
return new RegExp('^' + r + '$', 'i');
|
|
16
|
+
return new RegExp('^(?:' + r + ')$', 'i');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Wraps each expression in a group, so that its alternatives stay together
|
|
20
|
+
* when it is embedded in another expression.
|
|
21
|
+
*/
|
|
22
|
+
static group(exprs) {
|
|
23
|
+
for (const key in exprs) {
|
|
24
|
+
exprs[key] = `(?:${exprs[key]})`;
|
|
25
|
+
}
|
|
26
|
+
return exprs;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Matches one or more items, each followed by optional whitespace and `sep`.
|
|
30
|
+
* An item cannot be followed by a character that would continue it, so a
|
|
31
|
+
* value splits into items in only one way and is checked in linear time.
|
|
32
|
+
*/
|
|
33
|
+
static list(item, sep = '') {
|
|
34
|
+
return `(?:(?:${item})(?![\\w.%+-])\\s*${sep})+`;
|
|
17
35
|
}
|
|
18
36
|
}
|
|
19
37
|
/*
|
|
20
38
|
* Numeric base expressions used to help build more complex regular expressions
|
|
21
39
|
*/
|
|
22
|
-
CssProp.N = {
|
|
40
|
+
CssProp.N = CssProp.group({
|
|
23
41
|
integer: `[+-]?[0-9]+`,
|
|
24
42
|
integer_pos: `[+]?[0-9]+`,
|
|
25
43
|
integer_zero_ff: `([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])`,
|
|
26
44
|
integer_non_zero: `[+-]?([1-9][0-9]*)`,
|
|
27
45
|
integer_pos_non_zero: `[+]?([1-9][0-9]*)`,
|
|
28
|
-
number: `[+-]?([0-9]*[.])?[0-9]+(e
|
|
29
|
-
number_pos: `[+]?([0-9]*[.])?[0-9]+(e
|
|
46
|
+
number: `[+-]?([0-9]*[.])?[0-9]+(e[+-]?[0-9]+)?`,
|
|
47
|
+
number_pos: `[+]?([0-9]*[.])?[0-9]+(e[+-]?[0-9]+)?`,
|
|
30
48
|
number_zero_hundred: `[+]?(([0-9]|[1-9][0-9])([.][0-9]+)?|100)`,
|
|
31
49
|
number_zero_one: `[+]?(1([.][0]+)?|0?([.][0-9]+)?)`
|
|
32
|
-
};
|
|
50
|
+
});
|
|
51
|
+
/*
|
|
52
|
+
* calc() of numbers, lengths and percentages, without nesting or var()
|
|
53
|
+
*/
|
|
54
|
+
CssProp.CALC = `(?:calc\\(\\s*${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc|%)?(\\s*[-+*/]\\s*${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc|%)?)*\\s*\\))`;
|
|
55
|
+
/*
|
|
56
|
+
* Escape in an identifier or a string; it takes all hex digits and the
|
|
57
|
+
* whitespace after them, so that each value has only one match.
|
|
58
|
+
*/
|
|
59
|
+
CssProp.ESCAPE = String.raw `(?:\\(?:[0-9a-f]{1,6}(?![0-9a-f])(?:\r\n|[ \t\n\f]|\r(?!\n)|(?![ \t\r\n\f]))|[^\r\n\f0-9a-f]))`;
|
|
33
60
|
/*
|
|
34
61
|
* Base expressions of common CSS syntax elements
|
|
35
62
|
*/
|
|
36
|
-
CssProp._B = {
|
|
63
|
+
CssProp._B = CssProp.group({
|
|
37
64
|
angle: `(${CssProp.N.number}(deg|rad|grad|turn)|0)`,
|
|
38
65
|
frequency: `${CssProp.N.number}(Hz|kHz)`,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
// Not U+00A0: `\s` matches it, and the overlap makes the checks exponential.
|
|
67
|
+
ident: String.raw `-?([_a-z]|[\xA1-\xFF]|${CssProp.ESCAPE})([_a-z0-9-]|[\xA1-\xFF]|${CssProp.ESCAPE})*`,
|
|
68
|
+
len_or_perc: `(0|${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc|%)|${CssProp.CALC})`,
|
|
69
|
+
length: `(${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc)|0|${CssProp.CALC})`,
|
|
70
|
+
length_pos: `(${CssProp.N.number_pos}(px|em|rem|ex|in|cm|mm|pt|pc)|0|${CssProp.CALC})`,
|
|
43
71
|
percentage: `${CssProp.N.number}%`,
|
|
44
72
|
percentage_pos: `${CssProp.N.number_pos}%`,
|
|
45
73
|
percentage_zero_hundred: `${CssProp.N.number_zero_hundred}%`,
|
|
46
|
-
string: String.raw `(\"([^\n\r\f\\"]|\\\n|\r\n|\r|\f
|
|
74
|
+
string: String.raw `(\"([^\n\r\f\\"]|\\\n|\r\n|\r|\f|${CssProp.ESCAPE})*\")|(\'([^\n\r\f\\']|\\\n|\r\n|\r|\f|${CssProp.ESCAPE})*\')`,
|
|
47
75
|
time: `${CssProp.N.number}(s|ms)`,
|
|
48
|
-
url: `url\\(.*?\\)`,
|
|
49
76
|
z_index: `[+-]?[0-9]{1,7}`
|
|
50
|
-
};
|
|
77
|
+
});
|
|
51
78
|
/*
|
|
52
79
|
* Extended base expressions of common CSS syntax elements
|
|
53
80
|
*/
|
|
54
|
-
CssProp._B1 = {
|
|
55
|
-
flex: `(${CssProp.N.number}|${CssProp._B.len_or_perc}|none|auto)\\s
|
|
56
|
-
fixed_breadth: `${CssProp._B.len_or_perc}`,
|
|
81
|
+
CssProp._B1 = CssProp.group({
|
|
82
|
+
flex: `(${CssProp.N.number}|${CssProp._B.len_or_perc}|none|auto)(\\s+(${CssProp.N.number}|${CssProp._B.len_or_perc}|auto)){0,2}`,
|
|
57
83
|
grid_line: `auto|${CssProp._B.ident}|(${CssProp.N.integer_non_zero}(\\s+${CssProp._B.ident})?)|(span\\s+(${CssProp.N.integer_pos_non_zero}|${CssProp._B.ident}))`,
|
|
58
|
-
line_names: String.raw `\[\s*${CssProp._B.ident}(\s+${CssProp._B.ident})*\s*\]
|
|
59
|
-
}
|
|
60
|
-
|
|
84
|
+
line_names: String.raw `\[\s*${CssProp._B.ident}(\s+${CssProp._B.ident})*\s*\]`,
|
|
85
|
+
url: String.raw `url\(\s*((${CssProp._B.string}|([^"'()\\\s]|\\[^\r\n\f])+)\s*)?\)`
|
|
86
|
+
});
|
|
87
|
+
/*
|
|
88
|
+
* Grid expressions follow https://www.w3.org/TR/css-grid-2/#track-sizing
|
|
89
|
+
* loosely: lists take their items in any order, which keeps the expressions
|
|
90
|
+
* small, and browsers drop the values that are not valid.
|
|
91
|
+
*/
|
|
92
|
+
CssProp._B2 = CssProp.group({
|
|
61
93
|
inflexible_breadth: `${CssProp._B.len_or_perc}|auto|min-content|max-content`,
|
|
62
|
-
track_breadth: `${CssProp._B.len_or_perc}|${CssProp.
|
|
63
|
-
};
|
|
64
|
-
CssProp._B3 = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
CssProp.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
CssProp.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
grid_template_rows: `none|${CssProp._B5.track_list}|${CssProp._B5.auto_track_list}|subgrid\\s*(${CssProp._B1.line_names})?`,
|
|
80
|
-
grid_template_columns: `none|${CssProp._B5.track_list}|${CssProp._B5.auto_track_list}|subgrid\\s*(${CssProp._B1.line_names})?`
|
|
81
|
-
};
|
|
94
|
+
track_breadth: `${CssProp._B.len_or_perc}|${CssProp.N.number_pos}fr|auto|min-content|max-content`
|
|
95
|
+
});
|
|
96
|
+
CssProp._B3 = CssProp.group({
|
|
97
|
+
track_size: `${CssProp._B2.track_breadth}|minmax\\(\\s*${CssProp._B2.inflexible_breadth}\\s*,\\s*${CssProp._B2.track_breadth}\\s*\\)|fit-content\\(\\s*${CssProp._B.len_or_perc}\\s*\\)`
|
|
98
|
+
});
|
|
99
|
+
CssProp._B4 = CssProp.group({
|
|
100
|
+
name_repeat: `repeat\\(\\s*(${CssProp.N.integer_pos_non_zero}|auto-fill)\\s*,\\s*${CssProp.list(CssProp._B1.line_names)}\\)`,
|
|
101
|
+
track_repeat: `repeat\\(\\s*(${CssProp.N.integer_pos_non_zero}|auto-fill|auto-fit)\\s*,\\s*${CssProp.list(`${CssProp._B1.line_names}|${CssProp._B3.track_size}`)}\\)`
|
|
102
|
+
});
|
|
103
|
+
CssProp._B5 = CssProp.group({
|
|
104
|
+
subgrid: `subgrid(?![\\w.%+-])\\s*(${CssProp.list(`${CssProp._B1.line_names}|${CssProp._B4.name_repeat}`)})?`,
|
|
105
|
+
track_list: CssProp.list(`${CssProp._B1.line_names}|${CssProp._B3.track_size}|${CssProp._B4.track_repeat}`)
|
|
106
|
+
});
|
|
107
|
+
CssProp._B6 = CssProp.group({
|
|
108
|
+
grid_template_rows: `none|${CssProp._B5.track_list}|${CssProp._B5.subgrid}`,
|
|
109
|
+
grid_template_columns: `none|${CssProp._B5.track_list}|${CssProp._B5.subgrid}`
|
|
110
|
+
});
|
|
82
111
|
CssProp.B = {
|
|
83
112
|
...CssProp._B,
|
|
84
113
|
...CssProp._B1,
|
|
@@ -91,7 +120,7 @@ CssProp.B = {
|
|
|
91
120
|
/*
|
|
92
121
|
* Atomic (i.e. not dependent on other regular expressions) sub RegEx segments
|
|
93
122
|
*/
|
|
94
|
-
CssProp.A = {
|
|
123
|
+
CssProp.A = CssProp.group({
|
|
95
124
|
absolute_size: `xx-small|x-small|small|medium|large|x-large|xx-large`,
|
|
96
125
|
attachment: `scroll|fixed|local`,
|
|
97
126
|
bg_origin: `border-box|padding-box|content-box`,
|
|
@@ -100,67 +129,66 @@ CssProp.A = {
|
|
|
100
129
|
display_inside: `auto|block|table|flex|grid`,
|
|
101
130
|
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`,
|
|
102
131
|
ending_shape: `circle|ellipse`,
|
|
103
|
-
generic_family: `serif|sans-serif|cursive|fantasy|monospace`,
|
|
104
132
|
generic_voice: `male|female|child`,
|
|
105
133
|
relative_size: `smaller|larger`,
|
|
106
134
|
repeat_style: `repeat-x|repeat-y|((?:repeat|space|round|no-repeat)(?:\\s*(?:repeat|space|round|no-repeat))?)`,
|
|
107
|
-
side_or_corner: `(left|right)
|
|
135
|
+
side_or_corner: `(left|right)(\\s+(top|bottom))?|(top|bottom)(\\s+(left|right))?`,
|
|
108
136
|
single_animation_direction: `normal|reverse|alternate|alternate-reverse`,
|
|
109
137
|
single_animation_fill_mode: `none|forwards|backwards|both`,
|
|
110
138
|
single_animation_play_state: `running|paused`
|
|
111
|
-
};
|
|
139
|
+
});
|
|
112
140
|
/*
|
|
113
141
|
* Color definition sub expressions
|
|
114
142
|
*/
|
|
115
|
-
CssProp._COLOR = {
|
|
116
|
-
hex
|
|
117
|
-
|
|
143
|
+
CssProp._COLOR = CssProp.group({
|
|
144
|
+
// No word character follows, so that a run of hex digits matches in only one way.
|
|
145
|
+
hex: `\\#(0x)?[0-9a-f]+(?![\\w-])`,
|
|
146
|
+
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|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|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|rebeccapurple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|transparent|violet|wheat|white|whitesmoke|yellow|yellowgreen`,
|
|
118
147
|
rgb: String.raw `rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)`,
|
|
119
|
-
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}
|
|
120
|
-
};
|
|
148
|
+
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}|1[.]0+|0?[.][0-9]+|${CssProp.B.percentage_zero_hundred})\s*\)`
|
|
149
|
+
});
|
|
121
150
|
/*
|
|
122
151
|
* Compound (i.e. dependent on other (sub) regular expressions) sub RegEx segments
|
|
123
152
|
*/
|
|
124
|
-
CssProp._C = {
|
|
153
|
+
CssProp._C = CssProp.group({
|
|
125
154
|
alpha: `${CssProp.N.integer_zero_ff}|${CssProp.N.number_zero_one}|${CssProp.B.percentage_zero_hundred}`,
|
|
126
155
|
alphavalue: CssProp.N.number_zero_one,
|
|
127
|
-
bg_position: `(
|
|
128
|
-
bg_size: `(${CssProp.B.length_pos}|${CssProp.B.percentage}|auto){
|
|
156
|
+
bg_position: `(${CssProp.B.len_or_perc}|left|center|right|top|bottom)(\\s+(${CssProp.B.len_or_perc}|left|center|right|top|bottom)){0,3}`,
|
|
157
|
+
bg_size: `(${CssProp.B.length_pos}|${CssProp.B.percentage}|auto)(\\s+(${CssProp.B.length_pos}|${CssProp.B.percentage}|auto))?|cover|contain`,
|
|
129
158
|
border_width: `thin|medium|thick|${CssProp.B.length}`,
|
|
130
159
|
bottom: `${CssProp.B.length}|auto`,
|
|
131
160
|
color: `${CssProp._COLOR.hex}|${CssProp._COLOR.rgb}|${CssProp._COLOR.rgba}|${CssProp._COLOR.name}`,
|
|
132
|
-
color_stop_length: `(${CssProp.B.len_or_perc}\\s*){1,2}`,
|
|
133
161
|
linear_color_hint: `${CssProp.B.len_or_perc}`,
|
|
134
|
-
family_name: `${CssProp.B.string}
|
|
162
|
+
family_name: `${CssProp.B.string}|${CssProp.B.ident}(\\s+${CssProp.B.ident})*`,
|
|
135
163
|
image_decl: CssProp.B.url,
|
|
136
164
|
left: `${CssProp.B.length}|auto`,
|
|
137
165
|
loose_quotable_words: `(${CssProp.B.ident})+`,
|
|
138
166
|
margin_width: `${CssProp.B.len_or_perc}|auto`,
|
|
139
167
|
padding_width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}`,
|
|
140
168
|
page_url: CssProp.B.url,
|
|
141
|
-
position: `(
|
|
169
|
+
position: `(${CssProp.B.len_or_perc}|left|center|right|top|bottom)(\\s+(${CssProp.B.len_or_perc}|left|center|right|top|bottom)){0,3}`,
|
|
142
170
|
right: `${CssProp.B.length}|auto`,
|
|
143
171
|
shadow: '',
|
|
144
172
|
size: `closest-side|farthest-side|closest-corner|farthest-corner|${CssProp.B.length}|(${CssProp.B.len_or_perc})\\s+(${CssProp.B.len_or_perc})`,
|
|
145
173
|
top: `${CssProp.B.length}|auto`
|
|
146
|
-
};
|
|
147
|
-
CssProp._C1 = {
|
|
148
|
-
image_list: `image\\(\\s*(${CssProp.B.url}
|
|
149
|
-
linear_color_stop:
|
|
150
|
-
shadow:
|
|
151
|
-
};
|
|
152
|
-
CssProp._C2 = {
|
|
153
|
-
color_stop_list:
|
|
174
|
+
});
|
|
175
|
+
CssProp._C1 = CssProp.group({
|
|
176
|
+
image_list: `image\\(\\s*(${CssProp.B.url}\\s*)*(${CssProp.B.url}|${CssProp._C.color})\\s*\\)`,
|
|
177
|
+
linear_color_stop: `${CssProp._C.color}(\\s+${CssProp.B.len_or_perc}){0,2}`,
|
|
178
|
+
shadow: `${CssProp._C.color}\\s+${CssProp.B.length}(\\s+${CssProp.B.length}){1,3}(\\s+inset)?|(inset\\s+)?${CssProp.B.length}(\\s+${CssProp.B.length}){1,3}(\\s+${CssProp._C.color})?`
|
|
179
|
+
});
|
|
180
|
+
CssProp._C2 = CssProp.group({
|
|
181
|
+
color_stop_list: `${CssProp._C1.linear_color_stop}(\\s*,\\s*(${CssProp._C.linear_color_hint}\\s*,\\s*)?${CssProp._C1.linear_color_stop})+`,
|
|
154
182
|
shape: `rect\\(\\s*(${CssProp._C.top})\\s*,\\s*(${CssProp._C.right})\\s*,\\s*(${CssProp._C.bottom})\\s*,\\s*(${CssProp._C.left})\\s*\\)`
|
|
155
|
-
};
|
|
156
|
-
CssProp._C3 = {
|
|
157
|
-
linear_gradient: `linear-gradient\\((((${CssProp.B.angle})|to\\s+(${CssProp.A.side_or_corner}))\\s*,\\s*)
|
|
158
|
-
radial_gradient: `radial-gradient\\((((
|
|
159
|
-
};
|
|
160
|
-
CssProp._C4 = {
|
|
183
|
+
});
|
|
184
|
+
CssProp._C3 = CssProp.group({
|
|
185
|
+
linear_gradient: `linear-gradient\\(\\s*(((${CssProp.B.angle})|to\\s+(${CssProp.A.side_or_corner}))\\s*,\\s*)?(${CssProp._C2.color_stop_list})\\s*\\)`,
|
|
186
|
+
radial_gradient: `radial-gradient\\(\\s*(((${CssProp.A.ending_shape}(\\s+${CssProp._C.size})?|${CssProp._C.size}(\\s+${CssProp.A.ending_shape})?)(\\s+at\\s+${CssProp._C.position})?|at\\s+${CssProp._C.position})\\s*,\\s*)?(${CssProp._C2.color_stop_list})\\s*\\)`
|
|
187
|
+
});
|
|
188
|
+
CssProp._C4 = CssProp.group({
|
|
161
189
|
image: `${CssProp.B.url}|${CssProp._C3.linear_gradient}|${CssProp._C3.radial_gradient}|${CssProp._C1.image_list}`,
|
|
162
190
|
bg_image: `(${CssProp.B.url}|${CssProp._C3.linear_gradient}|${CssProp._C3.radial_gradient}|${CssProp._C1.image_list})|none`
|
|
163
|
-
};
|
|
191
|
+
});
|
|
164
192
|
CssProp.C = {
|
|
165
193
|
...CssProp._C,
|
|
166
194
|
...CssProp._C1,
|
|
@@ -171,7 +199,7 @@ CssProp.C = {
|
|
|
171
199
|
/*
|
|
172
200
|
* Property value regular expressions not dependent on other sub expressions
|
|
173
201
|
*/
|
|
174
|
-
CssProp.AP = {
|
|
202
|
+
CssProp.AP = CssProp.group({
|
|
175
203
|
baseline_position: `baseline|first baseline|last baseline`,
|
|
176
204
|
border_collapse: `collapse|separate`,
|
|
177
205
|
box: `normal|none|contents`,
|
|
@@ -191,21 +219,15 @@ CssProp.AP = {
|
|
|
191
219
|
font_weight: `normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900`,
|
|
192
220
|
list_style_position: `inside|outside`,
|
|
193
221
|
gap: `normal`,
|
|
194
|
-
grid_auto_flow: `row|column
|
|
195
|
-
justify_content: `start|end|center|stretch|space-between|space-around|space-evenly`,
|
|
196
|
-
justify_items: `start|end|center|stretch`,
|
|
197
|
-
justify_self: `auto|start|end|center|stretch`,
|
|
222
|
+
grid_auto_flow: `(row|column)(\\s+dense)?|dense(\\s+(row|column))?`,
|
|
198
223
|
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`,
|
|
199
|
-
overflow: `visible|hidden|scroll|auto
|
|
224
|
+
overflow: `(visible|hidden|scroll|auto)(\\s+(visible|hidden|scroll|auto))?`,
|
|
200
225
|
overflow_position: `unsafe|safe`,
|
|
201
226
|
overflow_wrap: `normal|break-word`,
|
|
202
227
|
overflow_x: `visible|hidden|scroll|auto|no-display|no-content`,
|
|
203
228
|
page_break_after: `auto|always|avoid|left|right`,
|
|
204
229
|
page_break_before: `auto|always|avoid|left|right`,
|
|
205
230
|
page_break_inside: `avoid|auto`,
|
|
206
|
-
place_content: `(center|start|end|space-between|space-around|space-evenly|stretch){1,2}`,
|
|
207
|
-
place_items: `(center|start|end|baseline|stretch){1,2}`,
|
|
208
|
-
place_self: `(center|start|end|baseline|stretch){1,2}`,
|
|
209
231
|
position: `static|relative|absolute`,
|
|
210
232
|
resize: `none|both|horizontal|vertical`,
|
|
211
233
|
speak: `normal|none|spell-out`,
|
|
@@ -222,12 +244,12 @@ CssProp.AP = {
|
|
|
222
244
|
visibility: `visible|hidden|collapse`,
|
|
223
245
|
white_space: `normal|pre|nowrap|pre-wrap|pre-line`,
|
|
224
246
|
word_break: `normal|keep-all|break-all`
|
|
225
|
-
};
|
|
247
|
+
});
|
|
226
248
|
/*
|
|
227
249
|
* Compound propertiy value regular expressions (i.e. dependent on other sub expressions)
|
|
228
250
|
*/
|
|
229
|
-
CssProp._CP = {
|
|
230
|
-
align_content: `normal|${CssProp.AP.baseline_position}|${CssProp.AP.content_distribution}
|
|
251
|
+
CssProp._CP = CssProp.group({
|
|
252
|
+
align_content: `normal|${CssProp.AP.baseline_position}|${CssProp.AP.content_distribution}|(${CssProp.AP.overflow_position}\\s+)?${CssProp.AP.content_position}`,
|
|
231
253
|
align_items: `normal|stretch|${CssProp.AP.baseline_position}|(${CssProp.AP.overflow_position})?\\s*${CssProp.AP.self_position}|anchor-center`,
|
|
232
254
|
align_self: `auto|normal|stretch|${CssProp.AP.baseline_position}|(${CssProp.AP.overflow_position})?\\s*${CssProp.AP.self_position}|anchor-center`,
|
|
233
255
|
background_attachment: `${CssProp.A.attachment}(,\\s*${CssProp.A.attachment})*`,
|
|
@@ -241,11 +263,11 @@ CssProp._CP = {
|
|
|
241
263
|
border_top_style: CssProp.A.border_style,
|
|
242
264
|
border_width: `((${CssProp.C.border_width})\\s*){1,4}`,
|
|
243
265
|
color: CssProp.C.color,
|
|
244
|
-
cursor: `(${CssProp.B.url}
|
|
245
|
-
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`,
|
|
266
|
+
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)`,
|
|
267
|
+
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|flow-root|${CssProp.A.display_inside}|${CssProp.A.display_outside}|inherit|inline-box|inline-stack|(block|inline|run-in)\\s+(flow|flow-root|table|flex|grid|ruby)|(flow|flow-root|table|flex|grid|ruby)\\s+(block|inline|run-in)`,
|
|
246
268
|
display_outside: CssProp.A.display_outside,
|
|
247
269
|
elevation: `${CssProp.B.angle}|below|level|above|higher|lower`,
|
|
248
|
-
font_family:
|
|
270
|
+
font_family: `${CssProp.C.family_name}(\\s*,\\s*${CssProp.C.family_name})*`,
|
|
249
271
|
height: `${CssProp.B.length}|${CssProp.B.percentage}|auto`,
|
|
250
272
|
letter_spacing: `normal|${CssProp.B.length}`,
|
|
251
273
|
list_style_image: `${CssProp.C.image}|none`,
|
|
@@ -261,7 +283,7 @@ CssProp._CP = {
|
|
|
261
283
|
right: `${CssProp.B.length}|${CssProp.B.percentage}|auto`,
|
|
262
284
|
stress: CssProp.N.number,
|
|
263
285
|
text_indent: `${CssProp.B.length}|${CssProp.B.percentage}`,
|
|
264
|
-
text_shadow: `none|${CssProp.C.shadow}(
|
|
286
|
+
text_shadow: `none|${CssProp.C.shadow}(\\s*,\\s*${CssProp.C.shadow})*`,
|
|
265
287
|
volume: `${CssProp.N.number_pos}|${CssProp.B.percentage_pos}|silent|x-soft|soft|medium|loud|x-loud`,
|
|
266
288
|
word_wrap: CssProp.AP.overflow_wrap,
|
|
267
289
|
zoom: `normal|${CssProp.N.number_pos}|${CssProp.B.percentage_pos}`,
|
|
@@ -276,7 +298,7 @@ CssProp._CP = {
|
|
|
276
298
|
border_style: `((${CssProp.A.border_style})\\s*){1,4}`,
|
|
277
299
|
border_top_left_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
|
|
278
300
|
border_top_width: CssProp.C.border_width,
|
|
279
|
-
box_shadow: `none|${CssProp.C.shadow}(
|
|
301
|
+
box_shadow: `none|${CssProp.C.shadow}(\\s*,\\s*${CssProp.C.shadow})*`,
|
|
280
302
|
clip: `${CssProp.C.shape}|auto`,
|
|
281
303
|
display_inside: CssProp.A.display_inside,
|
|
282
304
|
font_size: `${CssProp.A.absolute_size}|${CssProp.A.relative_size}|${CssProp.B.length_pos}|${CssProp.B.percentage_pos}`,
|
|
@@ -293,7 +315,7 @@ CssProp._CP = {
|
|
|
293
315
|
width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|auto`,
|
|
294
316
|
z_index: `auto|${CssProp.B.z_index}`,
|
|
295
317
|
// Simplified background
|
|
296
|
-
background:
|
|
318
|
+
background: CssProp.list(`${CssProp.B.len_or_perc}|auto|cover|contain|left|center|right|top|bottom|repeat-x|repeat-y|repeat|space|round|no-repeat|${CssProp.A.attachment}|${CssProp.A.bg_origin}|${CssProp.C.bg_image}|${CssProp.C.color}`, '(\\/\\s*)?'),
|
|
297
319
|
background_size: `${CssProp.C.bg_size}(,\\s*${CssProp.C.bg_size})*`,
|
|
298
320
|
border_bottom_left_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
|
|
299
321
|
border_bottom_width: CssProp.C.border_width,
|
|
@@ -301,7 +323,7 @@ CssProp._CP = {
|
|
|
301
323
|
border_right_style: CssProp.A.border_style,
|
|
302
324
|
border_top: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
|
|
303
325
|
bottom: `${CssProp.B.len_or_perc}|auto`,
|
|
304
|
-
list_style:
|
|
326
|
+
list_style: CssProp.list(`${CssProp.AP.list_style_type}|${CssProp.AP.list_style_position}|${CssProp.C.image}`),
|
|
305
327
|
margin_top: CssProp.C.margin_width,
|
|
306
328
|
outline: `((${CssProp.C.color}|invert|${CssProp.A.border_style}|${CssProp.C.border_width})\\s*){1,3}`,
|
|
307
329
|
overflow_y: CssProp.AP.overflow_x,
|
|
@@ -322,17 +344,17 @@ CssProp._CP = {
|
|
|
322
344
|
margin: `((${CssProp.C.margin_width})\\s*){1,4}`,
|
|
323
345
|
padding_left: CssProp.C.padding_width,
|
|
324
346
|
border_left: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
|
|
325
|
-
quotes: `(
|
|
347
|
+
quotes: `none|${CssProp.B.string}\\s*${CssProp.B.string}(\\s*${CssProp.B.string}\\s*${CssProp.B.string})*`,
|
|
326
348
|
border_top_right_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
|
|
327
349
|
min_width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|auto`,
|
|
328
350
|
// Add flexbox and grid properties
|
|
329
|
-
flex_basis: `${CssProp.B.len_or_perc}|auto|content|max-content|min-content|fit-content\\(\\s
|
|
351
|
+
flex_basis: `${CssProp.B.len_or_perc}|auto|content|max-content|min-content|fit-content\\(\\s*${CssProp.B.len_or_perc}\\s*\\)`, // simplified no <calc-size()> and <anchor-size()>
|
|
330
352
|
flex_grow: CssProp.N.number_pos,
|
|
331
353
|
flex_shrink: CssProp.N.number_pos,
|
|
332
354
|
grid: `(${CssProp.B.string}|none|subgrid)\\s*(\\/\\s*(${CssProp.B.string}|none|subgrid))?`,
|
|
333
|
-
grid_area: `${CssProp.B.
|
|
334
|
-
grid_auto_columns:
|
|
335
|
-
grid_auto_rows:
|
|
355
|
+
grid_area: `${CssProp.B.grid_line}(\\s*\\/\\s*${CssProp.B.grid_line}){0,3}`,
|
|
356
|
+
grid_auto_columns: CssProp.list(CssProp.B.track_size),
|
|
357
|
+
grid_auto_rows: CssProp.list(CssProp.B.track_size),
|
|
336
358
|
grid_column: `${CssProp.B.grid_line}(\\s*\\/\\s*${CssProp.B.grid_line})?`,
|
|
337
359
|
grid_column_start: `${CssProp.B.grid_line}`,
|
|
338
360
|
grid_column_end: `${CssProp.B.grid_line}`,
|
|
@@ -342,18 +364,24 @@ CssProp._CP = {
|
|
|
342
364
|
grid_row_start: `${CssProp.B.grid_line}`,
|
|
343
365
|
grid_row_end: `${CssProp.B.grid_line}`,
|
|
344
366
|
grid_row_gap: `${CssProp.B.len_or_perc}|normal`,
|
|
345
|
-
grid_template: `none|(${CssProp.B.
|
|
346
|
-
grid_template_areas: `none
|
|
367
|
+
grid_template: `none|(${CssProp.list(`${CssProp.B.line_names}|${CssProp.B.string}|${CssProp.B.track_size}|${CssProp.B.track_repeat}`)}|${CssProp.B.subgrid})(\\/\\s*(${CssProp.B.track_list}|${CssProp.B.subgrid}))?`,
|
|
368
|
+
grid_template_areas: `none|${CssProp.B.string}(\\s*${CssProp.B.string})*`,
|
|
347
369
|
grid_template_columns: `${CssProp.B.grid_template_columns}`,
|
|
348
370
|
grid_template_rows: `${CssProp.B.grid_template_rows}`,
|
|
349
371
|
row_gap: `${CssProp.B.len_or_perc}|normal`,
|
|
350
372
|
column_gap: `${CssProp.B.len_or_perc}|normal`,
|
|
351
373
|
gap: `(${CssProp.B.len_or_perc}|normal)(\\s*(${CssProp.B.len_or_perc}|normal))?`,
|
|
374
|
+
justify_content: `normal|${CssProp.AP.content_distribution}|(${CssProp.AP.overflow_position}\\s+)?(${CssProp.AP.content_position}|left|right)`,
|
|
375
|
+
justify_items: `normal|stretch|${CssProp.AP.baseline_position}|(${CssProp.AP.overflow_position}\\s+)?(${CssProp.AP.self_position}|left|right)|legacy(\\s+(left|right|center))?|(left|right|center)\\s+legacy|anchor-center`,
|
|
376
|
+
justify_self: `auto|normal|stretch|${CssProp.AP.baseline_position}|(${CssProp.AP.overflow_position}\\s+)?(${CssProp.AP.self_position}|left|right)|anchor-center`,
|
|
352
377
|
order: CssProp.N.integer
|
|
353
|
-
};
|
|
354
|
-
CssProp._CP1 = {
|
|
355
|
-
font: `(((((${CssProp.AP.font_style}|${CssProp.AP.font_variant}|${CssProp.AP.font_weight})\\s
|
|
356
|
-
}
|
|
378
|
+
});
|
|
379
|
+
CssProp._CP1 = CssProp.group({
|
|
380
|
+
font: `(((((${CssProp.AP.font_style}|${CssProp.AP.font_variant}|${CssProp.AP.font_weight})\\s+){1,3})?(${CssProp._CP.font_size})(\\s*\\/\\s*(${CssProp._CP.line_height}))?\\s+(${CssProp._CP.font_family}))|caption|icon|menu|message-box|small-caption|status-bar)`,
|
|
381
|
+
place_content: `${CssProp._CP.align_content}(\\s+${CssProp._CP.justify_content})?`,
|
|
382
|
+
place_items: `${CssProp._CP.align_items}(\\s+${CssProp._CP.justify_items})?`,
|
|
383
|
+
place_self: `${CssProp._CP.align_self}(\\s+${CssProp._CP.justify_self})?`
|
|
384
|
+
});
|
|
357
385
|
CssProp.CP = { ...CssProp._CP, ...CssProp._CP1 };
|
|
358
386
|
// CSS Property value validation regular expressions for use with sanitize-html
|
|
359
387
|
CssProp.BORDER_COLLAPSE = CssProp.reg(CssProp.AP.border_collapse);
|
|
@@ -496,9 +524,9 @@ CssProp.FLEX_DIRECTION = CssProp.reg(CssProp.AP.flex_direction);
|
|
|
496
524
|
CssProp.FLEX_GROW = CssProp.reg(CssProp.CP.flex_grow);
|
|
497
525
|
CssProp.FLEX_SHRINK = CssProp.reg(CssProp.CP.flex_shrink);
|
|
498
526
|
CssProp.FLEX_WRAP = CssProp.reg(CssProp.AP.flex_wrap);
|
|
499
|
-
CssProp.JUSTIFY_CONTENT = CssProp.reg(CssProp.
|
|
500
|
-
CssProp.JUSTIFY_ITEMS = CssProp.reg(CssProp.
|
|
501
|
-
CssProp.JUSTIFY_SELF = CssProp.reg(CssProp.
|
|
527
|
+
CssProp.JUSTIFY_CONTENT = CssProp.reg(CssProp.CP.justify_content);
|
|
528
|
+
CssProp.JUSTIFY_ITEMS = CssProp.reg(CssProp.CP.justify_items);
|
|
529
|
+
CssProp.JUSTIFY_SELF = CssProp.reg(CssProp.CP.justify_self);
|
|
502
530
|
CssProp.ORDER = CssProp.reg(CssProp.CP.order);
|
|
503
531
|
// Grid properties
|
|
504
532
|
CssProp.GRID = CssProp.reg(CssProp.CP.grid);
|
|
@@ -522,9 +550,45 @@ CssProp.GRID_TEMPLATE_ROWS = CssProp.reg(CssProp.CP.grid_template_rows);
|
|
|
522
550
|
CssProp.GAP = CssProp.reg(CssProp.CP.gap);
|
|
523
551
|
CssProp.ROW_GAP = CssProp.reg(CssProp.CP.row_gap);
|
|
524
552
|
CssProp.COLUMN_GAP = CssProp.reg(CssProp.CP.column_gap);
|
|
525
|
-
CssProp.PLACE_CONTENT = CssProp.reg(CssProp.
|
|
526
|
-
CssProp.PLACE_ITEMS = CssProp.reg(CssProp.
|
|
527
|
-
CssProp.PLACE_SELF = CssProp.reg(CssProp.
|
|
553
|
+
CssProp.PLACE_CONTENT = CssProp.reg(CssProp.CP.place_content);
|
|
554
|
+
CssProp.PLACE_ITEMS = CssProp.reg(CssProp.CP.place_items);
|
|
555
|
+
CssProp.PLACE_SELF = CssProp.reg(CssProp.CP.place_self);
|
|
556
|
+
/**
|
|
557
|
+
* Matches class names outside the prefixes of JupyterLab, Lumino, CodeMirror,
|
|
558
|
+
* react-toastify and xterm.js, whose styles include ones that `allowedStyles`
|
|
559
|
+
* rejects, such as `position: fixed`. Case is ignored for quirks mode pages.
|
|
560
|
+
*/
|
|
561
|
+
const UNRESERVED_CLASS_NAME = /^(?!jp-|lm-|cm-|toastify|xterm)/i;
|
|
562
|
+
/**
|
|
563
|
+
* Reserved class names that sanitized HTML may keep: JupyterLab adds them to
|
|
564
|
+
* Markdown before it is sanitized, users add them to hide a heading from the
|
|
565
|
+
* table of contents, or notebooks copy them with output HTML of JupyterLab.
|
|
566
|
+
* Their styles do not move content out of its cell.
|
|
567
|
+
*/
|
|
568
|
+
const ALLOWED_RESERVED_CLASS_NAMES = [
|
|
569
|
+
'jp-mod-mermaidTheme-dark',
|
|
570
|
+
'jp-mod-mermaidTheme-default',
|
|
571
|
+
'jp-mod-warning',
|
|
572
|
+
'jp-OutputArea-output',
|
|
573
|
+
'jp-RenderedHTMLCommon',
|
|
574
|
+
'jp-RenderedMermaid',
|
|
575
|
+
'jp-RenderedMermaid-Details',
|
|
576
|
+
'jp-RenderedMermaid-Summary',
|
|
577
|
+
'jp-RenderedText',
|
|
578
|
+
'jp-sr-only',
|
|
579
|
+
'jp-toc-ignore'
|
|
580
|
+
];
|
|
581
|
+
/**
|
|
582
|
+
* Reserved class names that extensions write into Markdown before it is
|
|
583
|
+
* sanitized: `@jupyter/chat` for mentions, and Jupyter AI personas for errors.
|
|
584
|
+
* They are kept with a warning, because this exception is deprecated. Their
|
|
585
|
+
* styles do not move content out of its cell.
|
|
586
|
+
*/
|
|
587
|
+
const DEPRECATED_RESERVED_CLASS_NAMES = [
|
|
588
|
+
'jp-chat-mention',
|
|
589
|
+
'jp-jai-error-details',
|
|
590
|
+
'jp-jai-error-traceback'
|
|
591
|
+
];
|
|
528
592
|
/**
|
|
529
593
|
* A class to sanitize HTML strings.
|
|
530
594
|
*/
|
|
@@ -533,6 +597,7 @@ export class Sanitizer {
|
|
|
533
597
|
this._autolink = true;
|
|
534
598
|
this._allowNamedProperties = false;
|
|
535
599
|
this._allowCommandLinker = true;
|
|
600
|
+
this._warnedClassNames = new Set();
|
|
536
601
|
this._generateOptions = () => {
|
|
537
602
|
const schemesToAllow = Array.isArray(this._customAllowedSchemes)
|
|
538
603
|
? this._customAllowedSchemes
|
|
@@ -895,6 +960,14 @@ export class Sanitizer {
|
|
|
895
960
|
'width'
|
|
896
961
|
]
|
|
897
962
|
},
|
|
963
|
+
// Class names that HTML tags may have.
|
|
964
|
+
allowedClasses: {
|
|
965
|
+
'*': [
|
|
966
|
+
...ALLOWED_RESERVED_CLASS_NAMES,
|
|
967
|
+
...DEPRECATED_RESERVED_CLASS_NAMES,
|
|
968
|
+
UNRESERVED_CLASS_NAME
|
|
969
|
+
]
|
|
970
|
+
},
|
|
898
971
|
// Inline CSS styles that HTML tags may have (and their allowed values)
|
|
899
972
|
allowedStyles: {
|
|
900
973
|
// To simplify the data, all styles are allowed on all tags that allow the style attribute
|
|
@@ -1073,23 +1146,22 @@ export class Sanitizer {
|
|
|
1073
1146
|
a: sanitize.simpleTransform('a', { rel: 'nofollow' }),
|
|
1074
1147
|
// Set the "disabled" attribute for <input> tags.
|
|
1075
1148
|
input: sanitize.simpleTransform('input', { disabled: 'disabled' }),
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
}
|
|
1090
|
-
};
|
|
1149
|
+
'*': (tagName, attribs) => {
|
|
1150
|
+
// Replace "id" attribute by "data-jupyter-id" if "id" is not allowed.
|
|
1151
|
+
if (!this._allowNamedProperties && attribs.id !== undefined) {
|
|
1152
|
+
attribs['data-jupyter-id'] = attribs.id;
|
|
1153
|
+
delete attribs.id;
|
|
1154
|
+
}
|
|
1155
|
+
if (attribs.class !== undefined) {
|
|
1156
|
+
this._warnDeprecatedClassNames(attribs.class);
|
|
1157
|
+
}
|
|
1158
|
+
return {
|
|
1159
|
+
tagName,
|
|
1160
|
+
attribs: {
|
|
1161
|
+
...attribs
|
|
1091
1162
|
}
|
|
1092
|
-
}
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1093
1165
|
},
|
|
1094
1166
|
allowedSchemes: schemesToAllow,
|
|
1095
1167
|
allowedSchemesByTag: {
|
|
@@ -1171,5 +1243,17 @@ export class Sanitizer {
|
|
|
1171
1243
|
this._allowCommandLinker = allowCommandLinker;
|
|
1172
1244
|
this._options = this._generateOptions();
|
|
1173
1245
|
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Warn once for each deprecated reserved class name in a class attribute.
|
|
1248
|
+
*/
|
|
1249
|
+
_warnDeprecatedClassNames(value) {
|
|
1250
|
+
for (const name of value.split(/\s+/)) {
|
|
1251
|
+
if (DEPRECATED_RESERVED_CLASS_NAMES.includes(name) &&
|
|
1252
|
+
!this._warnedClassNames.has(name)) {
|
|
1253
|
+
this._warnedClassNames.add(name);
|
|
1254
|
+
console.warn(`The HTML sanitizer kept the class name "${name}" because it is on an allowlist for extensions, which is deprecated. Use a class name that does not start with "jp-" instead.`);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1174
1258
|
}
|
|
1175
1259
|
//# sourceMappingURL=sanitizer.js.map
|