Compare commits

..

1 Commits

Author SHA1 Message Date
darshanr0107
f7d7fe42aa fix: prevent edge direction tokens L,R,T,B from breaking ID parsing
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
2025-10-27 13:33:48 +05:30
6 changed files with 66 additions and 41 deletions

View File

@@ -0,0 +1,5 @@
---
'mermaid': patch
---
fix: Allow IDs starting with L, R, T, or B in parser

View File

@@ -1,5 +0,0 @@
---
'mermaid': patch
---
fix: Mindmap rendering issue when the number of Level 2 nodes exceeds 11

View File

@@ -293,37 +293,5 @@ describe('MindmapDb getData function', () => {
expect(edgeA1_aaa.section).toBe(1);
expect(edgeA_a2.section).toBe(2);
});
it('should wrap section numbers when there are more than 11 level 2 nodes', () => {
db.addNode(0, 'root', 'Example', 0);
for (let i = 1; i <= 15; i++) {
db.addNode(1, `child${i}`, `${i}`, 0);
}
const result = db.getData();
expect(result.nodes).toHaveLength(16);
const child1 = result.nodes.find((n) => n.label === '1') as MindmapLayoutNode;
const child11 = result.nodes.find((n) => n.label === '11') as MindmapLayoutNode;
const child12 = result.nodes.find((n) => n.label === '12') as MindmapLayoutNode;
const child13 = result.nodes.find((n) => n.label === '13') as MindmapLayoutNode;
const child14 = result.nodes.find((n) => n.label === '14') as MindmapLayoutNode;
const child15 = result.nodes.find((n) => n.label === '15') as MindmapLayoutNode;
expect(child1.section).toBe(0);
expect(child11.section).toBe(10);
expect(child12.section).toBe(0);
expect(child13.section).toBe(1);
expect(child14.section).toBe(2);
expect(child15.section).toBe(3);
expect(child12.cssClasses).toBe('mindmap-node section-0');
expect(child13.cssClasses).toBe('mindmap-node section-1');
expect(child14.cssClasses).toBe('mindmap-node section-2');
expect(child15.cssClasses).toBe('mindmap-node section-3');
});
});
});

View File

@@ -203,7 +203,7 @@ export class MindmapDB {
// For other nodes, inherit parent's section number
if (node.children) {
for (const [index, child] of node.children.entries()) {
const childSectionNumber = node.level === 0 ? index % 11 : sectionNumber;
const childSectionNumber = node.level === 0 ? index : sectionNumber;
this.assignSections(child, childSectionNumber);
}
}

View File

@@ -20,11 +20,11 @@ fragment Statement:
;
fragment LeftPort:
':'lhsDir=ARROW_DIRECTION
':' lhsDir=ID
;
fragment RightPort:
rhsDir=ARROW_DIRECTION':'
rhsDir=ID ':'
;
fragment Arrow:
@@ -47,6 +47,5 @@ Edge:
lhsId=ID lhsGroup?=ARROW_GROUP? Arrow rhsId=ID rhsGroup?=ARROW_GROUP? EOL
;
terminal ARROW_DIRECTION: 'L' | 'R' | 'T' | 'B';
terminal ARROW_GROUP: /\{group\}/;
terminal ARROW_INTO: /<|>/;

View File

@@ -19,6 +19,64 @@ describe('architecture', () => {
});
});
describe('should handle services', () => {
it('should handle service with icon', () => {
const context = `architecture-beta
service TH(disk)
`;
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.services).toHaveLength(1);
expect(result.value.services?.[0].id).toBe('TH');
expect(result.value.services?.[0].icon).toBe('disk');
});
it('should handle service with icon starting with arrow direction letters', () => {
const context = `architecture-beta
service T(disk)
service TH(database)
service L(server)
service R(cloud)
service B(internet)
service TOP(disk)
service LEFT(disk)
service RIGHT(disk)
service BOTTOM(disk)
`;
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.services).toHaveLength(9);
});
it('should handle service with icon and title', () => {
const context = `architecture-beta
service db(database)[Database]
`;
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.services).toHaveLength(1);
expect(result.value.services?.[0].id).toBe('db');
expect(result.value.services?.[0].icon).toBe('database');
expect(result.value.services?.[0].title).toBe('Database');
});
it('should handle service in a group', () => {
const context = `architecture-beta
group api(cloud)[API]
service db(database)[Database] in api
`;
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
expect(result.value.services).toHaveLength(1);
expect(result.value.services?.[0].id).toBe('db');
expect(result.value.services?.[0].in).toBe('api');
});
});
describe('should handle TitleAndAccessibilities', () => {
it.each([
`architecture-beta title sample title`,