How to use the mermaid.mermaidAPI function in mermaid

To help you get started, we’ve selected a few mermaid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcegraph / sourcegraph / client / browser / src / libs / github / inject.tsx View on Github external
const renderMermaidCharts = () => {
        const pres = document.querySelectorAll('pre[lang=mermaid]')
        for (const pre of pres) {
            const el = pre as HTMLElement
            if (el.style.display === 'none') {
                // already rendered
                continue
            }
            el.style.display = 'none'
            const chartDefinition = pre.getElementsByTagName('code')[0].textContent || ''
            const chartID = `mermaid_${id++}`
            mermaid.mermaidAPI.render(chartID, chartDefinition, svg => el.insertAdjacentHTML('afterend', svg))
        }
    }
github chinakids / node-wiki / tools / markDown.js View on Github external
try {
          tex += katex.renderToString(line, {
            displayMode: true
          });
        } catch (err) {
          tex += '<pre>' + err + '</pre>';
        }
      }
    });
    return '<div data-line="' + line_number + '">' + tex + '</div>';
  } else if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' ||
    firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) {
    if (firstLine === 'sequenceDiagram') {
      code += '\n'; // 如果末尾没有空行,则语法错误
    }
    if (mermaid.mermaidAPI.parse(code)) {
      return '<div data-line="' + line_number + '" class="mermaid">' + code +
        '</div>';
    } else {
      return '<pre data-line="' + line_number + '">' + mermaidError +
        '</pre>';
    }
  } else {
    return markdown.Renderer.prototype.code.apply(this, arguments);
  }
};
renderer.html = function(html) {
github rogeruiz / scuttle / source / javascript / start.js View on Github external
// TODO This is very ugly, but for now it renders. This SVG creation should be
// done in the build step.
let ss = document.getElementById( 'js-stage' );
let btn = document.getElementById( 'save-png-button' );
btn.addEventListener('click', function() {
  let svgList = ss.getElementsByTagName('svg');
  let options = {
    scale: 2,
    backgroundColor: '#ffffff',
  };
  if (svgList.length) {
    svgPng.saveSvgAsPng(svgList[0], document.title+'.png', options);
  }
});

mermaid.mermaidAPI.render(
  'js-stage',
  ss.textContent.replace(/\n/g, '\\n'),
  function ( c ) {
    ss.innerHTML = c;
  }
);
github TimoSta / sprite / packages / app / src / Mermaid.tsx View on Github external
() => {
      try {
        console.log('redrawing')
        mermaid.mermaidAPI.parse(content)
        mermaid.mermaidAPI.render(id, content, setChart)
        setError(null)
      } catch (err) {
        console.log(err)
        setChart(null)
        setError(err.str)
      }
    },
    [id, content]
github TimoSta / sprite / packages / app / src / Mermaid.tsx View on Github external
import React, {useState, useEffect} from 'react'
import mermaid from 'mermaid'

import './Mermaid.css'

mermaid.mermaidAPI.initalize({startOnLoad: false})

interface Props {
  id: string
  content: string
}

const Mermaid = ({id, content}: Props) =&gt; {
  const [chart, setChart] = useState(null)
  const [error, setError] = useState(null)

  useEffect(
    () =&gt; {
      try {
        console.log('redrawing')
        mermaid.mermaidAPI.parse(content)
        mermaid.mermaidAPI.render(id, content, setChart)
github inkdropapp / inkdrop-mermaid / lib / index.js View on Github external
renderDiagram(code) {
    try {
      this.cleanupMermaidDiv();

      _mermaid.mermaidAPI.render(this.mermaidId, code, svg => this.setState({
        svg,
        error: null
      }));
    } catch (e) {
      this.setState({
        error: e,
        svg: ''
      });
    }
  }
github inkdropapp / inkdrop-mermaid / lib / index.js View on Github external
activate() {
    _mermaid.mermaidAPI.initialize({
      startOnLoad: false,
      theme: inkdrop.config.get('mermaid.theme')
    });

    if (_inkdrop.markdownRenderer) {
      _inkdrop.markdownRenderer.remarkCodeComponents.mermaid = Mermaid;
    }
  },
github lxerxa / actionview-fe / app / components / workflow / PreviewModal.jsx View on Github external
import React, { ReactText, PropTypes, Component } from 'react';
import { Modal, Button } from 'react-bootstrap';
import _ from 'lodash';

const mermaidAPI = require('mermaid').mermaidAPI;

export default class PreviewModal extends Component {
  constructor(props) {
    super(props);
    mermaidAPI.initialize({
      startOnLoad:false
    });
  }

  static propTypes = {
    name: PropTypes.string,
    state: PropTypes.string,
    collection: PropTypes.array.isRequired,
    close: PropTypes.func.isRequired
  }