less.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. const MODES = (hljs) => {
  2. return {
  3. IMPORTANT: {
  4. scope: 'meta',
  5. begin: '!important'
  6. },
  7. BLOCK_COMMENT: hljs.C_BLOCK_COMMENT_MODE,
  8. HEXCOLOR: {
  9. scope: 'number',
  10. begin: /#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/
  11. },
  12. FUNCTION_DISPATCH: {
  13. className: "built_in",
  14. begin: /[\w-]+(?=\()/
  15. },
  16. ATTRIBUTE_SELECTOR_MODE: {
  17. scope: 'selector-attr',
  18. begin: /\[/,
  19. end: /\]/,
  20. illegal: '$',
  21. contains: [
  22. hljs.APOS_STRING_MODE,
  23. hljs.QUOTE_STRING_MODE
  24. ]
  25. },
  26. CSS_NUMBER_MODE: {
  27. scope: 'number',
  28. begin: hljs.NUMBER_RE + '(' +
  29. '%|em|ex|ch|rem' +
  30. '|vw|vh|vmin|vmax' +
  31. '|cm|mm|in|pt|pc|px' +
  32. '|deg|grad|rad|turn' +
  33. '|s|ms' +
  34. '|Hz|kHz' +
  35. '|dpi|dpcm|dppx' +
  36. ')?',
  37. relevance: 0
  38. },
  39. CSS_VARIABLE: {
  40. className: "attr",
  41. begin: /--[A-Za-z][A-Za-z0-9_-]*/
  42. }
  43. };
  44. };
  45. const TAGS = [
  46. 'a',
  47. 'abbr',
  48. 'address',
  49. 'article',
  50. 'aside',
  51. 'audio',
  52. 'b',
  53. 'blockquote',
  54. 'body',
  55. 'button',
  56. 'canvas',
  57. 'caption',
  58. 'cite',
  59. 'code',
  60. 'dd',
  61. 'del',
  62. 'details',
  63. 'dfn',
  64. 'div',
  65. 'dl',
  66. 'dt',
  67. 'em',
  68. 'fieldset',
  69. 'figcaption',
  70. 'figure',
  71. 'footer',
  72. 'form',
  73. 'h1',
  74. 'h2',
  75. 'h3',
  76. 'h4',
  77. 'h5',
  78. 'h6',
  79. 'header',
  80. 'hgroup',
  81. 'html',
  82. 'i',
  83. 'iframe',
  84. 'img',
  85. 'input',
  86. 'ins',
  87. 'kbd',
  88. 'label',
  89. 'legend',
  90. 'li',
  91. 'main',
  92. 'mark',
  93. 'menu',
  94. 'nav',
  95. 'object',
  96. 'ol',
  97. 'p',
  98. 'q',
  99. 'quote',
  100. 'samp',
  101. 'section',
  102. 'span',
  103. 'strong',
  104. 'summary',
  105. 'sup',
  106. 'table',
  107. 'tbody',
  108. 'td',
  109. 'textarea',
  110. 'tfoot',
  111. 'th',
  112. 'thead',
  113. 'time',
  114. 'tr',
  115. 'ul',
  116. 'var',
  117. 'video'
  118. ];
  119. const MEDIA_FEATURES = [
  120. 'any-hover',
  121. 'any-pointer',
  122. 'aspect-ratio',
  123. 'color',
  124. 'color-gamut',
  125. 'color-index',
  126. 'device-aspect-ratio',
  127. 'device-height',
  128. 'device-width',
  129. 'display-mode',
  130. 'forced-colors',
  131. 'grid',
  132. 'height',
  133. 'hover',
  134. 'inverted-colors',
  135. 'monochrome',
  136. 'orientation',
  137. 'overflow-block',
  138. 'overflow-inline',
  139. 'pointer',
  140. 'prefers-color-scheme',
  141. 'prefers-contrast',
  142. 'prefers-reduced-motion',
  143. 'prefers-reduced-transparency',
  144. 'resolution',
  145. 'scan',
  146. 'scripting',
  147. 'update',
  148. 'width',
  149. // TODO: find a better solution?
  150. 'min-width',
  151. 'max-width',
  152. 'min-height',
  153. 'max-height'
  154. ];
  155. // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
  156. const PSEUDO_CLASSES = [
  157. 'active',
  158. 'any-link',
  159. 'blank',
  160. 'checked',
  161. 'current',
  162. 'default',
  163. 'defined',
  164. 'dir', // dir()
  165. 'disabled',
  166. 'drop',
  167. 'empty',
  168. 'enabled',
  169. 'first',
  170. 'first-child',
  171. 'first-of-type',
  172. 'fullscreen',
  173. 'future',
  174. 'focus',
  175. 'focus-visible',
  176. 'focus-within',
  177. 'has', // has()
  178. 'host', // host or host()
  179. 'host-context', // host-context()
  180. 'hover',
  181. 'indeterminate',
  182. 'in-range',
  183. 'invalid',
  184. 'is', // is()
  185. 'lang', // lang()
  186. 'last-child',
  187. 'last-of-type',
  188. 'left',
  189. 'link',
  190. 'local-link',
  191. 'not', // not()
  192. 'nth-child', // nth-child()
  193. 'nth-col', // nth-col()
  194. 'nth-last-child', // nth-last-child()
  195. 'nth-last-col', // nth-last-col()
  196. 'nth-last-of-type', //nth-last-of-type()
  197. 'nth-of-type', //nth-of-type()
  198. 'only-child',
  199. 'only-of-type',
  200. 'optional',
  201. 'out-of-range',
  202. 'past',
  203. 'placeholder-shown',
  204. 'read-only',
  205. 'read-write',
  206. 'required',
  207. 'right',
  208. 'root',
  209. 'scope',
  210. 'target',
  211. 'target-within',
  212. 'user-invalid',
  213. 'valid',
  214. 'visited',
  215. 'where' // where()
  216. ];
  217. // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
  218. const PSEUDO_ELEMENTS = [
  219. 'after',
  220. 'backdrop',
  221. 'before',
  222. 'cue',
  223. 'cue-region',
  224. 'first-letter',
  225. 'first-line',
  226. 'grammar-error',
  227. 'marker',
  228. 'part',
  229. 'placeholder',
  230. 'selection',
  231. 'slotted',
  232. 'spelling-error'
  233. ];
  234. const ATTRIBUTES = [
  235. 'align-content',
  236. 'align-items',
  237. 'align-self',
  238. 'all',
  239. 'animation',
  240. 'animation-delay',
  241. 'animation-direction',
  242. 'animation-duration',
  243. 'animation-fill-mode',
  244. 'animation-iteration-count',
  245. 'animation-name',
  246. 'animation-play-state',
  247. 'animation-timing-function',
  248. 'backface-visibility',
  249. 'background',
  250. 'background-attachment',
  251. 'background-blend-mode',
  252. 'background-clip',
  253. 'background-color',
  254. 'background-image',
  255. 'background-origin',
  256. 'background-position',
  257. 'background-repeat',
  258. 'background-size',
  259. 'block-size',
  260. 'border',
  261. 'border-block',
  262. 'border-block-color',
  263. 'border-block-end',
  264. 'border-block-end-color',
  265. 'border-block-end-style',
  266. 'border-block-end-width',
  267. 'border-block-start',
  268. 'border-block-start-color',
  269. 'border-block-start-style',
  270. 'border-block-start-width',
  271. 'border-block-style',
  272. 'border-block-width',
  273. 'border-bottom',
  274. 'border-bottom-color',
  275. 'border-bottom-left-radius',
  276. 'border-bottom-right-radius',
  277. 'border-bottom-style',
  278. 'border-bottom-width',
  279. 'border-collapse',
  280. 'border-color',
  281. 'border-image',
  282. 'border-image-outset',
  283. 'border-image-repeat',
  284. 'border-image-slice',
  285. 'border-image-source',
  286. 'border-image-width',
  287. 'border-inline',
  288. 'border-inline-color',
  289. 'border-inline-end',
  290. 'border-inline-end-color',
  291. 'border-inline-end-style',
  292. 'border-inline-end-width',
  293. 'border-inline-start',
  294. 'border-inline-start-color',
  295. 'border-inline-start-style',
  296. 'border-inline-start-width',
  297. 'border-inline-style',
  298. 'border-inline-width',
  299. 'border-left',
  300. 'border-left-color',
  301. 'border-left-style',
  302. 'border-left-width',
  303. 'border-radius',
  304. 'border-right',
  305. 'border-right-color',
  306. 'border-right-style',
  307. 'border-right-width',
  308. 'border-spacing',
  309. 'border-style',
  310. 'border-top',
  311. 'border-top-color',
  312. 'border-top-left-radius',
  313. 'border-top-right-radius',
  314. 'border-top-style',
  315. 'border-top-width',
  316. 'border-width',
  317. 'bottom',
  318. 'box-decoration-break',
  319. 'box-shadow',
  320. 'box-sizing',
  321. 'break-after',
  322. 'break-before',
  323. 'break-inside',
  324. 'caption-side',
  325. 'caret-color',
  326. 'clear',
  327. 'clip',
  328. 'clip-path',
  329. 'clip-rule',
  330. 'color',
  331. 'column-count',
  332. 'column-fill',
  333. 'column-gap',
  334. 'column-rule',
  335. 'column-rule-color',
  336. 'column-rule-style',
  337. 'column-rule-width',
  338. 'column-span',
  339. 'column-width',
  340. 'columns',
  341. 'contain',
  342. 'content',
  343. 'content-visibility',
  344. 'counter-increment',
  345. 'counter-reset',
  346. 'cue',
  347. 'cue-after',
  348. 'cue-before',
  349. 'cursor',
  350. 'direction',
  351. 'display',
  352. 'empty-cells',
  353. 'filter',
  354. 'flex',
  355. 'flex-basis',
  356. 'flex-direction',
  357. 'flex-flow',
  358. 'flex-grow',
  359. 'flex-shrink',
  360. 'flex-wrap',
  361. 'float',
  362. 'flow',
  363. 'font',
  364. 'font-display',
  365. 'font-family',
  366. 'font-feature-settings',
  367. 'font-kerning',
  368. 'font-language-override',
  369. 'font-size',
  370. 'font-size-adjust',
  371. 'font-smoothing',
  372. 'font-stretch',
  373. 'font-style',
  374. 'font-synthesis',
  375. 'font-variant',
  376. 'font-variant-caps',
  377. 'font-variant-east-asian',
  378. 'font-variant-ligatures',
  379. 'font-variant-numeric',
  380. 'font-variant-position',
  381. 'font-variation-settings',
  382. 'font-weight',
  383. 'gap',
  384. 'glyph-orientation-vertical',
  385. 'grid',
  386. 'grid-area',
  387. 'grid-auto-columns',
  388. 'grid-auto-flow',
  389. 'grid-auto-rows',
  390. 'grid-column',
  391. 'grid-column-end',
  392. 'grid-column-start',
  393. 'grid-gap',
  394. 'grid-row',
  395. 'grid-row-end',
  396. 'grid-row-start',
  397. 'grid-template',
  398. 'grid-template-areas',
  399. 'grid-template-columns',
  400. 'grid-template-rows',
  401. 'hanging-punctuation',
  402. 'height',
  403. 'hyphens',
  404. 'icon',
  405. 'image-orientation',
  406. 'image-rendering',
  407. 'image-resolution',
  408. 'ime-mode',
  409. 'inline-size',
  410. 'isolation',
  411. 'justify-content',
  412. 'left',
  413. 'letter-spacing',
  414. 'line-break',
  415. 'line-height',
  416. 'list-style',
  417. 'list-style-image',
  418. 'list-style-position',
  419. 'list-style-type',
  420. 'margin',
  421. 'margin-block',
  422. 'margin-block-end',
  423. 'margin-block-start',
  424. 'margin-bottom',
  425. 'margin-inline',
  426. 'margin-inline-end',
  427. 'margin-inline-start',
  428. 'margin-left',
  429. 'margin-right',
  430. 'margin-top',
  431. 'marks',
  432. 'mask',
  433. 'mask-border',
  434. 'mask-border-mode',
  435. 'mask-border-outset',
  436. 'mask-border-repeat',
  437. 'mask-border-slice',
  438. 'mask-border-source',
  439. 'mask-border-width',
  440. 'mask-clip',
  441. 'mask-composite',
  442. 'mask-image',
  443. 'mask-mode',
  444. 'mask-origin',
  445. 'mask-position',
  446. 'mask-repeat',
  447. 'mask-size',
  448. 'mask-type',
  449. 'max-block-size',
  450. 'max-height',
  451. 'max-inline-size',
  452. 'max-width',
  453. 'min-block-size',
  454. 'min-height',
  455. 'min-inline-size',
  456. 'min-width',
  457. 'mix-blend-mode',
  458. 'nav-down',
  459. 'nav-index',
  460. 'nav-left',
  461. 'nav-right',
  462. 'nav-up',
  463. 'none',
  464. 'normal',
  465. 'object-fit',
  466. 'object-position',
  467. 'opacity',
  468. 'order',
  469. 'orphans',
  470. 'outline',
  471. 'outline-color',
  472. 'outline-offset',
  473. 'outline-style',
  474. 'outline-width',
  475. 'overflow',
  476. 'overflow-wrap',
  477. 'overflow-x',
  478. 'overflow-y',
  479. 'padding',
  480. 'padding-block',
  481. 'padding-block-end',
  482. 'padding-block-start',
  483. 'padding-bottom',
  484. 'padding-inline',
  485. 'padding-inline-end',
  486. 'padding-inline-start',
  487. 'padding-left',
  488. 'padding-right',
  489. 'padding-top',
  490. 'page-break-after',
  491. 'page-break-before',
  492. 'page-break-inside',
  493. 'pause',
  494. 'pause-after',
  495. 'pause-before',
  496. 'perspective',
  497. 'perspective-origin',
  498. 'pointer-events',
  499. 'position',
  500. 'quotes',
  501. 'resize',
  502. 'rest',
  503. 'rest-after',
  504. 'rest-before',
  505. 'right',
  506. 'row-gap',
  507. 'scroll-margin',
  508. 'scroll-margin-block',
  509. 'scroll-margin-block-end',
  510. 'scroll-margin-block-start',
  511. 'scroll-margin-bottom',
  512. 'scroll-margin-inline',
  513. 'scroll-margin-inline-end',
  514. 'scroll-margin-inline-start',
  515. 'scroll-margin-left',
  516. 'scroll-margin-right',
  517. 'scroll-margin-top',
  518. 'scroll-padding',
  519. 'scroll-padding-block',
  520. 'scroll-padding-block-end',
  521. 'scroll-padding-block-start',
  522. 'scroll-padding-bottom',
  523. 'scroll-padding-inline',
  524. 'scroll-padding-inline-end',
  525. 'scroll-padding-inline-start',
  526. 'scroll-padding-left',
  527. 'scroll-padding-right',
  528. 'scroll-padding-top',
  529. 'scroll-snap-align',
  530. 'scroll-snap-stop',
  531. 'scroll-snap-type',
  532. 'scrollbar-color',
  533. 'scrollbar-gutter',
  534. 'scrollbar-width',
  535. 'shape-image-threshold',
  536. 'shape-margin',
  537. 'shape-outside',
  538. 'speak',
  539. 'speak-as',
  540. 'src', // @font-face
  541. 'tab-size',
  542. 'table-layout',
  543. 'text-align',
  544. 'text-align-all',
  545. 'text-align-last',
  546. 'text-combine-upright',
  547. 'text-decoration',
  548. 'text-decoration-color',
  549. 'text-decoration-line',
  550. 'text-decoration-style',
  551. 'text-emphasis',
  552. 'text-emphasis-color',
  553. 'text-emphasis-position',
  554. 'text-emphasis-style',
  555. 'text-indent',
  556. 'text-justify',
  557. 'text-orientation',
  558. 'text-overflow',
  559. 'text-rendering',
  560. 'text-shadow',
  561. 'text-transform',
  562. 'text-underline-position',
  563. 'top',
  564. 'transform',
  565. 'transform-box',
  566. 'transform-origin',
  567. 'transform-style',
  568. 'transition',
  569. 'transition-delay',
  570. 'transition-duration',
  571. 'transition-property',
  572. 'transition-timing-function',
  573. 'unicode-bidi',
  574. 'vertical-align',
  575. 'visibility',
  576. 'voice-balance',
  577. 'voice-duration',
  578. 'voice-family',
  579. 'voice-pitch',
  580. 'voice-range',
  581. 'voice-rate',
  582. 'voice-stress',
  583. 'voice-volume',
  584. 'white-space',
  585. 'widows',
  586. 'width',
  587. 'will-change',
  588. 'word-break',
  589. 'word-spacing',
  590. 'word-wrap',
  591. 'writing-mode',
  592. 'z-index'
  593. // reverse makes sure longer attributes `font-weight` are matched fully
  594. // instead of getting false positives on say `font`
  595. ].reverse();
  596. // some grammars use them all as a single group
  597. const PSEUDO_SELECTORS = PSEUDO_CLASSES.concat(PSEUDO_ELEMENTS);
  598. /*
  599. Language: Less
  600. Description: It's CSS, with just a little more.
  601. Author: Max Mikhailov <seven.phases.max@gmail.com>
  602. Website: http://lesscss.org
  603. Category: common, css, web
  604. */
  605. /** @type LanguageFn */
  606. function less(hljs) {
  607. const modes = MODES(hljs);
  608. const PSEUDO_SELECTORS$1 = PSEUDO_SELECTORS;
  609. const AT_MODIFIERS = "and or not only";
  610. const IDENT_RE = '[\\w-]+'; // yes, Less identifiers may begin with a digit
  611. const INTERP_IDENT_RE = '(' + IDENT_RE + '|@\\{' + IDENT_RE + '\\})';
  612. /* Generic Modes */
  613. const RULES = []; const VALUE_MODES = []; // forward def. for recursive modes
  614. const STRING_MODE = function(c) {
  615. return {
  616. // Less strings are not multiline (also include '~' for more consistent coloring of "escaped" strings)
  617. className: 'string',
  618. begin: '~?' + c + '.*?' + c
  619. };
  620. };
  621. const IDENT_MODE = function(name, begin, relevance) {
  622. return {
  623. className: name,
  624. begin: begin,
  625. relevance: relevance
  626. };
  627. };
  628. const AT_KEYWORDS = {
  629. $pattern: /[a-z-]+/,
  630. keyword: AT_MODIFIERS,
  631. attribute: MEDIA_FEATURES.join(" ")
  632. };
  633. const PARENS_MODE = {
  634. // used only to properly balance nested parens inside mixin call, def. arg list
  635. begin: '\\(',
  636. end: '\\)',
  637. contains: VALUE_MODES,
  638. keywords: AT_KEYWORDS,
  639. relevance: 0
  640. };
  641. // generic Less highlighter (used almost everywhere except selectors):
  642. VALUE_MODES.push(
  643. hljs.C_LINE_COMMENT_MODE,
  644. hljs.C_BLOCK_COMMENT_MODE,
  645. STRING_MODE("'"),
  646. STRING_MODE('"'),
  647. modes.CSS_NUMBER_MODE, // fixme: it does not include dot for numbers like .5em :(
  648. {
  649. begin: '(url|data-uri)\\(',
  650. starts: {
  651. className: 'string',
  652. end: '[\\)\\n]',
  653. excludeEnd: true
  654. }
  655. },
  656. modes.HEXCOLOR,
  657. PARENS_MODE,
  658. IDENT_MODE('variable', '@@?' + IDENT_RE, 10),
  659. IDENT_MODE('variable', '@\\{' + IDENT_RE + '\\}'),
  660. IDENT_MODE('built_in', '~?`[^`]*?`'), // inline javascript (or whatever host language) *multiline* string
  661. { // @media features (it’s here to not duplicate things in AT_RULE_MODE with extra PARENS_MODE overriding):
  662. className: 'attribute',
  663. begin: IDENT_RE + '\\s*:',
  664. end: ':',
  665. returnBegin: true,
  666. excludeEnd: true
  667. },
  668. modes.IMPORTANT,
  669. { beginKeywords: 'and not' },
  670. modes.FUNCTION_DISPATCH
  671. );
  672. const VALUE_WITH_RULESETS = VALUE_MODES.concat({
  673. begin: /\{/,
  674. end: /\}/,
  675. contains: RULES
  676. });
  677. const MIXIN_GUARD_MODE = {
  678. beginKeywords: 'when',
  679. endsWithParent: true,
  680. contains: [ { beginKeywords: 'and not' } ].concat(VALUE_MODES) // using this form to override VALUE’s 'function' match
  681. };
  682. /* Rule-Level Modes */
  683. const RULE_MODE = {
  684. begin: INTERP_IDENT_RE + '\\s*:',
  685. returnBegin: true,
  686. end: /[;}]/,
  687. relevance: 0,
  688. contains: [
  689. { begin: /-(webkit|moz|ms|o)-/ },
  690. modes.CSS_VARIABLE,
  691. {
  692. className: 'attribute',
  693. begin: '\\b(' + ATTRIBUTES.join('|') + ')\\b',
  694. end: /(?=:)/,
  695. starts: {
  696. endsWithParent: true,
  697. illegal: '[<=$]',
  698. relevance: 0,
  699. contains: VALUE_MODES
  700. }
  701. }
  702. ]
  703. };
  704. const AT_RULE_MODE = {
  705. className: 'keyword',
  706. begin: '@(import|media|charset|font-face|(-[a-z]+-)?keyframes|supports|document|namespace|page|viewport|host)\\b',
  707. starts: {
  708. end: '[;{}]',
  709. keywords: AT_KEYWORDS,
  710. returnEnd: true,
  711. contains: VALUE_MODES,
  712. relevance: 0
  713. }
  714. };
  715. // variable definitions and calls
  716. const VAR_RULE_MODE = {
  717. className: 'variable',
  718. variants: [
  719. // using more strict pattern for higher relevance to increase chances of Less detection.
  720. // this is *the only* Less specific statement used in most of the sources, so...
  721. // (we’ll still often loose to the css-parser unless there's '//' comment,
  722. // simply because 1 variable just can't beat 99 properties :)
  723. {
  724. begin: '@' + IDENT_RE + '\\s*:',
  725. relevance: 15
  726. },
  727. { begin: '@' + IDENT_RE }
  728. ],
  729. starts: {
  730. end: '[;}]',
  731. returnEnd: true,
  732. contains: VALUE_WITH_RULESETS
  733. }
  734. };
  735. const SELECTOR_MODE = {
  736. // first parse unambiguous selectors (i.e. those not starting with tag)
  737. // then fall into the scary lookahead-discriminator variant.
  738. // this mode also handles mixin definitions and calls
  739. variants: [
  740. {
  741. begin: '[\\.#:&\\[>]',
  742. end: '[;{}]' // mixin calls end with ';'
  743. },
  744. {
  745. begin: INTERP_IDENT_RE,
  746. end: /\{/
  747. }
  748. ],
  749. returnBegin: true,
  750. returnEnd: true,
  751. illegal: '[<=\'$"]',
  752. relevance: 0,
  753. contains: [
  754. hljs.C_LINE_COMMENT_MODE,
  755. hljs.C_BLOCK_COMMENT_MODE,
  756. MIXIN_GUARD_MODE,
  757. IDENT_MODE('keyword', 'all\\b'),
  758. IDENT_MODE('variable', '@\\{' + IDENT_RE + '\\}'), // otherwise it’s identified as tag
  759. {
  760. begin: '\\b(' + TAGS.join('|') + ')\\b',
  761. className: 'selector-tag'
  762. },
  763. modes.CSS_NUMBER_MODE,
  764. IDENT_MODE('selector-tag', INTERP_IDENT_RE, 0),
  765. IDENT_MODE('selector-id', '#' + INTERP_IDENT_RE),
  766. IDENT_MODE('selector-class', '\\.' + INTERP_IDENT_RE, 0),
  767. IDENT_MODE('selector-tag', '&', 0),
  768. modes.ATTRIBUTE_SELECTOR_MODE,
  769. {
  770. className: 'selector-pseudo',
  771. begin: ':(' + PSEUDO_CLASSES.join('|') + ')'
  772. },
  773. {
  774. className: 'selector-pseudo',
  775. begin: ':(:)?(' + PSEUDO_ELEMENTS.join('|') + ')'
  776. },
  777. {
  778. begin: /\(/,
  779. end: /\)/,
  780. relevance: 0,
  781. contains: VALUE_WITH_RULESETS
  782. }, // argument list of parametric mixins
  783. { begin: '!important' }, // eat !important after mixin call or it will be colored as tag
  784. modes.FUNCTION_DISPATCH
  785. ]
  786. };
  787. const PSEUDO_SELECTOR_MODE = {
  788. begin: IDENT_RE + ':(:)?' + `(${PSEUDO_SELECTORS$1.join('|')})`,
  789. returnBegin: true,
  790. contains: [ SELECTOR_MODE ]
  791. };
  792. RULES.push(
  793. hljs.C_LINE_COMMENT_MODE,
  794. hljs.C_BLOCK_COMMENT_MODE,
  795. AT_RULE_MODE,
  796. VAR_RULE_MODE,
  797. PSEUDO_SELECTOR_MODE,
  798. RULE_MODE,
  799. SELECTOR_MODE,
  800. MIXIN_GUARD_MODE,
  801. modes.FUNCTION_DISPATCH
  802. );
  803. return {
  804. name: 'Less',
  805. case_insensitive: true,
  806. illegal: '[=>\'/<($"]',
  807. contains: RULES
  808. };
  809. }
  810. export { less as default };