I totally understand what you mean, or trying to do. Unfortunately it is the Nova API shortcoming … which is quite frustrating.
As you said easily achieved in VS Code. But having said that, IF Nova implements this, the Tree-Sitter is far more superior
To clear up the confusion, let me expand a bit more.
With markdown, the injection node is defined by the grammar, under $.fenced_code_block_delimiter
[It is defined as an external scanner it is not part of grammar.js
].
As it is fundamental part of markdown, of course it makes sense to be part of the grammar.
Now that we have the facility. The injection happens sort of dynamic like this after capturing the node’s content. again defined in the markdown queries
folder.
; Fenced code blocks
(fenced_code_block
(info_string (language) @injection.language)
(code_fence_content) @injection.content
)
Now in your case, this means, sending pull request to every single tree-sitter
repo and ask them to define pre
or /*! */
or <pre>
in their grammar which is not practical… and to be honest not the best way anyways.
For example AlpineJS is used by many other frameworks, or even stand-alone. Rather than me changing the base tree-sitter-html
or any other framework, to define the x-whatever
and then inject JS inside it, Nova should give us a facility to “extend the injections” for the html
. Which is exactly what you need. The ability to extend the injection for css
, html
or any language you want to implement your functionality.
To give you a concrete example of the end result, here is how it can be achieved in NeoVim. As the guts are out and ready for manipulation, here is how one user managed to get the AlpineJS injection working in any framework, language, basically everywhere that is being parsed as html
. But that meant him manually changing content of the injections.scm
for tree-sitter-html
:
Look at the code example under “AlpineJS injection”. They are basically saying, in html if the attribute name is such and such, treat it’s attribute value’s content as JS
.
In your case you are doing the exact same thing, if it was allowed by Nova.
- grab the
$.tag_name
and check if it is <pre>
- Somehow grab the first word that follows
- This might be your biggest hurdle. As when you write:
<pre>html
//content
</pre>
- The whole
html+content
are grabbed as ONE node called $.text
- Not sure if you can grab the first-word pre space/newline/tab using the tree-sittter query capture and then apply the language.
- Use whatever language captured, as an injected language, inside the
$.text
It is geniunely a valid request you have but, for some reason our hands are tight, and a bit more complicated than it needs to be… If supported it will give us all a super power though.
As long as I know, injections were a pain, in any code editor I have ever worked in with… we are so close to nailing it, with tree-sitter though. This is the best and closest we have been in fixing the injection hell!