diff --git a/ui/packages/consul-ui/app/components/code-editor/index.js b/ui/packages/consul-ui/app/components/code-editor/index.js index 8fd0aee41..2d54bbb61 100644 --- a/ui/packages/consul-ui/app/components/code-editor/index.js +++ b/ui/packages/consul-ui/app/components/code-editor/index.js @@ -31,11 +31,18 @@ export default Component.extend({ } }, setMode: function(mode) { - set(this, 'options', { + let options = { ...DEFAULTS, mode: mode.mime, readOnly: this.readonly, - }); + }; + if (mode.name === 'XML') { + options.htmlMode = mode.htmlMode; + options.matchClosing = mode.matchClosing; + options.alignCDATA = mode.alignCDATA; + } + set(this, 'options', options); + const editor = this.editor; editor.setOption('mode', mode.mime); this.helper.lint(editor, mode.mode); diff --git a/ui/packages/consul-ui/app/components/code-editor/skin.scss b/ui/packages/consul-ui/app/components/code-editor/skin.scss index f4b35e6bd..6ba316787 100644 --- a/ui/packages/consul-ui/app/components/code-editor/skin.scss +++ b/ui/packages/consul-ui/app/components/code-editor/skin.scss @@ -128,6 +128,10 @@ $syntax-dark-gray: #535f73; color: var(--syntax-packer); } + span.cm-error { + color: var(--syntax-red); + } + span.cm-attribute { color: #9fca56; } diff --git a/ui/packages/consul-ui/app/instance-initializers/ivy-codemirror.js b/ui/packages/consul-ui/app/instance-initializers/ivy-codemirror.js index 7c17b7ba8..5b23f3987 100644 --- a/ui/packages/consul-ui/app/instance-initializers/ivy-codemirror.js +++ b/ui/packages/consul-ui/app/instance-initializers/ivy-codemirror.js @@ -16,6 +16,8 @@ export function initialize(application) { return fs.get(['codemirror', 'mode', 'ruby', 'ruby.js'].join('/')); case 'yaml': return fs.get(['codemirror', 'mode', 'yaml', 'yaml.js'].join('/')); + case 'xml': + return fs.get(['codemirror', 'mode', 'xml', 'xml.js'].join('/')); } }, }; diff --git a/ui/packages/consul-ui/app/services/code-mirror/linter.js b/ui/packages/consul-ui/app/services/code-mirror/linter.js index c89ba0b95..1e8a4f6b9 100644 --- a/ui/packages/consul-ui/app/services/code-mirror/linter.js +++ b/ui/packages/consul-ui/app/services/code-mirror/linter.js @@ -16,6 +16,16 @@ const MODES = [ alias: ['jruby', 'macruby', 'rake', 'rb', 'rbx'], }, { name: 'YAML', mime: 'text/x-yaml', mode: 'yaml', ext: ['yaml', 'yml'], alias: ['yml'] }, + { + name: 'XML', + mime: 'application/xml', + mode: 'xml', + htmlMode: false, + matchClosing: true, + alignCDATA: false, + ext: ['xml'], + alias: ['xml'], + }, ]; export default class LinterService extends Service { diff --git a/ui/packages/consul-ui/ember-cli-build.js b/ui/packages/consul-ui/ember-cli-build.js index 4bff448c2..b6fea5edc 100644 --- a/ui/packages/consul-ui/ember-cli-build.js +++ b/ui/packages/consul-ui/ember-cli-build.js @@ -206,6 +206,10 @@ module.exports = function(defaults, $ = process.env) { app.import('node_modules/codemirror/mode/yaml/yaml.js', { outputFile: 'assets/codemirror/mode/yaml/yaml.js', }); + // XML linting support. Possibly dynamically loaded via CodeMirror linting. See services/code-mirror/linter.js + app.import('node_modules/codemirror/mode/xml/xml.js', { + outputFile: 'assets/codemirror/mode/xml/xml.js', + }); // metrics-providers app.import('vendor/metrics-providers/consul.js', { outputFile: 'assets/metrics-providers/consul.js', diff --git a/ui/packages/consul-ui/lib/startup/templates/body.html.js b/ui/packages/consul-ui/lib/startup/templates/body.html.js index cb9016821..72738c9af 100644 --- a/ui/packages/consul-ui/lib/startup/templates/body.html.js +++ b/ui/packages/consul-ui/lib/startup/templates/body.html.js @@ -38,7 +38,8 @@ ${environment === 'production' ? `{{jsonEncode .}}` : JSON.stringify(config.oper "css.escape/css.escape.js": "${rootURL}assets/css.escape.js", "codemirror/mode/javascript/javascript.js": "${rootURL}assets/codemirror/mode/javascript/javascript.js", "codemirror/mode/ruby/ruby.js": "${rootURL}assets/codemirror/mode/ruby/ruby.js", - "codemirror/mode/yaml/yaml.js": "${rootURL}assets/codemirror/mode/yaml/yaml.js" + "codemirror/mode/yaml/yaml.js": "${rootURL}assets/codemirror/mode/yaml/yaml.js", + "codemirror/mode/xml/xml.js": "${rootURL}assets/codemirror/mode/xml/xml.js" }