1
0

xml.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Language: HTML, XML
  3. Category: common
  4. */
  5. function(hljs) {
  6. var XML_IDENT_RE = '[A-Za-z0-9\\._:-]+';
  7. var TAG_INTERNALS = {
  8. endsWithParent: true,
  9. illegal: /</,
  10. relevance: 0,
  11. contains: [
  12. {
  13. className: 'attr',
  14. begin: XML_IDENT_RE,
  15. relevance: 0
  16. },
  17. {
  18. begin: /=\s*/,
  19. relevance: 0,
  20. contains: [
  21. {
  22. className: 'string',
  23. endsParent: true,
  24. variants: [
  25. {begin: /"/, end: /"/},
  26. {begin: /'/, end: /'/},
  27. {begin: /[^\s"'=<>`]+/}
  28. ]
  29. }
  30. ]
  31. }
  32. ]
  33. };
  34. return {
  35. aliases: ['html', 'xhtml', 'rss', 'atom', 'xjb', 'xsd', 'xsl', 'plist'],
  36. case_insensitive: true,
  37. contains: [
  38. {
  39. className: 'meta',
  40. begin: '<!DOCTYPE', end: '>',
  41. relevance: 10,
  42. contains: [{begin: '\\[', end: '\\]'}]
  43. },
  44. hljs.COMMENT(
  45. '<!--',
  46. '-->',
  47. {
  48. relevance: 10
  49. }
  50. ),
  51. {
  52. begin: '<\\!\\[CDATA\\[', end: '\\]\\]>',
  53. relevance: 10
  54. },
  55. {
  56. begin: /<\?(php)?/, end: /\?>/,
  57. subLanguage: 'php',
  58. contains: [{begin: '/\\*', end: '\\*/', skip: true}]
  59. },
  60. {
  61. className: 'tag',
  62. /*
  63. The lookahead pattern (?=...) ensures that 'begin' only matches
  64. '<style' as a single word, followed by a whitespace or an
  65. ending braket. The '$' is needed for the lexeme to be recognized
  66. by hljs.subMode() that tests lexemes outside the stream.
  67. */
  68. begin: '<style(?=\\s|>|$)', end: '>',
  69. keywords: {name: 'style'},
  70. contains: [TAG_INTERNALS],
  71. starts: {
  72. end: '</style>', returnEnd: true,
  73. subLanguage: ['css', 'xml']
  74. }
  75. },
  76. {
  77. className: 'tag',
  78. // See the comment in the <style tag about the lookahead pattern
  79. begin: '<script(?=\\s|>|$)', end: '>',
  80. keywords: {name: 'script'},
  81. contains: [TAG_INTERNALS],
  82. starts: {
  83. end: '\<\/script\>', returnEnd: true,
  84. subLanguage: ['actionscript', 'javascript', 'handlebars', 'xml']
  85. }
  86. },
  87. {
  88. className: 'meta',
  89. variants: [
  90. {begin: /<\?xml/, end: /\?>/, relevance: 10},
  91. {begin: /<\?\w+/, end: /\?>/}
  92. ]
  93. },
  94. {
  95. className: 'tag',
  96. begin: '</?', end: '/?>',
  97. contains: [
  98. {
  99. className: 'name', begin: /[^\/><\s]+/, relevance: 0
  100. },
  101. TAG_INTERNALS
  102. ]
  103. }
  104. ]
  105. };
  106. }