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
|
.eslintcache
|
||||||
.tsbuildinfo
|
.tsbuildinfo
|
||||||
tsconfig.tsbuildinfo
|
tsconfig.tsbuildinfo
|
||||||
|
knsv*.html
|
||||||
|
@ -75,16 +75,6 @@ classDiagram
|
|||||||
<pre id="diagram" class="mermaid2">
|
<pre id="diagram" class="mermaid2">
|
||||||
mindmap
|
mindmap
|
||||||
root
|
root
|
||||||
A
|
|
||||||
B
|
|
||||||
C
|
|
||||||
D
|
|
||||||
E
|
|
||||||
A2
|
|
||||||
B2
|
|
||||||
C2
|
|
||||||
D2
|
|
||||||
E2
|
|
||||||
child1((Circle))
|
child1((Circle))
|
||||||
grandchild 1
|
grandchild 1
|
||||||
grandchild 2
|
grandchild 2
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "mermaid-monorepo",
|
"name": "mermaid-monorepo",
|
||||||
"private": true,
|
"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.",
|
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"main": "dist/mermaid.core.mjs",
|
"main": "dist/mermaid.core.mjs",
|
||||||
"module": "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) => {
|
const parse = (txt: string) => {
|
||||||
return mermaidAPI.parse(txt, mermaid.parseError);
|
return mermaidAPI.parse(txt, mermaid.parseError);
|
||||||
};
|
};
|
||||||
|
const parseAsync = (txt: string) => {
|
||||||
|
return mermaidAPI.parseAsync(txt, mermaid.parseError);
|
||||||
|
};
|
||||||
|
|
||||||
const mermaid: {
|
const mermaid: {
|
||||||
startOnLoad: boolean;
|
startOnLoad: boolean;
|
||||||
@ -317,6 +320,7 @@ const mermaid: {
|
|||||||
parseError?: Function;
|
parseError?: Function;
|
||||||
mermaidAPI: typeof mermaidAPI;
|
mermaidAPI: typeof mermaidAPI;
|
||||||
parse: typeof parse;
|
parse: typeof parse;
|
||||||
|
parseAsync: typeof parseAsync;
|
||||||
render: typeof mermaidAPI.render;
|
render: typeof mermaidAPI.render;
|
||||||
init: typeof init;
|
init: typeof init;
|
||||||
initThrowsErrors: typeof initThrowsErrors;
|
initThrowsErrors: typeof initThrowsErrors;
|
||||||
@ -328,6 +332,7 @@ const mermaid: {
|
|||||||
diagrams: {},
|
diagrams: {},
|
||||||
mermaidAPI,
|
mermaidAPI,
|
||||||
parse,
|
parse,
|
||||||
|
parseAsync,
|
||||||
render: mermaidAPI.render,
|
render: mermaidAPI.render,
|
||||||
init,
|
init,
|
||||||
initThrowsErrors,
|
initThrowsErrors,
|
||||||
|
@ -43,6 +43,18 @@ function parse(text: string, parseError?: Function): boolean {
|
|||||||
const diagram = new Diagram(text, parseError);
|
const diagram = new Diagram(text, parseError);
|
||||||
return diagram.parse(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 {
|
export const encodeEntities = function (text: string): string {
|
||||||
let txt = text;
|
let txt = text;
|
||||||
@ -760,6 +772,7 @@ export const mermaidAPI = Object.freeze({
|
|||||||
render,
|
render,
|
||||||
renderAsync,
|
renderAsync,
|
||||||
parse,
|
parse,
|
||||||
|
parseAsync,
|
||||||
parseDirective,
|
parseDirective,
|
||||||
initialize,
|
initialize,
|
||||||
getConfig: configApi.getConfig,
|
getConfig: configApi.getConfig,
|
||||||
@ -778,6 +791,7 @@ export const mermaidAPI = Object.freeze({
|
|||||||
setLogLevel(configApi.getConfig().logLevel);
|
setLogLevel(configApi.getConfig().logLevel);
|
||||||
configApi.reset(configApi.getConfig());
|
configApi.reset(configApi.getConfig());
|
||||||
export default mermaidAPI;
|
export default mermaidAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## mermaidAPI configuration defaults
|
* ## mermaidAPI configuration defaults
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user