Skip to content

Commit

Permalink
Add parsing of code-block ReST directives (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
JCGoran authored Sep 30, 2023
1 parent fdde9a8 commit 525a8a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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

0 comments on commit 525a8a2

Please sign in to comment.