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

mermaid-js / mermaid / 3702613472

pending completion
3702613472

Pull #3911

github

GitHub
Merge 774512df5 into a975c8c9c
Pull Request #3911: Release/9.3.0

1462 of 1820 branches covered (80.33%)

Branch coverage included in aggregate %.

3306 of 3306 new or added lines in 85 files covered. (100.0%)

14340 of 29071 relevant lines covered (49.33%)

413.51 hits per line

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

91.78
/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

1✔
9
/*
1✔
10
  Packaging and exposing resources for external diagrams so that they can import
1✔
11
  diagramAPI and have access to select parts of mermaid common code required to
1✔
12
  create diagrams working like the internal diagrams.
1✔
13
*/
1✔
14
export const log = _log;
1✔
15
export const setLogLevel = _setLogLevel;
1✔
16
export const getConfig = _getConfig;
1✔
17
export const sanitizeText = (text: string) => _sanitizeText(text, getConfig());
1✔
18
export const setupGraphViewbox = _setupGraphViewbox;
1✔
19

1✔
20
const diagrams: Record<string, DiagramDefinition> = {};
1✔
21
export interface Detectors {
1✔
22
  [key: string]: DiagramDetector;
1✔
23
}
1✔
24

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

131✔
48
  if (diagram.injectUtils) {
131!
49
    diagram.injectUtils(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox);
×
50
  }
×
51
};
131✔
52

1✔
53
export const getDiagram = (name: string): DiagramDefinition => {
1✔
54
  if (name in diagrams) {
249✔
55
    return diagrams[name];
246✔
56
  }
246✔
57
  throw new Error(`Diagram ${name} not found.`);
247✔
58
};
249✔
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