mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Fix for async issue in parse, adding parseAsync
This commit is contained in:
parent
c20b8a0664
commit
bc5ef5fb7d
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,3 +32,4 @@ cypress/snapshots/
|
||||
.eslintcache
|
||||
.tsbuildinfo
|
||||
tsconfig.tsbuildinfo
|
||||
knsv*.html
|
||||
|
@ -75,16 +75,6 @@ classDiagram
|
||||
<pre id="diagram" class="mermaid2">
|
||||
mindmap
|
||||
root
|
||||
A
|
||||
B
|
||||
C
|
||||
D
|
||||
E
|
||||
A2
|
||||
B2
|
||||
C2
|
||||
D2
|
||||
E2
|
||||
child1((Circle))
|
||||
grandchild 1
|
||||
grandchild 2
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "mermaid-monorepo",
|
||||
"private": true,
|
||||
"version": "9.2.0-rc2",
|
||||
"version": "9.2.0-rc4",
|
||||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||
"main": "dist/mermaid.core.mjs",
|
||||
"module": "dist/mermaid.core.mjs",
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user