From 0eadaef95c264b1074f54d9fc1d2a670e8128224 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 16 Sep 2016 12:58:24 +0200 Subject: [PATCH] Add html colorizer --- README.md | 3 +- gulpfile.js | 1 + src/html.ts | 205 +++++++++++++++++++++++++++++++++++++ src/monaco.contribution.ts | 7 ++ tsconfig.json | 1 + 5 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 src/html.ts diff --git a/README.md b/README.md index 693f4364..eacee0d7 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed * csharp * fsharp * go +* html * ini * jade * lua @@ -24,7 +25,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed * vb * xml -Also `css` dialects: +Also `css` dialects: * css * less diff --git a/gulpfile.js b/gulpfile.js index 58e7c745..a2a5b1b8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -53,6 +53,7 @@ gulp.task('release', ['clean-release','compile'], function() { bundleOne('src/dockerfile'), bundleOne('src/fsharp'), bundleOne('src/go'), + bundleOne('src/html'), bundleOne('src/ini'), bundleOne('src/jade'), bundleOne('src/java'), diff --git a/src/html.ts b/src/html.ts new file mode 100644 index 00000000..e4ac4203 --- /dev/null +++ b/src/html.ts @@ -0,0 +1,205 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; +import ILanguage = monaco.languages.IMonarchLanguage; + +const EMPTY_ELEMENTS:string[] = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']; + +export var conf:IRichLanguageConfiguration = { + wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g, + + comments: { + blockComment: [''] + }, + + brackets: [ + [''], + ['<', '>'], + ], + + __electricCharacterSupport: { + embeddedElectricCharacters: ['*', '}', ']', ')'] + }, + + autoClosingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' } + ], + + surroundingPairs: [ + { open: '"', close: '"' }, + { open: '\'', close: '\'' } + ], + + onEnterRules: [ + { + beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), + afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>$/i, + action: { indentAction: monaco.languages.IndentAction.IndentOutdent } + }, + { + beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), + action: { indentAction: monaco.languages.IndentAction.Indent } + } + ], +}; + +export var language = { + defaultToken: '', + tokenPostfix: '.html', + + // The main tokenizer for our languages + tokenizer: { + root: [ + [//, 'tag'], + [/ +// +// +// +// diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index df004bde..95439836 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -92,6 +92,13 @@ registerLanguage({ aliases: [ 'Go' ], module: './go' }); +registerLanguage({ + id: 'html', + extensions: ['.html', '.htm', '.shtml', '.xhtml', '.mdoc', '.jsp', '.asp', '.aspx', '.jshtm'], + aliases: ['HTML', 'htm', 'html', 'xhtml'], + mimetypes: ['text/html', 'text/x-jshtm', 'text/template', 'text/ng-template'], + module: './html' +}); registerLanguage({ id: 'ini', extensions: [ '.ini', '.properties', '.gitconfig' ], diff --git a/tsconfig.json b/tsconfig.json index b93ad892..2fbe02f3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,7 @@ "src/dockerfile.ts", "src/fsharp.ts", "src/go.ts", + "src/html.ts", "src/ini.ts", "src/jade.ts", "src/java.ts",