Skip to content

Commit ad1d314

Browse files
committed
Add json switch
1 parent 0ec0475 commit ad1d314

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/examples/csv/input.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
A,B,C
22
a1,b1,c1
33
a2,"b,2",c2
4-
a3,b3,c3
4+
a3,b3,c3

src/examples/url/grammar.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ scheme = ~[:/?#]+
66
auth = ~[/?#]*
77
path = ~[?#]*
88
query = ~'#'*
9-
frag = ~[ \t\n\r]*
9+
frag = ~[ \t\n\r]*

src/pages/index.astro

+13-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const examples = (await getCollection("examples")).map(c => c.data)
2525
const input = document.getElementById('input')
2626
const parse = parser.parse(input.innerText) //textContent),
2727
const output = document.getElementById('output');
28-
if (parse.ok) output.textContent = parse.show_ptree(); // TODO json?
28+
const showJson = document.getElementById<HTMLCheckboxElement>('json').checked
29+
if (parse.ok) output.textContent = parse.show_ptree(showJson);
2930
else output.textContent = parse.show_err();
3031
}
3132

@@ -93,6 +94,11 @@ const examples = (await getCollection("examples")).map(c => c.data)
9394
overflow-y: auto;
9495
}
9596

97+
.json {
98+
display: flex;
99+
align-items: center;
100+
}
101+
96102
@media (max-width: 768px) {
97103
body {
98104
grid-template-areas:
@@ -139,7 +145,12 @@ const examples = (await getCollection("examples")).map(c => c.data)
139145
<div id='input' contenteditable='true'></div>
140146
</div>
141147
<div class='output'>
142-
<div class='header'>Parse Tree</div>
148+
<div class='header'>Parse Tree
149+
<label class="json">
150+
JSON
151+
<input type="checkbox" id="json" name="json" onchange="run()">
152+
</label>
153+
</div>
143154
<div id='output'></div>
144155
</div>
145156
<div class="footer">Copyright 2024</div>

0 commit comments

Comments
 (0)