css_highlight_rules.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. define(function(require, exports, module) {
  31. "use strict";
  32. var oop = require("../lib/oop");
  33. var lang = require("../lib/lang");
  34. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  35. /* Exports are for Stylus and Less highlighters */
  36. var supportType = exports.supportType = "align-content|align-items|align-self|all|animation|animation-delay|animation-direction|animation-duration|animation-fill-mode|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|backface-visibility|background|background-attachment|background-blend-mode|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|border|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|bottom|box-shadow|box-sizing|caption-side|clear|clip|color|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|column-span|column-width|columns|content|counter-increment|counter-reset|cursor|direction|display|empty-cells|filter|flex|flex-basis|flex-direction|flex-flow|flex-grow|flex-shrink|flex-wrap|float|font|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|hanging-punctuation|height|justify-content|left|letter-spacing|line-height|list-style|list-style-image|list-style-position|list-style-type|margin|margin-bottom|margin-left|margin-right|margin-top|max-height|max-width|min-height|min-width|nav-down|nav-index|nav-left|nav-right|nav-up|opacity|order|outline|outline-color|outline-offset|outline-style|outline-width|overflow|overflow-x|overflow-y|padding|padding-bottom|padding-left|padding-right|padding-top|page-break-after|page-break-before|page-break-inside|perspective|perspective-origin|position|quotes|resize|right|tab-size|table-layout|text-align|text-align-last|text-decoration|text-decoration-color|text-decoration-line|text-decoration-style|text-indent|text-justify|text-overflow|text-shadow|text-transform|top|transform|transform-origin|transform-style|transition|transition-delay|transition-duration|transition-property|transition-timing-function|unicode-bidi|vertical-align|visibility|white-space|width|word-break|word-spacing|word-wrap|z-index";
  37. var supportFunction = exports.supportFunction = "rgb|rgba|url|attr|counter|counters";
  38. var supportConstant = exports.supportConstant = "absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero";
  39. var supportConstantColor = exports.supportConstantColor = "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow";
  40. var supportConstantFonts = exports.supportConstantFonts = "arial|century|comic|courier|cursive|fantasy|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace";
  41. var numRe = exports.numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
  42. var pseudoElements = exports.pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b";
  43. var pseudoClasses = exports.pseudoClasses = "(:)\\b(active|checked|disabled|empty|enabled|first-child|first-of-type|focus|hover|indeterminate|invalid|last-child|last-of-type|link|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|only-child|only-of-type|required|root|target|valid|visited)\\b";
  44. var CssHighlightRules = function() {
  45. var keywordMapper = this.createKeywordMapper({
  46. "support.function": supportFunction,
  47. "support.constant": supportConstant,
  48. "support.type": supportType,
  49. "support.constant.color": supportConstantColor,
  50. "support.constant.fonts": supportConstantFonts
  51. }, "text", true);
  52. // regexp must not have capturing parentheses. Use (?:) instead.
  53. // regexps are ordered -> the first match is used
  54. this.$rules = {
  55. "start" : [{
  56. token : "comment", // multi line comment
  57. regex : "\\/\\*",
  58. push : "comment"
  59. }, {
  60. token: "paren.lparen",
  61. regex: "\\{",
  62. push: "ruleset"
  63. }, {
  64. token: "string",
  65. regex: "@.*?{",
  66. push: "media"
  67. }, {
  68. token: "keyword",
  69. regex: "#[a-z0-9-_]+"
  70. }, {
  71. token: "variable",
  72. regex: "\\.[a-z0-9-_]+"
  73. }, {
  74. token: "string",
  75. regex: ":[a-z0-9-_]+"
  76. }, {
  77. token: "constant",
  78. regex: "[a-z0-9-_]+"
  79. }, {
  80. caseInsensitive: true
  81. }],
  82. "media" : [{
  83. token : "comment", // multi line comment
  84. regex : "\\/\\*",
  85. push : "comment"
  86. }, {
  87. token: "paren.lparen",
  88. regex: "\\{",
  89. push: "ruleset"
  90. }, {
  91. token: "string",
  92. regex: "\\}",
  93. next: "pop"
  94. }, {
  95. token: "keyword",
  96. regex: "#[a-z0-9-_]+"
  97. }, {
  98. token: "variable",
  99. regex: "\\.[a-z0-9-_]+"
  100. }, {
  101. token: "string",
  102. regex: ":[a-z0-9-_]+"
  103. }, {
  104. token: "constant",
  105. regex: "[a-z0-9-_]+"
  106. }, {
  107. caseInsensitive: true
  108. }],
  109. "comment" : [{
  110. token : "comment",
  111. regex : "\\*\\/",
  112. next : "pop"
  113. }, {
  114. defaultToken : "comment"
  115. }],
  116. "ruleset" : [
  117. {
  118. token : "paren.rparen",
  119. regex : "\\}",
  120. next: "pop"
  121. }, {
  122. token : "comment", // multi line comment
  123. regex : "\\/\\*",
  124. push : "comment"
  125. }, {
  126. token : "string", // single line
  127. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  128. }, {
  129. token : "string", // single line
  130. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  131. }, {
  132. token : ["constant.numeric", "keyword"],
  133. regex : "(" + numRe + ")(ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vm|vw|%)"
  134. }, {
  135. token : "constant.numeric",
  136. regex : numRe
  137. }, {
  138. token : "constant.numeric", // hex6 color
  139. regex : "#[a-f0-9]{6}"
  140. }, {
  141. token : "constant.numeric", // hex3 color
  142. regex : "#[a-f0-9]{3}"
  143. }, {
  144. token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
  145. regex : pseudoElements
  146. }, {
  147. token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
  148. regex : pseudoClasses
  149. }, {
  150. token : ["support.function", "string", "support.function"],
  151. regex : "(url\\()(.*)(\\))"
  152. }, {
  153. token : keywordMapper,
  154. regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  155. }, {
  156. caseInsensitive: true
  157. }]
  158. };
  159. this.normalizeRules();
  160. };
  161. oop.inherits(CssHighlightRules, TextHighlightRules);
  162. exports.CssHighlightRules = CssHighlightRules;
  163. });