'use strict';

const marked       = require( 'marked' );
const Viz          = require( 'viz.js' );
const uiflowParser = require( './uiflowParser.js' );

const UiflowMDRenderer = function ( options ) {

  marked.Renderer.call( this );
  this.options = options || {};

}

UiflowMDRenderer.prototype = Object.create( marked.Renderer.prototype );
UiflowMDRenderer.prototype.constructor = UiflowMDRenderer;

UiflowMDRenderer.prototype.code = function ( code, lang, escaped ) {

    if ( lang === 'uiflow' ) {

      let dotCode = uiflowParser( code );
      return `<div class="UISP-Dot">${ Viz( dotCode, { format:"svg", engine:"dot" } ) }</div>`;

    }

    if ( lang === 'dot' ) {

      return `<div class="UISP-Dot">${ Viz( code, { format:"svg", engine:"dot" } ) }</div>`;

    } else {

      let result = marked.Renderer.prototype.code.call( this, code, lang, escaped );
      return result.replace( /(class=")(lang-)/, '$1line-numbers $2' );

    }

}

module.exports = UiflowMDRenderer;

@@ -536,24 +536,223 @@
 er( code );%0A
+      let vizScraps = /%5E%3C%5C?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22%5C?%3E%5Cn%3C!DOCTYPE svg PUBLIC %22-%5C/%5C/W3C%5C/%5C/DTD SVG 1.1%5C/%5C/EN%22%5Cn %22http:%5C/%5C/www.w3.org%5C/Graphics%5C/SVG%5C/1.1%5C/DTD%5C/svg11.dtd%22%3E/;%0A%0A
       return
@@ -814,32 +814,57 @@
 , engine:%22dot%22 %7D
+ ).replace( vizScraps, ''
  ) %7D%3C/div%3E%60;%0A%0A  
@@ -977,16 +977,41 @@
 :%22dot%22 %7D
+ ).replace( vizScraps, ''
  ) %7D%3C/di

remove graphviz scrap code