diff --git a/src/twig/twig.ts b/src/twig/twig.ts index 86e03d31..de4f319b 100644 --- a/src/twig/twig.ts +++ b/src/twig/twig.ts @@ -5,8 +5,6 @@ 'use strict'; -import { conf as htmlConf, language as htmlLanguage } from '../html/html'; - import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; import ILanguage = monaco.languages.IMonarchLanguage; @@ -23,7 +21,10 @@ export const conf: IRichLanguageConfiguration = { ['{{', '}}'], ['(', ')'], ['[', ']'], - ...htmlConf.brackets, + + // HTML + [''], + ['<', '>'], ], autoClosingPairs: [ @@ -39,7 +40,9 @@ export const conf: IRichLanguageConfiguration = { surroundingPairs: [ { open: '"', close: '"' }, { open: '\'', close: '\'' }, - ...htmlConf.surroundingPairs, + + // HTML + { open: '<', close: '>' }, ], } @@ -61,13 +64,25 @@ export const language = { ], tokenizer: { - ...htmlLanguage.tokenizer, - root: [ + // whitespace + [/\s+/], + + // Twig Tag Delimiters [/{#/, 'comment.twig', '@commentState'], [/{%[-~]?/, 'delimiter.twig', '@blockState'], [/{{[-~]?/, 'delimiter.twig', '@variableState'], - ...htmlLanguage.tokenizer.root, + + // HTML + [/)/, ['delimiter.html', 'tag.html', '', 'delimiter.html']], + [/(<)(script)/, ['delimiter.html', { token: 'tag.html', next: '@script' }]], + [/(<)(style)/, ['delimiter.html', { token: 'tag.html', next: '@style' }]], + [/(<)((?:[\w\-]+:)?[\w\-]+)/, ['delimiter.html', { token: 'tag.html', next: '@otherTag' }]], + [/(<\/)((?:[\w\-]+:)?[\w\-]+)/, ['delimiter.html', { token: 'tag.html', next: '@otherTag' }]], + [/{ // assignment [/=/, 'operators.twig'], ], + + /** + * HTML + */ + doctype: [ + [/[^>]+/, 'metatag.content.html'], + [/>/, 'metatag.html', '@pop'], + ], + + comment: [ + [/-->/, 'comment.html', '@pop'], + [/[^-]+/, 'comment.content.html'], + [/./, 'comment.content.html'] + ], + + otherTag: [ + [/\/?>/, 'delimiter.html', '@pop'], + [/"([^"]*)"/, 'attribute.value.html'], + [/'([^']*)'/, 'attribute.value.html'], + [/[\w\-]+/, 'attribute.name.html'], + [/=/, 'delimiter.html'], + [/[ \t\r\n]+/], // whitespace + ], + + // -- BEGIN