ipynbdiff: strip ANSI color codes in output cells (stream and text outputs) and add tests
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
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
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
andansi_execute_text/input.ipynb
).
Validation Steps / Local Setup
-
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'
-
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