src/index.js
function replaceLinkWithEmbedded(node, index, parent, vFile) {
  const { title, url, position } = node;
  let newNode;

  // If the node isn't mermaid, ignore it.
  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 the node isn't mermaid, ignore it.
  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 the node isn't mermaid, ignore it. 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.

@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 .