UNPKG

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