pianello-api/resources/js/components/highlight/index.js
Ale Gallo 82f958e5da Committing laravel (part 3)
committing js templating files and components
2023-11-10 16:00:59 +01:00

32 lines
961 B
JavaScript

(function () {
"use strict";
// Highlight code
$(".highlight").each(function () {
let source = $(this).find("code").html();
// First replace
let replace = helper.replaceAll(source, "HTMLOpenTag", "<");
replace = helper.replaceAll(replace, "HTMLCloseTag", ">");
// Save for copy code function
let originalSource = $(
'<textarea class="absolute w-0 h-0 p-0 -mt-1 -ml-1"></textarea>'
).val(replace);
$(this).append(originalSource);
// Beautify code
if ($(this).find("code").hasClass("javascript")) {
replace = jsBeautify(replace);
} else {
replace = jsBeautify.html(replace);
}
// Format for highlight.js
replace = helper.replaceAll(replace, "<", "&lt;");
replace = helper.replaceAll(replace, ">", "&gt;");
$(this).find("code").html(replace);
});
hljs.highlightAll();
})();