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

Document how to render Mermaid graphs #1435

Merged
merged 1 commit into from
Nov 15, 2021

Conversation

jonatanklosko
Copy link
Member

Closes #1434.

@fhunleth please give it a try and let me know if it works for you.

FTR initially I tried a slightly simpler solution, which was to first replace all <pre> tags with <div class="mermaid"> and then run the automatic rendering:

document.addEventListener("DOMContentLoaded", function () {
  for (const codeEl of document.querySelectorAll("pre code.mermaid")) {
    const preEl = codeEl.parentElement;
    const graphDefinition = codeEl.textContent;
    const graphEl = document.createElement("div");
    graphEl.classList.add("mermaid");
    graphEl.textContent = graphDefinition;
    preEl.insertAdjacentElement("afterend", graphEl);
    preEl.remove();
  }
  mermaid.initialize({ startOnLoad: true });
});

Then I tried a more manual approach, which I included in this PR. The primary difference is when the graph definition is invalid. When rendering manually we keep the definition in a <pre> tag so it can be read and there is an error in the console. On the other hand, when using the auto rendering the element gets replaced with a huge "failed to render" image and there's nothing useful in the console.

@josevalim josevalim merged commit f4c234e into elixir-lang:main Nov 15, 2021
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@jonatanklosko jonatanklosko deleted the jk-mermaid branch November 15, 2021 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Trimmed whitespace in embedded HTML breaks Mermaid.js diagrams
2 participants