Skip to content

Commit

Permalink
ENH: Simple implementation of appending markdown extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessseee committed Jul 20, 2023
1 parent 3ecfbcf commit fed80a6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pdoc/html_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions pdoc/templates/config.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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': {}}
%>
2 changes: 1 addition & 1 deletion pdoc/templates/html.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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=':'):
Expand Down

0 comments on commit fed80a6

Please sign in to comment.