@jupyterlab/apputils 4.8.0-beta.3 → 4.8.0-rc.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/src/sanitizer.ts CHANGED
@@ -16,79 +16,116 @@ import type { IRenderMime } from '@jupyterlab/rendermime-interfaces';
16
16
  */
17
17
  class CssProp {
18
18
  static reg(r: string): RegExp {
19
- return new RegExp('^' + r + '$', 'i');
19
+ return new RegExp('^(?:' + r + ')$', 'i');
20
+ }
21
+
22
+ /**
23
+ * Wraps each expression in a group, so that its alternatives stay together
24
+ * when it is embedded in another expression.
25
+ */
26
+ private static group<K extends string>(
27
+ exprs: Record<K, string>
28
+ ): Record<K, string> {
29
+ for (const key in exprs) {
30
+ exprs[key] = `(?:${exprs[key]})`;
31
+ }
32
+ return exprs;
33
+ }
34
+
35
+ /**
36
+ * Matches one or more items, each followed by optional whitespace and `sep`.
37
+ * An item cannot be followed by a character that would continue it, so a
38
+ * value splits into items in only one way and is checked in linear time.
39
+ */
40
+ private static list(item: string, sep = ''): string {
41
+ return `(?:(?:${item})(?![\\w.%+-])\\s*${sep})+`;
20
42
  }
21
43
 
22
44
  /*
23
45
  * Numeric base expressions used to help build more complex regular expressions
24
46
  */
25
- private static readonly N = {
47
+ private static readonly N = CssProp.group({
26
48
  integer: `[+-]?[0-9]+`,
27
49
  integer_pos: `[+]?[0-9]+`,
28
50
  integer_zero_ff: `([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])`,
29
51
  integer_non_zero: `[+-]?([1-9][0-9]*)`,
30
52
  integer_pos_non_zero: `[+]?([1-9][0-9]*)`,
31
- number: `[+-]?([0-9]*[.])?[0-9]+(e-?[0-9]*)?`,
32
- number_pos: `[+]?([0-9]*[.])?[0-9]+(e-?[0-9]*)?`,
53
+ number: `[+-]?([0-9]*[.])?[0-9]+(e[+-]?[0-9]+)?`,
54
+ number_pos: `[+]?([0-9]*[.])?[0-9]+(e[+-]?[0-9]+)?`,
33
55
  number_zero_hundred: `[+]?(([0-9]|[1-9][0-9])([.][0-9]+)?|100)`,
34
56
  number_zero_one: `[+]?(1([.][0]+)?|0?([.][0-9]+)?)`
35
- };
57
+ });
58
+
59
+ /*
60
+ * calc() of numbers, lengths and percentages, without nesting or var()
61
+ */
62
+ private static readonly 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*\\))`;
63
+
64
+ /*
65
+ * Escape in an identifier or a string; it takes all hex digits and the
66
+ * whitespace after them, so that each value has only one match.
67
+ */
68
+ private static readonly 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]))`;
36
69
 
37
70
  /*
38
71
  * Base expressions of common CSS syntax elements
39
72
  */
40
- private static readonly _B = {
73
+ private static readonly _B = CssProp.group({
41
74
  angle: `(${CssProp.N.number}(deg|rad|grad|turn)|0)`,
42
75
  frequency: `${CssProp.N.number}(Hz|kHz)`,
43
- 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])*`,
44
- len_or_perc: `(0|${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc|%))`,
45
- length: `(${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc)|0)`,
46
- length_pos: `(${CssProp.N.number_pos}(px|em|rem|ex|in|cm|mm|pt|pc)|0)`,
76
+ // Not U+00A0: `\s` matches it, and the overlap makes the checks exponential.
77
+ ident: String.raw`-?([_a-z]|[\xA1-\xFF]|${CssProp.ESCAPE})([_a-z0-9-]|[\xA1-\xFF]|${CssProp.ESCAPE})*`,
78
+ len_or_perc: `(0|${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc|%)|${CssProp.CALC})`,
79
+ length: `(${CssProp.N.number}(px|em|rem|ex|in|cm|mm|pt|pc)|0|${CssProp.CALC})`,
80
+ length_pos: `(${CssProp.N.number_pos}(px|em|rem|ex|in|cm|mm|pt|pc)|0|${CssProp.CALC})`,
47
81
  percentage: `${CssProp.N.number}%`,
48
82
  percentage_pos: `${CssProp.N.number_pos}%`,
49
83
  percentage_zero_hundred: `${CssProp.N.number_zero_hundred}%`,
50
- 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])*\')`,
84
+ string: String.raw`(\"([^\n\r\f\\"]|\\\n|\r\n|\r|\f|${CssProp.ESCAPE})*\")|(\'([^\n\r\f\\']|\\\n|\r\n|\r|\f|${CssProp.ESCAPE})*\')`,
51
85
  time: `${CssProp.N.number}(s|ms)`,
52
- url: `url\\(.*?\\)`,
53
86
  z_index: `[+-]?[0-9]{1,7}`
54
- };
87
+ });
55
88
 
