Open
Description
This may be a bug, or just me doing it wrong, but I don't know which.
Problem Description
I am able to implement custom filters to my docstrings using pdoc.render.env.filters
, but these filters stop working if I ask for math mode.
Steps to reproduce the behavior:
- Create following module file
hello.py
:
"""
foo bar baz
"""
def foo():
"""
foo bar baz
"""
return 0
- Create following script
make_doc.py
to generate documentation:
import pdoc
print(pdoc.__version__) # prints out "15.0.1"
def myfilter(txt):
out = txt.replace('foo', 'FoO')
return out
pdoc.render.env.filters['myfilter'] = myfilter
pdoc.render.configure(template_directory = 'pdoc_templates')
# pdoc.render.configure(math = True)
with open('index.html', 'w') as fid:
fid.write(pdoc.pdoc('hello'))
- Create
pdoc_templates
directory with the following files:
math.html.jinja2
, copied from source with no modificationsmodule.html.jinja2
with the following contents:
{% extends "default/module.html.jinja2" %}
{% macro docstring(var) %}
{% if var.docstring %}
<div class="docstring">{{ var.docstring | to_markdown | myfilter | to_html | linkify(namespace=var.qualname) }}</div>
{% endif %}
{% endmacro %}
- Run
make_doc.py
and check the output, which usesFoO
instead offoo
, as intended. - Uncomment the line in
make_doc.py
withmath = True
. - Run
make_doc.py
again. The output now usesfoo
everywhere, implying thatmyfilter
was ignored.
System Information
15.0.1