prism-css-extras.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. (function (Prism) {
  2. var string = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
  3. var selectorInside;
  4. Prism.languages.css.selector = {
  5. pattern: Prism.languages.css.selector,
  6. inside: selectorInside = {
  7. 'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,
  8. 'pseudo-class': /:[-\w]+/,
  9. 'class': /\.[-\w]+/,
  10. 'id': /#[-\w]+/,
  11. 'attribute': {
  12. pattern: RegExp('\\[(?:[^[\\]"\']|' + string.source + ')*\\]'),
  13. greedy: true,
  14. inside: {
  15. 'punctuation': /^\[|\]$/,
  16. 'case-sensitivity': {
  17. pattern: /(\s)[si]$/i,
  18. lookbehind: true,
  19. alias: 'keyword'
  20. },
  21. 'namespace': {
  22. pattern: /^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,
  23. lookbehind: true,
  24. inside: {
  25. 'punctuation': /\|$/
  26. }
  27. },
  28. 'attr-name': {
  29. pattern: /^(\s*)[-\w\xA0-\uFFFF]+/,
  30. lookbehind: true
  31. },
  32. 'attr-value': [
  33. string,
  34. {
  35. pattern: /(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,
  36. lookbehind: true
  37. }
  38. ],
  39. 'operator': /[|~*^$]?=/
  40. }
  41. },
  42. 'n-th': [
  43. {
  44. pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,
  45. lookbehind: true,
  46. inside: {
  47. 'number': /[\dn]+/,
  48. 'operator': /[+-]/
  49. }
  50. },
  51. {
  52. pattern: /(\(\s*)(?:even|odd)(?=\s*\))/i,
  53. lookbehind: true
  54. }
  55. ],
  56. 'combinator': />|\+|~|\|\|/,
  57. // the `tag` token has been existed and removed.
  58. // because we can't find a perfect tokenize to match it.
  59. // if you want to add it, please read https://github.com/PrismJS/prism/pull/2373 first.
  60. 'punctuation': /[(),]/,
  61. }
  62. };
  63. Prism.languages.css['atrule'].inside['selector-function-argument'].inside = selectorInside;
  64. Prism.languages.insertBefore('css', 'property', {
  65. 'variable': {
  66. pattern: /(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,
  67. lookbehind: true
  68. }
  69. });
  70. var unit = {
  71. pattern: /(\b\d+)(?:%|[a-z]+\b)/,
  72. lookbehind: true
  73. };
  74. // 123 -123 .123 -.123 12.3 -12.3
  75. var number = {
  76. pattern: /(^|[^\w.-])-?\d*\.?\d+/,
  77. lookbehind: true
  78. };
  79. Prism.languages.insertBefore('css', 'function', {
  80. 'operator': {
  81. pattern: /(\s)[+\-*\/](?=\s)/,
  82. lookbehind: true
  83. },
  84. // CAREFUL!
  85. // Previewers and Inline color use hexcode and color.
  86. 'hexcode': {
  87. pattern: /\B#(?:[\da-f]{1,2}){3,4}\b/i,
  88. alias: 'color'
  89. },
  90. 'color': [
  91. /\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,
  92. {
  93. pattern: /\b(?:rgb|hsl)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:rgb|hsl)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,
  94. inside: {
  95. 'unit': unit,
  96. 'number': number,
  97. 'function': /[\w-]+(?=\()/,
  98. 'punctuation': /[(),]/
  99. }
  100. }
  101. ],
  102. // it's important that there is no boundary assertion after the hex digits
  103. 'entity': /\\[\da-f]{1,8}/i,
  104. 'unit': unit,
  105. 'number': number
  106. });
  107. })(Prism);