• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mermaid-js / mermaid / 4217648535

pending completion
4217648535

Pull #4110

github

GitHub
Merge c9c4320f8 into e22171c5b
Pull Request #4110: splitDiagrams

1586 of 1942 branches covered (81.67%)

Branch coverage included in aggregate %.

642 of 642 new or added lines in 38 files covered. (100.0%)

15818 of 32874 relevant lines covered (48.12%)

394.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.49
/packages/mermaid/src/diagram-api/diagramAPI.ts
1
import { addDetector } from './detectType';
1✔
2
import { log as _log, setLogLevel as _setLogLevel } from '../logger';
1✔
3
import { getConfig as _getConfig } from '../config';
1✔
4
import { sanitizeText as _sanitizeText } from '../diagrams/common/common';
1✔
5
import { setupGraphViewbox as _setupGraphViewbox } from '../setupGraphViewbox';
1✔
6
import { addStylesForDiagram } from '../styles';
1✔
7
import { DiagramDefinition, DiagramDetector } from './types';
1✔
8
import * as _commonDb from '../commonDb';
1✔
9
import { parseDirective as _parseDirective } from '../directiveUtils';
1✔
10

1✔
11
/*
1✔
12
  Packaging and exposing resources for external diagrams so that they can import
1✔
13
  diagramAPI and have access to select parts of mermaid common code required to
1✔
14
  create diagrams working like the internal diagrams.
1✔
15
*/
1✔
16
export const log = _log;
1✔
17
export const setLogLevel = _setLogLevel;
1✔
18
export const getConfig = _getConfig;
1✔
19
export const sanitizeText = (text: string) => _sanitizeText(text, getConfig());
1✔
20
export const setupGraphViewbox = _setupGraphViewbox;
1✔
21
export const getCommonDb = () => {
1✔
22
  return _commonDb;
×
23
};
×
24
export const parseDirective = (p: any, statement: string, context: string, type: string) =>
1✔
25
  _parseDirective(p, statement, context, type);
×
26

1✔
27
const diagrams: Record<string, DiagramDefinition> = {};
1✔
28
export interface Detectors {
1✔
29
  [key: string]: DiagramDetector;
1✔
30
}
1✔
31

1✔
32
/**
1✔
33
 * Registers the given diagram with Mermaid.
1✔
34
 *
1✔
35
 * Can be used for third-party custom diagrams.
1✔
36
 *
1✔
37
 * @param id - A unique ID for the given diagram.
1✔
38
 * @param diagram - The diagram definition.
1✔
39
 * @param detector - Function that returns `true` if a given mermaid text is this diagram definition.
1✔
40
 */
1✔
41
export const registerDiagram = (
1✔
42
  id: string,
46✔
43
  diagram: DiagramDefinition,
46✔
44
  detector?: DiagramDetector
46✔
45
) => {
46✔
46
  if (diagrams[id]) {
46!
47
    throw new Error(`Diagram ${id} already registered.`);
×
48
  }
×
49
  diagrams[id] = diagram;
46✔
50
  if (detector) {
46✔
51
    addDetector(id, detector);
30✔
52
  }
30✔
53
  addStylesForDiagram(id, diagram.styles);
46✔
54

46✔
55
  if (diagram.injectUtils) {
46!
56
    diagram.injectUtils(
×
57
      log,
×
58
      setLogLevel,
×
59
      getConfig,
×
60
      sanitizeText,
×
61
      setupGraphViewbox,
×
62
      getCommonDb(),
×
63
      parseDirective
×
64
    );
×
65
  }
×
66
};
46✔
67

1✔
68
export const getDiagram = (name: string): DiagramDefinition => {
1✔
69
  if (name in diagrams) {
391✔
70
    return diagrams[name];
351✔
71
  }
351✔
72
  throw new Error(`Diagram ${name} not found.`);
40✔
73
};
391✔
74

1✔
75
export class DiagramNotFoundError extends Error {
1✔
76
  constructor(message: string) {
1✔
77
    super(`Diagram ${message} not found.`);
×
78
  }
×
79
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc