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

About Markpad integration #323

Closed
kurai021 opened this issue Mar 18, 2016 · 6 comments
Closed

About Markpad integration #323

kurai021 opened this issue Mar 18, 2016 · 6 comments

Comments

@kurai021
Copy link

I'm not clear about Markpad integration, Mermaid seems not to work with key events. I even tried a simpler example by passing the value of a textarea to a div (without Markpad) and still does not work.

https://jsfiddle.net/rLLdgn3v

@kurai021
Copy link
Author

It works with mermaid.init(); but is deprecated in favor of mermaidAPI but I can understand how to use it

@Ryuno-Ki
Copy link

I toyed around with your fiddle and made some modifications.

First, I include these assets from their live editor:

Then, my HTML looks like this:

<textarea name="" id="input" cols="30" rows="10"></textarea>
Preview: <pre id="preview"></pre>
<button type="button" id="render">Render</button>
Output: <div id="output"></div>

My CSS:

#output, #preview {
  color: #000;
}

And the JavaScript code:

var input = document.getElementById("input");
var preview = document.getElementById("preview");
var output = document.getElementById("output");
var renderBtn = document.getElementById("render");

var config = {
    startOnLoad: false,
    flowchart: {
        useMaxWidth: false,
        htmlLabels:true
    }
};

render.onclick = function() {
    preview.innerHTML = input.value;
    // mermaid.initialize(config);
    mermaidAPI.render('output', input.value, function(svgCode, bindFunctions) {
        console.log("Render", svgCode, bindFunctions);
        output.innerHTML = svgCode;
    });
}

When I enter

sequenceDiagram
A->> B: Query
B->> C: Forward query
Note right of C: Thinking...
C->> B: Response
B->> A: Forward response

and hit the button, I see

ABCQueryForward queryThinking...

@Ryuno-Ki
Copy link

Working JavaScript part:

var input = document.getElementById("input");
var preview = document.getElementById("preview");
var output = document.getElementById("output");
var renderBtn = document.getElementById("render");

mermaidAPI.initialize({startOnLoad: false});

render.onclick = function() {
    preview.innerHTML = input.value;
    mermaidAPI.render('theGraph', input.value, function(svgCode) {
        output.innerHTML = svgCode;
    });
}

Note, that you need to include https://cdn.rawgit.com/knsv/mermaid/0.5.8/dist/mermaidAPI.js instead of mermaid.js!

The explanation of https://knsv.github.io/mermaid/#binding-events helped me.

@kurai021
Copy link
Author

wowww thanks bro, let me test it :D

@Ryuno-Ki
Copy link

The third argument of mermaidAPI.render takes a second argument bindFunctions which - according to the docs - could be used for event management.

@kurai021
Copy link
Author

I supposed it was for something like this

mgenereu pushed a commit to mgenereu/mermaid that referenced this issue Jun 25, 2022
…yarn/develop/tailwindcss-2.2.9

chore(deps-dev): bump tailwindcss from 2.2.7 to 2.2.9
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

2 participants