]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/less.js
1 /*! `less` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
6 const MODES
= (hljs
) => {
12 BLOCK_COMMENT: hljs
.C_BLOCK_COMMENT_MODE
,
15 begin: /#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/
18 className: "built_in",
21 ATTRIBUTE_SELECTOR_MODE: {
22 scope: 'selector-attr',
27 hljs
.APOS_STRING_MODE
,
28 hljs
.QUOTE_STRING_MODE
33 begin: hljs
.NUMBER_RE
+ '(' +
36 '|cm|mm|in|pt|pc|px' +
37 '|deg|grad|rad|turn' +
46 begin: /--[A-Za-z_][A-Za-z0-9_-]*/
142 'feComponentTransfer',
153 'feSpecularLighting',
180 // Sorting, then reversing makes sure longer attributes/elements like
181 // `font-weight` are matched fully instead of getting false positives on say `font`
183 const MEDIA_FEATURES
= [
190 'device-aspect-ratio',
204 'prefers-color-scheme',
206 'prefers-reduced-motion',
207 'prefers-reduced-transparency',
213 // TODO: find a better solution?
220 // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
221 const PSEUDO_CLASSES
= [
243 'host', // host or host()
244 'host-context', // host-context()
257 'nth-child', // nth-child()
258 'nth-col', // nth-col()
259 'nth-last-child', // nth-last-child()
260 'nth-last-col', // nth-last-col()
261 'nth-last-of-type', //nth-last-of-type()
262 'nth-of-type', //nth-of-type()
283 // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
284 const PSEUDO_ELEMENTS
= [
306 'alignment-baseline',
310 'animation-composition',
312 'animation-direction',
313 'animation-duration',
314 'animation-fill-mode',
315 'animation-iteration-count',
317 'animation-play-state',
319 'animation-range-end',
320 'animation-range-start',
321 'animation-timeline',
322 'animation-timing-function',
326 'backface-visibility',
328 'background-attachment',
329 'background-blend-mode',
334 'background-position',
335 'background-position-x',
336 'background-position-y',
343 'border-block-color',
345 'border-block-end-color',
346 'border-block-end-style',
347 'border-block-end-width',
348 'border-block-start',
349 'border-block-start-color',
350 'border-block-start-style',
351 'border-block-start-width',
352 'border-block-style',
353 'border-block-width',
355 'border-bottom-color',
356 'border-bottom-left-radius',
357 'border-bottom-right-radius',
358 'border-bottom-style',
359 'border-bottom-width',
362 'border-end-end-radius',
363 'border-end-start-radius',
365 'border-image-outset',
366 'border-image-repeat',
367 'border-image-slice',
368 'border-image-source',
369 'border-image-width',
371 'border-inline-color',
373 'border-inline-end-color',
374 'border-inline-end-style',
375 'border-inline-end-width',
376 'border-inline-start',
377 'border-inline-start-color',
378 'border-inline-start-style',
379 'border-inline-start-width',
380 'border-inline-style',
381 'border-inline-width',
388 'border-right-color',
389 'border-right-style',
390 'border-right-width',
392 'border-start-end-radius',
393 'border-start-start-radius',
397 'border-top-left-radius',
398 'border-top-right-radius',
404 'box-decoration-break',
424 'color-interpolation',
425 'color-interpolation-filters',
440 'contain-intrinsic-block-size',
441 'contain-intrinsic-height',
442 'contain-intrinsic-inline-size',
443 'contain-intrinsic-size',
444 'contain-intrinsic-width',
449 'content-visibility',
483 'font-feature-settings',
485 'font-language-override',
486 'font-optical-sizing',
495 'font-synthesis-position',
496 'font-synthesis-small-caps',
497 'font-synthesis-style',
498 'font-synthesis-weight',
500 'font-variant-alternates',
502 'font-variant-east-asian',
503 'font-variant-emoji',
504 'font-variant-ligatures',
505 'font-variant-numeric',
506 'font-variant-position',
507 'font-variation-settings',
509 'forced-color-adjust',
511 'glyph-orientation-horizontal',
512 'glyph-orientation-vertical',
526 'grid-template-areas',
527 'grid-template-columns',
528 'grid-template-rows',
529 'hanging-punctuation',
531 'hyphenate-character',
532 'hyphenate-limit-chars',
540 'initial-letter-align',
549 'inset-inline-start',
563 'list-style-position',
568 'margin-block-start',
572 'margin-inline-start',
585 'mask-border-outset',
586 'mask-border-repeat',
588 'mask-border-source',
638 'overflow-clip-margin',
644 'overscroll-behavior',
645 'overscroll-behavior-block',
646 'overscroll-behavior-inline',
647 'overscroll-behavior-x',
648 'overscroll-behavior-y',
652 'padding-block-start',
655 'padding-inline-end',
656 'padding-inline-start',
669 'perspective-origin',
676 'position-visibility',
677 'print-color-adjust',
692 'scroll-margin-block',
693 'scroll-margin-block-end',
694 'scroll-margin-block-start',
695 'scroll-margin-bottom',
696 'scroll-margin-inline',
697 'scroll-margin-inline-end',
698 'scroll-margin-inline-start',
699 'scroll-margin-left',
700 'scroll-margin-right',
703 'scroll-padding-block',
704 'scroll-padding-block-end',
705 'scroll-padding-block-start',
706 'scroll-padding-bottom',
707 'scroll-padding-inline',
708 'scroll-padding-inline-end',
709 'scroll-padding-inline-start',
710 'scroll-padding-left',
711 'scroll-padding-right',
712 'scroll-padding-top',
717 'scroll-timeline-axis',
718 'scroll-timeline-name',
722 'shape-image-threshold',
745 'text-combine-upright',
747 'text-decoration-color',
748 'text-decoration-line',
749 'text-decoration-skip',
750 'text-decoration-skip-ink',
751 'text-decoration-style',
752 'text-decoration-thickness',
754 'text-emphasis-color',
755 'text-emphasis-position',
756 'text-emphasis-style',
765 'text-underline-offset',
766 'text-underline-position',
778 'transition-behavior',
780 'transition-duration',
781 'transition-property',
782 'transition-timing-function',
790 'view-timeline-axis',
791 'view-timeline-inset',
792 'view-timeline-name',
793 'view-transition-name',
804 'white-space-collapse',
818 // some grammars use them all as a single group
819 const PSEUDO_SELECTORS
= PSEUDO_CLASSES
.concat(PSEUDO_ELEMENTS
).sort().reverse();
823 Description: It's CSS, with just a little more.
824 Author: Max Mikhailov <seven.phases.max@gmail.com>
825 Website: http://lesscss.org
826 Category: common, css, web
830 /** @type LanguageFn */
831 function less(hljs
) {
832 const modes
= MODES(hljs
);
833 const PSEUDO_SELECTORS
$1 = PSEUDO_SELECTORS
;
835 const AT_MODIFIERS
= "and or not only";
836 const IDENT_RE
= '[\\w-]+'; // yes, Less identifiers may begin with a digit
837 const INTERP_IDENT_RE
= '(' + IDENT_RE
+ '|@\\{' + IDENT_RE
+ '\\})';
841 const RULES
= []; const VALUE_MODES
= []; // forward def. for recursive modes
843 const STRING_MODE = function(c
) {
845 // Less strings are not multiline (also include '~' for more consistent coloring of "escaped" strings)
847 begin: '~?' + c
+ '.*?' + c
851 const IDENT_MODE = function(name
, begin
, relevance
) {
859 const AT_KEYWORDS
= {
861 keyword: AT_MODIFIERS
,
862 attribute: MEDIA_FEATURES
.join(" ")
865 const PARENS_MODE
= {
866 // used only to properly balance nested parens inside mixin call, def. arg list
869 contains: VALUE_MODES
,
870 keywords: AT_KEYWORDS
,
874 // generic Less highlighter (used almost everywhere except selectors):
876 hljs
.C_LINE_COMMENT_MODE
,
877 hljs
.C_BLOCK_COMMENT_MODE
,
880 modes
.CSS_NUMBER_MODE
, // fixme: it does not include dot for numbers like .5em :(
882 begin: '(url|data-uri)\\(',
891 IDENT_MODE('variable', '@@?' + IDENT_RE
, 10),
892 IDENT_MODE('variable', '@\\{' + IDENT_RE
+ '\\}'),
893 IDENT_MODE('built_in', '~?`[^`]*?`'), // inline javascript (or whatever host language) *multiline* string
894 { // @media features (it’s here to not duplicate things in AT_RULE_MODE with extra PARENS_MODE overriding):
895 className: 'attribute',
896 begin: IDENT_RE
+ '\\s*:',
902 { beginKeywords: 'and not' },
903 modes
.FUNCTION_DISPATCH
906 const VALUE_WITH_RULESETS
= VALUE_MODES
.concat({
912 const MIXIN_GUARD_MODE
= {
913 beginKeywords: 'when',
914 endsWithParent: true,
915 contains: [ { beginKeywords: 'and not' } ].concat(VALUE_MODES
) // using this form to override VALUE’s 'function' match
918 /* Rule-Level Modes */
921 begin: INTERP_IDENT_RE
+ '\\s*:',
926 { begin: /-(webkit|moz|ms|o)-/ },
929 className: 'attribute',
930 begin: '\\b(' + ATTRIBUTES
.join('|') + ')\\b',
933 endsWithParent: true,
936 contains: VALUE_MODES
942 const AT_RULE_MODE
= {
943 className: 'keyword',
944 begin: '@(import|media|charset|font-face|(-[a-z]+-)?keyframes|supports|document|namespace|page|viewport|host)\\b',
947 keywords: AT_KEYWORDS
,
949 contains: VALUE_MODES
,
954 // variable definitions and calls
955 const VAR_RULE_MODE
= {
956 className: 'variable',
958 // using more strict pattern for higher relevance to increase chances of Less detection.
959 // this is *the only* Less specific statement used in most of the sources, so...
960 // (we’ll still often loose to the css-parser unless there's '//' comment,
961 // simply because 1 variable just can't beat 99 properties :)
963 begin: '@' + IDENT_RE
+ '\\s*:',
966 { begin: '@' + IDENT_RE
}
971 contains: VALUE_WITH_RULESETS
975 const SELECTOR_MODE
= {
976 // first parse unambiguous selectors (i.e. those not starting with tag)
977 // then fall into the scary lookahead-discriminator variant.
978 // this mode also handles mixin definitions and calls
981 begin: '[\\.#:&\\[>]',
982 end: '[;{}]' // mixin calls end with ';'
985 begin: INTERP_IDENT_RE
,
994 hljs
.C_LINE_COMMENT_MODE
,
995 hljs
.C_BLOCK_COMMENT_MODE
,
997 IDENT_MODE('keyword', 'all\\b'),
998 IDENT_MODE('variable', '@\\{' + IDENT_RE
+ '\\}'), // otherwise it’s identified as tag
1001 begin: '\\b(' + TAGS
.join('|') + ')\\b',
1002 className: 'selector-tag'
1004 modes
.CSS_NUMBER_MODE
,
1005 IDENT_MODE('selector-tag', INTERP_IDENT_RE
, 0),
1006 IDENT_MODE('selector-id', '#' + INTERP_IDENT_RE
),
1007 IDENT_MODE('selector-class', '\\.' + INTERP_IDENT_RE
, 0),
1008 IDENT_MODE('selector-tag', '&', 0),
1009 modes
.ATTRIBUTE_SELECTOR_MODE
,
1011 className: 'selector-pseudo',
1012 begin: ':(' + PSEUDO_CLASSES
.join('|') + ')'
1015 className: 'selector-pseudo',
1016 begin: ':(:)?(' + PSEUDO_ELEMENTS
.join('|') + ')'
1022 contains: VALUE_WITH_RULESETS
1023 }, // argument list of parametric mixins
1024 { begin: '!important' }, // eat !important after mixin call or it will be colored as tag
1025 modes
.FUNCTION_DISPATCH
1029 const PSEUDO_SELECTOR_MODE
= {
1030 begin: IDENT_RE
+ ':(:)?' + `(${PSEUDO_SELECTORS$1.join('|')})`,
1032 contains: [ SELECTOR_MODE
]
1036 hljs
.C_LINE_COMMENT_MODE
,
1037 hljs
.C_BLOCK_COMMENT_MODE
,
1040 PSEUDO_SELECTOR_MODE
,
1044 modes
.FUNCTION_DISPATCH
1049 case_insensitive: true,
1050 illegal: '[=>\'/<($"]',
1059 hljs
.registerLanguage('less', hljsGrammar
);