Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ excalidraw-cli convert diagram.excalidraw --format svg --no-export-background
| `->` | Arrow | Forward connection |
| `<-` | Reverse Arrow | Reverse connection, logically parsed as right-to-left |
| `<->` | Bidirectional Arrow | Connection with arrowheads on both ends |
| `-->` | Dashed Arrow | Dashed connection |
| `-->` | Dashed Arrow | Dashed forward connection |
| `<--` | Dashed Reverse Arrow | Dashed reversed connection |
| `<-->` | Dashed Bidirectional Arrow | Dashed connection with arrowheads on both ends |
| `-> "text" ->` | Labeled Arrow | Connection with label |

### Example DSL
Expand All @@ -104,6 +106,9 @@ excalidraw-cli convert diagram.excalidraw --format svg --no-export-background
(Start) -> [Enter Credentials] -> {Valid?}
{Valid?} -> "yes" -> [Dashboard] -> (End)
{Valid?} -> "no" -> [Show Error] -> [Enter Credentials]
[Client] --> [Webhook]
[Worker] <-- [Queue]
[Service A] <--> [Service B]
[Reviewer] <- [Approved]
[Client] <-> [API]
```
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/parser/dsl-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,25 @@ function tokenize(input: string): Token[] {
continue;
}

// Dashed bidirectional arrow <-->
if (
input[i] === '<' &&
input[i + 1] === '-' &&
input[i + 2] === '-' &&
input[i + 3] === '>'
) {
tokens.push({ type: 'arrow', value: '<-->', dashed: true, bidirectional: true });
i += 4;
continue;
}

// Dashed reverse arrow <--
if (input[i] === '<' && input[i + 1] === '-' && input[i + 2] === '-') {
tokens.push({ type: 'arrow', value: '<--', dashed: true, reversed: true });
i += 3;
continue;
}

// Bidirectional arrow <->
if (input[i] === '<' && input[i + 1] === '-' && input[i + 2] === '>') {
tokens.push({ type: 'arrow', value: '<->', bidirectional: true });
Expand Down
74 changes: 73 additions & 1 deletion tests/unit/parser/dsl-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,49 @@ describe('DSL Parser', () => {

it('should parse dashed connections', () => {
const result = parseDSL('[A] --> [B]');
expect(result.edges[0].style?.strokeStyle).toBe('dashed');
expect(result.edges[0].source).toBe(result.nodes[0].id);
expect(result.edges[0].target).toBe(result.nodes[1].id);
expect(result.edges[0].style).toEqual({ strokeStyle: 'dashed' });
});

it('should parse dashed reverse connections', () => {
const result = parseDSL('[A] <-- [B]');
expect(result.edges[0].source).toBe(result.nodes[1].id);
expect(result.edges[0].target).toBe(result.nodes[0].id);
expect(result.edges[0].style).toEqual({
strokeStyle: 'dashed',
startArrowhead: 'arrow',
endArrowhead: null,
});
});

it('should parse dashed bidirectional connections', () => {
const result = parseDSL('[A] <--> [B]');
expect(result.edges[0].source).toBe(result.nodes[0].id);
expect(result.edges[0].target).toBe(result.nodes[1].id);
expect(result.edges[0].style).toEqual({
strokeStyle: 'dashed',
startArrowhead: 'arrow',
endArrowhead: 'arrow',
});
});

it('should preserve solid reverse and bidirectional semantics', () => {
const reverse = parseDSL('[A] <- [B]');
expect(reverse.edges[0].source).toBe(reverse.nodes[1].id);
expect(reverse.edges[0].target).toBe(reverse.nodes[0].id);
expect(reverse.edges[0].style).toEqual({
startArrowhead: 'arrow',
endArrowhead: null,
});

const bidirectional = parseDSL('[A] <-> [B]');
expect(bidirectional.edges[0].source).toBe(bidirectional.nodes[0].id);
expect(bidirectional.edges[0].target).toBe(bidirectional.nodes[1].id);
expect(bidirectional.edges[0].style).toEqual({
startArrowhead: 'arrow',
endArrowhead: 'arrow',
});
});

it('should parse reverse connections as logical right-to-left edges', () => {
Expand Down Expand Up @@ -347,5 +389,35 @@ describe('DSL Parser', () => {
backgroundColor: '#a5d8ff',
});
});

it('should generate dashed reverse arrows with dashed styling and reversed arrowheads', async () => {
const graph = parseDSL('[A] <-- [B]');
const layoutedGraph = await layoutGraph(graph);
const excalidrawFile = generateExcalidraw(layoutedGraph);
const arrow = excalidrawFile.elements.find(
(element) => element.type === 'arrow' && element.id === graph.edges[0].id
);

expect(arrow).toMatchObject({
strokeStyle: 'dashed',
startArrowhead: 'arrow',
endArrowhead: null,
});
});

it('should generate dashed bidirectional arrows with arrowheads on both ends', async () => {
const graph = parseDSL('[A] <--> [B]');
const layoutedGraph = await layoutGraph(graph);
const excalidrawFile = generateExcalidraw(layoutedGraph);
const arrow = excalidrawFile.elements.find(
(element) => element.type === 'arrow' && element.id === graph.edges[0].id
);

expect(arrow).toMatchObject({
strokeStyle: 'dashed',
startArrowhead: 'arrow',
endArrowhead: 'arrow',
});
});
});
});
Loading