56
89
  /*
57
90
  * Extended base expressions of common CSS syntax elements
58
91
  */
59
- private static readonly _B1 = {
60
- flex: `(${CssProp.N.number}|${CssProp._B.len_or_perc}|none|auto)\\s*((${CssProp.N.number}|${CssProp._B.len_or_perc}|auto)\\s*){0,2}`,
61
- fixed_breadth: `${CssProp._B.len_or_perc}`,
92
+ private static readonly _B1 = CssProp.group({
93
+ flex: `(${CssProp.N.number}|${CssProp._B.len_or_perc}|none|auto)(\\s+(${CssProp.N.number}|${CssProp._B.len_or_perc}|auto)){0,2}`,
62
94
  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}))`,
63
- line_names: String.raw`\[\s*${CssProp._B.ident}(\s+${CssProp._B.ident})*\s*\]`
64
- };
95
+ line_names: String.raw`\[\s*${CssProp._B.ident}(\s+${CssProp._B.ident})*\s*\]`,
96
+ url: String.raw`url\(\s*((${CssProp._B.string}|([^"'()\\\s]|\\[^\r\n\f])+)\s*)?\)`
97
+ });
65
98
 
66
- private static readonly _B2 = {
99
+ /*
100
+ * Grid expressions follow https://www.w3.org/TR/css-grid-2/#track-sizing
101
+ * loosely: lists take their items in any order, which keeps the expressions
102
+ * small, and browsers drop the values that are not valid.
103
+ */
104
+ private static readonly _B2 = CssProp.group({
67
105
  inflexible_breadth: `${CssProp._B.len_or_perc}|auto|min-content|max-content`,
68
- track_breadth: `${CssProp._B.len_or_perc}|${CssProp._B1.flex}|auto|min-content|max-content`
69
- };
106
+ track_breadth: `${CssProp._B.len_or_perc}|${CssProp.N.number_pos}fr|auto|min-content|max-content`
107
+ });
70
108
 
71
- private static readonly _B3 = {
72
- fixed_size: `${CssProp._B1.fixed_breadth}|minmax\\(\\s*${CssProp._B2.inflexible_breadth}\\s*,\\s*${CssProp._B1.fixed_breadth}\\s*\\)|minmax\\(\\s*${CssProp._B1.fixed_breadth}\\s*,\\s*${CssProp._B2.track_breadth}\\s*\\)`,
73
- 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*)*\\)`
74
- };
109
+ private static readonly _B3 = CssProp.group({
110
+ 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*\\)`
111
+ });
75
112
 
76
- private static readonly _B4 = {
77
- name_repeat: `repeat\\(\\s*(${CssProp.N.integer_pos_non_zero}|auto-fill)\\s*,\\s*(${CssProp._B1.line_names})+\\s*\\)`,
78
- auto_repeat: `repeat\\(\\s*(auto-fill|auto-fit)\\s*,\\s*((${CssProp._B1.line_names}\\s+)?${CssProp._B3.fixed_size}\\s*)+(${CssProp._B1.line_names})?\\s*\\)`,
79
- fixed_repeat: `repeat\\(\\s*(${CssProp.N.integer_pos_non_zero})\\s*,\\s*((${CssProp._B1.line_names}\\s+)?${CssProp._B3.fixed_size}\\s*)+(${CssProp._B1.line_names})?\\s*\\)`
80
- };
113
+ private static readonly _B4 = CssProp.group({
114
+ name_repeat: `repeat\\(\\s*(${CssProp.N.integer_pos_non_zero}|auto-fill)\\s*,\\s*${CssProp.list(CssProp._B1.line_names)}\\)`,
115
+ 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}`)}\\)`
116
+ });
81
117
 
82
- private static readonly _B5 = {
83
- auto_track_list: `(${CssProp._B1.line_names}\\s*)?(${CssProp._B3.fixed_size}|${CssProp._B4.fixed_repeat})*(${CssProp._B1.line_names}\\s*)?${CssProp._B4.auto_repeat}(${CssProp._B1.line_names}\\s*)?(${CssProp._B3.fixed_size}|${CssProp._B4.fixed_repeat})*(${CssProp._B1.line_names}\\s*)?`,
84
- explicit_track_list: `(${CssProp._B1.line_names}\\s*)?(${CssProp._B3.track_size})+(${CssProp._B1.line_names}\\s*)?`,
85
- track_list: `(${CssProp._B1.line_names}\\s*)?(${CssProp._B3.track_size}|${CssProp._B4.name_repeat})+(${CssProp._B1.line_names}\\s*)?`
86
- };
118
+ private static readonly _B5 = CssProp.group({
119
+ subgrid: `subgrid(?![\\w.%+-])\\s*(${CssProp.list(`${CssProp._B1.line_names}|${CssProp._B4.name_repeat}`)})?`,
120
+ track_list: CssProp.list(
121
+ `${CssProp._B1.line_names}|${CssProp._B3.track_size}|${CssProp._B4.track_repeat}`
122
+ )
123
+ });
87
124
 
88
- private static readonly _B6 = {
89
- grid_template_rows: `none|${CssProp._B5.track_list}|${CssProp._B5.auto_track_list}|subgrid\\s*(${CssProp._B1.line_names})?`,
90
- grid_template_columns: `none|${CssProp._B5.track_list}|${CssProp._B5.auto_track_list}|subgrid\\s*(${CssProp._B1.line_names})?`
91
- };
125
+ private static readonly _B6 = CssProp.group({
126
+ grid_template_rows: `none|${CssProp._B5.track_list}|${CssProp._B5.subgrid}`,
127
+ grid_template_columns: `none|${CssProp._B5.track_list}|${CssProp._B5.subgrid}`
128
+ });
92
129
 
93
130
  private static readonly B = {
94
131
  ...CssProp._B,
@@ -103,7 +140,7 @@ class CssProp {
103
140
  /*
104
141
  * Atomic (i.e. not dependent on other regular expressions) sub RegEx segments
105
142
  */
106
- private static readonly A = {
143
+ private static readonly A = CssProp.group({
107
144
  absolute_size: `xx-small|x-small|small|medium|large|x-large|xx-large`,
108
145
  attachment: `scroll|fixed|local`,
109
146
  bg_origin: `border-box|padding-box|content-box`,
@@ -112,73 +149,72 @@ class CssProp {
112
149
  display_inside: `auto|block|table|flex|grid`,
113
150
  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`,
114
151
  ending_shape: `circle|ellipse`,
115
- generic_family: `serif|sans-serif|cursive|fantasy|monospace`,
116
152
  generic_voice: `male|female|child`,
117
153
  relative_size: `smaller|larger`,
118
154
  repeat_style: `repeat-x|repeat-y|((?:repeat|space|round|no-repeat)(?:\\s*(?:repeat|space|round|no-repeat))?)`,
119
- side_or_corner: `(left|right)?\\s*(top|bottom)?`,
155
+ side_or_corner: `(left|right)(\\s+(top|bottom))?|(top|bottom)(\\s+(left|right))?`,
120
156
  single_animation_direction: `normal|reverse|alternate|alternate-reverse`,
121
157
  single_animation_fill_mode: `none|forwards|backwards|both`,
122
158
  single_animation_play_state: `running|paused`
123
- };
159
+ });
124
160
 
125
161
  /*
126
162
  * Color definition sub expressions
127
163
  */
128
- private static readonly _COLOR = {
129
- hex: `\\#(0x)?[0-9a-f]+`,
130
- 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`,
164
+ private static readonly _COLOR = CssProp.group({
165
+ // No word character follows, so that a run of hex digits matches in only one way.
166
+ hex: `\\#(0x)?[0-9a-f]+(?![\\w-])`,
167
+ 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`,
131
168
  rgb: String.raw`rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)`,
132
- 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*\)`
133
- };
169
+ 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*\)`
170
+ });
134
171
 
135
172
  /*
136
173
  * Compound (i.e. dependent on other (sub) regular expressions) sub RegEx segments
137
174
  */
138
- private static readonly _C = {
175
+ private static readonly _C = CssProp.group({
139
176
  alpha: `${CssProp.N.integer_zero_ff}|${CssProp.N.number_zero_one}|${CssProp.B.percentage_zero_hundred}`,
140
177
  alphavalue: CssProp.N.number_zero_one,
141
- bg_position: `((${CssProp.B.len_or_perc}|left|center|right|top|bottom)\\s*){1,4}`,
142
- bg_size: `(${CssProp.B.length_pos}|${CssProp.B.percentage}|auto){1,2}|cover|contain`,
178
+ 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}`,
179
+ bg_size: `(${CssProp.B.length_pos}|${CssProp.B.percentage}|auto)(\\s+(${CssProp.B.length_pos}|${CssProp.B.percentage}|auto))?|cover|contain`,
143
180
  border_width: `thin|medium|thick|${CssProp.B.length}`,
144
181
  bottom: `${CssProp.B.length}|auto`,
145
182
  color: `${CssProp._COLOR.hex}|${CssProp._COLOR.rgb}|${CssProp._COLOR.rgba}|${CssProp._COLOR.name}`,
146
- color_stop_length: `(${CssProp.B.len_or_perc}\\s*){1,2}`,
147
183
  linear_color_hint: `${CssProp.B.len_or_perc}`,
148
- family_name: `${CssProp.B.string}|(${CssProp.B.ident}\\s*)+`,
184
+ family_name: `${CssProp.B.string}|${CssProp.B.ident}(\\s+${CssProp.B.ident})*`,
149
185
  image_decl: CssProp.B.url,
150
186
  left: `${CssProp.B.length}|auto`,
151
187
  loose_quotable_words: `(${CssProp.B.ident})+`,
152
188
  margin_width: `${CssProp.B.len_or_perc}|auto`,
153
189
  padding_width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}`,
154
190
  page_url: CssProp.B.url,
155
- position: `((${CssProp.B.len_or_perc}|left|center|right|top|bottom)\\s*){1,4}`,
191
+ position: `(${CssProp.B.len_or_perc}|left|center|right|top|bottom)(\\s+(${CssProp.B.len_or_perc}|left|center|right|top|bottom)){0,3}`,
156
192
  right: `${CssProp.B.length}|auto`,
157
193
  shadow: '',
158
194
  size: `closest-side|farthest-side|closest-corner|farthest-corner|${CssProp.B.length}|(${CssProp.B.len_or_perc})\\s+(${CssProp.B.len_or_perc})`,
159
195
  top: `${CssProp.B.length}|auto`
160
- };
196
+ });
161
197
 
162
- private static readonly _C1 = {
163
- image_list: `image\\(\\s*(${CssProp.B.url})*\\s*(${CssProp.B.url}|${CssProp._C.color})\\s*\\)`,
164
- linear_color_stop: `(${CssProp._C.color})(\\s*${CssProp._C.color_stop_length})?`,
165
- 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})?)`
166
- };
198
+ private static readonly _C1 = CssProp.group({
199
+ image_list: `image\\(\\s*(${CssProp.B.url}\\s*)*(${CssProp.B.url}|${CssProp._C.color})\\s*\\)`,
200
+ linear_color_stop: `${CssProp._C.color}(\\s+${CssProp.B.len_or_perc}){0,2}`,
201
+ 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})?`
202
+ });
167
203
 
168
- private static readonly _C2 = {
169
- color_stop_list: `((${CssProp._C1.linear_color_stop})(\\s*(${CssProp._C.linear_color_hint}))?\\s*,\\s*)+(${CssProp._C1.linear_color_stop})`,
204
+ private static readonly _C2 = CssProp.group({
205
+ color_stop_list: `${CssProp._C1.linear_color_stop}(\\s*,\\s*(${CssProp._C.linear_color_hint}\\s*,\\s*)?${CssProp._C1.linear_color_stop})+`,
170
206
  shape: `rect\\(\\s*(${CssProp._C.top})\\s*,\\s*(${CssProp._C.right})\\s*,\\s*(${CssProp._C.bottom})\\s*,\\s*(${CssProp._C.left})\\s*\\)`
171
- };
207
+ });
172
208
 
173
- private static readonly _C3 = {
174
- linear_gradient: `linear-gradient\\((((${CssProp.B.angle})|to\\s+(${CssProp.A.side_or_corner}))\\s*,\\s*)?\\s*(${CssProp._C2.color_stop_list})\\s*\\)`,
175
- 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*\\)`
176
- };
209
+ private static readonly _C3 = CssProp.group({
210
+ linear_gradient: `linear-gradient\\(\\s*(((${CssProp.B.angle})|to\\s+(${CssProp.A.side_or_corner}))\\s*,\\s*)?(${CssProp._C2.color_stop_list})\\s*\\)`,
211
+ 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*\\)`
212
+ });
177
213
 
178
- private static readonly _C4 = {
214
+ private static readonly _C4 = CssProp.group({
179
215
  image: `${CssProp.B.url}|${CssProp._C3.linear_gradient}|${CssProp._C3.radial_gradient}|${CssProp._C1.image_list}`,
180
216
  bg_image: `(${CssProp.B.url}|${CssProp._C3.linear_gradient}|${CssProp._C3.radial_gradient}|${CssProp._C1.image_list})|none`
181
- };
217
+ });
182
218
 
183
219
  private static readonly C = {
184
220
  ...CssProp._C,
@@ -191,7 +227,7 @@ class CssProp {
191
227
  /*
192
228
  * Property value regular expressions not dependent on other sub expressions
193
229
  */
194
- private static readonly AP = {
230
+ private static readonly AP = CssProp.group({
195
231
  baseline_position: `baseline|first baseline|last baseline`,
196
232
  border_collapse: `collapse|separate`,
197
233
  box: `normal|none|contents`,
@@ -211,21 +247,15 @@ class CssProp {
211
247
  font_weight: `normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900`,
212
248
  list_style_position: `inside|outside`,
213
249
  gap: `normal`,
214
- grid_auto_flow: `row|column|dense|row dense|column dense`,
215
- justify_content: `start|end|center|stretch|space-between|space-around|space-evenly`,
216
- justify_items: `start|end|center|stretch`,
217
- justify_self: `auto|start|end|center|stretch`,
250
+ grid_auto_flow: `(row|column)(\\s+dense)?|dense(\\s+(row|column))?`,
218
251
  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`,
219
- overflow: `visible|hidden|scroll|auto`,
252
+ overflow: `(visible|hidden|scroll|auto)(\\s+(visible|hidden|scroll|auto))?`,
220
253
  overflow_position: `unsafe|safe`,
221
254
  overflow_wrap: `normal|break-word`,
222
255
  overflow_x: `visible|hidden|scroll|auto|no-display|no-content`,
223
256
  page_break_after: `auto|always|avoid|left|right`,
224
257
  page_break_before: `auto|always|avoid|left|right`,
225
258
  page_break_inside: `avoid|auto`,
226
- place_content: `(center|start|end|space-between|space-around|space-evenly|stretch){1,2}`,
227
- place_items: `(center|start|end|baseline|stretch){1,2}`,
228
- place_self: `(center|start|end|baseline|stretch){1,2}`,
229
259
  position: `static|relative|absolute`,
230
260
  resize: `none|both|horizontal|vertical`,
231
261
  speak: `normal|none|spell-out`,
@@ -242,13 +272,13 @@ class CssProp {
242
272
  visibility: `visible|hidden|collapse`,
243
273
  white_space: `normal|pre|nowrap|pre-wrap|pre-line`,
244
274
  word_break: `normal|keep-all|break-all`
245
- };
275
+ });
246
276
 
