Skip to content

Commit 35bbfc5

Browse files
authored
(fix) Handle syntax highlighting for most markdown files (#1537)
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.
1 parent c2466bf commit 35bbfc5

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

packages/svelte-vscode/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,20 @@
474474
"meta.embedded.block.svelte": "svelte"
475475
}
476476
},
477+
{
478+
"scopeName": "markdown.svelte.codeblock.script",
479+
"path": "./syntaxes/markdown-svelte-js.json",
480+
"injectTo": [
481+
"text.html.markdown"
482+
]
483+
},
484+
{
485+
"scopeName": "markdown.svelte.codeblock.style",
486+
"path": "./syntaxes/markdown-svelte-css.json",
487+
"injectTo": [
488+
"text.html.markdown"
489+
]
490+
},
477491
{
478492
"scopeName": "source.css.postcss",
479493
"path": "./syntaxes/postcss.json",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"scopeName": "markdown.svelte.codeblock.style",
3+
"fileTypes": [],
4+
"injectionSelector": "L:meta.style.svelte",
5+
"patterns": [
6+
{
7+
"include": "#svelte-script-css"
8+
}
9+
],
10+
"repository": {
11+
"svelte-script-css": {
12+
"begin": "(?<=style.*>)(?!</)",
13+
"end": "(?=</)",
14+
"name": "meta.embedded.block.svelte.style",
15+
"contentName": "source.css",
16+
"patterns": [
17+
{
18+
"include": "source.css"
19+
}
20+
]
21+
}
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"scopeName": "markdown.svelte.codeblock.script",
3+
"fileTypes": [],
4+
"injectionSelector": "L:meta.script.svelte",
5+
"patterns": [
6+
{
7+
"include": "#svelte-script-js"
8+
}
9+
],
10+
"repository": {
11+
"svelte-script-js": {
12+
"begin": "(?<=script.*>)(?!</)",
13+
"end": "(?=</)",
14+
"name": "meta.embedded.block.svelte.script",
15+
"contentName": "source.ts",
16+
"patterns": [
17+
{
18+
"include": "source.ts"
19+
}
20+
]
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)