{{ message }}
fix: crashes in --latex --inline when there is no colour to apply - #275
Open
Thorsrud22 wants to merge 1 commit into
Open
Thorsrud22 wants to merge 1 commit into
Thorsrud22 wants to merge 1 commit into
Conversation
Thorsrud22
force-pushed
the
latex-inline-crashes
branch
from
September 11, 2026 16:36
2eefbf6 to
07628ac
Compare
The inline LaTeX branch assumed every active CSS class had a style rule and that at least one of them was a colour. Two inputs broke that: - italic-only text (ESC[3m): the class "ansi3" has a font-style rule but no colour, so indexing the first colour raised IndexError (pycontribs#127) - a foreground code with no parameter (ESC[38m): the class "ansi38" has no rule at all, so the lookup raised KeyError (pycontribs#252) Collect colours only from classes that have a rule, and when there is no colour open a plain LaTeX group instead of \textcolor so the closing brace emitted later stays balanced. Fixes pycontribs#127 Fixes pycontribs#252 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Thorsrud22
force-pushed
the
latex-inline-crashes
branch
from
September 13, 2026 18:56
07628ac to
8d5bc73
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #127. Fixes #252. Supersedes #253.
The inline LaTeX branch in
_handle_ansi_codeassumed every active CSS class had a style rule and that at least one of them was a colour. Two inputs break that assumption:ESC[3m, Crash for--latexand italic^[[3m#127): the classansi3has afont-stylerule but no colour, sostyle[0]raisedIndexError.ESC[38m, [>=1.7.0] Crash for latex inline mode #252): the classansi38has no rule at all, soself.styles[klass]raisedKeyError.#253 addressed the
KeyErrorwith a.get()guard, but as @hartwork noted in review it then falls through to the sameIndexErroras #127. This PR handles both in one place.Change
colorproperty rather than assuming it is the first one.{instead of\textcolor[HTML]{...}{. The closing}emitted later when the span ends keeps the output balanced, and a bare group is a no-op in LaTeX.Coloured output is unchanged:
ESC[33mYELLOWstill renders as\textcolor[HTML]{aa5500}{YELLOW}.Verification
--latexand italic^[[3m#127 and [>=1.7.0] Crash for latex inline mode #252 now convert with--latex --inlineinstead of raising, with balanced braces.🤖 Generated with Claude Code