prism-css-extras.js 4.3 KB

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