diff --git a/.changeset/bright-coats-fry.md b/.changeset/bright-coats-fry.md new file mode 100644 index 00000000..ab31a805 --- /dev/null +++ b/.changeset/bright-coats-fry.md @@ -0,0 +1,5 @@ +--- +"astro-vscode": patch +--- + +Fix Astro codeblock syntax highlighting for MDX files diff --git a/packages/vscode/package.json b/packages/vscode/package.json index 2c027976..589bc08d 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -217,13 +217,14 @@ } }, { - "scopeName": "text.mdx.astro.codeblock", + "scopeName": "source.mdx.astro", "path": "./syntaxes/mdx.astro.tmLanguage.json", "injectTo": [ "source.mdx" ], "embeddedLanguages": { - "mdx.embedded.astro": "astro" + "mdx.embedded.astro": "astro", + "mdx.embedded.astro.frontmatter": "typescriptreact" } } ] diff --git a/packages/vscode/syntaxes/mdx.astro.tmLanguage.json b/packages/vscode/syntaxes/mdx.astro.tmLanguage.json index eec3a84e..abebd3b6 100644 --- a/packages/vscode/syntaxes/mdx.astro.tmLanguage.json +++ b/packages/vscode/syntaxes/mdx.astro.tmLanguage.json @@ -1,84 +1,61 @@ { - "fileTypes": [], - "scopeName": "text.mdx.astro.codeblock", + "scopeName": "source.mdx.astro", "injectionSelector": "L:source.mdx", "patterns": [ { - "begin": "(?:^|\\G)[\\t ]*(`{3,})(?:[\\t ]*((?i:(?:.*\\.)?astro))(?:[\\t ]+((?:[^\\n\\r`])+))?)(?:[\\t ]*$)", - "beginCaptures": { - "1": { - "name": "string.other.begin.code.fenced.mdx" - }, - "2": { - "name": "entity.name.function.mdx" - } - }, - "contentName": "meta.embedded.astro", - "end": "(\\1)(?:[\\t ]*$)", - "endCaptures": { - "1": { - "name": "string.other.end.code.fenced.mdx" - } - }, - "name": "markup.code.astro.mdx", - "patterns": [ - { - "include": "#astro-code-block" - } - ] - }, - { - "begin": "(?:^|\\G)[\\t ]*(~{3,})(?:[\\t ]*((?i:(?:.*\\.)?astro))(?:[\\t ]+((?:[^\\n\\r])+))?)(?:[\\t ]*$)", + "include": "#mdx_fenced_code_block_astro" + } + ], + "repository": { + "mdx_fenced_code_block_astro": { + "begin": "(?:^|\\G)[\\t ]*([`~]{3,})(?:[\\t ]*((?:astro|(?:.*\\.)?(?:astro)))(?:[\\t ]+((?:[^\\n\\r`])+))?)(?:[\\t ]*$)", "beginCaptures": { "1": { - "name": "string.other.begin.code.fenced.mdx" + "name": "punctuation.definition.markdown" }, "2": { - "name": "entity.name.function.mdx" + "name": "entity.name.function.markdown" } }, - "contentName": "meta.embedded.astro", - "end": "(\\1)(?:[\\t ]*$)", + "end": "(^\\1)\\s*$", "endCaptures": { - "1": { - "name": "string.other.end.code.fenced.mdx" + "3": { + "name": "punctuation.definition.markdown" } }, "name": "markup.code.astro.mdx", "patterns": [ { - "include": "#astro-code-block" - } - ] - } - ], - "repository": { - "astro-code-block": { - "patterns": [ - { - "begin": "^\\s*---\\s*$", - "end": "^\\s*---\\s*$", - "beginCaptures": { - "0": { - "name": "punctuation.definition.tag.xi.begin.t" - } - }, - "endCaptures": { - "0": { - "name": "punctuation.definition.tag.xi.end.t" - } - }, - "contentName": "meta.embedded.block.astro.frontmatter", + "begin": "(^|\\G)(\\s*)(.*)", + "while": "(^|\\G)(?!\\s*([`~]{3,})\\s*$)", "patterns": [ { - "include": "source.tsx" + "begin": "^\\s*---\\s*$", + "end": "^\\s*---\\s*$", + "beginCaptures": { + "0": { + "name": "punctuation.definition.tag.xi.begin.t" + } + }, + "endCaptures": { + "0": { + "name": "punctuation.definition.tag.xi.end.t" + } + }, + "contentName": "mdx.embedded.astro.frontmatter", + "patterns": [ + { + "include": "source.tsx" + } + ] + }, + { + "contentName": "mdx.embedded.astro", + "include": "source.astro" } ] - }, - { - "include": "source.astro" } ] } } -} +} \ No newline at end of file