From 0cc6ef9ebfc6c6e4e0bbfbab9540daa41e56b241 Mon Sep 17 00:00:00 2001 From: Alberto Cuevas Date: Mon, 10 Nov 2025 21:03:05 -0600 Subject: [PATCH] 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 --- js/src/functions.js | 22 ++++++++++++++++++++++ js/src/sql.js | 1 + js/src/transformations/json.js | 13 +------------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/js/src/functions.js b/js/src/functions.js index 449e1e8ba4..ce9532f20c 100644 --- a/js/src/functions.js +++ b/js/src/functions.js @@ -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 = $('
'); + $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. * diff --git a/js/src/sql.js b/js/src/sql.js index 28e090c5c1..1180842d0f 100644 --- a/js/src/sql.js +++ b/js/src/sql.js @@ -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 diff --git a/js/src/transformations/json.js b/js/src/transformations/json.js index 4326a2eda3..4e2383656e 100644 --- a/js/src/transformations/json.js +++ b/js/src/transformations/json.js @@ -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 = $('
'); - $json.append($highlight); - CodeMirror.runMode($json.text(), 'application/json', $highlight[0]); - $pre.hide(); - } - }); + Functions.highlightJson($('#page_content')); });