Skip to content

Commit fba8b40

Browse files
Merge pull request #66 from William9923/fix/no-whitespace-arrow-head-support
2 parents 6fffb8e + 45a204f commit fba8b40

5 files changed

Lines changed: 86 additions & 8 deletions

File tree

cmd/parse.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,27 +214,27 @@ func (gp *graphProperties) parseString(line string) ([]textNode, error) {
214214
},
215215
},
216216
{
217-
regex: regexp.MustCompile(`(?s)^(.+)\s+-->\s+(.+)$`),
217+
regex: regexp.MustCompile(`(?s)^(.+)\s*-->\s*\|(.+)\|\s*(.+)$`),
218218
handler: func(match []string) ([]textNode, error) {
219219
if lhs, err = gp.parseString(match[0]); err != nil {
220220
lhs = []textNode{parseNode(match[0])}
221221
}
222-
if rhs, err = gp.parseString(match[1]); err != nil {
223-
rhs = []textNode{parseNode(match[1])}
222+
if rhs, err = gp.parseString(match[2]); err != nil {
223+
rhs = []textNode{parseNode(match[2])}
224224
}
225-
return setArrow(lhs, rhs, gp), nil
225+
return setArrowWithLabel(lhs, rhs, match[1], gp), nil
226226
},
227227
},
228228
{
229-
regex: regexp.MustCompile(`(?s)^(.+)\s+-->\|(.+)\|\s+(.+)$`),
229+
regex: regexp.MustCompile(`(?s)^(.+)\s*-->\s*(.+)$`),
230230
handler: func(match []string) ([]textNode, error) {
231231
if lhs, err = gp.parseString(match[0]); err != nil {
232232
lhs = []textNode{parseNode(match[0])}
233233
}
234-
if rhs, err = gp.parseString(match[2]); err != nil {
235-
rhs = []textNode{parseNode(match[2])}
234+
if rhs, err = gp.parseString(match[1]); err != nil {
235+
rhs = []textNode{parseNode(match[1])}
236236
}
237-
return setArrowWithLabel(lhs, rhs, match[1], gp), nil
237+
return setArrow(lhs, rhs, gp), nil
238238
},
239239
},
240240
{

cmd/testdata/ascii/tight_arrow.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
graph LR
2+
A-->B
3+
---
4+
+---+ +---+
5+
| | | |
6+
| A |---->| B |
7+
| | | |
8+
+---+ +---+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
graph TD
2+
A-->B
3+
B -->C
4+
C-->|back1|A
5+
C -->|back2|B
6+
---
7+
+---+
8+
| |
9+
| A |<--+
10+
| | |
11+
+---+ |
12+
| |
13+
| |
14+
| |
15+
| |
16+
v |
17+
+---+ |
18+
| | |
19+
| B |<back1
20+
| | |
21+
+---+ |
22+
| |
23+
| |
24+
| back2
25+
| |
26+
v |
27+
+---+ |
28+
| | |
29+
| C |---+
30+
| |
31+
+---+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
graph LR
2+
A-->B
3+
---
4+
┌───┐ ┌───┐
5+
│ │ │ │
6+
│ A ├────►│ B │
7+
│ │ │ │
8+
└───┘ └───┘
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
graph TD
2+
A-->B
3+
B--> C
4+
C-->|back1|A
5+
C -->|back2|B
6+
---
7+
┌───┐
8+
│ │
9+
│ A │◄──┐
10+
│ │ │
11+
└─┬─┘ │
12+
│ │
13+
│ │
14+
│ │
15+
│ │
16+
▼ │
17+
┌───┐ │
18+
│ │ │
19+
│ B │◄back1
20+
│ │ │
21+
└─┬─┘ │
22+
│ │
23+
│ │
24+
│ back2
25+
│ │
26+
▼ │
27+
┌───┐ │
28+
│ │ │
29+
│ C ├───┘
30+
│ │
31+
└───┘

0 commit comments

Comments
 (0)