From 94e5ad1056372518e56e79229f517963789f0ab9 Mon Sep 17 00:00:00 2001 From: Marco Fontani Date: Thu, 2 Oct 2025 10:33:51 +0200 Subject: [PATCH] ignore "CSI K" (erase until EOL) sequences Closes https://github.com/mfontani/ansi2html/issues/37 --- src/main.c | 15 +++++++++++++++ tests/csi-k.sh | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 tests/csi-k.sh diff --git a/src/main.c b/src/main.c index 23e9d49..b6f8881 100644 --- a/src/main.c +++ b/src/main.c @@ -264,6 +264,11 @@ just_strip_it(bool ignore_sgr_errors) { state = STATE_TEXT; } + else if (c == 'K') + { + // Ignore "Erase in Line" sequence. + state = STATE_TEXT; + } else { if (ignore_sgr_errors) @@ -519,6 +524,16 @@ static inline __attribute__((always_inline)) void ansi2html( ); span_outputted = false; } + else if (c == 'K') + { + // Ignore "Erase in Line" sequence. + state = STATE_TEXT; + if (span && !span_outputted) + { + append_to_buffer(span); + span_outputted = true; + } + } else { // The character should be a digit, or semicolon. diff --git a/tests/csi-k.sh b/tests/csi-k.sh new file mode 100755 index 0000000..f7fb9c0 --- /dev/null +++ b/tests/csi-k.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e + +. "$(dirname "$0")/".functions.sh + +# CSI K is a no-op when stripping OR converting to HTML +str=$'Hello, \e[0;1mBold\e[K\e[0m world!' +want=$'Hello, Bold world!' +got=$(printf '%s' "$str" | ./ansi2html -p vga) +str_eq_html "$str" "$want" "$got" + +want=$'Hello, Bold world!' +got=$(printf '%s' "$str" | ./ansi2html -S) +str_eq_html "$str" "$want" "$got" + +done_testing