GithubHelp home page GithubHelp logo

edheltzel / nunjucks-for-visual-studio-code Goto Github PK

View Code? Open in Web Editor NEW
22.0 1.0 1.0 31.88 MB

๐Ÿฆพ Better Nunjucks for Visual Studio Code with Snippets

Home Page: https://marketplace.visualstudio.com/items?itemName=ginfuru.better-nunjucks

License: MIT License

JavaScript 100.00%
nunjucks vscode-extension 11ty eleventy nunjucks-snippets nunjucks-syntax visual-studio-code-extension nunjucks-grammar vscode-grammar vscode-language-support visual-studio-code-snippets

nunjucks-for-visual-studio-code's Introduction

Better Nunjucks for Visual Studio Code
with Snippets

release license

๐Ÿ“” Table of Contents
  1. Syntax Highlighting
  2. Snippets
  3. Known Issues
  4. TODO

Syntax Highlighting:

For .njk, .html, and .md files the grammar is auto-detected. All .njk files will default to html and provide syntax highlighting for Nunjucks tags, filers, and variables which are injected into the default html grammar. This attempts to keep the developer experience (DX) as simple as possible, without having to configure global or workspace settings with files.association. Hopefully this will provide the least amount of friction between other extensions that support Markdown or HTML.

nunjucks-snippets-in-markdown
Nunjucks inside of Markdown + frontmatter support
nunjucks-complex-page
Complex example of Nunjucks inside of HTML + frontmatter support
nunjucks-in-html
Nunjucks inside of HTML + frontmatter support
nunjucks-with-11ty
Using the Nunjucks grammar also support highlighting and frontmatter

Snippets:

The snippets are a combined fork of other Nunjucks snippet extensions but is extended to include all of Nunjucks built-in tags and provide support for multiple file extensions โ€“ .njk, .html, & .md

The reason for the fork is to avoid conflicts and behavior issues when editing njk, html, and/or md files or when altering files.association

Note: If you would rather not use the snippets provided in this extension, no worries - I highly recommend installing Control Snippets to enable or disable VS Code's built-in or manually installed snippets.



nunjucks-snippets-in-markdown
Nunjucks Snippets in Markdown ๐Ÿ˜
nunjucks-snippets-in-html
Nunjucks Snippets in HTML/Nunjucks ๐Ÿ˜

Known Issues

There are a few "gotchas" or work arounds to enable some of the creature comforts with Visual Studio Code.

Emmet Support

One "gotcha" is when selecting the nunjucks grammar, enabling support for Emmet is provided though the editor or the workspace settings:

  //"_comment": "add this to your Global or Workspace settings.json"
  "emmet.includeLanguages": {
    "md": "html",
    "nunjucks": "html",
  },
  "emmet.syntaxProfiles": {
    "md": "html",
    "nunjucks": "html",
  }

Another is when trying to use HTML comments. With PR 18 using the keyboard shortcut cmd+/ or ctrl+/ will add a NJK comment block.

If you need to add HTML comments, the extension provides a couple of options to support this behavior.

  • Use the hcomm snippet to add an HTML comment block
  • Use the commenthtml snippet to add an HTML comment line
  • Use Emmet to add an HTML comment block (I set use ctrl+alt+/ as the shortcut).

Emmet: Toggle Comment

Code Folding

Another "gotcha" is code folding support. You will need to include the below to enable code folding for Nunjucks tags:

//"_comment": "add this to your Global or Workspace settings.json"
"editor.foldingStrategy": "indentation"

nunjucks-code-folding

TODO

  • Document how code folding works
  • Write about syntax injection with Auto detect
  • Setting nunjucks grammar and changes from auto-detect
  • Need images of syntax
  • Nunjucks Style Comments โ€“ Issue #1
  • Add more support for custom tags and filter (syntax)
  • Add all built-in filers to snippets If I missed some, please create a PR.
  • Add built-in variables to snippets
  • Add support of Eleventy
    • detect if .eleventy.js is available ๐Ÿคทidk if this is even possible
  • Add custom settings options to enable/disable snippets
  • Add custom settings options to enable/disable nunjucks comments with cmd+/ or ctrl+/
  • Add support for additional grammars for embedded languages - see issue 11

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.