lang-css.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2009 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview
  16. * Registers a language handler for CSS.
  17. *
  18. *
  19. * To use, include prettify.js and this file in your HTML page.
  20. * Then put your code in an HTML tag like
  21. * <pre class="prettyprint lang-css"></pre>
  22. *
  23. *
  24. * http://www.w3.org/TR/CSS21/grammar.html Section G2 defines the lexical
  25. * grammar. This scheme does not recognize keywords containing escapes.
  26. *
  27. * @author mikesamuel@gmail.com
  28. */
  29. PR['registerLangHandler'](
  30. PR['createSimpleLexer'](
  31. [
  32. // The space production <s>
  33. [PR['PR_PLAIN'], /^[ \t\r\n\f]+/, null, ' \t\r\n\f']
  34. ],
  35. [
  36. // Quoted strings. <string1> and <string2>
  37. [PR['PR_STRING'],
  38. /^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/, null],
  39. [PR['PR_STRING'],
  40. /^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/, null],
  41. ['lang-css-str', /^url\(([^\)\"\']*)\)/i],
  42. [PR['PR_KEYWORD'],
  43. /^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,
  44. null],
  45. // A property name -- an identifier followed by a colon.
  46. ['lang-css-kw', /^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],
  47. // A C style block comment. The <comment> production.
  48. [PR['PR_COMMENT'], /^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],
  49. // Escaping text spans
  50. [PR['PR_COMMENT'], /^(?:<!--|-->)/],
  51. // A number possibly containing a suffix.
  52. [PR['PR_LITERAL'], /^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],
  53. // A hex color
  54. [PR['PR_LITERAL'], /^#(?:[0-9a-f]{3}){1,2}/i],
  55. // An identifier
  56. [PR['PR_PLAIN'],
  57. /^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],
  58. // A run of punctuation
  59. [PR['PR_PUNCTUATION'], /^[^\s\w\'\"]+/]
  60. ]),
  61. ['css']);
  62. PR['registerLangHandler'](
  63. PR['createSimpleLexer']([],
  64. [
  65. [PR['PR_KEYWORD'],
  66. /^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]
  67. ]),
  68. ['css-kw']);
  69. PR['registerLangHandler'](
  70. PR['createSimpleLexer']([],
  71. [
  72. [PR['PR_STRING'], /^[^\)\"\']+/]
  73. ]),
  74. ['css-str']);