Preserve syntax highlighting across wrapped reprs
Fixes #161.
PrettyFormat currently feeds Pygments the already-wrapped text. When textwrap splits a quoted value, the inserted newline can change the lexer state and even the color of the next value. For highlighted calls, this records where wrapped fragments came from, lexes the original representation, and applies the token colors at the displayed positions. The plain wrapping rules are unchanged.
The regression tests cover split strings, escapes, identifiers, tab expansion, actual line breaks, and nested calls. With the locked runtime dependencies on CPython 3.14.5, the suite had 156 passes and eight skips. A separate comparison across seven widths and two nesting levels matched the original token colors in 140/140 cases and the plain output was byte-identical to the base. Ruff 0.17.0 passed. BasedPyright showed no new diagnostics versus base in the reduced environment; I did not test the full optional-dependency matrix.
Prepared with OpenAI Codex on behalf of @vibhor-aggr.
Summary by cubic
Fixes #161. Wrapped representations are now lexed from the original text and token colors are mapped onto the displayed positions, so syntax highlighting no longer shifts when textwrap splits a quoted value. The plain wrapping output is byte-identical to before.
Bug Fixes
- Added regression tests for split strings, escapes, identifiers, tab expansion, real line breaks, and nested/reentrant formatting.
- Highlighting without Pygments installed falls back to plain output as before.