Skip to content
New issue

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

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

Already on GitHub? # to your account

Module and macro docstrings #2059

Closed
azmeuk opened this issue Dec 17, 2024 · 2 comments
Closed

Module and macro docstrings #2059

azmeuk opened this issue Dec 17, 2024 · 2 comments
Labels

Comments

@azmeuk
Copy link

azmeuk commented Dec 17, 2024

I use flask-themer in a project to let users extend the Jinja templates and put it at their color, customize the wording etc.
I would like to document the templates, write a few lines about what they do, which context vars are available etc.
I have forked the old unmaintained sphinxcontrib.jinjadomain into a new quick and dirty project: jinja-autodoc.

Currently jinja-autodoc expect a comment at the start of templates and considers it is a docstring. To achieve this it uses a regex.
While it works for simple use cases, I wish it could do more, such as documenting macros or blocks, but currently it seems jinja does not handle docstrings:

>>> from jinja2 import Template
>>> t = Template('{# foo #}{% macro foo() %}{# bar #}42{% endmacro %}')
>>> m = t.module
>>> m.__doc__
'Represents an imported template.  All the exported names of the\n    template are available as attributes on this object.  Additionally\n    converting it into a string renders the contents.\n    '
>>> m.foo.__doc__
'Wraps a macro function.'

I would suggest to read the first comment in templates, macros and block, and use them as docstrings.
I am not familiar with the jinja code. Are there technical blockers? Would a PR be welcome?

@CheeseCake87
Copy link

CheeseCake87 commented Dec 18, 2024

Would this be related to what you're looking to achieve? : #1967

@azmeuk
Copy link
Author

azmeuk commented Dec 18, 2024

Absolutely. Thank you.

@azmeuk azmeuk closed this as completed Dec 18, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2025
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants