mirror of
https://github.com/directus/directus.git
synced 2026-02-17 13:51:32 -05:00
@@ -124,14 +124,19 @@ export default defineComponent({
|
||||
async function setLanguage() {
|
||||
if (codemirror.value) {
|
||||
const lang = props.language.toLowerCase();
|
||||
|
||||
if (lang === 'json') {
|
||||
// @ts-ignore
|
||||
await import('codemirror/mode/javascript/javascript.js');
|
||||
|
||||
const jsonlint = (await import('jsonlint-mod')) as any;
|
||||
|
||||
codemirror.value.setOption('mode', { name: 'javascript', json: true });
|
||||
|
||||
CodeMirror.registerHelper('lint', 'json', (text: string) => {
|
||||
const found: {}[] = [];
|
||||
const parser = jsonlint.parser;
|
||||
|
||||
parser.parseError = (str: string, hash: any) => {
|
||||
const loc = hash.loc;
|
||||
found.push({
|
||||
@@ -147,25 +152,6 @@ export default defineComponent({
|
||||
}
|
||||
return found;
|
||||
});
|
||||
} else if (lang === 'javascript' || lang === 'htmlmixed' || lang === 'yaml') {
|
||||
let linter = lang;
|
||||
if (lang === 'javascript') {
|
||||
const jshint = await import('jshint');
|
||||
(window as any).JSHINT = jshint;
|
||||
} else if (lang === 'htmlmixed') {
|
||||
linter = 'html';
|
||||
const htmlhint = await import('htmlhint');
|
||||
(window as any).HTMLHint = htmlhint;
|
||||
} else if (lang === 'yaml') {
|
||||
const jsyaml = await import('js-yaml');
|
||||
(window as any).jsyaml = jsyaml;
|
||||
}
|
||||
await import(`codemirror/mode/${lang}/${lang}.js`);
|
||||
await import(`codemirror/addon/lint/${linter}-lint.js`);
|
||||
codemirror.value.setOption('lint', (CodeMirror as any).lint[linter]);
|
||||
|
||||
await import(`codemirror/mode/${lang}/${lang}.js`);
|
||||
codemirror.value.setOption('mode', { name: lang });
|
||||
} else if (lang === 'text/plain') {
|
||||
codemirror.value.setOption('mode', { name: null });
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user