source: node_modules/highlight.js/lib/languages/stylus.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: Stylus
431Author: Bryant Williams <b.n.williams@gmail.com>
432Description: Stylus is an expressive, robust, feature-rich CSS language built for nodejs.
433Website: https://github.com/stylus/stylus
434Category: css
435*/
436
437/** @type LanguageFn */
438function stylus(hljs) {
439 const modes = MODES(hljs);
440
441 const AT_MODIFIERS = "and or not only";
442 const VARIABLE = {
443 className: 'variable',
444 begin: '\\$' + hljs.IDENT_RE
445 };
446
447 const AT_KEYWORDS = [
448 'charset',
449 'css',
450 'debug',
451 'extend',
452 'font-face',
453 'for',
454 'import',
455 'include',
456 'keyframes',
457 'media',
458 'mixin',
459 'page',
460 'warn',
461 'while'
462 ];
463
464 const LOOKAHEAD_TAG_END = '(?=[.\\s\\n[:,(])';
465
466 // illegals
467 const ILLEGAL = [
468 '\\?',
469 '(\\bReturn\\b)', // monkey
470 '(\\bEnd\\b)', // monkey
471 '(\\bend\\b)', // vbscript
472 '(\\bdef\\b)', // gradle
473 ';', // a whole lot of languages
474 '#\\s', // markdown
475 '\\*\\s', // markdown
476 '===\\s', // markdown
477 '\\|',
478 '%' // prolog
479 ];
480
481 return {
482 name: 'Stylus',
483 aliases: [ 'styl' ],
484 case_insensitive: false,
485 keywords: 'if else for in',
486 illegal: '(' + ILLEGAL.join('|') + ')',
487 contains: [
488
489 // strings
490 hljs.QUOTE_STRING_MODE,
491 hljs.APOS_STRING_MODE,
492
493 // comments
494 hljs.C_LINE_COMMENT_MODE,
495 hljs.C_BLOCK_COMMENT_MODE,
496
497 // hex colors
498 modes.HEXCOLOR,
499
500 // class tag
501 {
502 begin: '\\.[a-zA-Z][a-zA-Z0-9_-]*' + LOOKAHEAD_TAG_END,
503 className: 'selector-class'
504 },
505
506 // id tag
507 {
508 begin: '#[a-zA-Z][a-zA-Z0-9_-]*' + LOOKAHEAD_TAG_END,
509 className: 'selector-id'
510 },
511
512 // tags
513 {
514 begin: '\\b(' + TAGS.join('|') + ')' + LOOKAHEAD_TAG_END,
515 className: 'selector-tag'
516 },
517
518 // psuedo selectors
519 {
520 className: 'selector-pseudo',
521 begin: '&?:(' + PSEUDO_CLASSES.join('|') + ')' + LOOKAHEAD_TAG_END
522 },
523 {
524 className: 'selector-pseudo',
525 begin: '&?::(' + PSEUDO_ELEMENTS.join('|') + ')' + LOOKAHEAD_TAG_END
526 },
527
528 modes.ATTRIBUTE_SELECTOR_MODE,
529
530 {
531 className: "keyword",
532 begin: /@media/,
533 starts: {
534 end: /[{;}]/,
535 keywords: {
536 $pattern: /[a-z-]+/,
537 keyword: AT_MODIFIERS,
538 attribute: MEDIA_FEATURES.join(" ")
539 },
540 contains: [ hljs.CSS_NUMBER_MODE ]
541 }
542 },
543
544 // @ keywords
545 {
546 className: 'keyword',
547 begin: '\@((-(o|moz|ms|webkit)-)?(' + AT_KEYWORDS.join('|') + '))\\b'
548 },
549
550 // variables
551 VARIABLE,
552
553 // dimension
554 hljs.CSS_NUMBER_MODE,
555
556 // functions
557 // - only from beginning of line + whitespace
558 {
559 className: 'function',
560 begin: '^[a-zA-Z][a-zA-Z0-9_\-]*\\(.*\\)',
561 illegal: '[\\n]',
562 returnBegin: true,
563 contains: [
564 {
565 className: 'title',
566 begin: '\\b[a-zA-Z][a-zA-Z0-9_\-]*'
567 },
568 {
569 className: 'params',
570 begin: /\(/,
571 end: /\)/,
572 contains: [
573 modes.HEXCOLOR,
574 VARIABLE,
575 hljs.APOS_STRING_MODE,
576 hljs.CSS_NUMBER_MODE,
577 hljs.QUOTE_STRING_MODE
578 ]
579 }
580 ]
581 },
582
583 // attributes
584 // - only from beginning of line + whitespace
585 // - must have whitespace after it
586 {
587 className: 'attribute',
588 begin: '\\b(' + ATTRIBUTES.join('|') + ')\\b',
589 starts: {
590 // value container
591 end: /;|$/,
592 contains: [
593 modes.HEXCOLOR,
594 VARIABLE,
595 hljs.APOS_STRING_MODE,
596 hljs.QUOTE_STRING_MODE,
597 hljs.CSS_NUMBER_MODE,
598 hljs.C_BLOCK_COMMENT_MODE,
599 modes.IMPORTANT
600 ],
601 illegal: /\./,
602 relevance: 0
603 }
604 }
605 ]
606 };
607}
608
609module.exports = stylus;
Note: See TracBrowser for help on using the repository browser.