diff --git a/CHANGELOG.md b/CHANGELOG.md index 22519608..4e99fbcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ # Unreleased: pdoc next + - Improve display of reStructuredText admonitions. + ([#372](https://github.com/mitmproxy/pdoc/issues/372), [@mhils](https://github.com/mhils)) - Add support for reStructuredText field lists: `:param foo: text`. ([#275](https://github.com/mitmproxy/pdoc/issues/275), [@mhils](https://github.com/mhils)) diff --git a/pdoc/docstrings.py b/pdoc/docstrings.py index f5266974..95724cb4 100644 --- a/pdoc/docstrings.py +++ b/pdoc/docstrings.py @@ -328,10 +328,17 @@ def _rst_admonition(m: re.Match[str]) -> str: return indent(included, ind) if type == "math": return f"{ind}$${val}{contents}$$\n" - if type == "note": - text = val or "Note" - elif type == "warning": - text = val or "Warning" + if type in ("note", "warning", "danger"): + if val: + heading = f"{ind}###### {val}\n" + else: + heading = "" + return ( + f'{ind}