Skip to content

Commit bf3ce85

Browse files
authored
Reinstate the prettyPrint radio on the playground (#511)
1 parent 3f21c09 commit bf3ce85

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

playground/index.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,30 @@ <h3>Math font:</h3>
4141
</select>
4242
</div>
4343
</div>
44+
<div id="prettyprint" class="option-group">
45+
<h3>Pretty print:</h3>
46+
<div class="options">
47+
<label
48+
><input
49+
type="radio"
50+
id="pretty-true"
51+
name="prettyprint"
52+
value="true"
53+
checked
54+
/>
55+
True</label
56+
>
57+
<label
58+
><input
59+
type="radio"
60+
id="pretty-false"
61+
name="prettyprint"
62+
value="false"
63+
/>
64+
False</label
65+
>
66+
</div>
67+
</div>
4468
<div id="displaystyle" class="option-group">
4569
<h3>Display style:</h3>
4670
<div class="options">
@@ -71,7 +95,6 @@ <h3>Display style:</h3>
7195
<summary><strong>JSON config</strong> (click to open)</summary>
7296
<div>
7397
<textarea rows="10" id="configField" spellcheck="false">{
74-
"prettyPrint": true,
7598
"macros": {
7699
"d": "\\mathrm{d}\\mspace{0mu}",
77100
"ceil": "\\lceil #1 \\rceil",

playground/main.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,25 @@ function updateIsBlockCache() {
1919
}
2020

2121
function updateConfig() {
22+
const prettyRadio = document.querySelector(
23+
'#prettyprint input[type="radio"]:checked',
24+
);
25+
const isPrettyPrint = prettyRadio ? prettyRadio.value === "true" : true;
26+
2227
const configField = document.getElementById("configField");
2328

2429
try {
2530
const jsonString = configField.value.trim();
2631

2732
// Parse JSON with custom reviver to convert macros to Map
28-
const parsed = JSON.parse(jsonString, (key, value) => {
33+
let parsed = JSON.parse(jsonString, (key, value) => {
2934
if (key === 'macros') {
3035
return new Map(Object.entries(value));
3136
}
3237
return value;
3338
});
39+
// Set the prettyPrint property from the radio selection
40+
parsed["prettyPrint"] = isPrettyPrint;
3441
set_config(parsed);
3542

3643
} catch (error) {
@@ -246,6 +253,15 @@ document.addEventListener("DOMContentLoaded", () => {
246253
});
247254
});
248255

256+
document
257+
.querySelectorAll('#prettyprint input[type="radio"]')
258+
.forEach((radio) => {
259+
radio.addEventListener("change", () => {
260+
updateConfig(); // Update config when radio button changes
261+
updateOutput();
262+
});
263+
});
264+
249265
// Add listener for config field changes
250266
configField.addEventListener("input", () => {
251267
const success = updateConfig(); // Update config when textarea content changes

0 commit comments

Comments
 (0)