Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for html comments to template syntax #3662

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

iamllama
Copy link
Contributor

@iamllama iamllama commented Dec 24, 2024

From https://forums.ankiweb.net/t/conditional-brackets-are-still-recognized-inside-html-comments/2207 and https://forums.ankiweb.net/t/is-it-possible-to-add-comment-in-template-that-is-not-displayed-in-review-mode/19962

This PR proposes adding support for html comments (<!-- -->) to the template syntax, e.g.

{{#A}}
    <!-- {{B}} -->
    {{C}}
    <!--
    {{#Image}}
        {{Image}}
        {{Caption}}
    {{/Image}}
    -->
{{/A}}

where brackets inside closed comment blocks are treated as text

Just as styling allows comments in it, it can be handy to keep old/useful snippets around without having to make another note/card type or stash it somewhere else. Since templates are html, html comments are used instead of something like /* */. As per the standard, they cannot be nested, i.e the nearest --> closes a <!--

Couldn't find a suitable parser combination that could pass current tests and avoid allocations, hence the mess 😅
Extra relevant tests have been added as well. Unclosed comments aren't treated as errors, since the card layout editor doesn't enforce closed comments (unlike the desktop field editor, for example)

Breakage:

  • Legacy mode is left alone, as i assumed it to be under feature-freeze

  • The following would no longer cause card generation, despite currently not rendering anything:

<!--
{{#A}}
    {{B}}
{{/A}}
-->

This seems like the most concerning one, but it can be fixed by moving the comments inside the {{#A}} scope instead of around EDIT: nope, there has to be at least one valid uncommented handlebar inside

  • This would no longer be valid:
<!-- {{#A}} -->
    {{B}}
{{/A}}

Given the breakages and the lack of issues requesting this for quite some time, this might not be well received, so i'd just like to put it out here to gather feedback. Perhaps we could add something like the legacy directive to enable comment mode 🤔

Happy holidays!

@brishtibheja
Copy link
Contributor

Given the breakages and the lack of issues requesting this for quite some time, this might not be well received, so i'd just like to put it out here to gather feedback.

I personally don't think there would be a lot of people with templates that depend on the current behaviour. I like the change 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants