-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support Mermaid's callback configuration #6
Comments
Thank you for your contribution! This is very appreciated. |
Thank you. This seems a good idea. Adding code into the javascript To give me a better idea, what do usually do with a callback function on a mermaid diagram? Is it code that you want to have to rewrite ad-hoc for each specific website, or is it a standard code ? Do you have a suggestion of where the callback function should sit ? (My first reaction would be in the source directory of the project.) |
In my case right now, I want to adjust the SVG I've seen others do things like add tooltips and, perhaps most commonly, click handlers to diagram elements.
In my case right now, this is ad-hoc, though I'd certainly like to use it on all of my MkDocs sites until such a time that upstream (Mermaid) fixes the
I'd just expect to define the function in my custom extra_javascript:
- https://unpkg.com/mermaid@8.5.2/dist/mermaid.min.js
- js/extra.js |
Thanks for this useful information, as this gives me context (I would also like to learn to do what you describe 🤔). To make sure we are on the same page: the directory In that case, what about a syntax that would look like this:
We could then be smart and detect if it's an absolute path or an URL, and treat it accordingly? |
That's relative to the
That'd be fine, but I'm unsure why the plugin would need to know which file the callback function is located in? Wouldn't it just work to generate the following code, trusting that the user has made the function available: mermaid.initialize({
mermaid: {
callback: myMermaidCallbackFunction,
},
}); |
Why not? 🤔 That would really simplify the code, and if it comes as natural to you, I assume it would for any other person who practices javascript... We'll do that. Would you give me a sample function |
Wait a minute 🤦 ... but can't we already do it? What about this? plugins:
- mermaid2:
arguments:
theme: neutral
mermaid:
callback: myMermaidCallbackFunction
extra_javascript:
- https://unpkg.com/mermaid@8.5.2/dist/mermaid.min.js
- js/extra.js Shouldn't that work? |
Almost, but not quite. That generates this code: <script>mermaid.initialize({"theme": "neutral", "mermaid": {"callback": "myMermaidCallbackFunction"}});</script></body> Since the |
The simplest thing would be to just check the browser's developer console to see that the configured callback function was indeed invoked: // js/extra.js
function myMermaidCallbackFunction(id) {
console.log('myMermaidCallbackFunction', id);
} |
Right. "For want of nail, a shoe was lost...".
Yes. I guess so. |
- Fixes issue #6 - This is done by exactly replicating the proper initialize sequence: ```yaml - mermaid2: arguments: theme: dark mermaid: callback: ^myMermaidCallbackFunction ``` - The caret in front of the function name signifies that this is a literal and not a string. - A new function `pyjs.dumps` had to be created.
I found a solution that works on my side. The Here is my "not too ugly" solution: I wrote a new I used the caret ( Aside of that, I did not change the logic of the plugin. I tested it on my side with the javascript function you gave me, and it works OK. I also updated the README.md. Could you let me know if it works for you? If it works OK, I will update the pypi repository. |
Two additional notes:
mermaid:
callback: |
^function() {...
} |
Great! That works 👍
Hmm, I can't recall. Probably from examples in the wild, or Mermaid issues.
Sure, I think that'd be nice for all those users who don't plan to add any other custom JS. |
It's now published on pypi under 0.3.1. |
Mermaid has the ability (see src/mermaid.js) to invoke a user-configured callback function as it renders each diagram:
This is invaluable for doing any number of things on Mermaid diagrams that simply cannot be done with CSS.
Right now, I don't see any way to configure a Mermaid callback function in this plugin. Could that be supported in the plugin configuration? The obvious way would seem to be as follows:
The text was updated successfully, but these errors were encountered: