import * as _ from 'lodash' ; const decache = require ( 'decache' ) ; export class MarkdownToPDFEngine { private static instance : MarkdownToPDFEngine ; private markedInstance ; private convertedTokens = [ ] ; private constructor ( ) { decache ( 'marked' ) ; const { marked } = require ( 'marked' ) ; this . markedInstance = marked ; const renderer = new this . markedInstance . Renderer ( ) ; renderer . strong = text => { return { text : text , bold : true } ; } ; renderer . em = text => { this . convertedTokens . push ( { text : text , italics : true } ) ; return text ; } ; renderer . paragraph = text => { return text ; } ; this . markedInstance . setOptions ( { renderer : renderer , gfm : true , breaks : false } ) ; } public static getInstance ( ) { if ( ! MarkdownToPDFEngine . instance ) { MarkdownToPDFEngine . instance = new MarkdownToPDFEngine ( ) ; } return MarkdownToPDFEngine . instance ; } public convert ( stringToConvert ) { this . convertedTokens = [ ] ; const tokens = this . markedInstance . lexer ( stringToConvert ) ; const pdfmakeData = this . markedInstance . Parser . parse ( tokens ) ; const result = { text : this . convertedTokens } ; return result ; } } export default MarkdownToPDFEngine . getInstance ( ) ;