Jump to content

MediaWiki:Common.js: Difference between revisions

From Knowledge Base
No edit summary
No edit summary
Line 1: Line 1:
importScriptURI('/skins/common/highlight.js');
// Check if highlight.js has been loaded properly
if (typeof hljs === "undefined") {
if (typeof hljs === "undefined") {
     console.error("highlight.js is not loaded properly.");
     console.error("highlight.js is not loaded properly. Ensure the correct path to highlight.js is used.");
} else {
} else {
     console.log("highlight.js is loaded successfully.");
     console.log("highlight.js is loaded successfully.");
   
     // Attempt to highlight all code blocks
     // Attempt to highlight all code blocks
     try {
     try {
         hljs.highlightAll();
         if (typeof hljs.highlightAll === "function") {
        console.log("highlight.js executed successfully on all code blocks.");
            hljs.highlightAll();
            console.log("highlight.js executed successfully on all code blocks.");
        } else {
            console.error("highlight.js does not have the 'highlightAll' function. Check if the script is correct.");
        }
     } catch (e) {
     } catch (e) {
         console.error("Error highlighting code blocks: ", e);
         console.error("Error highlighting code blocks: ", e);
     }
     }
}
}

Revision as of 10:16, 18 January 2025

// Check if highlight.js has been loaded properly
if (typeof hljs === "undefined") {
    console.error("highlight.js is not loaded properly. Ensure the correct path to highlight.js is used.");
} else {
    console.log("highlight.js is loaded successfully.");
    
    // Attempt to highlight all code blocks
    try {
        if (typeof hljs.highlightAll === "function") {
            hljs.highlightAll();
            console.log("highlight.js executed successfully on all code blocks.");
        } else {
            console.error("highlight.js does not have the 'highlightAll' function. Check if the script is correct.");
        }
    } catch (e) {
        console.error("Error highlighting code blocks: ", e);
    }
}