Selecting of extension syntax in HTML files that begin with <!DOCTYPE html> fails

I have just released my first Nova syntax extension for Handlebars, which is a templating extension for HTML. The syntax is now detected in HTML files using the following combo selector:

<detectors>
    <extension priority="1.0">hbs,handlebars,mustache</extension>
    <match-content lines="1" priority="1.0">\#\!handlebars\b</match-content>
    <combo priority="1.0">
        <extension>html</extension>
        <match-content>\{\{[^}]+\}\}</match-content>
    </combo>
</detectors>

This works in all HTML files containing a Handlebars typical string {{…}}, but in files starting with <!DOCTYPE html> the detector fails and the syntax highlighting stays on HTML.

Is there something wrong with the detector or is there a way to override the default HTML detection?

The repository of the extension can be found on GitLab: Nova Handlebars Extension

1 Like

Hmm. I just loaded your extension, and it seems to be working properly for me.

I created a document with the following content:

<!DOCTYPE html>

{{ testing }}

Opening this file correctly chooses the “Handlebars” language.

If perhaps there’s something more file-specific going on, would you mind providing a file you’re seeing this behavior in, and I can continue investigating! Otherwise, I guess my first suggestion would be to perhaps check that you don’t have any user-level overrides in your Nova Preferences → Files → Custom File Types that might force these files to HTML or something similar?

2024-01-12 14.08.14

@logan Thank you for testing and finding out, that the Doctype string is not the problem. I have checked my preferences and there are no rules defined either for Handlebars or HTMl files.

I have now run some more tests and now it is getting weird. A file with the following content is not detected as Handlebars:

<!DOCTYPE html>

<html>

    <head>
        <meta charset="utf-8"/>
        <title>Handlebars Extension Test File</title>
    </head>

    <body>
        {{ testing }}

If I remove a random line from it, it shows up as Handlebars – even a blank line. I have stripped the structure down to a minimum that is not detected as Handlebars (the two blank lines at the top are mandatory):



<foo>

    <foo>
        <foo />
        <foo />
    </foo>

    <foo>
        {{ testing }}

Sorry for the delay in getting back!

I think I’ve found the issue. Nova’s match-content syntax detector type has a default line count (of 10 lines) enforced if you don’t specify one yourself, a fact that I’ve entirely overlooked. These are documented to be unbounded by default, and you might be the first person for whom we’ve now discovered this.

I’ll make sure this gets amended in the implementation for our next major release to be truly unbounded, but in the interim, if you add a lines attribute, such as <match-content lines="10000"> (or set to a similar high-bound), it should hopefully get things working?

Actually, even better: setting lines="0" should make it unbounded as expected.

1 Like

@logan Thank you for solving this problem. I have just updated the extension and everything seems to be working fine.

2 Likes