src/index.js
/**
 * Given a link to a mermaid diagram, grab the contents from the link and put it
 * into a div that Mermaid JS can act upon.
 *
 * @param  {Object}   node
 * @param  {integer}  index
 * @param  {Object}   parent
 * @param  {vFile}    vFile
 * @return {Object}
 */
Given a link to a mermaid diagram, grab the contents from the link and put it
into a div that Mermaid JS can act upon.


Given a link to a mermaid diagram grab the contents from the link and put it into a div that Mermaid JS can act upon .
function replaceLinkWithEmbedded(node, index, parent, vFile) {
  const { title, url, position } = node;
  let newNode;
  if (!isMermaid(title)) {
    return node;
  }
  try {
    const value = fs.readFileSync(`${vFile.dirname}/${url}`, { encoding: 'utf-8' });
    newNode = createMermaidDiv(value);
    parent.children.splice(index, 1, newNode);
    vFile.info('mermaid link replaced with div', position, PLUGIN_NAME);
  } catch (error) {
    vFile.message(error, position, PLUGIN_NAME);
    return node;
  }
  return node;
}
function replaceLinkWithEmbedded ( node , index , parent , vFile ) { const { title , url , position } = node ; let newNode ; if ( ! isMermaid ( title ) ) { return node ; } try { const value = fs . readFileSync ( ` ${ vFile . dirname } ${ url } ` , { encoding : 'utf-8' } ) ; newNode = createMermaidDiv ( value ) ; parent . children . splice ( index , 1 , newNode ) ; vFile . info ( 'mermaid link replaced with div' , position , PLUGIN_NAME ) ; } catch ( error ) { vFile . message ( error , position , PLUGIN_NAME ) ; return node ; } return node ; }
Given a link to a mermaid diagram, grab the contents from the link and put it
 into a div that Mermaid JS can act upon.
Given a link to a mermaid diagram grab the contents from the link and put it into a div that Mermaid JS can act upon .
// If the node isn't mermaid, ignore it.