mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
fix: Optional detector
This commit is contained in:
parent
97b39bca95
commit
de5ad8644e
@ -81,10 +81,8 @@ export class Diagram {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Diagram;
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
export const getDiagramFromText = async (txt: string, parseError?: Function) => {
|
export const getDiagramFromText = async (txt: string, parseError?: Function): Promise<Diagram> => {
|
||||||
const type = detectType(txt, configApi.getConfig());
|
const type = detectType(txt, configApi.getConfig());
|
||||||
try {
|
try {
|
||||||
// Trying to find the diagram
|
// Trying to find the diagram
|
||||||
@ -94,24 +92,14 @@ export const getDiagramFromText = async (txt: string, parseError?: Function) =>
|
|||||||
if (!loader) {
|
if (!loader) {
|
||||||
throw new Error(`Diagram ${type} not found.`);
|
throw new Error(`Diagram ${type} not found.`);
|
||||||
}
|
}
|
||||||
// Diagram not avaiable, loading it
|
// Diagram not available, loading it
|
||||||
// const path = getPathForDiagram(type);
|
const { diagram } = await loader();
|
||||||
const { diagram } = await loader(); // eslint-disable-line @typescript-eslint/no-explicit-any
|
registerDiagram(type, diagram, undefined, diagram.injectUtils);
|
||||||
registerDiagram(
|
|
||||||
type,
|
|
||||||
{
|
|
||||||
db: diagram.db,
|
|
||||||
renderer: diagram.renderer,
|
|
||||||
parser: diagram.parser,
|
|
||||||
styles: diagram.styles,
|
|
||||||
},
|
|
||||||
diagram.injectUtils
|
|
||||||
);
|
|
||||||
// await loadDiagram('./packages/mermaid-mindmap/dist/mermaid-mindmap.js');
|
|
||||||
// await loadDiagram(path + 'mermaid-' + type + '.js');
|
|
||||||
// new diagram will try getDiagram again and if fails then it is a valid throw
|
// new diagram will try getDiagram again and if fails then it is a valid throw
|
||||||
}
|
}
|
||||||
// If either of the above worked, we have the diagram
|
// If either of the above worked, we have the diagram
|
||||||
// logic and can continue
|
// logic and can continue
|
||||||
return new Diagram(txt, parseError);
|
return new Diagram(txt, parseError);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default Diagram;
|
||||||
|
@ -26,7 +26,7 @@ export interface Detectors {
|
|||||||
export const registerDiagram = (
|
export const registerDiagram = (
|
||||||
id: string,
|
id: string,
|
||||||
diagram: DiagramDefinition,
|
diagram: DiagramDefinition,
|
||||||
detector: DiagramDetector,
|
detector?: DiagramDetector,
|
||||||
callback?: (
|
callback?: (
|
||||||
_log: any,
|
_log: any,
|
||||||
_setLogLevel: any,
|
_setLogLevel: any,
|
||||||
@ -39,7 +39,9 @@ export const registerDiagram = (
|
|||||||
throw new Error(`Diagram ${id} already registered.`);
|
throw new Error(`Diagram ${id} already registered.`);
|
||||||
}
|
}
|
||||||
diagrams[id] = diagram;
|
diagrams[id] = diagram;
|
||||||
|
if (detector) {
|
||||||
addDetector(id, detector);
|
addDetector(id, detector);
|
||||||
|
}
|
||||||
addStylesForDiagram(id, diagram.styles);
|
addStylesForDiagram(id, diagram.styles);
|
||||||
if (typeof callback !== 'undefined') {
|
if (typeof callback !== 'undefined') {
|
||||||
callback(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox);
|
callback(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user