mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-24 01:39:53 +02:00
Fix for async issue in parse, adding parseAsync
This commit is contained in:
@@ -309,6 +309,9 @@ const setParseErrorHandler = function (newParseErrorHandler: (err: any, hash: an
|
||||
const parse = (txt: string) => {
|
||||
return mermaidAPI.parse(txt, mermaid.parseError);
|
||||
};
|
||||
const parseAsync = (txt: string) => {
|
||||
return mermaidAPI.parseAsync(txt, mermaid.parseError);
|
||||
};
|
||||
|
||||
const mermaid: {
|
||||
startOnLoad: boolean;
|
||||
@@ -317,6 +320,7 @@ const mermaid: {
|
||||
parseError?: Function;
|
||||
mermaidAPI: typeof mermaidAPI;
|
||||
parse: typeof parse;
|
||||
parseAsync: typeof parseAsync;
|
||||
render: typeof mermaidAPI.render;
|
||||
init: typeof init;
|
||||
initThrowsErrors: typeof initThrowsErrors;
|
||||
@@ -328,6 +332,7 @@ const mermaid: {
|
||||
diagrams: {},
|
||||
mermaidAPI,
|
||||
parse,
|
||||
parseAsync,
|
||||
render: mermaidAPI.render,
|
||||
init,
|
||||
initThrowsErrors,
|
||||
|
@@ -43,6 +43,18 @@ function parse(text: string, parseError?: Function): boolean {
|
||||
const diagram = new Diagram(text, parseError);
|
||||
return diagram.parse(text, parseError);
|
||||
}
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
/**
|
||||
*
|
||||
* @param text
|
||||
* @param parseError
|
||||
*/
|
||||
async function parseAsync(text: string, parseError?: Function): Promise<boolean> {
|
||||
addDiagrams();
|
||||
const diagram = await getDiagramFromText(text, parseError);
|
||||
return diagram.parse(text, parseError);
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/ban-types */
|
||||
|
||||
export const encodeEntities = function (text: string): string {
|
||||
let txt = text;
|
||||
@@ -760,6 +772,7 @@ export const mermaidAPI = Object.freeze({
|
||||
render,
|
||||
renderAsync,
|
||||
parse,
|
||||
parseAsync,
|
||||
parseDirective,
|
||||
initialize,
|
||||
getConfig: configApi.getConfig,
|
||||
@@ -778,6 +791,7 @@ export const mermaidAPI = Object.freeze({
|
||||
setLogLevel(configApi.getConfig().logLevel);
|
||||
configApi.reset(configApi.getConfig());
|
||||
export default mermaidAPI;
|
||||
|
||||
/**
|
||||
* ## mermaidAPI configuration defaults
|
||||
*
|
||||
|
Reference in New Issue
Block a user