-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Draw diagrams from markdown within ReDoc page #266
Comments
The last diagram example on this page http://jumly.tmtk.net/ is sort of what diagrams I am trying to draw.. |
@avkonst thanks for this feature request.
But I see your use case and I have an idea of how we can cover it: What do you think? |
Hi, Thanks for the proposal. Maybe hooks/plugins is good feature to have, keep this in mind, but I am not very much dependent on this now. I have solved the problem by inserting a picture link into markdown, and the picture link points out to my backend which generates pictures from text. It allowed me to write documentation in separate markdown editor and still have pictures in preview in the editor. I have not tried it yet to deploy to ReDoc, but as long as the markdown renderer you use in ReDoc can insert SVG and PNG pictures, it should be all good as it is now. Thanks |
Sounds good, I would vote for a plugin for mermaid :) |
For those who want mermaid anyway, I've made a hacky way to render it. mermaid.initialize({startOnLoad: false});
let id = 0;
Redoc.init(url, {
...configs,
theme: {
extensionsHook: (name, props) => {
if (name !== "Markdown" || props.html === undefined) return "";
var markdown = document.createElement("div");
markdown.innerHTML = props.html;
var mermaidNodes = markdown.querySelectorAll("pre > code.language-mermaid");
for (const mermaidNode of mermaidNodes) {
mermaid.render(`mermaid-${id++}`, mermaidNode.textContent, svg => {
mermaidNode.parentNode.outerHTML = svg;
});
}
props.dangerouslySetInnerHTML.__html = markdown.innerHTML;
return "";
}
}
}, container); |
If you're generating static docs using
|
With Mermaid v10's breaking change and its dependence on async/await, I've only been able to get it to work by waiting for Redoc to finish rendering. <body>
<div id="redoc"></div>
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"></script>
<script type="module">
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs";
mermaid.initialize({ startOnLoad: true });
Redoc.init("./docs/swagger.json", {}, document.getElementById("redoc"), async () => {
let id = 0;
const mermaidNodes = document.getElementById("redoc").querySelectorAll("pre > code.language-mermaid");
for (const mermaidNode of mermaidNodes) {
const { svg } = await mermaid.render(`mermaid-${id++}`, mermaidNode.textContent);
mermaidNode.parentNode.outerHTML = svg;
}
});
</script>
</body> |
I have discovered needs to embed various diagrams within the documentation page rendered by the ReDoc. Currently I generate pictures from PlantUML text and hope to refer to these pictures from the markdown text embedded within the swagger specification, provided to the ReDoc. The problem is that the pictures need to be saved and served from somewhere and could get dis-synchronized with the documentation eventually, because the documentation content ends up in different places.
Instead, it would be great to have a way to render diagrams within the ReDoc page from markdown text embedded within the swagger specification. Something similar to this: http://support.typora.io/Draw-Diagrams-With-Markdown/
Is it valid idea? or I am taking some non-advised approach? If valid, would this feature be possible for implementation?
The text was updated successfully, but these errors were encountered: