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