// import {parser, configureNesting} from "@lezer/html" import { parser, configureNesting } from './grammar/index.js'; import { Parser } from '@lezer/common'; import { cssLanguage, css } from '@codemirror/lang-css'; import { javascriptLanguage, typescriptLanguage, jsxLanguage, tsxLanguage, javascript, } from '@codemirror/lang-javascript'; import { EditorView } from '@codemirror/view'; import { EditorSelection } from '@codemirror/state'; import { LRLanguage, indentNodeProp, foldNodeProp, LanguageSupport, syntaxTree, } from '@codemirror/language'; import { elementName, htmlCompletionSourceWith, TagSpec, eventAttributes } from './complete'; export { htmlCompletionSource, TagSpec, htmlCompletionSourceWith } from './complete'; type NestedLang = { tag: string; attrs?: (attrs: { [attr: string]: string }) => boolean; parser: Parser; }; const defaultNesting: NestedLang[] = [ { tag: 'script', attrs: (attrs) => attrs.type == 'text/typescript' || attrs.lang == 'ts', parser: typescriptLanguage.parser, }, { tag: 'script', attrs: (attrs) => attrs.type == 'text/babel' || attrs.type == 'text/jsx', parser: jsxLanguage.parser, }, { tag: 'script', attrs: (attrs) => attrs.type == 'text/typescript-jsx', parser: tsxLanguage.parser, }, { tag: 'script', attrs(attrs) { return ( !attrs.type || /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(attrs.type) ); }, parser: javascriptLanguage.parser, }, { tag: 'style', attrs(attrs) { return ( (!attrs.lang || attrs.lang == 'css') && (!attrs.type || /^(text\/)?(x-)?(stylesheet|css)$/i.test(attrs.type)) ); }, parser: cssLanguage.parser, }, ]; type NestedAttr = { name: string; tagName?: string; parser: Parser; }; const defaultAttrs: NestedAttr[] = [ { name: 'style', parser: cssLanguage.parser.configure({ top: 'Styles' }) }, ].concat(eventAttributes.map((name) => ({ name, parser: javascriptLanguage.parser }))); /// A language provider based on the [Lezer HTML /// parser](https://github.com/lezer-parser/html), extended with the /// JavaScript and CSS parsers to parse the content of `