diff --git a/CHANGELOG.md b/CHANGELOG.md index ba0f41f4..7d542ab7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [1.6.0] - 2020-09-23 + +- Syntax highlighting for Hugo shortcodes has been added + ## [1.5.0] - 2020-09-10 - [#17](https://github.com/estruyf/vscode-front-matter/issues/17): Make front matter be indentation `tabSize` aware diff --git a/README.md b/README.md index ee1be51f..5e856fa8 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ The extension will automatically verify if your title and description are SEO co > If you see something missing in your article creation flow, please feel free to reach out. +## Syntax highlighting for Hugo Shortcodes + +![Shortcode syntax highlighting](./assets/syntax-highlighting.png) + ## Available commands: **Front Matter: Create ** diff --git a/assets/syntax-highlighting.png b/assets/syntax-highlighting.png new file mode 100644 index 00000000..b750fc2f Binary files /dev/null and b/assets/syntax-highlighting.png differ diff --git a/package.json b/package.json index 1a43428e..26e6ad5b 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,14 @@ "command": "frontMatter.generateSlug", "title": "Front Matter: Generate slug based on article title" } - ] + ], + "grammars": [ + { + "path": "./syntaxes/hugo.tmLanguage.json", + "scopeName": "frontmatter.markdown.hugo", + "injectTo": [ "text.html.markdown" ] + } + ] }, "scripts": { "vscode:prepublish": "webpack --mode production", diff --git a/syntaxes/hugo.tmLanguage.json b/syntaxes/hugo.tmLanguage.json new file mode 100644 index 00000000..e880f87f --- /dev/null +++ b/syntaxes/hugo.tmLanguage.json @@ -0,0 +1,63 @@ +{ + "scopeName": "frontmatter.markdown.hugo", + "injectionSelector": "L:text.html.markdown", + "patterns": [ + { + "include": "#shortcodes" + } + ], + "repository": { + "string-double-quoted": { + "begin": "\"", + "beginCaptures": { + "0": { "name": "punctuation.definition.string.begin.hugo" } + }, + "end": "\"", + "endCaptures": { + "0": { "name": "punctuation.definition.string.end.hugo" } + }, + "name": "string.quoted.double.hugo", + "patterns": [ + ] + }, + "unquoted-attribute": { + "match": "(?<==)(?:[^\\s<>/'\"]|/(?!>))+", + "name": "string.unquoted.hugo" + }, + "tag-generic-attribute": { + "match": "(?<=[^=])\\b([a-zA-Z0-9:-]+)", + "name": "entity.other.attribute-name.hugo" + }, + "shortcode-name": { + "match": "(\\s[\\w\\-\\_]+\\s)", + "name": "hugo.shortcode.name", + "captures": { + "1": { "name": "keyword.other.important.hugo" } + } + }, + "shortcodes": { + "begin": "{{<|{{%", + "end": ">}}|%}}", + "beginCaptures": { + "0": { "name": "punctuation.definition.tag.begin.hugo" } + }, + "endCaptures": { + "0": { "name": "punctuation.definition.tag.end.hugo" } + }, + "patterns": [ + { + "include": "#shortcode-name" + }, + { + "include": "#tag-generic-attribute" + }, + { + "include": "#string-double-quoted" + }, + { + "include": "#unquoted-attribute" + } + ] + } + } +} \ No newline at end of file diff --git a/vsc-extension-quickstart.md b/vsc-extension-quickstart.md index d0c8e8ea..bc4b387b 100644 --- a/vsc-extension-quickstart.md +++ b/vsc-extension-quickstart.md @@ -40,3 +40,9 @@ * Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/testing-extension). * [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace. * Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). + + +## Usefull links + +https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars +https://github.com/microsoft/vscode-textmate/blob/e8f439d613afa00674e83b3b3ae382fc774665e1/test-cases/themes/syntaxes/html.json \ No newline at end of file