mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-08 18:16:44 +02:00
Handling indentation
This commit is contained in:
@@ -46,6 +46,9 @@ IconDecoration:
|
||||
ClassDecoration:
|
||||
CLASS_KEYWORD content=(ID|STRING);
|
||||
|
||||
// This should be processed before whitespace is ignored
|
||||
terminal INDENTATION: /[ \t]{2,}/; // Two or more spaces/tabs for indentation
|
||||
|
||||
// Keywords with fixed text patterns
|
||||
terminal MINDMAP_KEYWORD: 'mindmap';
|
||||
terminal ICON_KEYWORD: '::icon(';
|
||||
@@ -57,11 +60,13 @@ terminal ID: /[a-zA-Z0-9_\-\.\/]+/;
|
||||
terminal CIRCLE_STR: /\(\(([\s\S]*?)\)\)/;
|
||||
// terminal CIRCLE_STR: /(?!\(\()[\s\S]+?(?!\(\()/;
|
||||
terminal STRING: /"[^"]*"|'[^']*'/;
|
||||
terminal INDENTATION: /[ \t]{2,}/; // Two or more spaces/tabs for indentation
|
||||
|
||||
// Modified indentation rule to have higher priority than WS
|
||||
|
||||
terminal NL: /\r?\n/;
|
||||
|
||||
// Hidden tokens
|
||||
hidden terminal WS: /[ \t]/; // Single space or tab for hidden whitespace
|
||||
terminal WS: /[ \t]/; // Single space or tab for hidden whitespace
|
||||
hidden terminal ML_COMMENT: /\%\%[^\n]*/;
|
||||
|
||||
// Type definition for node types
|
||||
|
@@ -8,13 +8,15 @@ export class MindmapValueConverter extends AbstractMermaidValueConverter {
|
||||
input: string,
|
||||
_cstNode: CstNode
|
||||
): ValueType | undefined {
|
||||
console.debug('MermaidValueConverter', rule.name, input);
|
||||
console.debug('MermaidValueConverter', rule.name);
|
||||
if (rule.name === 'CIRCLE_STR') {
|
||||
return input.replace('((', '').replace('))', '').trim();
|
||||
} else if (rule.name === 'ARCH_TEXT_ICON') {
|
||||
return input.replace(/["()]/g, '');
|
||||
} else if (rule.name === 'ARCH_TITLE') {
|
||||
return input.replace(/[[\]]/g, '').trim();
|
||||
} else if (rule.name === 'INDENTATION') {
|
||||
return input.length;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
@@ -40,7 +40,13 @@ describe('MindMap Parser Tests', () => {
|
||||
|
||||
const rows = result.value.MindmapRows;
|
||||
const r0 = rows[0];
|
||||
expect(r0.indent).toBe(undefined);
|
||||
const r1 = rows[1];
|
||||
expect(r1.indent).toBe(2);
|
||||
const r2 = rows[2];
|
||||
expect(r2.indent).toBe(2);
|
||||
const r3 = rows[3];
|
||||
expect(r3.indent).toBe(4);
|
||||
|
||||
expect(r0.$type).toBe('MindmapRow');
|
||||
const node0 = r0.item as CircleNode;
|
||||
@@ -49,6 +55,7 @@ describe('MindMap Parser Tests', () => {
|
||||
expect(node0.id).toBe('root');
|
||||
|
||||
expect(r1.$type).toBe('MindmapRow');
|
||||
// console.debug('R1:', r1);
|
||||
const node1 = r1.item as CircleNode;
|
||||
expect(node1.$type).toBe('CircleNode');
|
||||
expect(node1.id).toBe('child1');
|
||||
|
Reference in New Issue
Block a user