Nova

Extensions


Readme

Twig for Nova (regex-based)

This extension for Nova, a text editor from Panic, adds syntax highlighting for Twig, a popular templating language. It supports all relevant language features from Twig 3.0+ and even some custom tags/filters from Craft CMS 3.0+.

This extension also includes a huge list of completions for Twig and Craft CMS 3.0+, including Element Queries.

Please note: When this plugin was released, syntax highlighting in Nova was regex-based. Starting with Nova 10, Panic migrated to Tree-sitter, a totally different form of syntax definitions. There are no plans to migrate this plugin to Tree-sitter, because it would require a full rewrite. However, this plugin will be supported until Panic decides to drop support for regex-based grammars altogether.

With the introduction of Tree-sitter support in Nova 10, building new regex grammars is discouraged. Support will remain for the forseeable future for backward compatibility, but new features will be targeted exclusively at Tree-sitter. See: https://docs.nova.app/syntax-reference/regex-grammars/

Installation

In Nova, go to “Extension > Extensions Library”, search for “Twig” and install the extension.

Manual way: Download this repository, extract the .zip file and open the folder with Nova.

If you use Twig inside Markdown files (e.g. Grav CMS): Map “.md” to “Twig-Markdown” in settings to activate syntax highlighting for Twig inside regular Markdown files.

Development

Clone this repository and open the folder with Nova. In Nova, go to “Settings > General” and enable “Show extension development items in the Extension menu”. Then activate the extension via the “Extension” menu.

Ideas for future development

  • [ ] Migrate all syntax definitions and completions to Tree-sitter (Nova 10+)
  • [ ] Restore subsyntax highlighting for <script>, <style>, {% css %} and {% js %} (requires migration to Tree-sitter)
  • [ ] Update completions for Craft 4+
  • [ ] Add support for matching Twig brackets (not possible at the moment?)

If you have some tips or want to help with development, feel free to let me know!


Changelog

Version 1.9.0

When this plugin was released, syntax highlighting in Nova was regex-based. Starting with Nova 10, Panic migrated to Tree-sitter, a totally different form of syntax definitions. Until now, Nova included two versions for each built-in grammar: a new Tree-sitter version and an old regex-based version for backwards compatibility. The Twig plugin relies on the regex-based grammars for syntax highlighting of HTML and Markdown. Nova 13 removed them, so I decided to include the original grammars with this plugin to restore compatibility.

Pleae note: Since Nova’s new built-in syntax definitions can’t be used as subsyntax inside of regex-based grammars, syntax highlighting inside of <script>, <style>, {% css %} and {% js %} isn’t supported anymore.

  • Re-add support for HTML syntax highlighting for compatibility with Nova 13+.
  • Re-add support for Markdown syntax highlighting for compatibility with Nova 13+.
  • Remove support for nested syntax highlighting inside {% css %} and {% js %} (Craft CMS).

Version 1.8.2

  • Fix: Re-add support for HTML completions for compatibility with Nova 10+.

Version 1.8.1

  • Add support for modifiers (e.g. at head) on fenced code blocks ({% css %} and {% js %})

Version 1.8

  • Add support for nested syntax highlighting inside {% css %} and {% js %} (Craft CMS)

Version 1.7

  • Add optional Twig-Markdown syntax definition: Map “.md” to “Twig-Markdown” in settings to activate syntax highlighting for Twig inside Markdown files (Grav CMS).

Version 1.6

  • Add completions for Craft Element Queries and common properties

Version 1.5

  • Add completions without closing tags
  • Fix: Don’t show completions right before %}

Version 1.4.1

  • Fix: Don’t show syntax highlighting inside comments

Version 1.4

  • Add symbols for macro definitions
  • Add completions for variables and macros defined in the same file
  • Add completions for argument lists

Version 1.3

  • Add basic tag completions for Twig-HTML (outside opening brackets)
  • Fix: correct end tag for autoescape completion
  • Fix: correct syntax highlighting for blocks and variables named like keywords

Version 1.2

  • Auto insert %} after tags in completions
  • Auto insert {% endif %}, {% endfor %} etc. in tag completions
  • Auto insert space after function calls in completions
  • Improve context for completions
  • Remove matching {} from Twig-HTML syntax

Version 1.1

  • Completions for Craft CMS 3.0+
  • Better Syntax Highlighting for Craft CMS 3.0+
  • Better Icon

Version 1.0

Initial release

  • Syntax Highlighting for Twig 3.0+
  • Syntax Highlighting for custom tags/filters from Craft CMS 3.0+
  • Completions for Twig 3.0+

License

MIT License

Copyright (c) 2023

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.