From 525a8a26b8e645aebd36048953abe7a76227949c Mon Sep 17 00:00:00 2001 From: JCGoran Date: Sat, 30 Sep 2023 04:01:31 +0200 Subject: [PATCH] Add parsing of `code-block` ReST directives (#624) --- CHANGELOG.md | 2 ++ pdoc/docstrings.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c652d12..f1d1e824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ + - Add support for `code-block` ReST directives + ([#624](https://github.com/mitmproxy/pdoc/pull/624), @JCGoran) - If a variable's value meets certain entropy criteria and matches an environment variable value, pdoc will now emit a warning and display the variable's name as a placeholder instead. This heuristic is meant to prevent accidental leakage of environment secrets and can be disabled by setting diff --git a/pdoc/docstrings.py b/pdoc/docstrings.py index 3d3196d3..ff0fa95a 100644 --- a/pdoc/docstrings.py +++ b/pdoc/docstrings.py @@ -393,7 +393,9 @@ def _rst_admonition(m: re.Match[str]) -> str: f"{indent(contents, ind)}\n" f"{ind}\n" ) - elif type == "versionadded": + if type == "code-block": + return f"{ind}```{val}\n{contents}\n```\n" + if type == "versionadded": text = f"New in version {val}" elif type == "versionchanged": text = f"Changed in version {val}" @@ -409,7 +411,7 @@ def _rst_admonition(m: re.Match[str]) -> str: return text - admonition = "note|warning|danger|versionadded|versionchanged|deprecated|seealso|math|include" + admonition = "note|warning|danger|versionadded|versionchanged|deprecated|seealso|math|include|code-block" return re.sub( rf""" ^(?P[ ]*)\.\.[ ]+(?P{admonition})::(?P.*)