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.
splunk_fy.html
<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment