xml.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. define(["require", "exports"], function (require, exports) {
  6. 'use strict';
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.conf = {
  9. comments: {
  10. blockComment: ['<!--', '-->'],
  11. },
  12. brackets: [
  13. ['<', '>']
  14. ],
  15. autoClosingPairs: [
  16. { open: '<', close: '>' },
  17. { open: '\'', close: '\'' },
  18. { open: '"', close: '"' },
  19. ],
  20. surroundingPairs: [
  21. { open: '<', close: '>' },
  22. { open: '\'', close: '\'' },
  23. { open: '"', close: '"' },
  24. ]
  25. };
  26. exports.language = {
  27. defaultToken: '',
  28. tokenPostfix: '.xml',
  29. ignoreCase: true,
  30. // Useful regular expressions
  31. qualifiedName: /(?:[\w\.\-]+:)?[\w\.\-]+/,
  32. tokenizer: {
  33. root: [
  34. [/[^<&]+/, ''],
  35. { include: '@whitespace' },
  36. // Standard opening tag
  37. [/(<)(@qualifiedName)/, [
  38. { token: 'delimiter' },
  39. { token: 'tag', next: '@tag' }
  40. ]],
  41. // Standard closing tag
  42. [/(<\/)(@qualifiedName)(\s*)(>)/, [
  43. { token: 'delimiter' },
  44. { token: 'tag' },
  45. '',
  46. { token: 'delimiter' }
  47. ]],
  48. // Meta tags - instruction
  49. [/(<\?)(@qualifiedName)/, [
  50. { token: 'delimiter' },
  51. { token: 'metatag', next: '@tag' }
  52. ]],
  53. // Meta tags - declaration
  54. [/(<\!)(@qualifiedName)/, [
  55. { token: 'delimiter' },
  56. { token: 'metatag', next: '@tag' }
  57. ]],
  58. // CDATA
  59. [/<\!\[CDATA\[/, { token: 'delimiter.cdata', next: '@cdata' }],
  60. [/&\w+;/, 'string.escape'],
  61. ],
  62. cdata: [
  63. [/[^\]]+/, ''],
  64. [/\]\]>/, { token: 'delimiter.cdata', next: '@pop' }],
  65. [/\]/, '']
  66. ],
  67. tag: [
  68. [/[ \t\r\n]+/, ''],
  69. [/(@qualifiedName)(\s*=\s*)("[^"]*"|'[^']*')/, ['attribute.name', '', 'attribute.value']],
  70. [/(@qualifiedName)(\s*=\s*)("[^">?\/]*|'[^'>?\/]*)(?=[\?\/]\>)/, ['attribute.name', '', 'attribute.value']],
  71. [/(@qualifiedName)(\s*=\s*)("[^">]*|'[^'>]*)/, ['attribute.name', '', 'attribute.value']],
  72. [/@qualifiedName/, 'attribute.name'],
  73. [/\?>/, { token: 'delimiter', next: '@pop' }],
  74. [/(\/)(>)/, [
  75. { token: 'tag' },
  76. { token: 'delimiter', next: '@pop' }
  77. ]],
  78. [/>/, { token: 'delimiter', next: '@pop' }],
  79. ],
  80. whitespace: [
  81. [/[ \t\r\n]+/, ''],
  82. [/<!--/, { token: 'comment', next: '@comment' }]
  83. ],
  84. comment: [
  85. [/[^<\-]+/, 'comment.content'],
  86. [/-->/, { token: 'comment', next: '@pop' }],
  87. [/<!--/, 'comment.content.invalid'],
  88. [/[<\-]/, 'comment.content']
  89. ],
  90. },
  91. };
  92. });