Add support for html comments to template syntax #3662
+97
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.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:
This seems like the most concerning one,
but it can be fixed by moving the comments inside the {{#A}} scope instead of aroundEDIT: nope, there has to be at least one valid uncommented handlebar insideGiven 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!