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

add: support for in-Markdown Mermaid diagrams #525

Merged
merged 7 commits into from
Mar 28, 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 rendering [Mermaid diagrams](https://mermaid.js.org/) by passing `--mermaid`.
([#525](https://github.com/mitmproxy/pdoc/pull/525), @thearchitector, @mhils)
- Add additional Jinja2 blocks to allow a more fine-grained customization of the menu.
([#521](https://github.com/mitmproxy/pdoc/pull/521), @mikkelakromann)
- Fix a crash in pdoc 13.0.0 when `__init__.py` is passed as a file to pdoc.
Expand Down
14 changes: 14 additions & 0 deletions docs/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@
output_directory=here / "docs" / "math",
)

# Render mermaid example
pdoc.render.configure(
mermaid=True,
logo="/logo.svg",
logo_link="https://pdoc.dev",
edit_url_map={
"math_demo": "https://github.com/mitmproxy/pdoc/blob/main/test/testdata/mermaid_demo"
},
)
pdoc.pdoc(
here / ".." / "test" / "testdata" / "mermaid_demo.py",
output_directory=here / "docs" / "mermaid",
)

# Add sitemap.xml
with (here / "sitemap.xml").open("w", newline="\n") as f:
f.write(
Expand Down
8 changes: 8 additions & 0 deletions pdoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ class GoldenRetriever(Dog):
[`math_demo`](https://pdoc.dev/docs/math/math_demo.html) for details.


## ...render Mermaid diagrams?

Run `pdoc --mermaid`, and pdoc will render mermaid diagrams in your docstrings. See
[`mermaid_demo`](https://pdoc.dev/docs/mermaid/mermaid_demo.html) for details.


## ...add my project's logo?

See [*Customizing pdoc*](#customizing-pdoc).
Expand Down Expand Up @@ -418,6 +424,7 @@ def bark(self, loud: bool) -> None:
- **[markdown-in-html][]:** Allow the use of `markdown="1"` in a
block HTML tag to have markdown processing be done on its contents.
Similar to [PHP-Markdown Extra][] but with some limitations.
- **[mermaid][]:** Allows rendering Mermaid diagrams from included Markdown files using <code>```mermaid</code> fence blocks.
- **[pyshell][]:** Treats unindented Python interactive shell
sessions as `<code>` blocks.
- **strike:** Parse `~~strikethrough~~` formatting.
Expand All @@ -434,6 +441,7 @@ def bark(self, loud: bool) -> None:
[footnotes]: https://github.com/trentm/python-markdown2/wiki/footnotes
[header-ids]: https://github.com/trentm/python-markdown2/wiki/header-ids
[markdown-in-html]: https://github.com/trentm/python-markdown2/wiki/markdown-in-html
[mermaid]: https://github.com/trentm/python-markdown2/wiki/mermaid
[pyshell]: https://github.com/trentm/python-markdown2/wiki/pyshell
[tables]: https://github.com/trentm/python-markdown2/wiki/tables
[GitHub-Flavored Markdown]: https://github.github.com/gfm/
Expand Down
7 changes: 7 additions & 0 deletions pdoc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
default=False,
help="Include MathJax from a CDN to enable math formula rendering.",
)
renderopts.add_argument(
"--mermaid",
action=BooleanOptionalAction,
default=False,
help="Include Mermaid.js from a CDN to enable Mermaid diagram rendering.",
)
renderopts.add_argument(
"--search",
action=BooleanOptionalAction,
Expand Down Expand Up @@ -176,6 +182,7 @@ def cli(args: list[str] | None = None) -> None:
logo=opts.logo,
logo_link=opts.logo_link,
math=opts.math,
mermaid=opts.mermaid,
search=opts.search,
show_source=opts.show_source,
template_directory=opts.template_directory,
Expand Down
Loading