-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 a `display_mermaid(diagram: str) function which rendered the provided diagram as a Mermaid diagram #14319
Comments
@krassowski, |
Really I don't think we should, if something has a mermaid repr, then
The current |
Also see this talk I did with Paul Ivanov at JupyterCon arround 20 ish minutes you see a prototype where the frontend let you choise the repr you want, making |
Sure, I actually agree with that - I was just trying to follow existing convention. All I care about is that I can view a str object as a mermaid diagram. Maybe that just needs a |
Maybe the issue title should be changed to: Allow displaying a string variable as a Mermaid diagram |
You can register custom mimetype for any objects, even builtin types, or types you don't control methods of: https://ipython.readthedocs.io/en/stable/config/integrating.html#formatters-for-third-party-types https://ipython.readthedocs.io/en/stable/config/shell_mimerenderer.html https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.formatters.html That is if you want to display all strings via mermaid. Otherwise yes, I believe you "just" need an object that define |
Don't you need a From the current markdown implementation it looks like it's being converted to an inline svg: <div class="jp-RenderedMermaid" style="">
<figure>
<img src="data:image/svg+xml,%3Csvg%20<snip>">
</figure>
</div> |
NB: the ipython/docs/source/config/integrating.rst Line 134 in 8b1204b
https://ipython.readthedocs.io/en/stable/config/integrating.html#more-powerful-methods |
I can create a string variable, representing html, wrap it in the I'd like to be able to do the same with a string object representing a mermaid diagram - import a class from Since not all strings are mermaid diagrams I think I need some custom class to wrap them and it would seem to make sense for that to live alongside the other rich-repr classes in |
...it doesn't have to though - I would be happy to define my own class: class MyMermaidJS:
def _repr_mimebundle_(self, include=None, exclude=None) -> tuple[dict, dict]:
...
return ??? ...I'm just not too sure what I need to return for JupyterLab to understand how to display it as a rendered Mermaid diagram 🤔 |
Yep - I know of your efforts in that area ( ❤️ ) and I've thought for a long time that it would be very useful to have that capability. Funnily enough, this came up for me again just the other week where the rich-repr of a ...but since you can force the text-repr easily it wasn't a big deal for that use-case. |
Gha... sphinx is resolving to the wrong thing indeed. |
Yes, JupyterLab would need to know about the mermaid mimetype, it would need a mimerender: https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#mime-renderer-plugins Here are a few renderer: https://github.com/jupyterlab/jupyter-renderers It seem it's currently a provider, I'm not sure the difference between a provider and renderer, you woudl have to ask the JupyterLab team, but my guess is if there is a provider it's likely only a few line to add a render, you just need to decide the mimetipe (and file extension), but mermaid already recommend |
I sort-of expected that which was why I initially opened the issue in the JupyterLab repo. I'll try and see what the JL devs say about it. Thanks for your help here! |
There is already a notebook that should display a mermaid diagram: it basically show you what |
Yep, The Indeed, the argument could be made that things like Some possible contribution targets for an actual
|
Would there be any interest in having this in It's certainly where I'd first look for this functionality. (I'd be happy with just the |
I am not familiar with technical detail. I thought Jupyter notebook was a web application and the ability to display any HTML (including the support of Mermaid diagram) was natural. It seems not. So may Jupyter provide a more general display_html function? If so, mermaid or any formats supported by web can be displayed. I understand there may be some security concerns. Any ideas? |
As mentioned by @dhirschfeld in jupyterlab/jupyterlab#15725
With jupyterlab 4.1 coming out and supporting Mermaid.js diagrams, it would be useful to display programmatically generated Mermaid diagrams in JupyterLab.
See this comment for the initial idea:
jupyterlab/jupyterlab#15725 (comment)
The text was updated successfully, but these errors were encountered: