From fed80a6c152ccc548c21599b0d48a97f24b08f8d Mon Sep 17 00:00:00 2001 From: Jesse Visser Date: Thu, 20 Jul 2023 22:18:24 +0200 Subject: [PATCH] ENH: Simple implementation of appending markdown extensions --- pdoc/html_helpers.py | 10 ++++++++-- pdoc/templates/config.mako | 3 +++ pdoc/templates/html.mako | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pdoc/html_helpers.py b/pdoc/html_helpers.py index 51861947..444bd665 100644 --- a/pdoc/html_helpers.py +++ b/pdoc/html_helpers.py @@ -409,8 +409,10 @@ def handleMatch(self, m, data): def to_html(text: str, *, docformat: str = None, - module: pdoc.Module = None, link: Callable[..., str] = None, - latex_math: bool = False): + module: pdoc.Module = None, + link: Callable[..., str] = None, + latex_math: bool = False, + md_extensions: dict = None): """ Returns HTML of `text` interpreted as `docformat`. `__docformat__` is respected if present, otherwise Numpydoc and Google-style docstrings are assumed, @@ -428,6 +430,10 @@ def to_html(text: str, *, _MathPattern.NAME, _MathPattern.PRIORITY) + # Optionally register additional markdown extensions + if md_extensions is not None: + _md.registerExtensions(md_extensions['extensions'], md_extensions['configs']) + md = to_markdown(text, docformat=docformat, module=module, link=link) return _md.reset().convert(md) diff --git a/pdoc/templates/config.mako b/pdoc/templates/config.mako index 992ff2eb..4b0c1c13 100644 --- a/pdoc/templates/config.mako +++ b/pdoc/templates/config.mako @@ -61,4 +61,7 @@ # Note: in Python docstrings, either all backslashes need to be escaped (\\) # or you need to use raw r-strings. latex_math = False + + # Register additional markdown extensions. See: https://python-markdown.github.io/extensions/admonition/ + md_extensions = {'extensions': [], 'configs': {}} %> diff --git a/pdoc/templates/html.mako b/pdoc/templates/html.mako index f0517880..6018f0c5 100644 --- a/pdoc/templates/html.mako +++ b/pdoc/templates/html.mako @@ -15,7 +15,7 @@ def to_html(text): - return _to_html(text, docformat=docformat, module=module, link=link, latex_math=latex_math) + return _to_html(text, docformat=docformat, module=module, link=link, latex_math=latex_math, md_extensions=md_extensions) def get_annotation(bound_method, sep=':'):