Preprocess ANSI Input for `--export-svg` and `--export-html`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Trace how rich-cli handles piped input and the --export-svg and --export-html options, then compare that path with the provided rich.ansi.AnsiDecoder example. Verify the change with the documented shell command and confirm that ANSI-colored input produces styled, parseable SVG and HTML rather than literal escape sequences.
Written by the indexing model from the issue text.
Description
When exporting to SVG or HTML, rich-cli does not interpret ANSI escape codes from piped input. Instead of converting them into styled output, it writes the raw escape sequences directly into the file. This leads to broken exports where the ANSI codes appear as literal text or cause XML parsing errors.
For example, running:
rich -p "[green]hello" | rich --export-svg hello.svg -
should generate an SVG with "hello" in green. Instead, the file contains the raw ANSI codes, making the output unusable.
A solution could be to preprocess the input and convert ANSI sequences into Rich’s internal format before rendering. Adding a flag like --preprocess-ansi would ensure that exports correctly reflect the intended formatting.
This behavior is already possible in Python using rich.ansi.AnsiDecoder, as shown in this minimal script:
#!/usr/bin/env python3
import sys
from rich.console import Console
from rich.ansi import AnsiDecoder
from pathlib import Path
console = Console(record=True)
decoder = AnsiDecoder()
input_text = sys.stdin.read()
for segment in decoder.decode(input_text):
console.print(segment)
Path("output.svg").write_text(console.export_svg())
A similar approach within rich-cli would allow users to export properly formatted SVG or HTML files without losing ANSI colors. This would make exports consistent with Rich’s behavior in the terminal.
Would love to see this implemented—thanks for all the great work on rich! 🚀
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 117
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/rich-cli
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Textualize/rich-cli#136 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Textualize/rich-cli#19 · 4 comments · 4 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
Textualize/rich-cli#135 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
Textualize/rich-cli#132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
Textualize/rich-cli#128 · 1 reaction ·
All issues in Textualize/rich-cli
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100