Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parsing of code-block ReST directives #624

Merged
merged 3 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<!-- ✨ You do not need to add a pull request reference or an author, this will be added automatically by CI. ✨ -->

- 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
Expand Down
6 changes: 4 additions & 2 deletions pdoc/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ def _rst_admonition(m: re.Match[str]) -> str:
f"{indent(contents, ind)}\n"
f"{ind}</div>\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}"
Expand All @@ -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<indent>[ ]*)\.\.[ ]+(?P<type>{admonition})::(?P<val>.*)
Expand Down