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