Skip to content

Fix/code class pygments short hex #2355 - #2465

Open
leonor-p wants to merge 4 commits into
3b1b:masterfrom
motamdaniela:fix/code-class-pygments-short-hex-#2355
Open

Fix/code class pygments short hex #2355#2465
leonor-p wants to merge 4 commits into
3b1b:masterfrom
motamdaniela:fix/code-class-pygments-short-hex-#2355

Conversation

@leonor-p

Copy link
Copy Markdown

Motivation

The Code class raises an exception when instantiated with any string.
PangoMarkupFormatter in pygments >= 2.14 generates 3-digit hex color
codes (e.g. #abc) in markup attributes. Pango does not support short
hex notation, causing MarkupText to fail on instantiation.

Fixes #2355

Proposed changes

  • Added regex substitution in Code.__init__ in manimlib/mobject/svg/text_mobject.py that expands all 3-digit hex colors to 6-digit after pygments.highlight(), before passing markup to MarkupText
  • Added unit tests in tests/test_code_class.py verifying the regex expansion works correctly on Python 3.9

Test

Code:

c = Code('sorted(iterable, key=None, reverse=False)')

Result: Code object created successfully without exception.
Unit tests pass on Python 3.9.25 — 2 passed in 0.02s.
image

@3b1b

3b1b commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Looks reasonable, but do you mind updating the PR to remove the stray files, and implement it by defining the expand_hex function, and calling it on that one tex_mobject.py line insetad of putting the regex logic in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code Class not work

2 participants