fix: Re-apply JSON syntax highlighting after AJAX updates

- Extract JSON highlighting logic into Functions.highlightJson()
- Call highlightJson() after display options form submission
- Ensures CodeMirror highlighting persists on dynamic content updates

Signed-off-by: Alberto Cuevas <mexslacker@gmail.com>
This commit is contained in:
Alberto Cuevas 2025-11-10 21:03:05 -06:00
parent 13393ef053
commit 0cc6ef9ebf
3 changed files with 24 additions and 12 deletions

View File

@ -1730,6 +1730,28 @@ Functions.highlightSql = function ($base) {
});
};
/**
* Applies JSON syntax highlighting transformation using CodeMirror
*
* @param {JQuery} $base base element which contains the JSON code blocks
*/
Functions.highlightJson = function ($base) {
var $elm = $base.find('code.json');
$elm.each(function () {
var $json = $(this);
var $pre = $json.find('pre');
/* We only care about visible elements to avoid double processing */
if ($pre.is(':visible')) {
var $highlight = $('<div class="json-highlight cm-s-default"></div>');
$json.append($highlight);
if (typeof CodeMirror !== 'undefined' && typeof CodeMirror.runMode === 'function') {
CodeMirror.runMode($json.text(), 'application/json', $highlight[0]);
$pre.hide();
}
}
});
};
/**
* Updates an element containing code.
*

View File

@ -675,6 +675,7 @@ AJAX.registerOnload('sql.js', function () {
.html(data.message)
.trigger('makeGrid');
Functions.highlightSql($sqlqueryresults);
Functions.highlightJson($sqlqueryresults);
}); // end $.post()
}); // end displayOptionsForm handler

View File

@ -2,16 +2,5 @@
* JSON syntax highlighting transformation plugin
*/
AJAX.registerOnload('transformations/json.js', function () {
var $elm = $('#page_content').find('code.json');
$elm.each(function () {
var $json = $(this);
var $pre = $json.find('pre');
/* We only care about visible elements to avoid double processing */
if ($pre.is(':visible')) {
var $highlight = $('<div class="json-highlight cm-s-default"></div>');
$json.append($highlight);
CodeMirror.runMode($json.text(), 'application/json', $highlight[0]);
$pre.hide();
}
});
Functions.highlightJson($('#page_content'));
});