Skip to content

Add static comment helpers#200

Merged
jg-rp merged 1 commit intomainfrom
static-comment-helpers
Apr 29, 2026
Merged

Add static comment helpers#200
jg-rp merged 1 commit intomainfrom
static-comment-helpers

Conversation

@jg-rp
Copy link
Copy Markdown
Owner

@jg-rp jg-rp commented Apr 28, 2026

This PR adds BoundTemplate.comments() and BoundTemplate.docs() for statically retrieving a template's {% comment %}, {% # inline comment %} and {% doc %} nodes.

from liquid import parse

source = """\
{% doc %}
    some doc comment
{% enddoc %}

Hello!

{% comment %}
    some comment
{% endcomment %}

{% if false %}
    {% # an inline comment %}
{% endif %}
"""

template = parse(source)
print([node.text for node in template.comments()])
print([node.text for node in template.docs()])

Output

['\n    some comment\n', 'an inline comment']
['\n    some doc comment\n']

Fixes #199
Fixes #196.

@jg-rp jg-rp merged commit 011d2bd into main Apr 29, 2026
28 checks passed
@jg-rp jg-rp deleted the static-comment-helpers branch April 29, 2026 06:12
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.

Static {% comment %} and {% doc %} retrieval Documentation for {% doc %}

1 participant