247
277
  /*
248
278
  * Compound propertiy value regular expressions (i.e. dependent on other sub expressions)
249
279
  */
250
- private static readonly _CP = {
251
- align_content: `normal|${CssProp.AP.baseline_position}|${CssProp.AP.content_distribution}|${CssProp.AP.overflow_position}|${CssProp.AP.content_position}`,
280
+ private static readonly _CP = CssProp.group({
281
+ align_content: `normal|${CssProp.AP.baseline_position}|${CssProp.AP.content_distribution}|(${CssProp.AP.overflow_position}\\s+)?${CssProp.AP.content_position}`,
252
282
  align_items: `normal|stretch|${CssProp.AP.baseline_position}|(${CssProp.AP.overflow_position})?\\s*${CssProp.AP.self_position}|anchor-center`,
253
283
  align_self: `auto|normal|stretch|${CssProp.AP.baseline_position}|(${CssProp.AP.overflow_position})?\\s*${CssProp.AP.self_position}|anchor-center`,
254
284
  background_attachment: `${CssProp.A.attachment}(,\\s*${CssProp.A.attachment})*`,
@@ -262,11 +292,11 @@ class CssProp {
262
292
  border_top_style: CssProp.A.border_style,
263
293
  border_width: `((${CssProp.C.border_width})\\s*){1,4}`,
264
294
  color: CssProp.C.color,
265
- 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)`,
266
- 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`,
295
+ 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)`,
296
+ 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)`,
267
297
  display_outside: CssProp.A.display_outside,
268
298
  elevation: `${CssProp.B.angle}|below|level|above|higher|lower`,
269
- font_family: `(${CssProp.C.family_name}|${CssProp.A.generic_family})(,\\s*(${CssProp.C.family_name}|${CssProp.A.generic_family}))*`,
299
+ font_family: `${CssProp.C.family_name}(\\s*,\\s*${CssProp.C.family_name})*`,
270
300
  height: `${CssProp.B.length}|${CssProp.B.percentage}|auto`,
271
301
  letter_spacing: `normal|${CssProp.B.length}`,
272
302
  list_style_image: `${CssProp.C.image}|none`,
@@ -282,7 +312,7 @@ class CssProp {
282
312
  right: `${CssProp.B.length}|${CssProp.B.percentage}|auto`,
283
313
  stress: CssProp.N.number,
284
314
  text_indent: `${CssProp.B.length}|${CssProp.B.percentage}`,
285
- text_shadow: `none|${CssProp.C.shadow}(,\\s*(${CssProp.C.shadow}))*`,
315
+ text_shadow: `none|${CssProp.C.shadow}(\\s*,\\s*${CssProp.C.shadow})*`,
286
316
  volume: `${CssProp.N.number_pos}|${CssProp.B.percentage_pos}|silent|x-soft|soft|medium|loud|x-loud`,
287
317
  word_wrap: CssProp.AP.overflow_wrap,
288
318
  zoom: `normal|${CssProp.N.number_pos}|${CssProp.B.percentage_pos}`,
@@ -297,7 +327,7 @@ class CssProp {
297
327
  border_style: `((${CssProp.A.border_style})\\s*){1,4}`,
298
328
  border_top_left_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
299
329
  border_top_width: CssProp.C.border_width,
300
- box_shadow: `none|${CssProp.C.shadow}(,\\s*(${CssProp.C.shadow}))*`,
330
+ box_shadow: `none|${CssProp.C.shadow}(\\s*,\\s*${CssProp.C.shadow})*`,
301
331
  clip: `${CssProp.C.shape}|auto`,
302
332
  display_inside: CssProp.A.display_inside,
303
333
  font_size: `${CssProp.A.absolute_size}|${CssProp.A.relative_size}|${CssProp.B.length_pos}|${CssProp.B.percentage_pos}`,
@@ -314,7 +344,10 @@ class CssProp {
314
344
  width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|auto`,
315
345
  z_index: `auto|${CssProp.B.z_index}`,
316
346
  // Simplified background
317
- 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*)+`,
347
+ background: CssProp.list(
348
+ `${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}`,
349
+ '(\\/\\s*)?'
350
+ ),
318
351
  background_size: `${CssProp.C.bg_size}(,\\s*${CssProp.C.bg_size})*`,
319
352
  border_bottom_left_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
320
353
  border_bottom_width: CssProp.C.border_width,
@@ -322,7 +355,9 @@ class CssProp {
322
355
  border_right_style: CssProp.A.border_style,
323
356
  border_top: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
324
357
  bottom: `${CssProp.B.len_or_perc}|auto`,
325
- list_style: `((${CssProp.AP.list_style_type}|${CssProp.AP.list_style_position}|${CssProp.C.image}|none})\\s*){1,3}`,
358
+ list_style: CssProp.list(
359
+ `${CssProp.AP.list_style_type}|${CssProp.AP.list_style_position}|${CssProp.C.image}`
360
+ ),
326
361
  margin_top: CssProp.C.margin_width,
327
362
  outline: `((${CssProp.C.color}|invert|${CssProp.A.border_style}|${CssProp.C.border_width})\\s*){1,3}`,
328
363
  overflow_y: CssProp.AP.overflow_x,
@@ -343,17 +378,17 @@ class CssProp {
343
378
  margin: `((${CssProp.C.margin_width})\\s*){1,4}`,
344
379
  padding_left: CssProp.C.padding_width,
345
380
  border_left: `((${CssProp.C.border_width}|${CssProp.A.border_style}|${CssProp.C.color})\\s*){1,3}`,
346
- quotes: `(${CssProp.B.string}\\s*${CssProp.B.string})+|none`,
381
+ quotes: `none|${CssProp.B.string}\\s*${CssProp.B.string}(\\s*${CssProp.B.string}\\s*${CssProp.B.string})*`,
347
382
  border_top_right_radius: `(${CssProp.B.length}|${CssProp.B.percentage})(\\s*(${CssProp.B.length}|${CssProp.B.percentage}))?`,
348
383
  min_width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|auto`,
349
384
  // Add flexbox and grid properties
350
- 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()>
385
+ 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()>
351
386
  flex_grow: CssProp.N.number_pos,
352
387
  flex_shrink: CssProp.N.number_pos,
353
388
  grid: `(${CssProp.B.string}|none|subgrid)\\s*(\\/\\s*(${CssProp.B.string}|none|subgrid))?`,
354
- grid_area: `${CssProp.B.ident}|auto|(${CssProp.N.integer}\\s*\\/\\s*${CssProp.N.integer}\\s*\\/\\s*${CssProp.N.integer}\\s*\\/\\s*${CssProp.N.integer})`,
355
- grid_auto_columns: `(${CssProp.B.track_size})+`,
356
- grid_auto_rows: `(${CssProp.B.track_size})+`,
389
+ grid_area: `${CssProp.B.grid_line}(\\s*\\/\\s*${CssProp.B.grid_line}){0,3}`,
390
+ grid_auto_columns: CssProp.list(CssProp.B.track_size),
391
+ grid_auto_rows: CssProp.list(CssProp.B.track_size),
357
392
  grid_column: `${CssProp.B.grid_line}(\\s*\\/\\s*${CssProp.B.grid_line})?`,
358
393
  grid_column_start: `${CssProp.B.grid_line}`,
359
394
  grid_column_end: `${CssProp.B.grid_line}`,
@@ -363,19 +398,25 @@ class CssProp {
363
398
  grid_row_start: `${CssProp.B.grid_line}`,
364
399
  grid_row_end: `${CssProp.B.grid_line}`,
365
400
  grid_row_gap: `${CssProp.B.len_or_perc}|normal`,
366
- grid_template: `none|(${CssProp.B.grid_template_rows}\\s*\\/\\s*${CssProp.B.grid_template_columns})|(${CssProp.B.line_names}\\s*)?(${CssProp.B.string}\\s*${CssProp.B.track_size}\\s*(${CssProp.B.line_names}\\s*)?)+\\s*(\\/\\s*${CssProp.B.explicit_track_list})?`,
367
- grid_template_areas: `none|(${CssProp.B.string})+`,
401
+ 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}))?`,
402
+ grid_template_areas: `none|${CssProp.B.string}(\\s*${CssProp.B.string})*`,
368
403
  grid_template_columns: `${CssProp.B.grid_template_columns}`,
369
404
  grid_template_rows: `${CssProp.B.grid_template_rows}`,
370
405
  row_gap: `${CssProp.B.len_or_perc}|normal`,
371
406
  column_gap: `${CssProp.B.len_or_perc}|normal`,
372
407
  gap: `(${CssProp.B.len_or_perc}|normal)(\\s*(${CssProp.B.len_or_perc}|normal))?`,
408
+ justify_content: `normal|${CssProp.AP.content_distribution}|(${CssProp.AP.overflow_position}\\s+)?(${CssProp.AP.content_position}|left|right)`,
409
+ 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`,
410
+ justify_self: `auto|normal|stretch|${CssProp.AP.baseline_position}|(${CssProp.AP.overflow_position}\\s+)?(${CssProp.AP.self_position}|left|right)|anchor-center`,
373
411
  order: CssProp.N.integer
374
- };
412
+ });
375
413
 
376
- private static readonly _CP1 = {
377
- 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)`
378
- };
414
+ private static readonly _CP1 = CssProp.group({
415
+ 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)`,
416
+ place_content: `${CssProp._CP.align_content}(\\s+${CssProp._CP.justify_content})?`,
417
+ place_items: `${CssProp._CP.align_items}(\\s+${CssProp._CP.justify_items})?`,
418
+ place_self: `${CssProp._CP.align_self}(\\s+${CssProp._CP.justify_self})?`
419
+ });
379
420
 
380
421
  private static readonly CP = { ...CssProp._CP, ...CssProp._CP1 };
381
422
 
@@ -531,9 +572,9 @@ class CssProp {
531
572
  static FLEX_GROW = CssProp.reg(CssProp.CP.flex_grow);
532
573
  static FLEX_SHRINK = CssProp.reg(CssProp.CP.flex_shrink);
533
574
  static FLEX_WRAP = CssProp.reg(CssProp.AP.flex_wrap);
534
- static JUSTIFY_CONTENT = CssProp.reg(CssProp.AP.justify_content);
535
- static JUSTIFY_ITEMS = CssProp.reg(CssProp.AP.justify_items);
536
- static JUSTIFY_SELF = CssProp.reg(CssProp.AP.justify_self);
575
+ static JUSTIFY_CONTENT = CssProp.reg(CssProp.CP.justify_content);
576
+ static JUSTIFY_ITEMS = CssProp.reg(CssProp.CP.justify_items);
577
+ static JUSTIFY_SELF = CssProp.reg(CssProp.CP.justify_self);
537
578
  static ORDER = CssProp.reg(CssProp.CP.order);
538
579
 
539
580
  // Grid properties
@@ -558,11 +599,50 @@ class CssProp {
558
599
  static GAP = CssProp.reg(CssProp.CP.gap);
559
600
  static ROW_GAP = CssProp.reg(CssProp.CP.row_gap);
560
601
  static COLUMN_GAP = CssProp.reg(CssProp.CP.column_gap);
561
- static PLACE_CONTENT = CssProp.reg(CssProp.AP.place_content);
562
- static PLACE_ITEMS = CssProp.reg(CssProp.AP.place_items);
563
- static PLACE_SELF = CssProp.reg(CssProp.AP.place_self);
602
+ static PLACE_CONTENT = CssProp.reg(CssProp.CP.place_content);
603
+ static PLACE_ITEMS = CssProp.reg(CssProp.CP.place_items);
604
+ static PLACE_SELF = CssProp.reg(CssProp.CP.place_self);
564
605
  }
565
606
 
607
+ /**
608
+ * Matches class names outside the prefixes of JupyterLab, Lumino, CodeMirror,
609
+ * react-toastify and xterm.js, whose styles include ones that `allowedStyles`
610
+ * rejects, such as `position: fixed`. Case is ignored for quirks mode pages.
611
+ */
612
+ const UNRESERVED_CLASS_NAME = /^(?!jp-|lm-|cm-|toastify|xterm)/i;
613
+
614
+ /**
615
+ * Reserved class names that sanitized HTML may keep: JupyterLab adds them to
616
+ * Markdown before it is sanitized, users add them to hide a heading from the
617
+ * table of contents, or notebooks copy them with output HTML of JupyterLab.
618
+ * Their styles do not move content out of its cell.
619
+ */
620
+ const ALLOWED_RESERVED_CLASS_NAMES = [
621
+ 'jp-mod-mermaidTheme-dark',
622
+ 'jp-mod-mermaidTheme-default',
623
+ 'jp-mod-warning',
624
+ 'jp-OutputArea-output',
625
+ 'jp-RenderedHTMLCommon',
626
+ 'jp-RenderedMermaid',
627
+ 'jp-RenderedMermaid-Details',
628
+ 'jp-RenderedMermaid-Summary',
629
+ 'jp-RenderedText',
630
+ 'jp-sr-only',
631
+ 'jp-toc-ignore'
632
+ ];
633
+
634
+ /**
635
+ * Reserved class names that extensions write into Markdown before it is
636
+ * sanitized: `@jupyter/chat` for mentions, and Jupyter AI personas for errors.
637
+ * They are kept with a warning, because this exception is deprecated. Their
638
+ * styles do not move content out of its cell.
639
+ */
640
+ const DEPRECATED_RESERVED_CLASS_NAMES = [
641
+ 'jp-chat-mention',
642
+ 'jp-jai-error-details',
643
+ 'jp-jai-error-traceback'
644
+ ];
645
+
566
646
  /**
567
647
  * A class to sanitize HTML strings.
568
648
  */
@@ -665,11 +745,29 @@ export class Sanitizer implements IRenderMime.ISanitizer {
665
745
  this._options = this._generateOptions();
666
746
  }
667
747
 
748
+ /**
749
+ * Warn once for each deprecated reserved class name in a class attribute.
750
+ */
751
+ private _warnDeprecatedClassNames(value: string): void {
752
+ for (const name of value.split(/\s+/)) {
753
+ if (
754
+ DEPRECATED_RESERVED_CLASS_NAMES.includes(name) &&
755
+ !this._warnedClassNames.has(name)
756
+ ) {
757
+ this._warnedClassNames.add(name);
758
+ console.warn(
759
+ `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.`
760
+ );
761
+ }
762
+ }
763
+ }
764
+
668
765
  private _autolink: boolean = true;
669
766
  private _incrementalAutolink: boolean = true;
670
767
  private _allowNamedProperties: boolean = false;
671
768
  private _allowCommandLinker: boolean = true;
672
769
  private _customAllowedSchemes: string[] | undefined;
770
+ private _warnedClassNames = new Set<string>();
673
771
  private _options: sanitize.IOptions;
674
772
  private _generateOptions = (): sanitize.IOptions => {
675
773
  const schemesToAllow = Array.isArray(this._customAllowedSchemes)
@@ -1034,6 +1132,14 @@ export class Sanitizer implements IRenderMime.ISanitizer {
1034
1132
  'width'
1035
1133
  ]
1036
1134
  },
1135
+ // Class names that HTML tags may have.
1136
+ allowedClasses: {
1137
+ '*': [
1138
+ ...ALLOWED_RESERVED_CLASS_NAMES,
1139
+ ...DEPRECATED_RESERVED_CLASS_NAMES,
1140
+ UNRESERVED_CLASS_NAME
1141
+ ]
1142
+ },
1037
1143
  // Inline CSS styles that HTML tags may have (and their allowed values)
1038
1144
  allowedStyles: {
1039
1145
  // To simplify the data, all styles are allowed on all tags that allow the style attribute
@@ -1212,23 +1318,22 @@ export class Sanitizer implements IRenderMime.ISanitizer {
1212
1318
  a: sanitize.simpleTransform('a', { rel: 'nofollow' }),
1213
1319
  // Set the "disabled" attribute for <input> tags.
1214
1320
  input: sanitize.simpleTransform('input', { disabled: 'disabled' }),
1215
- // Replace "id" attribute by "data-jupyter-id" if "id" is not allowed.
1216
- ...(this._allowNamedProperties
1217
- ? {}
1218
- : {
1219
- '*': function (tagName: string, attribs: sanitize.Attributes) {
1220
- if (attribs.id !== undefined) {
1221
- attribs['data-jupyter-id'] = attribs.id;
1222
- delete attribs.id;
1223
- }
1224
- return {
1225
- tagName,
1226
- attribs: {
1227
- ...attribs
1228
- }
1229
- };
1230
- }
1231
- })
1321
+ '*': (tagName: string, attribs: sanitize.Attributes) => {
1322
+ // Replace "id" attribute by "data-jupyter-id" if "id" is not allowed.
1323
+ if (!this._allowNamedProperties && attribs.id !== undefined) {
1324
+ attribs['data-jupyter-id'] = attribs.id;
1325
+ delete attribs.id;
1326
+ }
1327
+ if (attribs.class !== undefined) {
1328
+ this._warnDeprecatedClassNames(attribs.class);
1329
+ }
1330
+ return {
1331
+ tagName,
1332
+ attribs: {
1333
+ ...attribs
1334
+ }
1335
+ };
1336
+ }
1232
1337
  },
1233
1338
  allowedSchemes: schemesToAllow,
1234
1339
  allowedSchemesByTag: {