mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 16:29:40 +02:00
Add interface for DiagramDb and other minor changes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { DiagramDb } from './types';
|
||||
// The "* as yaml" part is necessary for tree-shaking
|
||||
import * as yaml from 'js-yaml';
|
||||
|
||||
@@ -15,11 +16,11 @@ type FrontMatterMetadata = {
|
||||
/**
|
||||
* Extract and parse frontmatter from text, if present, and sets appropriate
|
||||
* properties in the provided db.
|
||||
* @param text -
|
||||
* @param db -
|
||||
* @param text - The text that may have a YAML frontmatter.
|
||||
* @param db - Diagram database, could be of any diagram.
|
||||
* @returns text with frontmatter stripped out
|
||||
*/
|
||||
export function extractFrontMatter(text: string, db: any): string {
|
||||
export function extractFrontMatter(text: string, db: DiagramDb): string {
|
||||
const matches = text.match(frontMatterRegex);
|
||||
if (matches) {
|
||||
const parsed: FrontMatterMetadata = yaml.load(matches[1], {
|
||||
@@ -28,8 +29,8 @@ export function extractFrontMatter(text: string, db: any): string {
|
||||
schema: yaml.FAILSAFE_SCHEMA,
|
||||
}) as FrontMatterMetadata;
|
||||
|
||||
if (parsed && parsed.title) {
|
||||
db?.setDiagramTitle(parsed.title);
|
||||
if (parsed?.title) {
|
||||
db.setDiagramTitle?.(parsed.title);
|
||||
}
|
||||
|
||||
return text.slice(matches[0].length);
|
||||
|
@@ -8,8 +8,16 @@ export interface InjectUtils {
|
||||
_setupGraphViewbox: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic Diagram DB that may apply to any diagram type.
|
||||
*/
|
||||
export interface DiagramDb {
|
||||
clear?: () => void;
|
||||
setDiagramTitle?: (title: string) => void;
|
||||
}
|
||||
|
||||
export interface DiagramDefinition {
|
||||
db: any;
|
||||
db: DiagramDb;
|
||||
renderer: any;
|
||||
parser: any;
|
||||
styles: any;
|
||||
|
Reference in New Issue
Block a user