mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 14:59:53 +02:00
feat: Add title to parseResult
This commit is contained in:
@@ -68,17 +68,23 @@ function processAndSetConfigs(text: string) {
|
|||||||
async function parse(
|
async function parse(
|
||||||
text: string,
|
text: string,
|
||||||
parseOptions: ParseOptions & { suppressErrors: true }
|
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>;
|
||||||
async function parse(text: string, parseOptions?: ParseOptions): Promise<ParseResult | false> {
|
async function parse(
|
||||||
|
text: string,
|
||||||
|
parseOptions?: ParseOptions
|
||||||
|
): Promise<ParseResult & { error?: unknown }> {
|
||||||
addDiagrams();
|
addDiagrams();
|
||||||
|
let code = '';
|
||||||
|
let title = undefined;
|
||||||
|
let config: MermaidConfig = {};
|
||||||
try {
|
try {
|
||||||
const { code, config } = processAndSetConfigs(text);
|
({ code, config, title } = processAndSetConfigs(text));
|
||||||
const diagram = await getDiagramFromText(code);
|
const diagram = await getDiagramFromText(code);
|
||||||
return { diagram, config };
|
return { diagram, code, config, title, success: true };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (parseOptions?.suppressErrors) {
|
if (parseOptions?.suppressErrors) {
|
||||||
return false;
|
return { code, config, title, success: false, error };
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@@ -58,16 +58,21 @@ export interface ParseOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ParseResult {
|
export interface ParseResult {
|
||||||
|
success: boolean;
|
||||||
|
|
||||||
|
code: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The config passed as YAML frontmatter or directives
|
* The config passed as YAML frontmatter or directives
|
||||||
*/
|
*/
|
||||||
config: MermaidConfig;
|
config: MermaidConfig;
|
||||||
|
|
||||||
|
title?: string;
|
||||||
/**
|
/**
|
||||||
* The diagram AST
|
* 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.
|
// 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