import { appEngine } from './appEngine'; import mermaid from 'mermaid'; import { marked, MarkedOptions } from 'marked'; let renderMermaid: boolean = false; abstract class Markdown { public static initialize(): void { const renderer = { code: (token: { lang?: string; text: string }): string => { switch (token.lang) { case 'mermaid': renderMermaid = true; return `
${token.text}`;
}
},
codespan: (token: { text: string }): string => {
const text = token.text.trim();
const singleMatch = text.match(/^%([\s\S]*?)%$/);
const doubleMatch = text.match(/^%%([\s\S]*?)%%$/);
if (doubleMatch) {
return appEngine.evaluator.ToMathML(doubleMatch[1], 'block');
} else if (singleMatch) {
return appEngine.evaluator.ToMathML(singleMatch[1], 'inline');
} else {
return `${token.text}`;
}
},
};
marked.use({
renderer,
breaks: false,
});
mermaid.initialize({
startOnLoad: false,
theme: 'neutral',
securityLevel: 'loose',
});
}
/**
*
* @param src
* @param options
* @returns
*/
public static parse: (src: string, options?: MarkedOptions