Add <span> counter

Signed-off-by: yubiuser <github@yubiuser.dev>
This commit is contained in:
yubiuser
2025-06-24 20:19:04 +02:00
parent b884688a84
commit 785494e60b

View File

@@ -85,16 +85,21 @@ function parseLines(ta, str) {
ta.html(ta.html().substring(0, ta.html().lastIndexOf("\n")));
}
// Replace ANSI escape codes with HTML tags
line = line.replaceAll("", "</span>"); //COL_NC
line = line.replaceAll("", '<span class="text-bold">'); //COL_BOLD
line = line.replaceAll("", '<span class="log-gray">'); //COL_GRAY
line = line.replaceAll("", '<span class="log-red">'); //COL_RED
line = line.replaceAll("", '<span class="log-green">'); //COL_GREEN
line = line.replaceAll("", '<span class="log-yellow">'); //COL_YELLOW
line = line.replaceAll("", '<span class="log-blue">'); //COL_BLUE
line = line.replaceAll("", '<span class="log-purple">'); //COL_PURPLE
line = line.replaceAll("", '<span class="log-cyan">'); //COL_CYAN
// Track the number of opening spans
let spanCount = 0;
// Replace ANSI escape codes with HTML tags and count opening spans
line = line.replaceAll("", () => { spanCount++; return '<span class="text-bold">'; }); //COL_BOLD
line = line.replaceAll("", () => { spanCount++; return '<span class="log-gray">'; }); //COL_GRAY
line = line.replaceAll("", () => { spanCount++; return '<span class="log-red">'; }); //COL_RED
line = line.replaceAll("", () => { spanCount++; return '<span class="log-green">'; }); //COL_GREEN
line = line.replaceAll("", () => { spanCount++; return '<span class="log-yellow">'; }); //COL_YELLOW
line = line.replaceAll("", () => { spanCount++; return '<span class="log-blue">'; }); //COL_BLUE
line = line.replaceAll("", () => { spanCount++; return '<span class="log-purple">'; }); //COL_PURPLE
line = line.replaceAll("", () => { spanCount++; return '<span class="log-cyan">'; }); //COL_CYAN
// Replace [0m with the appropriate number of closing spans
line = line.replaceAll("", "</span>".repeat(spanCount)); //COL_NC
// Append the new text to the end of the output
ta.append(line);