xml.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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('vs/basic-languages/xml/xml',["require", "exports", "../fillers/monaco-editor-core"], function (require, exports, monaco_editor_core_1) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  10. comments: {
  11. blockComment: ['<!--', '-->']
  12. },
  13. brackets: [['<', '>']],
  14. autoClosingPairs: [
  15. { open: '<', close: '>' },
  16. { open: "'", close: "'" },
  17. { open: '"', close: '"' }
  18. ],
  19. surroundingPairs: [
  20. { open: '<', close: '>' },
  21. { open: "'", close: "'" },
  22. { open: '"', close: '"' }
  23. ],
  24. onEnterRules: [
  25. {
  26. beforeText: new RegExp("<([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$", 'i'),
  27. afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>$/i,
  28. action: {
  29. indentAction: monaco_editor_core_1.languages.IndentAction.IndentOutdent
  30. }
  31. },
  32. {
  33. beforeText: new RegExp("<(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$", 'i'),
  34. action: { indentAction: monaco_editor_core_1.languages.IndentAction.Indent }
  35. }
  36. ]
  37. };
  38. exports.language = {
  39. defaultToken: '',
  40. tokenPostfix: '.xml',
  41. ignoreCase: true,
  42. // Useful regular expressions
  43. qualifiedName: /(?:[\w\.\-]+:)?[\w\.\-]+/,
  44. tokenizer: {
  45. root: [
  46. [/[^<&]+/, ''],
  47. { include: '@whitespace' },
  48. // Standard opening tag
  49. [/(<)(@qualifiedName)/, [{ token: 'delimiter' }, { token: 'tag', next: '@tag' }]],
  50. // Standard closing tag
  51. [
  52. /(<\/)(@qualifiedName)(\s*)(>)/,
  53. [{ token: 'delimiter' }, { token: 'tag' }, '', { token: 'delimiter' }]
  54. ],
  55. // Meta tags - instruction
  56. [/(<\?)(@qualifiedName)/, [{ token: 'delimiter' }, { token: 'metatag', next: '@tag' }]],
  57. // Meta tags - declaration
  58. [/(<\!)(@qualifiedName)/, [{ token: 'delimiter' }, { token: 'metatag', next: '@tag' }]],
  59. // CDATA
  60. [/<\!\[CDATA\[/, { token: 'delimiter.cdata', next: '@cdata' }],
  61. [/&\w+;/, 'string.escape']
  62. ],
  63. cdata: [
  64. [/[^\]]+/, ''],
  65. [/\]\]>/, { token: 'delimiter.cdata', next: '@pop' }],
  66. [/\]/, '']
  67. ],
  68. tag: [
  69. [/[ \t\r\n]+/, ''],
  70. [
  71. /(@qualifiedName)(\s*=\s*)("[^"]*"|'[^']*')/,
  72. ['attribute.name', '', 'attribute.value']
  73. ],
  74. [
  75. /(@qualifiedName)(\s*=\s*)("[^">?\/]*|'[^'>?\/]*)(?=[\?\/]\>)/,
  76. ['attribute.name', '', 'attribute.value']
  77. ],
  78. [
  79. /(@qualifiedName)(\s*=\s*)("[^">]*|'[^'>]*)/,
  80. ['attribute.name', '', 'attribute.value']
  81. ],
  82. [/@qualifiedName/, 'attribute.name'],
  83. [/\?>/, { token: 'delimiter', next: '@pop' }],
  84. [/(\/)(>)/, [{ token: 'tag' }, { token: 'delimiter', next: '@pop' }]],
  85. [/>/, { token: 'delimiter', next: '@pop' }]
  86. ],
  87. whitespace: [
  88. [/[ \t\r\n]+/, ''],
  89. [/<!--/, { token: 'comment', next: '@comment' }]
  90. ],
  91. comment: [
  92. [/[^<\-]+/, 'comment.content'],
  93. [/-->/, { token: 'comment', next: '@pop' }],
  94. [/<!--/, 'comment.content.invalid'],
  95. [/[<\-]/, 'comment.content']
  96. ]
  97. }
  98. };
  99. });