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

Can't combine math and custom filter #772

Open
mdaeron opened this issue Jan 31, 2025 · 0 comments
Open

Can't combine math and custom filter #772

mdaeron opened this issue Jan 31, 2025 · 0 comments
Labels

Comments

@mdaeron
Copy link

mdaeron commented Jan 31, 2025

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:

  1. Create following module file hello.py:
"""
foo bar baz
"""

def foo():
	"""
	foo bar baz
	"""
	return 0
  1. 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'))
  1. Create pdoc_templates directory with the following files:
  • math.html.jinja2, copied from source with no modifications
  • module.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 %}
  1. Run make_doc.py and check the output, which uses FoO instead of foo, as intended.
  2. Uncomment the line in make_doc.py with math = True.
  3. Run make_doc.py again. The output now uses fooeverywhere, implying that myfilter was ignored.

System Information

15.0.1

@mdaeron mdaeron added the bug label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant