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

How we integrated mermaid with our docs #20

Open
DanielJoyce opened this issue Jun 10, 2022 · 1 comment
Open

How we integrated mermaid with our docs #20

DanielJoyce opened this issue Jun 10, 2022 · 1 comment

Comments

@DanielJoyce
Copy link

Hey, decided to drop a line

First we created some doc-assets

header.html:

<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>

after-content:

<script> mermaid.init({ startOnLoad: true, theme: "neutral" }, "pre.language-mermaid > code");</script>

the magic is the pre.language-mermaid selector. When rustdoc renders a mermaid comment, it renders it in a pre element with class of .language-mermad. So all we need to do is init the mermaid library with that selector.

Then we run rustdoc with

#!/usr/bin/env bash

set -eou pipefail

cargo rustdoc --open -- --default-theme=ayu --html-in-header=doc-assets/header.html --html-after-content=doc-assets/after-content.html

And now any comment block with a mermaid comment inside it will render graphs. This works both in item and module comments.

Once doc directives get support for html-in-header and html-after-content, the special build command can go away.

@DanielJoyce
Copy link
Author

DanielJoyce commented Jun 10, 2022

There is a bug in rustdoc where the first line of a included markdown file may not be rendered properly in some cases.

For now, you can add this to the top of a MD file that will be included in your docs to fix it

<!--- Do not delete this comment or the newline after, rustdoc md bug -->
<!--- https://github.com/rust-lang/rust/issues/97966 -->

The extra line MUST be present before the first line of MD Content. This is only an issue for pulling MD files, not with mermaid supprot itself.

github-merge-queue bot pushed a commit to paritytech/polkadot-sdk that referenced this issue Apr 4, 2024
Closes #2977

The issue appears to stem from the `aquamarine` crate failing to render
diagrams in re-exported crates.

e.g. as raised
[here](#2977), diagrams
would render at `frame_support::traits::Hooks` but not the re-exported
doc `frame::traits::Hooks`, even if I added `aquamarine` as a `frame`
crate dependency.

To resolve this, I followed advice in
mersinvald/aquamarine#20 to instead render
mermaid diagrams directly using JS by adding an `after-content.js`.

---

Also fixes compile warnings, enables `--all-features` and disallows
future warnings in CI.

---------

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Ank4n pushed a commit to paritytech/polkadot-sdk that referenced this issue Apr 9, 2024
Closes #2977

The issue appears to stem from the `aquamarine` crate failing to render
diagrams in re-exported crates.

e.g. as raised
[here](#2977), diagrams
would render at `frame_support::traits::Hooks` but not the re-exported
doc `frame::traits::Hooks`, even if I added `aquamarine` as a `frame`
crate dependency.

To resolve this, I followed advice in
mersinvald/aquamarine#20 to instead render
mermaid diagrams directly using JS by adding an `after-content.js`.

---

Also fixes compile warnings, enables `--all-features` and disallows
future warnings in CI.

---------

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
dharjeezy pushed a commit to dharjeezy/polkadot-sdk that referenced this issue Apr 9, 2024
Closes paritytech#2977

The issue appears to stem from the `aquamarine` crate failing to render
diagrams in re-exported crates.

e.g. as raised
[here](paritytech#2977), diagrams
would render at `frame_support::traits::Hooks` but not the re-exported
doc `frame::traits::Hooks`, even if I added `aquamarine` as a `frame`
crate dependency.

To resolve this, I followed advice in
mersinvald/aquamarine#20 to instead render
mermaid diagrams directly using JS by adding an `after-content.js`.

---

Also fixes compile warnings, enables `--all-features` and disallows
future warnings in CI.

---------

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant