mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Add initial mdx language
This commit is contained in:
parent
ab869e8469
commit
7d2065d55d
3 changed files with 97 additions and 0 deletions
24
src/basic-languages/mdx/mdx.contribution.ts
Normal file
24
src/basic-languages/mdx/mdx.contribution.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import { registerLanguage } from '../_.contribution';
|
||||||
|
|
||||||
|
declare var AMD: any;
|
||||||
|
declare var require: any;
|
||||||
|
|
||||||
|
registerLanguage({
|
||||||
|
id: 'mdx',
|
||||||
|
extensions: ['.mdx'],
|
||||||
|
aliases: ['MDX', 'mdx'],
|
||||||
|
loader: () => {
|
||||||
|
if (AMD) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
require(['vs/basic-languages/mdx/mdx'], resolve, reject);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return import('./mdx');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
8
src/basic-languages/mdx/mdx.test.ts
Normal file
8
src/basic-languages/mdx/mdx.test.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import { testTokenization } from '../test/testRunner';
|
||||||
|
|
||||||
|
testTokenization('mdx', []);
|
||||||
65
src/basic-languages/mdx/mdx.ts
Normal file
65
src/basic-languages/mdx/mdx.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import type { languages } from '../../fillers/monaco-editor-core';
|
||||||
|
|
||||||
|
export const conf: languages.LanguageConfiguration = {
|
||||||
|
comments: {
|
||||||
|
blockComment: ['{/*', '*/}']
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const language = <languages.IMonarchLanguage>{
|
||||||
|
defaultToken: '',
|
||||||
|
tokenPostfix: '.mdx',
|
||||||
|
escapes: /\\(?:["'\\abfnrtv]|x[\dA-Fa-f]{1,4}|u[\dA-Fa-f]{4}|U[\dA-Fa-f]{8})/,
|
||||||
|
bracket_open: ['{'],
|
||||||
|
single_quote: ["'"],
|
||||||
|
double_quote: ['"'],
|
||||||
|
tokenizer: {
|
||||||
|
root: [
|
||||||
|
[/^\s*import/, { token: 'keyword', next: '@import', nextEmbedded: 'js' }],
|
||||||
|
[/<\w+/, { token: 'keyword', next: '@jsx' }],
|
||||||
|
[/<\/?\w+>/, { token: 'keyword' }],
|
||||||
|
[/\*\*.+\*\*/, 'strong'],
|
||||||
|
[/{/, { token: 'delimiter.bracket', nextEmbedded: 'js' }],
|
||||||
|
{ include: 'expression' }
|
||||||
|
],
|
||||||
|
import: [[/'\s*(;|$)/, { token: 'string', next: '@pop', nextEmbedded: '@pop' }]],
|
||||||
|
expression: [[/}/, { token: 'delimiter.bracket', nextEmbedded: '@pop' }]],
|
||||||
|
jsx: [
|
||||||
|
[/\w+=/, { token: 'delimiter.bracket', next: '@jsx_expression' }],
|
||||||
|
[/\/?>/, { token: 'keyword', next: '@pop' }]
|
||||||
|
],
|
||||||
|
jsx_expression: [
|
||||||
|
[
|
||||||
|
/["'{]/,
|
||||||
|
{
|
||||||
|
cases: {
|
||||||
|
'@bracket_open': {
|
||||||
|
token: 'delimiter.bracket',
|
||||||
|
next: '@expression',
|
||||||
|
nextEmbedded: 'js'
|
||||||
|
},
|
||||||
|
'@double_quote': { token: 'string', next: '@string_double' },
|
||||||
|
'@single_quote': { token: 'string', next: '@string_single' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
string_double: [
|
||||||
|
[/[^"\\]+/, 'string'],
|
||||||
|
[/@escapes/, 'string.escape'],
|
||||||
|
[/\\./, 'string.escape.invalid'],
|
||||||
|
[/"/, 'string', '@pop']
|
||||||
|
],
|
||||||
|
string_single: [
|
||||||
|
[/[^'\\]+/, 'string'],
|
||||||
|
[/@escapes/, 'string.escape'],
|
||||||
|
[/\\./, 'string.escape.invalid'],
|
||||||
|
[/'/, 'string', '@pop']
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue