Skip to content

ipynbdiff: strip ANSI color codes in output cells (stream and text outputs) and add tests

What does this MR do and why?

ipynbdiff: strip ANSI color codes in output cells (stream and text outputs) and add tests

This merge request strips ANSI color codes from Jupyter Notebook output cells in the ipynbdiff gem, for both stream and text outputs. Previously, outputs contained ANSI escape sequences (e.g., \e[31mError in red\e[0m) which made diffs harder to read. Now outputs are plain text, improving readability.

Signed-off-by: Yash Suthar yashsuthar983@gmail.com

Related Issue

Issue #429656

Changes Made

  • Updated IpynbDiff.transform to remove ANSI escape codes from outputs.
  • Added regression tests for notebooks containing ANSI codes (ansi_stream_text/input.ipynb and ansi_execute_text/input.ipynb).

Validation Steps / Local Setup

  1. Run transformation commands on test notebooks:

    BUNDLE_GEMFILE=gems/ipynbdiff/Gemfile bundle exec ruby -e 'require "ipynb_diff"; f=File.read("gems/ipynbdiff/spec/testdata/ansi_stream_text/input.ipynb"); puts IpynbDiff.transform(f, include_frontmatter: false).inspect' BUNDLE_GEMFILE=gems/ipynbdiff/Gemfile bundle exec ruby -e 'require "ipynb_diff"; f=File.read("gems/ipynbdiff/spec/testdata/ansi_execute_text/input.ipynb"); puts IpynbDiff.transform(f, include_frontmatter: false).inspect'

  2. Confirm that the output no longer contains ANSI escape codes.

Before / After

Before:

\e[31mError in red\e[0m \e[1;32mSuccess\e[0m

After:

Error in red
Success

Edited by Yash Suthar

Merge request reports

Loading