Skip to content

Commit 2a9082a

Browse files
committed
feat: Add a checkbox to recognize JavaScript-style comments to the web page
1 parent 7379be8 commit 2a9082a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

web/jsonlint.html

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
window.onload = function () {
1010
document.getElementById("button").onclick = function () {
1111
try {
12-
var result = jsonlint.parse(document.getElementById("source").value);
12+
var parser = jsonlint
13+
if (document.getElementById("comments").checked) {
14+
parser = new jsonlint.parser.ParserWithComments
15+
}
16+
var result = parser.parse(document.getElementById("source").value);
1317
if (result) {
1418
document.getElementById("result").innerHTML = "JSON is valid!";
1519
document.getElementById("result").className = "pass";
@@ -45,15 +49,19 @@
4549
<body>
4650
<h1>JSON Lint</h1>
4751
<p>A pure JavaScript version of the service provided at <a href="http://jsonlint.com/">jsonlint.com</a>.</p>
48-
<textarea id="source" rows="20" cols="50">
49-
50-
</textarea>
52+
<textarea id="source" rows="20" cols="50"></textarea>
53+
<p>
54+
<input type="checkbox" checked id="reformat">
55+
<label for="reformat">reformat JSON</label>
56+
<br>
57+
<input type="checkbox" id="comments">
58+
<label for="comments">ignore JavaScript-style comments</label>
59+
</p>
5160
<p>
5261
<button id="button">Validate</button>
53-
<input type="checkbox" value="yes" id="reformat" /><label for="reformat">reformat JSON</label>
5462
</p>
5563
<h2>Results</h2>
5664
<pre id="result"></pre>
57-
<p><a href="http://github.com/zaach/jsonlint">project on github</a></p>
65+
<p><a href="http://github.com/prantlf/jsonlint">project on github</a></p>
5866
</body>
5967
</html>

0 commit comments

Comments
 (0)