diff --git a/README.md b/README.md index 1e0d421..6518919 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This [extension for VSCode](https://marketplace.visualstudio.com/items?itemName= ## Features -- Syntax highlighting grammar for Nushell scripts (`.nu` files) +- Syntax highlighting grammar for Nushell scripts (`.nu` files) and ``nushell`` codeblocks in Markdown files - Goto definition - Hover support - Validation (errors with red squiggly lines) diff --git a/package.json b/package.json index a6ee4c7..60ddf4c 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,16 @@ "language": "nushell", "scopeName": "source.nushell", "path": "./syntaxes/nushell.tmLanguage.json" + }, + { + "scopeName": "markdown.nushell.codeblock", + "path": "./syntaxes/codeblock.json", + "injectTo": [ + "text.html.markdown" + ], + "embeddedLanguages": { + "meta.embedded.block.nushell": "nushell" + } } ], "keybindings": [ diff --git a/syntaxes/codeblock.json b/syntaxes/codeblock.json new file mode 100644 index 0000000..8a0bab3 --- /dev/null +++ b/syntaxes/codeblock.json @@ -0,0 +1,45 @@ +{ + "fileTypes": [], + "injectionSelector": "L:text.html.markdown", + "patterns": [ + { + "include": "#nushell-code-block" + } + ], + "repository": { + "nushell-code-block": { + "begin": "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(nushell)(\\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.nushell", + "patterns": [ + { + "include": "source.nushell" + } + ] + } + ] + } + }, + "scopeName": "markdown.nushell.codeblock" +} \ No newline at end of file