ansi2html icon indicating copy to clipboard operation
ansi2html copied to clipboard

Stray characters in html output

Open mikepurvis opened this issue 5 years ago • 2 comments
trafficstars

Not totally sure what's going on here, but this is diagnostic output from GCC 9:

^[[01m^[[K/path/to/my/file.cpp:127:30:^[[m^[[K ^[[01;35m^[[Kwarning: ^[[m^[[Kcomparison of integer expressions of different signedness: ~@~X^[[01m^[[Kunsgned int^[[m^[[K~@~Y and ~@~X^[[01m^[[Kint^[[m^[[K~@~Y [^[[01;35m^[[K-Wsign-compare^[[m^[[K]
  127 |   for (unsigned int y = 0; ^[[01;35m^[[Ky < height^[[m^[[K; y++)
      |                            ^[[01;35m^[[K~~^~~~~~~~^[[m^[[K

Which is rendered by ansi2html into:

<span class="ansi1">/path/to/my/file.cpp:127:30:</span> <span class="ansi1 ansi35">warning: </span>comparison of integer expressions of different signedness: ‘<span class="ansi1">unsigned int</span>’ and ‘<span class="ansi1">int</span>’ [<span class="ansi1 ansi35">-Wsign-compare</span>]
  127 |   for (unsigned int y = 0; <span class="ansi1 ansi35">y &lt; height</span>; y++)
      |                            <span class="ansi1 ansi35">~~^~~~~~~~</span>

Anyone know what those extra ‘ sequences are, and if they can be filtered out somehow?

mikepurvis avatar Feb 06 '20 04:02 mikepurvis

When trying to reproduce it…

# echo 'int main(int argc, char ** argv) { return argc < (unsigned)argc; }' > main.c
# gcc -Wextra -fdiagnostics-color=always main.c |& ansi2html > gcc.htm
# gcc -dumpversion
11.2.1
# ansi2html --version
ansi2html 1.7.1.dev1  # i.e. Git master

…what I see in the browser is this: gcc

Which looks sane. So I'll need help with reproducing.

hartwork avatar Feb 03 '22 22:02 hartwork

PS: Here's what I get for your very example pasted into input.txt. Note the sed call to repair the ANSI on the fly:

# sed $'s,\^\[,\x1b,g' input.txt | ansi2html > gcc.htm

Then in Chromium: gcc2

hartwork avatar Feb 03 '22 23:02 hartwork