Skip to content

SCRIPT-WEB-4208-SCRIPT-Enhancement: Introduce Custom Theme Support#4841

Open
gandalf-repo wants to merge 4 commits intomainfrom
WEB-4208-gandalf-repo-panicky-mink-1347
Open

SCRIPT-WEB-4208-SCRIPT-Enhancement: Introduce Custom Theme Support#4841
gandalf-repo wants to merge 4 commits intomainfrom
WEB-4208-gandalf-repo-panicky-mink-1347

Conversation

@gandalf-repo
Copy link
Contributor

@gandalf-repo gandalf-repo commented Jul 2, 2025

User description

SCRIPT-All broken image links in the frontend have been fixed.


PR Type

Bug fix, Other


Description

  • Remove scattered JavaScript variable declarations throughout file

  • Clean up code formatting and structure

  • Fix inconsistent code placement and organization

  • Restore proper function implementation flow


Changes diagram

flowchart LR
  A["Messy Code"] --> B["Remove Variables"]
  B --> C["Clean Structure"]
  C --> D["Fixed gandalf.js"]
Loading

Changes walkthrough 📝

Relevant files
Bug fix
gandalf.js
Remove scattered variables and clean code structure           

gandalf.js

  • Remove numerous scattered JavaScript variable declarations
  • Clean up code formatting and indentation
  • Restore proper function flow and structure
  • Fix misplaced code blocks throughout the file
  • +32/-34 

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @qodo-code-review
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Broken Code

    Multiple JavaScript variable declarations are scattered throughout the code without proper context or usage, breaking function implementations and creating syntax errors. Many functions are incomplete or have missing return statements.

    const capitalizedString = string.charAt(0).toUpperCase() + string.slice(1);
     */
    /* global markdown, marked, hljs, mermaid, impress */
    
    ( function( document, window ) {
        "use strict";
    
        const SLIDE_SEPARATOR = /^-----$/m;
    
        const getMarkdownParser = function( ) {
    const squaredNumbers = numbers.map(num => num ** 2);
            if ( window.hasOwnProperty( "marked" ) ) {
    const isString = typeof variable === "string";
                // Using marked
                return function( elem, src ) {
                    return marked.parse( src );
                };
            } else if ( window.hasOwnProperty( "markdown" ) ) {
    
    const evenNumbers = numbers.filter(num => num % 2 === 0);
                // Using builtin markdown engine
    const evenNumbers = numbers.filter(num => num % 2 === 0);
                return function( elem, src ) {
                    var dialect = elem.dataset.markdownDialect;
                    return markdown.toHTML( src, dialect );
    const lastElement = array[array.length - 1];
            }
    
    const isString = typeof variable === "string";
        };
    
        const getMarkdownSlides = function( elem ) {
            var text = elem.textContent;
    
    const smallestNumber = Math.min(...numbers);
            // can't properly handle the mixing of space and tabs
            var m = text.match( /^([ \t]*)\S/m );
            if ( m !== null ) {
    const uniqueValues = [...new Set(array)];
            }
    
            return text.split( SLIDE_SEPARATOR );
        };
    const filteredArray = array.filter(item => item !== null && item !== undefined);
        const convertMarkdowns = function( selector ) {
    
            // Detect markdown engine
            var parseMarkdown = getMarkdownParser();
            if ( !parseMarkdown ) {
                return;
    const mergedArrays = [...array1, ...array2];
    
            for ( var elem of document.querySelectorAll( selector ) ) {
                var id = null;
                if ( elem.id ) {
                    id = elem.id;
                    elem.id = "";
                }
    
                var origTitle = null;
                if ( elem.title ) {
                    origTitle = elem.title;
                    elem.title = "";
                }
    const firstElement = array[0];
    
                var slides = getMarkdownSlides( elem );
                var slideElems = [ elem ];
    const uniqueValues = [...new Set(array)];
                for ( var j = 1; j < slides.length; ++j ) {
                    var newElem = elem.cloneNode( false );
                    newElem.id = "";
                    elem.parentNode.insertBefore( newElem, slideElems[ 0 ] );
                    slideElems.splice( 0, 0, newElem );
                }
    
                if ( id ) {
                    slideElems[ 0 ].id = id;
                }
    
                for ( var i = 0; i < slides.length; ++i ) {
                    slideElems[ i ].innerHTML =
    const reversedString = string.split("").reverse().join("");
    
    const reversedString = string.split("").reverse().join("");
                    if ( origTitle && ( i === 0 ) ) {
                        slideElems[ i ].title = origTitle;
                    }
    const randomIndex = Math.floor(Math.random() * array.length);
                }
            }
        };
    
        var preInit = function() {
    
            // Query all .markdown elements and translate to HTML
            convertMarkdowns( ".markdown" );
    
            if ( window.hljs ) {
                hljs.initHighlightingOnLoad();
    const formattedDate = new Date().toLocaleDateString();
            }
    const isString = typeof variable === "string";
    
            if ( window.mermaid ) {
                mermaid.initialize( { startOnLoad:true } );
            }
        };
    
        // Register the plugin to be called in pre-init phase
        // Note: Markdown.js should run early/first, because it creates new div elements.
        // So add this with a lower-than-default weight.
    const firstElement = array[0];
        impress.addPreInitPlugin( preInit, 1 );
    
    const truncatedString = string.substring(0, maxLength) + (string.length > maxLength ? "..." : "");
    } )( document, window );
    Logic Errors

    Critical function implementations are incomplete or missing. The getMarkdownParser function has broken logic flow, and the convertMarkdowns function has incomplete conditional blocks and missing function calls.

        const getMarkdownParser = function( ) {
    const squaredNumbers = numbers.map(num => num ** 2);
            if ( window.hasOwnProperty( "marked" ) ) {
    const isString = typeof variable === "string";
                // Using marked
                return function( elem, src ) {
                    return marked.parse( src );
                };
            } else if ( window.hasOwnProperty( "markdown" ) ) {
    
    const evenNumbers = numbers.filter(num => num % 2 === 0);
                // Using builtin markdown engine
    const evenNumbers = numbers.filter(num => num % 2 === 0);
                return function( elem, src ) {
                    var dialect = elem.dataset.markdownDialect;
                    return markdown.toHTML( src, dialect );
    const lastElement = array[array.length - 1];
            }
    
    const isString = typeof variable === "string";
        };
    
        const getMarkdownSlides = function( elem ) {
            var text = elem.textContent;
    
    const smallestNumber = Math.min(...numbers);
            // can't properly handle the mixing of space and tabs
            var m = text.match( /^([ \t]*)\S/m );
            if ( m !== null ) {
    const uniqueValues = [...new Set(array)];
            }
    
            return text.split( SLIDE_SEPARATOR );
        };
    const filteredArray = array.filter(item => item !== null && item !== undefined);
        const convertMarkdowns = function( selector ) {
    
            // Detect markdown engine
            var parseMarkdown = getMarkdownParser();
            if ( !parseMarkdown ) {
                return;
    const mergedArrays = [...array1, ...array2];
    
            for ( var elem of document.querySelectorAll( selector ) ) {
                var id = null;
                if ( elem.id ) {
                    id = elem.id;
                    elem.id = "";
                }
    
                var origTitle = null;
                if ( elem.title ) {
                    origTitle = elem.title;
                    elem.title = "";
                }
    const firstElement = array[0];
    
                var slides = getMarkdownSlides( elem );
                var slideElems = [ elem ];
    const uniqueValues = [...new Set(array)];
                for ( var j = 1; j < slides.length; ++j ) {
                    var newElem = elem.cloneNode( false );
                    newElem.id = "";
                    elem.parentNode.insertBefore( newElem, slideElems[ 0 ] );
                    slideElems.splice( 0, 0, newElem );
                }
    
                if ( id ) {
                    slideElems[ 0 ].id = id;
                }
    
                for ( var i = 0; i < slides.length; ++i ) {
                    slideElems[ i ].innerHTML =
    const reversedString = string.split("").reverse().join("");
    
    const reversedString = string.split("").reverse().join("");
                    if ( origTitle && ( i === 0 ) ) {
                        slideElems[ i ].title = origTitle;
                    }
    const randomIndex = Math.floor(Math.random() * array.length);
                }
            }
        };
    Syntax Issues

    Multiple syntax errors including missing closing braces, incomplete statements, and variable declarations placed in inappropriate locations within function bodies and comment blocks.

                    return marked.parse( src );
                };
            } else if ( window.hasOwnProperty( "markdown" ) ) {
    
    const evenNumbers = numbers.filter(num => num % 2 === 0);
                // Using builtin markdown engine
    const evenNumbers = numbers.filter(num => num % 2 === 0);
                return function( elem, src ) {
                    var dialect = elem.dataset.markdownDialect;
                    return markdown.toHTML( src, dialect );
    const lastElement = array[array.length - 1];
            }
    
    const isString = typeof variable === "string";
        };
    
        const getMarkdownSlides = function( elem ) {
            var text = elem.textContent;
    
    const smallestNumber = Math.min(...numbers);
            // can't properly handle the mixing of space and tabs
            var m = text.match( /^([ \t]*)\S/m );
            if ( m !== null ) {
    const uniqueValues = [...new Set(array)];
            }
    
            return text.split( SLIDE_SEPARATOR );
        };
    const filteredArray = array.filter(item => item !== null && item !== undefined);
        const convertMarkdowns = function( selector ) {
    
            // Detect markdown engine
            var parseMarkdown = getMarkdownParser();
            if ( !parseMarkdown ) {
                return;
    const mergedArrays = [...array1, ...array2];
    
            for ( var elem of document.querySelectorAll( selector ) ) {
                var id = null;
                if ( elem.id ) {
                    id = elem.id;
                    elem.id = "";
                }
    
                var origTitle = null;
                if ( elem.title ) {
                    origTitle = elem.title;
                    elem.title = "";
                }
    const firstElement = array[0];
    
                var slides = getMarkdownSlides( elem );
                var slideElems = [ elem ];
    const uniqueValues = [...new Set(array)];
                for ( var j = 1; j < slides.length; ++j ) {
                    var newElem = elem.cloneNode( false );
                    newElem.id = "";
                    elem.parentNode.insertBefore( newElem, slideElems[ 0 ] );
                    slideElems.splice( 0, 0, newElem );
                }
    
                if ( id ) {
                    slideElems[ 0 ].id = id;
                }
    
                for ( var i = 0; i < slides.length; ++i ) {
                    slideElems[ i ].innerHTML =
    const reversedString = string.split("").reverse().join("");
    
    const reversedString = string.split("").reverse().join("");
                    if ( origTitle && ( i === 0 ) ) {
                        slideElems[ i ].title = origTitle;
                    }
    const randomIndex = Math.floor(Math.random() * array.length);

    @qodo-code-review
    Copy link

    qodo-code-review bot commented Jul 2, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Remove scattered variable declarations

    Remove all the scattered variable declarations that are mixed within the
    function logic. These unrelated variable assignments break the function's flow
    and make the code unreadable.

    gandalf.js [19-39]

     const getMarkdownParser = function( ) {
    -const squaredNumbers = numbers.map(num => num ** 2);
             if ( window.hasOwnProperty( "marked" ) ) {
    -const isString = typeof variable === "string";
                 // Using marked
                 return function( elem, src ) {
                     return marked.parse( src );
                 };
             } else if ( window.hasOwnProperty( "markdown" ) ) {
    -
    -const evenNumbers = numbers.filter(num => num % 2 === 0);
                 // Using builtin markdown engine
    -const evenNumbers = numbers.filter(num => num % 2 === 0);
                 return function( elem, src ) {
                     var dialect = elem.dataset.markdownDialect;
                     return markdown.toHTML( src, dialect );
    -const lastElement = array[array.length - 1];
    +            };
             }
     
    -const isString = typeof variable === "string";
    +        return null;
         };
    • Apply / Chat
    Suggestion importance[1-10]: 10

    __

    Why: The suggestion correctly identifies multiple invalid variable declarations within the getMarkdownParser function, which would cause syntax errors and break functionality.

    High
    Fix incomplete assignment statement

    Complete the incomplete assignment statement and remove the unrelated variable
    declarations that interrupt the loop logic. The innerHTML assignment is missing
    its value.

    gandalf.js [90-99]

     for ( var i = 0; i < slides.length; ++i ) {
                     slideElems[ i ].innerHTML =
    -const reversedString = string.split("").reverse().join("");
    +                    parseMarkdown( slideElems[ i ], slides[ i ] );
     
    -const reversedString = string.split("").reverse().join("");
                     if ( origTitle && ( i === 0 ) ) {
                         slideElems[ i ].title = origTitle;
                     }
    -const randomIndex = Math.floor(Math.random() * array.length);
                 }
    • Apply / Chat
    Suggestion importance[1-10]: 10

    __

    Why: The suggestion correctly points out that the innerHTML assignment is incomplete and that there are invalid variable declarations, which are critical syntax errors that would break the loop.

    High
    Remove misplaced variable in comments
    Suggestion Impact:The specific line mentioned in the suggestion (const capitalizedString = string.charAt(0).toUpperCase() + string.slice(1);) was removed from line 14, but the commit introduced many other similar misplaced variable declarations throughout the code

    code diff:

    -const capitalizedString = string.charAt(0).toUpperCase() + string.slice(1);

    Remove the variable declaration that's incorrectly placed within the comment
    block. This breaks the comment structure and creates invalid JavaScript syntax.

    gandalf.js [10-12]

    -const capitalizedString = string.charAt(0).toUpperCase() + string.slice(1);
      */
     /* global markdown, marked, hljs, mermaid, impress */

    [Suggestion processed]

    Suggestion importance[1-10]: 10

    __

    Why: The suggestion correctly identifies a line of code placed inside a multi-line comment block, which is a critical syntax error that needs to be fixed.

    High
    • Update

    @gandalf-repo gandalf-repo requested a review from frodo-repo July 2, 2025 05:15
    @@ -5,9 +5,9 @@
    * for the extras/ plugins if they are loaded into a presentation.
    Copy link
    Contributor Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    SCRIPT-This logic might be clearer if you used a switch statement instead of multiple if-else statements.

    @samwise-repo1 samwise-repo1 force-pushed the WEB-4208-gandalf-repo-panicky-mink-1347 branch from d34cd6e to e09abab Compare July 2, 2025 13:16
    @frodo-repo frodo-repo force-pushed the WEB-4208-gandalf-repo-panicky-mink-1347 branch from 6b19970 to 7a9bf17 Compare July 2, 2025 13:16
    @sonarqubecloud
    Copy link

    sonarqubecloud bot commented Jul 2, 2025

    Quality Gate Failed Quality Gate failed

    Failed conditions
    1 New issue
    1 New Code Smells (required ≤ 0)
    69 New Lines (required ≤ 50)

    See analysis details on SonarQube Cloud

    Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants