Skip to content

Commit

Permalink
Syntax highlight MDX code blocks in markdown files
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Oct 31, 2023
1 parent 160a201 commit 91f986f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-rice-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vscode-mdx': minor
---

Syntax highlight MDX code blocks in markdown files.
10 changes: 10 additions & 0 deletions packages/vscode-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@
"meta.embedded.xml": "xml",
"meta.embedded.yaml": "yaml"
}
},
{
"scopeName": "source.markdown.mdx.codeblock",
"path": "./syntaxes/mdx.markdown.tmLanguage.json",
"injectTo": [
"text.html.markdown"
],
"embeddedLanguages": {
"meta.embedded.block.mdx": "mdx"
}
}
]
}
Expand Down
45 changes: 45 additions & 0 deletions packages/vscode-mdx/syntaxes/mdx.markdown.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"fileTypes": [],
"injectionSelector": "L:text.html.markdown",
"patterns": [
{
"include": "#mdxCodeBlock"
}
],
"repository": {
"mdxCodeBlock": {
"begin": "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(mdx)(\\s+[^`~]*)?$)",
"name": "markup.fenced_code.block.markdown",
"end": "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$",
"beginCaptures": {
"3": {
"name": "punctuation.definition.markdown"
},
"4": {
"name": "fenced_code.block.language.markdown"
},
"5": {
"name": "fenced_code.block.language.attributes.markdown"
}
},
"endCaptures": {
"3": {
"name": "punctuation.definition.markdown"
}
},
"patterns": [
{
"begin": "(^|\\G)(\\s*)(.*)",
"while": "(^|\\G)(?!\\s*([`~]{3,})\\s*$)",
"contentName": "meta.embedded.block.mdx",
"patterns": [
{
"include": "source.mdx"
}
]
}
]
}
},
"scopeName": "source.markdown.mdx.codeblock"
}

0 comments on commit 91f986f

Please sign in to comment.