@@ -18,30 +18,43 @@ function extractColors(colors, name, ast) {
18
18
colors [ name ] = Object . assign ( [ ] , { name} ) ;
19
19
colors . push ( colors [ name ] ) ;
20
20
21
+ function pushOrReplace ( declaration ) {
22
+ const { property, value} = declaration ;
23
+ if ( property in colors [ name ] ) {
24
+ if ( colors [ name ] [ property ] !== value ) {
25
+ colors [ name ] [ property ] = value ;
26
+ const index = colors [ name ] . findIndex ( declaration => declaration . property === property ) ;
27
+ colors [ name ] [ index ] = declaration ;
28
+ }
29
+ } else {
30
+ colors [ name ] [ property ] = value ;
31
+ colors [ name ] . push ( declaration ) ;
32
+ }
33
+ }
34
+
21
35
for ( const rule of walkRules ( ast ) ) {
22
36
for ( const declaration of rule . declarations ) {
23
37
if ( declaration . type === 'declaration' ) {
24
- const { property, value} = declaration ;
25
- colors [ name ] [ property ] = value ;
26
- colors [ name ] . push ( declaration ) ;
38
+ pushOrReplace ( declaration ) ;
27
39
}
28
40
}
29
41
}
30
42
43
+ colors [ name ] [ '--base-size-8' ] = '8px' ;
44
+ colors [ name ] [ '--base-size-16' ] = '16px' ;
31
45
colors [ name ] [ '--base-text-weight-normal' ] = '400' ;
46
+ colors [ name ] [ '--base-text-weight-medium' ] = '500' ;
32
47
colors [ name ] [ '--base-text-weight-semibold' ] = '600' ;
33
48
}
34
49
35
- // https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline /sanitization_filter.rb
50
+ // https://github.com/gjtorikian/html-pipeline/blob/main/lib/html_pipeline /sanitization_filter.rb
36
51
const ALLOW_TAGS = new Set ( [
37
52
'h1' ,
38
53
'h2' ,
39
54
'h3' ,
40
55
'h4' ,
41
56
'h5' ,
42
57
'h6' ,
43
- 'h7' ,
44
- 'h8' ,
45
58
'br' ,
46
59
'b' ,
47
60
'i' ,
@@ -58,6 +71,7 @@ const ALLOW_TAGS = new Set([
58
71
'sup' ,
59
72
'sub' ,
60
73
'p' ,
74
+ 'picture' ,
61
75
'ol' ,
62
76
'ul' ,
63
77
'table' ,
@@ -93,6 +107,7 @@ const ALLOW_TAGS = new Set([
93
107
'dfn' ,
94
108
'mark' ,
95
109
'small' ,
110
+ 'source' ,
96
111
'span' ,
97
112
'time' ,
98
113
'wbr' ,
@@ -112,14 +127,19 @@ const ALLOW_CLASS = new Set([
112
127
'.task-list-item' ,
113
128
'.task-list-item-checkbox' ,
114
129
// For Markdown alerts.
130
+ '.octicon-info' ,
131
+ '.octicon-light-bulb' ,
132
+ '.octicon-report' ,
133
+ '.octicon-alert' ,
134
+ '.octicon-stop' ,
115
135
'.markdown-alert' ,
116
- '.color-fg-accent ' ,
117
- '.color-fg-attention ' ,
118
- '.color-fg-done ' ,
119
- '.text-semibold ' ,
120
- '.d-inline-flex ' ,
121
- '.flex-items-center ' ,
122
- '.mb-1 ' ,
136
+ '.markdown-alert-title ' ,
137
+ '.markdown-alert-note ' ,
138
+ '.markdown-alert-tip ' ,
139
+ '.markdown-alert-important ' ,
140
+ '.markdown-alert-warning ' ,
141
+ '.markdown-alert-caution ' ,
142
+ '.mr-2 ' ,
123
143
] ) ;
124
144
125
145
function extractStyles ( rules , ast ) {
@@ -182,14 +202,23 @@ function extractStyles(rules, ast) {
182
202
}
183
203
184
204
for ( const rule of walkRules ( ast ) ) {
185
- if ( rule . declarations . some ( ( { value} ) => value . includes ( 'prettylights' ) ) ) {
205
+ if ( ! rule . selectors . some ( selector => selector . includes ( 'QueryBuilder' ) )
206
+ && rule . declarations . some ( ( { value} ) => value . includes ( 'prettylights' ) ) ) {
186
207
rules . push ( rule ) ;
187
208
} else {
188
209
rule . selectors = rule . selectors
189
210
. filter ( selector => select ( selector ) )
190
211
. map ( selector => fixSelector ( selector ) ) ;
191
212
if ( rule . selectors . length > 0 ) {
192
213
rule . declarations . map ( declaration => fixDeclaration ( declaration ) ) ;
214
+
215
+ // '-webkit-appearance: x' << 'appearance: x'
216
+ const index = rule . declarations . findIndex ( declaration => declaration . property === '-webkit-appearance' ) ;
217
+ if ( index >= 0 ) {
218
+ const { value} = rule . declarations [ index ] ;
219
+ rule . declarations . splice ( index + 1 , 0 , { type : 'declaration' , property : 'appearance' , value} ) ;
220
+ }
221
+
193
222
rules . push ( rule ) ;
194
223
}
195
224
}
@@ -282,22 +311,57 @@ const manuallyAddedStyle = `
282
311
function applyColors ( colors , rules ) {
283
312
for ( const rule of rules ) {
284
313
for ( const declaration of rule . declarations ) {
285
- const match = / v a r \( (?< name > .+ ?) \) / . exec ( declaration . value ) ;
286
- if ( match ) {
287
- let { name} = match . groups ;
288
- name = name . split ( ',' ) [ 0 ] ;
289
- if ( name === '--color-text-primary' ) {
290
- name = '--color-fg-default' ;
291
- }
314
+ if ( declaration . value . includes ( 'var(' ) ) {
315
+ declaration . value = declaration . value . replaceAll ( / v a r \( ( .+ ?) \) / g, ( match , name ) => {
316
+ name = name . split ( ',' ) [ 0 ] ;
317
+ if ( name === '--color-text-primary' ) {
318
+ name = '--color-fg-default' ;
319
+ }
320
+
321
+ if ( name in colors ) {
322
+ return colors [ name ] ;
323
+ }
324
+
325
+ return match [ 0 ] ;
326
+ } ) ;
327
+ }
328
+ }
329
+ }
330
+
331
+ return rules ;
332
+ }
292
333
293
- if ( name in colors ) {
294
- declaration . value = declaration . value . replace ( match [ 0 ] , colors [ name ] ) ;
334
+ // Workaround for module 'css' does not understand new CSS syntaxes (@container, etc.)
335
+ // Strip them as they are not used in the output anyway.
336
+ function patchCSSText ( cssText ) {
337
+ function strip ( mark , left = '{' , right = '}' ) {
338
+ const ranges = [ ] ;
339
+
340
+ let i = - 1 ;
341
+ while ( ( i = cssText . indexOf ( mark , i + 1 ) ) >= 0 ) {
342
+ let j = cssText . indexOf ( left , i ) + 1 ;
343
+ let depth = 1 ;
344
+ while ( depth > 0 ) {
345
+ if ( cssText [ j ] === left ) {
346
+ depth ++ ;
347
+ } else if ( cssText [ j ] === right ) {
348
+ depth -- ;
295
349
}
350
+
351
+ j ++ ;
296
352
}
353
+
354
+ ranges . push ( [ i , j ] ) ;
355
+ }
356
+
357
+ for ( const [ i , j ] of ranges . reverse ( ) ) {
358
+ cssText = cssText . slice ( 0 , i ) + cssText . slice ( j ) ;
297
359
}
298
360
}
299
361
300
- return rules ;
362
+ strip ( '@container' ) ;
363
+
364
+ return cssText ;
301
365
}
302
366
303
367
/**
@@ -356,7 +420,8 @@ export default async function getCSS({
356
420
}
357
421
358
422
const [ name ] = match ;
359
- const ast = css . parse ( cssText ) ;
423
+ const patched = patchCSSText ( cssText ) ;
424
+ const ast = css . parse ( patched ) ;
360
425
361
426
// If it's a theme variable file extract colors, otherwise extract style
362
427
if ( / ^ ( l i g h t | d a r k ) / . test ( name ) ) {
0 commit comments