Skip to content

Commit

Permalink
add support for GitHub Markdown alerts (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils authored Jul 24, 2024
1 parent f2ffa5e commit 1f08df5
Show file tree
Hide file tree
Showing 32 changed files with 101 additions and 83 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- If `example.data.Data` is also exposed as `example.Data`, pdoc now links to `example.Data` in documentation.
([#670](https://github.com/mitmproxy/pdoc/pull/670), @nathanthorpe, @mhils)
- Add support for [GitHub Markdown Alerts](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts).
([#718](https://github.com/mitmproxy/pdoc/pull/718), @mhils)
- Improve rendering of enums on Python 3.12+.
([#708](https://github.com/mitmproxy/pdoc/pull/708), @mhils)
- Fix a bug where hyperlinks would get parsed as docstring references.
Expand Down
2 changes: 1 addition & 1 deletion pdoc/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def _rst_admonition(m: re.Match[str]) -> str:
else:
heading = ""
return (
f'{ind}<div class="pdoc-alert pdoc-alert-{type}" markdown="1">\n'
f'{ind}<div class="alert {type}" markdown="1">\n'
f"{heading}"
f"{indent(contents, ind)}\n"
f"{ind}</div>\n"
Expand Down
1 change: 1 addition & 0 deletions pdoc/render_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

# Keep in sync with the documentation in pdoc/__init__.py!
markdown_extensions = {
"alerts": None,
"code-friendly": None,
"cuddled-lists": None,
"fenced-code-blocks": {"cssclass": formatter.cssclass},
Expand Down
14 changes: 9 additions & 5 deletions pdoc/templates/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This makes sure that the pdoc styling doesn't leak to the rest of the page when


/* Admonitions */
.pdoc .pdoc-alert {
.pdoc .alert {
padding: 1rem 1rem 1rem calc(1.5rem + 24px);
border: 1px solid transparent;
border-radius: .25rem;
Expand All @@ -36,26 +36,30 @@ This makes sure that the pdoc styling doesn't leak to the rest of the page when
margin-bottom: 1rem;
}

.pdoc .pdoc-alert > *:last-child {
.pdoc .alert > em {
display: none;
}

.pdoc .alert > *:last-child {
margin-bottom: 0;
}

/* Admonitions are currently not stylable via theme.css */
.pdoc .pdoc-alert-note {
.pdoc .alert.note {
color: #084298;
background-color: #cfe2ff;
border-color: #b6d4fe;
background-image: url("data:image/svg+xml,{% filter urlencode %}{% include 'resources/info-circle-fill.svg' %}{% endfilter %}");
}

.pdoc .pdoc-alert-warning {
.pdoc .alert.warning {
color: #664d03;
background-color: #fff3cd;
border-color: #ffecb5;
background-image: url("data:image/svg+xml,{% filter urlencode %}{% include 'resources/exclamation-triangle-fill.svg' %}{% endfilter %}");
}

.pdoc .pdoc-alert-danger {
.pdoc .alert.danger {
color: #842029;
background-color: #f8d7da;
border-color: #f5c2c7;
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/ast_parsing.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/demo.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/demo_eager.html

Large diffs are not rendered by default.

74 changes: 41 additions & 33 deletions test/testdata/demo_long.html

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions test/testdata/demo_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,21 @@ def embed_image():

def admonitions():
"""
pdoc also supports basic reStructuredText admonitions:
pdoc also supports basic reStructuredText admonitions or GitHub's Markdown alerts:
```
> [!NOTE/WARNING/DANGER]
> Useful information that users should know, even when skimming content.
.. note/warning/danger:: Optional title
Body text
```
.. note::
Hi there!
> [!NOTE]
> Hi there!
.. warning:: Be Careful!
This warning has both a title and content.
This warning has both a title *and* content.
.. danger::
Danger ahead.
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/demopackage.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions test/testdata/demopackage_dir.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/enums.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/example_customtemplate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/example_darkmode.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/example_mkdocs.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/flavors_google.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/flavors_numpy.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/testdata/flavors_rst.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/math_demo.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/math_misc.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/mermaid_demo.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/misc.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/misc_py310.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/misc_py311.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/misc_py312.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/misc_py39.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/pyo3_sample_library.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions test/testdata/render_options.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/top_level_reimports.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/type_checking_imports.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/type_stub.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/testdata/visibility.html

Large diffs are not rendered by default.

0 comments on commit 1f08df5

Please sign in to comment.