Skip to content

Commit

Permalink
(fix) Handle syntax highlighting for most markdown files (#1537)
Browse files Browse the repository at this point in the history
Mostly fixes_ #1094. Do this by injecting rules to parse typescript and
css for svelte script/style blocks inside markdown only. This
should cover *most* cases of embedded svelte blocks inside
markdown.

It would not be *too* difficult to extend this further to handle other
types of embedded script/style tags (as is done in the original grammar),
though it would be somewhat tedious.
  • Loading branch information
wlach committed Jun 26, 2022
1 parent c2466bf commit 35bbfc5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/svelte-vscode/package.json
Expand Up @@ -474,6 +474,20 @@
"meta.embedded.block.svelte": "svelte"
}
},
{
"scopeName": "markdown.svelte.codeblock.script",
"path": "./syntaxes/markdown-svelte-js.json",
"injectTo": [
"text.html.markdown"
]
},
{
"scopeName": "markdown.svelte.codeblock.style",
"path": "./syntaxes/markdown-svelte-css.json",
"injectTo": [
"text.html.markdown"
]
},
{
"scopeName": "source.css.postcss",
"path": "./syntaxes/postcss.json",
Expand Down
23 changes: 23 additions & 0 deletions packages/svelte-vscode/syntaxes/markdown-svelte-css.json
@@ -0,0 +1,23 @@
{
"scopeName": "markdown.svelte.codeblock.style",
"fileTypes": [],
"injectionSelector": "L:meta.style.svelte",
"patterns": [
{
"include": "#svelte-script-css"
}
],
"repository": {
"svelte-script-css": {
"begin": "(?<=style.*>)(?!</)",
"end": "(?=</)",
"name": "meta.embedded.block.svelte.style",
"contentName": "source.css",
"patterns": [
{
"include": "source.css"
}
]
}
}
}
23 changes: 23 additions & 0 deletions packages/svelte-vscode/syntaxes/markdown-svelte-js.json
@@ -0,0 +1,23 @@
{
"scopeName": "markdown.svelte.codeblock.script",
"fileTypes": [],
"injectionSelector": "L:meta.script.svelte",
"patterns": [
{
"include": "#svelte-script-js"
}
],
"repository": {
"svelte-script-js": {
"begin": "(?<=script.*>)(?!</)",
"end": "(?=</)",
"name": "meta.embedded.block.svelte.script",
"contentName": "source.ts",
"patterns": [
{
"include": "source.ts"
}
]
}
}
}

0 comments on commit 35bbfc5

Please sign in to comment.