phpmyadmin/resources/js/modules/json-highlight.ts
Maurício Meneghini Fauth 0d843e68fe
Replace var with let or const in TypeScript files
Most of the changes were done by PhpStorm.

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
2026-04-09 20:48:22 -03:00

25 lines
900 B
TypeScript

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