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

Option to preserve comment text when parsing templates #70

Closed
jg-rp opened this issue Sep 4, 2022 · 1 comment
Closed

Option to preserve comment text when parsing templates #70

jg-rp opened this issue Sep 4, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@jg-rp
Copy link
Owner

jg-rp commented Sep 4, 2022

Comment text from {% comment %} and {% # .. %} tags is currently not included in a template's abstract syntax tree.

The translation message extractor under development in the Liquid Babel project needs access to comment text when building message catalogues. Therefore, we need the option to store comments in CommentNode objects for later static analysis.

Non-standard shorthand comment syntax gets stripped out by the lexer. For now, we'll say shorthand comments are not supported by the translation message extractor.

@jg-rp jg-rp added the enhancement New feature or request label Sep 4, 2022
@jg-rp jg-rp added bug Something isn't working and removed enhancement New feature or request labels Sep 8, 2022
@jg-rp
Copy link
Owner Author

jg-rp commented Sep 8, 2022

I've decided to call this a bug, which has been fixed in version 1.4.4.

The default behaviour is now to keep comment text in a template's AST. If anyone needs to save a bit of memory by excluding comment text, you can register liquid.builting.tags.comment_tag.CommentTag with a liquid.Environment, then load and render templates from that environment.

from liquid import Environment
from liquid.builting.tags.comment_tag import CommentTag

# This will override the default `CommentTextTag` with one that discards comment text.
env = Environment()
env.add_tag(CommentTag)

template = env.from_string("{% comment %}hello{% endcomment %}")

@jg-rp jg-rp closed this as completed Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant