mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-17 22:39:56 +02:00
feat: Add title to parseResult
This commit is contained in:
@@ -68,17 +68,23 @@ function processAndSetConfigs(text: string) {
|
||||
async function parse(
|
||||
text: string,
|
||||
parseOptions: ParseOptions & { suppressErrors: true }
|
||||
): Promise<ParseResult | false>;
|
||||
): Promise<ParseResult & { error?: unknown }>;
|
||||
async function parse(text: string, parseOptions?: ParseOptions): Promise<ParseResult>;
|
||||
async function parse(text: string, parseOptions?: ParseOptions): Promise<ParseResult | false> {
|
||||
async function parse(
|
||||
text: string,
|
||||
parseOptions?: ParseOptions
|
||||
): Promise<ParseResult & { error?: unknown }> {
|
||||
addDiagrams();
|
||||
let code = '';
|
||||
let title = undefined;
|
||||
let config: MermaidConfig = {};
|
||||
try {
|
||||
const { code, config } = processAndSetConfigs(text);
|
||||
({ code, config, title } = processAndSetConfigs(text));
|
||||
const diagram = await getDiagramFromText(code);
|
||||
return { diagram, config };
|
||||
return { diagram, code, config, title, success: true };
|
||||
} catch (error) {
|
||||
if (parseOptions?.suppressErrors) {
|
||||
return false;
|
||||
return { code, config, title, success: false, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
@@ -58,16 +58,21 @@ export interface ParseOptions {
|
||||
}
|
||||
|
||||
export interface ParseResult {
|
||||
success: boolean;
|
||||
|
||||
code: string;
|
||||
|
||||
/**
|
||||
* The config passed as YAML frontmatter or directives
|
||||
*/
|
||||
config: MermaidConfig;
|
||||
|
||||
title?: string;
|
||||
/**
|
||||
* The diagram AST
|
||||
*
|
||||
*/
|
||||
diagram: Diagram;
|
||||
diagram?: Diagram;
|
||||
}
|
||||
|
||||
// This makes it clear that we're working with a d3 selected element of some kind, even though it's hard to specify the exact type.
|
||||
|
Reference in New Issue
Block a user