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 additional markdown extras / mermaid #524

Closed
thearchitector opened this issue Mar 25, 2023 · 2 comments · Fixed by #525
Closed

Add support for additional markdown extras / mermaid #524

thearchitector opened this issue Mar 25, 2023 · 2 comments · Fixed by #525

Comments

@thearchitector
Copy link
Contributor

thearchitector commented Mar 25, 2023

Problem Description

GitHub supports rendering Markdown files with Mermaid diagrams, which aren't supported by default with markdown2 and thus don't get translated correctly.

It seems like a pretty common use case to include your project's README in your module's top-level docstring. Since the diagram doesn't render, I've found that I need to maintain 2 copies of the README, one using the mermaid fence block syntax and another with a static <img> of the diagram (and making them both an img doesn't work since the img doesn't respond to GitHub's theme changes).

Proposal

This proposal requires bumping the vendored version of the markdown2.

More recent versions have built-in support for rendering mermaid diagrams via the mermaid extra. The extra requires some additional HTML stuff, but I don't think that needs to be included in default template (people can add the necessary JavaScript themselves via a custom template, maybe with a doc explaining how to do it).

Alternatives

Rather than always enable the mermaid extra and having to maintain the list of extras enabled, more recent versions of markdown2 also support enabling extras from within a markdown document via the use-file-vars extra. Adding that one extra would let people customize the rendering of their markdowns themselves rather than either fork this project or find another solution.

@mhils
Copy link
Member

mhils commented Mar 26, 2023

I'd be happy to merge a PR that bumps markdown2, and I'd also be happy to enable the mermaid extra by default. 👍

The extra requires some additional HTML stuff, but I don't think that needs to be included in default template (people can add the necessary JavaScript themselves via a custom template, maybe with a doc explaining how to do it).

This sounds about right. We definitely don't want to pull in stuff from third parties by default. But adding this with an "How can I ...?" entry on https://pdoc.dev/docs/pdoc.html and optionally an example in ./examples would be great! Do you want to send a PR?

more recent versions of markdown2 also support enabling extras from within a markdown document via the use-file-vars extra.

One problem here is that we render each docstring individually, so you'd need to repeat that string a lot. If you need to customize the included extras, it's probably more convenient to write a small Python script that patches https://pdoc.dev/docs/pdoc/render_helpers.html#markdown_extensions and then calls pdoc.pdoc(...). But again, for the specific case of the mermaid extra there's no harm in enabling it by default. 😃

@thearchitector
Copy link
Contributor Author

thearchitector commented Mar 26, 2023

Sure! I'll put together a PR with the version bump and doc updates. Re file-vars, since each doc is separate then that makes sense to me -- at a certain point the granularity required would probably exceed the benefit of the customizability.

Clarifying question -- is there a reason that markdown2 is vendored instead of just listed as a dependency?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants