fileoverview author NHN FE Development Lab <dl_javascript@nhn.com>
  import plantumlEncoder from 'plantuml-encoder' ; import { PluginOptions } from '../index' ; import type { MdNode , PluginContext , PluginInfo } from '@toast-ui/editor' ; import type { HTMLToken } from '@toast-ui/toastmark' ; const DEFAULT_RENDERER_URL = '//www.plantuml.com/plantuml/png/' ; function createUMLTokens ( text , rendererURL ) { let renderedHTML ; try { if ( ! plantumlEncoder ) { throw new Error ( 'plantuml-encoder dependency required' ) ; } renderedHTML = `<img src="${ rendererURL }${ plantumlEncoder . encode ( text ) }" />` ; } catch ( err ) { renderedHTML = `Error occurred on encoding uml: ${ err . message }` ; } return [ { type : 'openTag' , tagName : 'div' , outerNewLine : true } , { type : 'html' , content : renderedHTML } , { type : 'closeTag' , tagName : 'div' , outerNewLine : true } , ] ; } param { Object } context param options param { string } options . rendererURL export default function umlPlugin ( _ , options = { } ) { const { rendererURL = DEFAULT_RENDERER_URL } = options ; return { toHTMLRenderers : { uml ( node ) { return createUMLTokens ( node . literal ! , rendererURL ) ; } , plantUml ( node ) { return createUMLTokens ( node . literal ! , rendererURL ) ; } , } , } ; }