Skip to content

Commit 93cc5c7

Browse files
committed
Fix #55
1 parent 4912edb commit 93cc5c7

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

assets/js/scripts.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,39 @@ document.addEventListener('DOMContentLoaded', function () {
234234
* JSON syntax highlighter
235235
*/
236236
const json_syntax_highlight = (json) => {
237+
if (typeof json !== 'string') {
238+
json = JSON.stringify(json, null, 2);
239+
}
240+
241+
json = json.replace(/&/g, '&')
242+
.replace(/</g, '&lt;')
243+
.replace(/>/g, '&gt;');
244+
237245
return json.replace(
238-
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?|[[\]{}:,s])/g,
246+
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?|[{}\[\],:])/g,
239247
match => {
240-
if (match.startsWith("\"")) {
241-
if (/"(\w+)":/.test(match)) {
242-
return `<span class="json-key">${match.replace('":', '"')}</span><span class="json-colon">:</span>`;
248+
let cls = '';
249+
if (/^"/.test(match)) {
250+
if (/:$/.test(match)) {
251+
cls = 'json-key';
243252
} else {
244-
return `<span class="json-string">${match}</span>`;
253+
cls = 'json-string';
245254
}
246-
} else if (/[[\]{}]/.test(match)) {
247-
return `<span class="json-bracket">${match}</span>`;
248255
} else if (/true|false/.test(match)) {
249-
return `<span class="json-boolean">${match}</span>`;
256+
cls = 'json-boolean';
250257
} else if (/null/.test(match)) {
251-
return `<span class="json-null">${match}</span>`;
258+
cls = 'json-null';
252259
} else if (/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/.test(match)) {
253-
return `<span class="json-number">${match}</span>`;
260+
cls = 'json-number';
261+
} else if (/[\[\]{}]/.test(match)) {
262+
cls = 'json-bracket';
254263
} else if (match === ',') {
255-
return `<span class="json-comma">${match}</span>`;
256-
} else {
257-
return match;
264+
cls = 'json-comma';
265+
} else if (match === ':') {
266+
cls = 'json-colon';
258267
}
268+
269+
return cls ? `<span class="${cls}">${match}</span>` : match;
259270
}
260271
);
261272
};

src/Admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use RobiNN\Pca\Dashboards\DashboardInterface;
1212

1313
class Admin {
14-
public const VERSION = '2.3.1';
14+
public const VERSION = '2.3.2';
1515

1616
private readonly Template $template;
1717

0 commit comments

Comments
 (0)