Skip to content

Commit

Permalink
feat: markdown embedded support
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoortheen committed Aug 16, 2020
1 parent b1cf2ef commit 4debbfd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Adds [nix](https://nixos.org/) language support for VSCode Editor.
## Features

* Syntax Highlight
+ nix code snippets inside `markdown` files also work.
+ Thanks to https://github.com/wmertens/sublime-nix for the grammer file
* Formatting support
+ with the help of [nixpkgs-format](https://github.com/nix-community/nixpkgs-fmt)
Expand Down Expand Up @@ -53,4 +54,4 @@ I have created this since the other nix-language extension hasn't been updated o
---
Special thanks to
* [article](https://blog.nojaf.com/2018/12/17/writing-a-vscode-extension-with-fable-2-1/) to have all the pieces in one place to develop vscode extension with `Fable` .
* Many of the functions are copied from [vscode-fish](https://github.com/bmalehorn/vscode-fish/)
* The extension [vscode-fish](https://github.com/bmalehorn/vscode-fish/) is modified to work for `nix` .
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
"language": "nix",
"scopeName": "source.nix",
"path": "./syntaxes/nix.tmLanguage.json"
},
{
"scopeName": "markdown.nix.codeblock",
"path": "./syntaxes/injection.json",
"injectTo": [
"text.html.markdown"
],
"embeddedLanguages": {
"meta.embedded.block.nix": "nix"
}
}
],
"snippets": [
Expand All @@ -64,7 +74,7 @@
"vscode": "^1.1.25"
},
"scripts": {
"prebuild": "js-yaml syntaxes/nix.YAML-tmLanguage > syntaxes/nix.tmLanguage.json",
"prebuild": "js-yaml syntaxes/nix.YAML-tmLanguage > syntaxes/nix.tmLanguage.json && js-yaml syntaxes/injection.yml > syntaxes/injection.json",
"build": "tsc -p ./",
"watch": "yarn build --watch",
"postinstall": "node ./node_modules/vscode/bin/install",
Expand Down
27 changes: 27 additions & 0 deletions syntaxes/injection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
fileTypes: []
injectionSelector: L:text.html.markdown
patterns:
- include: "#nix-code-block"
repository:
nix-code-block:
begin: "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(nix)(\\s+[^`~]*)?$)"
name: markup.fenced_code.block.markdown
end: "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$"
beginCaptures:
"3":
name: punctuation.definition.markdown
"5":
name: fenced_code.block.language
"6":
name: fenced_code.block.language.attributes
endCaptures:
"3":
name: punctuation.definition.markdown
patterns:
- begin: "(^|\\G)(\\s*)(.*)"
while: "(^|\\G)(?!\\s*([`~]{3,})\\s*$)"
contentName: meta.embedded.block.nix
patterns:
- include: source.nix
scopeName: markdown.nix.codeblock

0 comments on commit 4debbfd

Please sign in to comment.