@zombie-mermaid/core 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/diagram-type.test.ts +38 -0
- package/src/diagram-type.ts +9 -0
- package/src/style-directives.ts +6 -1
package/package.json
CHANGED
|
@@ -10,6 +10,44 @@ describe('detectDiagramType', () => {
|
|
|
10
10
|
expect(detectDiagramType('xychart-beta\nx-axis [a, b]')).toBe('xychart')
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
+
it('detects architecture diagrams under both header spellings', () => {
|
|
14
|
+
expect(detectDiagramType('architecture-beta\nservice a')).toBe(
|
|
15
|
+
'architecture',
|
|
16
|
+
)
|
|
17
|
+
expect(detectDiagramType('architecture\nservice a')).toBe('architecture')
|
|
18
|
+
expect(detectDiagramType('Architecture-Beta\nservice a')).toBe(
|
|
19
|
+
'architecture',
|
|
20
|
+
)
|
|
21
|
+
expect(detectDiagramType('architecture-beta;service a')).toBe(
|
|
22
|
+
'architecture',
|
|
23
|
+
)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('does not match an architecture header with an unsupported suffix', () => {
|
|
27
|
+
expect(detectDiagramType('architecture-foo\nservice a')).toBe('flowchart')
|
|
28
|
+
expect(detectDiagramType('architecture-beta TB\nservice a')).toBe(
|
|
29
|
+
'flowchart',
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('detects every C4 variant header, case-insensitively', () => {
|
|
34
|
+
for (const header of [
|
|
35
|
+
'C4Context',
|
|
36
|
+
'C4Container',
|
|
37
|
+
'C4Component',
|
|
38
|
+
'C4Dynamic',
|
|
39
|
+
'C4Deployment',
|
|
40
|
+
'c4context',
|
|
41
|
+
]) {
|
|
42
|
+
expect(detectDiagramType(`${header}\nPerson(a, "A")`)).toBe('c4')
|
|
43
|
+
}
|
|
44
|
+
expect(detectDiagramType('C4Context;Person(a, "A")')).toBe('c4')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('does not match an unknown C4 variant', () => {
|
|
48
|
+
expect(detectDiagramType('C4Foo\nPerson(a, "A")')).toBe('flowchart')
|
|
49
|
+
})
|
|
50
|
+
|
|
13
51
|
it('isolates the header on a semicolon-separated single line', () => {
|
|
14
52
|
expect(detectDiagramType('sequenceDiagram;A->>B: Hi')).toBe('sequence')
|
|
15
53
|
expect(detectDiagramType('classDiagram;class Foo')).toBe('class')
|
package/src/diagram-type.ts
CHANGED
|
@@ -22,6 +22,9 @@ export const DIAGRAM_TYPES = [
|
|
|
22
22
|
'class',
|
|
23
23
|
'er',
|
|
24
24
|
'xychart',
|
|
25
|
+
'architecture',
|
|
26
|
+
|
|
27
|
+
'c4',
|
|
25
28
|
] as const
|
|
26
29
|
|
|
27
30
|
/** The diagram types this library can detect and route to a renderer. */
|
|
@@ -40,6 +43,12 @@ export function detectDiagramType(text: string): DiagramType {
|
|
|
40
43
|
const firstLine = splitStatements(text)[0]?.text.toLowerCase() ?? ''
|
|
41
44
|
|
|
42
45
|
if (/^xychart(?:-beta)?(?:\s|$)/.test(firstLine)) return 'xychart'
|
|
46
|
+
if (/^architecture(?:-beta)?\s*$/.test(firstLine)) return 'architecture'
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
/^c4(?:context|container|component|dynamic|deployment)\s*$/.test(firstLine)
|
|
50
|
+
)
|
|
51
|
+
return 'c4'
|
|
43
52
|
if (/^sequencediagram\s*$/.test(firstLine)) return 'sequence'
|
|
44
53
|
if (/^classdiagram\s*$/.test(firstLine)) return 'class'
|
|
45
54
|
if (/^erdiagram\s*$/.test(firstLine)) return 'er'
|
package/src/style-directives.ts
CHANGED
|
@@ -68,6 +68,9 @@ export function tryApplyClassDef(
|
|
|
68
68
|
/**
|
|
69
69
|
* `class A,B className` — attach a style class to one or more nodes.
|
|
70
70
|
*
|
|
71
|
+
* Whitespace around commas is allowed (`class A, B foo`) — the state-diagram
|
|
72
|
+
* docs show that form (`class Moving, Crash movement`).
|
|
73
|
+
*
|
|
71
74
|
* Allows an optional trailing semicolon (`class A,B foo;`) — Mermaid treats
|
|
72
75
|
* it as valid/optional, and `classDef`/`style` already tolerate it via their
|
|
73
76
|
* `(.+)$` capture. Without this, the semicolon form fails to match here and
|
|
@@ -79,7 +82,9 @@ export function tryApplyClassAssignment(
|
|
|
79
82
|
line: string,
|
|
80
83
|
target: StyleDirectives,
|
|
81
84
|
): boolean {
|
|
82
|
-
const match = line.match(
|
|
85
|
+
const match = line.match(
|
|
86
|
+
/^class\s+([\w-]+(?:\s*,\s*[\w-]+)*)\s+([\w-]+)\s*;?\s*$/,
|
|
87
|
+
)
|
|
83
88
|
if (!match) return false
|
|
84
89
|
const className = match[2]!
|
|
85
90
|
for (const id of match[1]!.split(',')) {
|