xml.js 3.5 KB

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