prism-css.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (function (Prism) {
  2. var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
  3. Prism.languages.css = {
  4. 'comment': /\/\*[\s\S]*?\*\//,
  5. 'atrule': {
  6. pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
  7. inside: {
  8. 'rule': /^@[\w-]+/,
  9. 'selector-function-argument': {
  10. pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
  11. lookbehind: true,
  12. alias: 'selector'
  13. },
  14. 'keyword': {
  15. pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
  16. lookbehind: true
  17. }
  18. // See rest below
  19. }
  20. },
  21. 'url': {
  22. // https://drafts.csswg.org/css-values-3/#urls
  23. pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
  24. greedy: true,
  25. inside: {
  26. 'function': /^url/i,
  27. 'punctuation': /^\(|\)$/,
  28. 'string': {
  29. pattern: RegExp('^' + string.source + '$'),
  30. alias: 'url'
  31. }
  32. }
  33. },
  34. 'selector': {
  35. pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
  36. lookbehind: true
  37. },
  38. 'string': {
  39. pattern: string,
  40. greedy: true
  41. },
  42. 'property': {
  43. pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
  44. lookbehind: true
  45. },
  46. 'important': /!important\b/i,
  47. 'function': {
  48. pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
  49. lookbehind: true
  50. },
  51. 'punctuation': /[(){};:,]/
  52. };
  53. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  54. var markup = Prism.languages.markup;
  55. if (markup) {
  56. markup.tag.addInlined('style', 'css');
  57. markup.tag.addAttribute('style', 'css');
  58. }
  59. }(Prism));