Skip to content

Instantly share code, notes, and snippets.

@scheler
Created January 23, 2025 06:52
Show Gist options
  • Save scheler/0f9360487959aabba0951838d21b4825 to your computer and use it in GitHub Desktop.
Save scheler/0f9360487959aabba0951838d21b4825 to your computer and use it in GitHub Desktop.

Revisions

  1. scheler renamed this gist Jan 23, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. scheler created this gist Jan 23, 2025.
    74 changes: 74 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ANSI to HTML</title>
    <style>
    body {
    font-family: Arial, sans-serif;
    background-color: #f9f9f9;
    margin: 0;
    padding: 20px;
    }
    .output {
    font-family: monospace;
    background-color: #f0f0f0; /* Light grey background */
    color: #333;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    line-height: 1.6;
    border: 1px solid #ddd;
    white-space: pre;
    }
    </style>
    </head>
    <body>
    <div id="terminal-output" class="output"></div>

    <script>
    function ansiToHtml(ansiText) {
    // ANSI color code mappings to corresponding HTML styles
    const ansiStyles = {
    '[1;32m': '<span style="color:#32CD32">', // green
    '[1;34m': '<span style="color:#1E90FF">', // blue
    '[1;33m': '<span style="color:#000000">', // black (replacing yellow)
    '[0;35m': '<span style="color:#9370DB">', // purple (for FY25)
    '[1;35m': '<span style="color:#9370DB">', // purple (for FY26)
    '[1;31m': '<span style="color:#FF4500">', // red
    '[0;36m': '<span style="color:#00CED1">', // cyan
    '[1;37m': '<span style="color:#333">', // dark gray
    '[0m': '</span>' // reset/close tag
    };

    // Replace ANSI codes with corresponding HTML tags
    let htmlText = ansiText;
    Object.keys(ansiStyles).forEach(ansiCode => {
    const htmlTag = ansiStyles[ansiCode];
    const regex = new RegExp(ansiCode.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'); // Escape special characters
    htmlText = htmlText.replace(regex, htmlTag);
    });

    // Replace newlines with <br> tags to preserve the formatting
    htmlText = htmlText.replace(/\n/g, '<br>');

    return htmlText;
    }

    window.onload = function() {
    const ansiContent = `
    [1;32mFY25 | Q3 | Jan 26 to Apr 29 2025
    FY25 | Q4 | Apr 30 to Jul 26 2025
    FY26 | Q1 | Jul 27 to Oct 26 2025
    FY26 | Q2 | Oct 27 to Jan 26 2026
    FY26 | Q3 | Jan 27 to Apr 26 2026
    FY26 | Q4 | Apr 27 to Jul 26 2026
    FY27 | Q1 | Jul 27 to Oct 26 2026
    `;
    const htmlContent = ansiToHtml(ansiContent);
    document.getElementById("terminal-output").innerHTML = htmlContent; // Display result in the web page
    };
    </script>
    </body>
    </html>