prism-stylus.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. (function (Prism) {
  2. var unit = {
  3. pattern: /(\b\d+)(?:%|[a-z]+)/,
  4. lookbehind: true
  5. };
  6. // 123 -123 .123 -.123 12.3 -12.3
  7. var number = {
  8. pattern: /(^|[^\w.-])-?(?:\d+(?:\.\d+)?|\.\d+)/,
  9. lookbehind: true
  10. };
  11. var inside = {
  12. 'comment': {
  13. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  14. lookbehind: true
  15. },
  16. 'url': {
  17. pattern: /\burl\((["']?).*?\1\)/i,
  18. greedy: true
  19. },
  20. 'string': {
  21. pattern: /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,
  22. greedy: true
  23. },
  24. 'interpolation': null, // See below
  25. 'func': null, // See below
  26. 'important': /\B!(?:important|optional)\b/i,
  27. 'keyword': {
  28. pattern: /(^|\s+)(?:(?:else|for|if|return|unless)(?=\s|$)|@[\w-]+)/,
  29. lookbehind: true
  30. },
  31. 'hexcode': /#[\da-f]{3,6}/i,
  32. 'color': [
  33. /\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i,
  34. {
  35. pattern: /\b(?:hsl|rgb)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:hsl|rgb)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,
  36. inside: {
  37. 'unit': unit,
  38. 'number': number,
  39. 'function': /[\w-]+(?=\()/,
  40. 'punctuation': /[(),]/
  41. }
  42. }
  43. ],
  44. 'entity': /\\[\da-f]{1,8}/i,
  45. 'unit': unit,
  46. 'boolean': /\b(?:false|true)\b/,
  47. 'operator': [
  48. // We want non-word chars around "-" because it is
  49. // accepted in property names.
  50. /~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.{2,3}|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/
  51. ],
  52. 'number': number,
  53. 'punctuation': /[{}()\[\];:,]/
  54. };
  55. inside['interpolation'] = {
  56. pattern: /\{[^\r\n}:]+\}/,
  57. alias: 'variable',
  58. inside: {
  59. 'delimiter': {
  60. pattern: /^\{|\}$/,
  61. alias: 'punctuation'
  62. },
  63. rest: inside
  64. }
  65. };
  66. inside['func'] = {
  67. pattern: /[\w-]+\([^)]*\).*/,
  68. inside: {
  69. 'function': /^[^(]+/,
  70. rest: inside
  71. }
  72. };
  73. Prism.languages.stylus = {
  74. 'atrule-declaration': {
  75. pattern: /(^[ \t]*)@.+/m,
  76. lookbehind: true,
  77. inside: {
  78. 'atrule': /^@[\w-]+/,
  79. rest: inside
  80. }
  81. },
  82. 'variable-declaration': {
  83. pattern: /(^[ \t]*)[\w$-]+\s*.?=[ \t]*(?:\{[^{}]*\}|\S.*|$)/m,
  84. lookbehind: true,
  85. inside: {
  86. 'variable': /^\S+/,
  87. rest: inside
  88. }
  89. },
  90. 'statement': {
  91. pattern: /(^[ \t]*)(?:else|for|if|return|unless)[ \t].+/m,
  92. lookbehind: true,
  93. inside: {
  94. 'keyword': /^\S+/,
  95. rest: inside
  96. }
  97. },
  98. // A property/value pair cannot end with a comma or a brace
  99. // It cannot have indented content unless it ended with a semicolon
  100. 'property-declaration': {
  101. pattern: /((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)(?!\s)[^{\r\n]*(?:;|[^{\r\n,]$(?!(?:\r?\n|\r)(?:\{|\2[ \t])))/m,
  102. lookbehind: true,
  103. inside: {
  104. 'property': {
  105. pattern: /^[^\s:]+/,
  106. inside: {
  107. 'interpolation': inside.interpolation
  108. }
  109. },
  110. rest: inside
  111. }
  112. },
  113. // A selector can contain parentheses only as part of a pseudo-element
  114. // It can span multiple lines.
  115. // It must end with a comma or an accolade or have indented content.
  116. 'selector': {
  117. pattern: /(^[ \t]*)(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\)|(?![\w-]))|\{[^}\r\n]+\})+)(?:(?:\r?\n|\r)(?:\1(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\)|(?![\w-]))|\{[^}\r\n]+\})+)))*(?:,$|\{|(?=(?:\r?\n|\r)(?:\{|\1[ \t])))/m,
  118. lookbehind: true,
  119. inside: {
  120. 'interpolation': inside.interpolation,
  121. 'comment': inside.comment,
  122. 'punctuation': /[{},]/
  123. }
  124. },
  125. 'func': inside.func,
  126. 'string': inside.string,
  127. 'comment': {
  128. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  129. lookbehind: true,
  130. greedy: true
  131. },
  132. 'interpolation': inside.interpolation,
  133. 'punctuation': /[{}()\[\];:.]/
  134. };
  135. }(Prism));