Files
backroad/app/portainer/services/codeMirror.js
Chaim Lev-Ari cf5056d9c0 chore(project): add prettier for code format (#3645)
* chore(project): install prettier and lint-staged

* chore(project): apply prettier to html too

* chore(project): git ignore eslintcache

* chore(project): add a comment about format script

* chore(prettier): update printWidth

* chore(prettier): remove useTabs option

* chore(prettier): add HTML validation

* refactor(prettier): fix closing tags

* feat(prettier): define angular parser for html templates

* style(prettier): run prettier on codebase

Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
2020-04-11 09:54:53 +12:00

47 lines
1.1 KiB
JavaScript

import _ from 'lodash-es';
import CodeMirror from 'codemirror';
import 'codemirror/mode/yaml/yaml.js';
import 'codemirror/addon/lint/lint.js';
import 'codemirror/addon/lint/yaml-lint.js';
import 'codemirror/addon/display/placeholder.js';
angular.module('portainer.app').factory('CodeMirrorService', function CodeMirrorService() {
'use strict';
var service = {};
var codeMirrorGenericOptions = {
lineNumbers: true,
};
var codeMirrorYAMLOptions = {
mode: 'text/x-yaml',
gutters: ['CodeMirror-lint-markers'],
lint: true,
extraKeys: {
Tab: function (cm) {
var spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
cm.replaceSelection(spaces);
},
},
};
service.applyCodeMirrorOnElement = function (element, yamlLint, readOnly) {
var options = angular.copy(codeMirrorGenericOptions);
if (yamlLint) {
_.assign(options, codeMirrorYAMLOptions);
}
if (readOnly) {
options.readOnly = true;
}
var cm = CodeMirror.fromTextArea(element, options);
cm.setSize('100%', 500);
return cm;
};
return service;
});