Skip to content

Can't combine math and custom filter #772

Open
@mdaeron

Description

@mdaeron

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions