Skip to content

Commit

Permalink
(fix) Handle syntax highlighting for most markdown files
Browse files Browse the repository at this point in the history
Mostly fixes sveltejs#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 22, 2022
1 parent e91eeba commit 38b6c6c
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 38b6c6c

Please sign in to comment.