Skip to content

Commit 73baa82

Browse files
committed
Fix a bug in md2sexpr
1 parent 4390b72 commit 73baa82

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

md2sexpr.d

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,32 @@ struct ConvertToSExprEventHandler {
1212
}
1313
}
1414
struct ConvertToSExprListEventHandler {
15-
bool multiple = false;
15+
int[] nchildren;
1616
string start(string text) {
17-
if (multiple) {
17+
int current;
18+
if (nchildren.length) {
19+
nchildren[$-1]++;
20+
current = nchildren[$-1];
21+
} else {
22+
current = 0;
23+
}
24+
nchildren ~= 0;
25+
// If we are starting a list with more than one child, add 2 parens
26+
if (current == 1) {
1827
return " ((" ~ escape(text);
1928
} else {
20-
multiple = true;
21-
return "(" ~ escape(text);
29+
return " (" ~ escape(text);
2230
}
2331
}
2432
string end() {
25-
if (multiple) {
26-
multiple = false;
33+
// If we are ending a list with more than one child, add 2 parens
34+
if (nchildren.length > 0 && nchildren[$-1] > 0) {
35+
nchildren.length--;
2736
return "))";
28-
} else return ") ";
37+
} else {
38+
nchildren.length--;
39+
return ")";
40+
}
2941
}
3042
}
3143
void main(string[] args) {

0 commit comments

Comments
 (0)