docsifyjs / docsify

🃏 A magical documentation site generator.
https://docsify.js.org
MIT License
27.85k stars 5.68k forks source link

Mermaid integration is broken #836

Closed mkiddTempus closed 5 years ago

mkiddTempus commented 5 years ago

Bug Report

Provided examples do not render when used in markdown file using mermaid 7.1.2 (install defaults to 8.0.0 by mistake it seems) and docsify 4.8.6.

Steps to reproduce

Have a docsify site that uses a navbar and sidebar, provide the

What is current behaviour

A graph definition like:

graph TD; 
    A --> B;

renders as plain text instead of a graph.

What is the expected behaviour

Mermaid correctly draws an svg graph.

Other relevant information

Here is the full docsify set up I tried:

Attempted to use the provided method in the docs as well as a few hacks found on the web:

    <script>
      var mermaids = document.getElementsByClassName('language-mermaid');
      console.log('mermaids count: ', mermaids.length);
      while(mermaids.length > 0) {
        mermaids[0].className = 'mermaid';
      }
    </script>

The above would never run as the document never contained any language-mermaid classes.

    <script>
      function makeid(len) {
        var text = new Array(len);
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        for (var i = 0; i < len; i++) text[i] = possible.charAt(Math.floor(Math.random() * possible.length));
        console.log('text: ' + text);
        return text.join("");
      }

      window.$docsify = {
        name: "My Site",
        repo: "https://github.com/mycompany/mysite",
        markdown: {
          renderer: {
            code: function(code, lang) {
              var id = makeid(10);
              console.log('lang: ' + lang);
              if (lang === "mermaid") {
                console.log("I ran for lang==+mermaid");
                return (
                  '<div class="mermaid">' + mermaid.render('mermaid-svg-' + id, code) + '</div>'
                );
              } else {
                console.log("welp")
              }
              return this.origin.code.apply(this, arguments);
            }
          }
        },
        loadNavbar: "sidebar.md",
        loadSidebar: "sidebar.md",
        maxLevel: 100,
        subMaxLevel: 100,
        auto2top: true,
        coverpage: "coverpage.md",
        homepage: "home.md",
        logo: "/my.png",
        themeColor: "rgb(57, 171, 209)",
        alias: {
          "/.*/sidebar.md": "/sidebar.md"
        },
        search: {
          maxAge: location.hostname === "localhost" ? 0 : 3600000, // 1 hr expiration IRL, 0 in dev
          depth: 6, // max indexing depth
          hideOtherSidebarContent: true,
          namespace: "mysite"
        }
      };

    </script>
mkiddTempus commented 5 years ago

Issue is the docs themselves as they don't show to wrap the intended SVG text in a div but the mermaid docs do here: https://mermaidjs.github.io/usage.html