source: node_modules/highlight.js/lib/languages/scss.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 11.0 KB
Line 
1const MODES = (hljs) => {
2 return {
3 IMPORTANT: {
4 className: 'meta',
5 begin: '!important'
6 },
7 HEXCOLOR: {
8 className: 'number',
9 begin: '#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})'
10 },
11 ATTRIBUTE_SELECTOR_MODE: {
12 className: 'selector-attr',
13 begin: /\[/,
14 end: /\]/,
15 illegal: '$',
16 contains: [
17 hljs.APOS_STRING_MODE,
18 hljs.QUOTE_STRING_MODE
19 ]
20 }
21 };
22};
23
24const TAGS = [
25 'a',
26 'abbr',
27 'address',
28 'article',
29 'aside',
30 'audio',
31 'b',
32 'blockquote',
33 'body',
34 'button',
35 'canvas',
36 'caption',
37 'cite',
38 'code',
39 'dd',
40 'del',
41 'details',
42 'dfn',
43 'div',
44 'dl',
45 'dt',
46 'em',
47 'fieldset',
48 'figcaption',
49 'figure',
50 'footer',
51 'form',
52 'h1',
53 'h2',
54 'h3',
55 'h4',
56 'h5',
57 'h6',
58 'header',
59 'hgroup',
60 'html',
61 'i',
62 'iframe',
63 'img',
64 'input',
65 'ins',
66 'kbd',
67 'label',
68 'legend',
69 'li',
70 'main',
71 'mark',
72 'menu',
73 'nav',
74 'object',
75 'ol',
76 'p',
77 'q',
78 'quote',
79 'samp',
80 'section',
81 'span',
82 'strong',
83 'summary',
84 'sup',
85 'table',
86 'tbody',
87 'td',
88 'textarea',
89 'tfoot',
90 'th',
91 'thead',
92 'time',
93 'tr',
94 'ul',
95 'var',
96 'video'
97];
98
99const MEDIA_FEATURES = [
100 'any-hover',
101 'any-pointer',
102 'aspect-ratio',
103 'color',
104 'color-gamut',
105 'color-index',
106 'device-aspect-ratio',
107 'device-height',
108 'device-width',
109 'display-mode',
110 'forced-colors',
111 'grid',
112 'height',
113 'hover',
114 'inverted-colors',
115 'monochrome',
116 'orientation',
117 'overflow-block',
118 'overflow-inline',
119 'pointer',
120 'prefers-color-scheme',
121 'prefers-contrast',
122 'prefers-reduced-motion',
123 'prefers-reduced-transparency',
124 'resolution',
125 'scan',
126 'scripting',
127 'update',
128 'width',
129 // TODO: find a better solution?
130 'min-width',
131 'max-width',
132 'min-height',
133 'max-height'
134];
135
136// https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
137const PSEUDO_CLASSES = [
138 'active',
139 'any-link',
140 'blank',
141 'checked',
142 'current',
143 'default',
144 'defined',
145 'dir', // dir()
146 'disabled',
147 'drop',
148 'empty',
149 'enabled',
150 'first',
151 'first-child',
152 'first-of-type',
153 'fullscreen',
154 'future',
155 'focus',
156 'focus-visible',
157 'focus-within',
158 'has', // has()
159 'host', // host or host()
160 'host-context', // host-context()
161 'hover',
162 'indeterminate',
163 'in-range',
164 'invalid',
165 'is', // is()
166 'lang', // lang()
167 'last-child',
168 'last-of-type',
169 'left',
170 'link',
171 'local-link',
172 'not', // not()
173 'nth-child', // nth-child()
174 'nth-col', // nth-col()
175 'nth-last-child', // nth-last-child()
176 'nth-last-col', // nth-last-col()
177 'nth-last-of-type', //nth-last-of-type()
178 'nth-of-type', //nth-of-type()
179 'only-child',
180 'only-of-type',
181 'optional',
182 'out-of-range',
183 'past',
184 'placeholder-shown',
185 'read-only',
186 'read-write',
187 'required',
188 'right',
189 'root',
190 'scope',
191 'target',
192 'target-within',
193 'user-invalid',
194 'valid',
195 'visited',
196 'where' // where()
197];
198
199// https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
200const PSEUDO_ELEMENTS = [
201 'after',
202 'backdrop',
203 'before',
204 'cue',
205 'cue-region',
206 'first-letter',
207 'first-line',
208 'grammar-error',
209 'marker',
210 'part',
211 'placeholder',
212 'selection',
213 'slotted',
214 'spelling-error'
215];
216
217const ATTRIBUTES = [
218 'align-content',
219 'align-items',
220 'align-self',
221 'animation',
222 'animation-delay',
223 'animation-direction',
224 'animation-duration',
225 'animation-fill-mode',
226 'animation-iteration-count',
227 'animation-name',
228 'animation-play-state',
229 'animation-timing-function',
230 'auto',
231 'backface-visibility',
232 'background',
233 'background-attachment',
234 'background-clip',
235 'background-color',
236 'background-image',
237 'background-origin',
238 'background-position',
239 'background-repeat',
240 'background-size',
241 'border',
242 'border-bottom',
243 'border-bottom-color',
244 'border-bottom-left-radius',
245 'border-bottom-right-radius',
246 'border-bottom-style',
247 'border-bottom-width',
248 'border-collapse',
249 'border-color',
250 'border-image',
251 'border-image-outset',
252 'border-image-repeat',
253 'border-image-slice',
254 'border-image-source',
255 'border-image-width',
256 'border-left',
257 'border-left-color',
258 'border-left-style',
259 'border-left-width',
260 'border-radius',
261 'border-right',
262 'border-right-color',
263 'border-right-style',
264 'border-right-width',
265 'border-spacing',
266 'border-style',
267 'border-top',
268 'border-top-color',
269 'border-top-left-radius',
270 'border-top-right-radius',
271 'border-top-style',
272 'border-top-width',
273 'border-width',
274 'bottom',
275 'box-decoration-break',
276 'box-shadow',
277 'box-sizing',
278 'break-after',
279 'break-before',
280 'break-inside',
281 'caption-side',
282 'clear',
283 'clip',
284 'clip-path',
285 'color',
286 'column-count',
287 'column-fill',
288 'column-gap',
289 'column-rule',
290 'column-rule-color',
291 'column-rule-style',
292 'column-rule-width',
293 'column-span',
294 'column-width',
295 'columns',
296 'content',
297 'counter-increment',
298 'counter-reset',
299 'cursor',
300 'direction',
301 'display',
302 'empty-cells',
303 'filter',
304 'flex',
305 'flex-basis',
306 'flex-direction',
307 'flex-flow',
308 'flex-grow',
309 'flex-shrink',
310 'flex-wrap',
311 'float',
312 'font',
313 'font-display',
314 'font-family',
315 'font-feature-settings',
316 'font-kerning',
317 'font-language-override',
318 'font-size',
319 'font-size-adjust',
320 'font-smoothing',
321 'font-stretch',
322 'font-style',
323 'font-variant',
324 'font-variant-ligatures',
325 'font-variation-settings',
326 'font-weight',
327 'height',
328 'hyphens',
329 'icon',
330 'image-orientation',
331 'image-rendering',
332 'image-resolution',
333 'ime-mode',
334 'inherit',
335 'initial',
336 'justify-content',
337 'left',
338 'letter-spacing',
339 'line-height',
340 'list-style',
341 'list-style-image',
342 'list-style-position',
343 'list-style-type',
344 'margin',
345 'margin-bottom',
346 'margin-left',
347 'margin-right',
348 'margin-top',
349 'marks',
350 'mask',
351 'max-height',
352 'max-width',
353 'min-height',
354 'min-width',
355 'nav-down',
356 'nav-index',
357 'nav-left',
358 'nav-right',
359 'nav-up',
360 'none',
361 'normal',
362 'object-fit',
363 'object-position',
364 'opacity',
365 'order',
366 'orphans',
367 'outline',
368 'outline-color',
369 'outline-offset',
370 'outline-style',
371 'outline-width',
372 'overflow',
373 'overflow-wrap',
374 'overflow-x',
375 'overflow-y',
376 'padding',
377 'padding-bottom',
378 'padding-left',
379 'padding-right',
380 'padding-top',
381 'page-break-after',
382 'page-break-before',
383 'page-break-inside',
384 'perspective',
385 'perspective-origin',
386 'pointer-events',
387 'position',
388 'quotes',
389 'resize',
390 'right',
391 'src', // @font-face
392 'tab-size',
393 'table-layout',
394 'text-align',
395 'text-align-last',
396 'text-decoration',
397 'text-decoration-color',
398 'text-decoration-line',
399 'text-decoration-style',
400 'text-indent',
401 'text-overflow',
402 'text-rendering',
403 'text-shadow',
404 'text-transform',
405 'text-underline-position',
406 'top',
407 'transform',
408 'transform-origin',
409 'transform-style',
410 'transition',
411 'transition-delay',
412 'transition-duration',
413 'transition-property',
414 'transition-timing-function',
415 'unicode-bidi',
416 'vertical-align',
417 'visibility',
418 'white-space',
419 'widows',
420 'width',
421 'word-break',
422 'word-spacing',
423 'word-wrap',
424 'z-index'
425 // reverse makes sure longer attributes `font-weight` are matched fully
426 // instead of getting false positives on say `font`
427].reverse();
428
429/*
430Language: SCSS
431Description: Scss is an extension of the syntax of CSS.
432Author: Kurt Emch <kurt@kurtemch.com>
433Website: https://sass-lang.com
434Category: common, css
435*/
436
437/** @type LanguageFn */
438function scss(hljs) {
439 const modes = MODES(hljs);
440 const PSEUDO_ELEMENTS$1 = PSEUDO_ELEMENTS;
441 const PSEUDO_CLASSES$1 = PSEUDO_CLASSES;
442
443 const AT_IDENTIFIER = '@[a-z-]+'; // @font-face
444 const AT_MODIFIERS = "and or not only";
445 const IDENT_RE = '[a-zA-Z-][a-zA-Z0-9_-]*';
446 const VARIABLE = {
447 className: 'variable',
448 begin: '(\\$' + IDENT_RE + ')\\b'
449 };
450
451 return {
452 name: 'SCSS',
453 case_insensitive: true,
454 illegal: '[=/|\']',
455 contains: [
456 hljs.C_LINE_COMMENT_MODE,
457 hljs.C_BLOCK_COMMENT_MODE,
458 {
459 className: 'selector-id',
460 begin: '#[A-Za-z0-9_-]+',
461 relevance: 0
462 },
463 {
464 className: 'selector-class',
465 begin: '\\.[A-Za-z0-9_-]+',
466 relevance: 0
467 },
468 modes.ATTRIBUTE_SELECTOR_MODE,
469 {
470 className: 'selector-tag',
471 begin: '\\b(' + TAGS.join('|') + ')\\b',
472 // was there, before, but why?
473 relevance: 0
474 },
475 {
476 className: 'selector-pseudo',
477 begin: ':(' + PSEUDO_CLASSES$1.join('|') + ')'
478 },
479 {
480 className: 'selector-pseudo',
481 begin: '::(' + PSEUDO_ELEMENTS$1.join('|') + ')'
482 },
483 VARIABLE,
484 { // pseudo-selector params
485 begin: /\(/,
486 end: /\)/,
487 contains: [ hljs.CSS_NUMBER_MODE ]
488 },
489 {
490 className: 'attribute',
491 begin: '\\b(' + ATTRIBUTES.join('|') + ')\\b'
492 },
493 {
494 begin: '\\b(whitespace|wait|w-resize|visible|vertical-text|vertical-ideographic|uppercase|upper-roman|upper-alpha|underline|transparent|top|thin|thick|text|text-top|text-bottom|tb-rl|table-header-group|table-footer-group|sw-resize|super|strict|static|square|solid|small-caps|separate|se-resize|scroll|s-resize|rtl|row-resize|ridge|right|repeat|repeat-y|repeat-x|relative|progress|pointer|overline|outside|outset|oblique|nowrap|not-allowed|normal|none|nw-resize|no-repeat|no-drop|newspaper|ne-resize|n-resize|move|middle|medium|ltr|lr-tb|lowercase|lower-roman|lower-alpha|loose|list-item|line|line-through|line-edge|lighter|left|keep-all|justify|italic|inter-word|inter-ideograph|inside|inset|inline|inline-block|inherit|inactive|ideograph-space|ideograph-parenthesis|ideograph-numeric|ideograph-alpha|horizontal|hidden|help|hand|groove|fixed|ellipsis|e-resize|double|dotted|distribute|distribute-space|distribute-letter|distribute-all-lines|disc|disabled|default|decimal|dashed|crosshair|collapse|col-resize|circle|char|center|capitalize|break-word|break-all|bottom|both|bolder|bold|block|bidi-override|below|baseline|auto|always|all-scroll|absolute|table|table-cell)\\b'
495 },
496 {
497 begin: ':',
498 end: ';',
499 contains: [
500 VARIABLE,
501 modes.HEXCOLOR,
502 hljs.CSS_NUMBER_MODE,
503 hljs.QUOTE_STRING_MODE,
504 hljs.APOS_STRING_MODE,
505 modes.IMPORTANT
506 ]
507 },
508 // matching these here allows us to treat them more like regular CSS
509 // rules so everything between the {} gets regular rule highlighting,
510 // which is what we want for page and font-face
511 {
512 begin: '@(page|font-face)',
513 lexemes: AT_IDENTIFIER,
514 keywords: '@page @font-face'
515 },
516 {
517 begin: '@',
518 end: '[{;]',
519 returnBegin: true,
520 keywords: {
521 $pattern: /[a-z-]+/,
522 keyword: AT_MODIFIERS,
523 attribute: MEDIA_FEATURES.join(" ")
524 },
525 contains: [
526 {
527 begin: AT_IDENTIFIER,
528 className: "keyword"
529 },
530 {
531 begin: /[a-z-]+(?=:)/,
532 className: "attribute"
533 },
534 VARIABLE,
535 hljs.QUOTE_STRING_MODE,
536 hljs.APOS_STRING_MODE,
537 modes.HEXCOLOR,
538 hljs.CSS_NUMBER_MODE
539 ]
540 }
541 ]
542 };
543}
544
545module.exports = scss;
Note: See TracBrowser for help on using the repository browser.