From 09a74e3e245923064ca291e62d50d31a80a70b02 Mon Sep 17 00:00:00 2001 From: leonor-p Date: Tue, 12 May 2026 22:58:53 +0100 Subject: [PATCH 1/4] fix: expand pygments short hex colors in Code class markup --- fix_code_class_pygments_hex.patch | 17 +++++++++++++++++ manimlib/mobject/svg/text_mobject.py | 6 ++++++ test_code_fix.py | 8 ++++++++ 3 files changed, 31 insertions(+) create mode 100644 fix_code_class_pygments_hex.patch create mode 100644 test_code_fix.py diff --git a/fix_code_class_pygments_hex.patch b/fix_code_class_pygments_hex.patch new file mode 100644 index 0000000000..f9c72c6a84 --- /dev/null +++ b/fix_code_class_pygments_hex.patch @@ -0,0 +1,17 @@ +diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py +index 91bfada8..ed4c8283 100644 +--- a/manimlib/mobject/svg/text_mobject.py ++++ b/manimlib/mobject/svg/text_mobject.py +@@ -454,6 +454,12 @@ class Code(MarkupText): + style=code_style + ) + markup = pygments.highlight(code, lexer, formatter) ++ # Pango does not support 3-digit hex colors generated by pygments >= 2.14 ++ markup = re.sub( ++ r'(?<=["\'])#([0-9a-fA-F]{3})(?=["\'])', ++ lambda m: '#' + ''.join(c * 2 for c in m.group(1)), ++ markup ++ ) + markup = re.sub(r"", "", markup) + super().__init__( + markup, diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index 91bfada8fc..ed4c828317 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -454,6 +454,12 @@ def __init__( style=code_style ) markup = pygments.highlight(code, lexer, formatter) + # Pango does not support 3-digit hex colors generated by pygments >= 2.14 + markup = re.sub( + r'(?<=["\'])#([0-9a-fA-F]{3})(?=["\'])', + lambda m: '#' + ''.join(c * 2 for c in m.group(1)), + markup + ) markup = re.sub(r"", "", markup) super().__init__( markup, diff --git a/test_code_fix.py b/test_code_fix.py new file mode 100644 index 0000000000..1d12be7ce7 --- /dev/null +++ b/test_code_fix.py @@ -0,0 +1,8 @@ +from manimlib import * + + +class TestCodeFix(Scene): + def construct(self): + c = Code('sorted(iterable, key=None, reverse=False)') + self.play(FadeIn(c)) + self.wait() From 25fcc04881389937991382f32e8b1f806bc7acf9 Mon Sep 17 00:00:00 2001 From: leonor-p Date: Wed, 13 May 2026 19:25:32 +0100 Subject: [PATCH 2/4] test: add unit tests for pygments short hex color fix --- tests/test_code_class.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/test_code_class.py diff --git a/tests/test_code_class.py b/tests/test_code_class.py new file mode 100644 index 0000000000..f310e667ca --- /dev/null +++ b/tests/test_code_class.py @@ -0,0 +1,22 @@ +import re +import pytest + + +def expand_hex(markup): + return re.sub( + r'(?<=["\'])#([0-9a-fA-F]{3})(?=["\'])', + lambda m: '#' + ''.join(c * 2 for c in m.group(1)), + markup + ) + + +def test_expand_3digit_hex(): + assert expand_hex('foreground="#abc"') == 'foreground="#aabbcc"' + assert expand_hex('foreground="#fff"') == 'foreground="#ffffff"' + assert expand_hex('foreground="#aabbcc"') == 'foreground="#aabbcc"' + + +def test_expand_multiple_colors(): + markup = 'color="#abc" background="#def"' + result = expand_hex(markup) + assert result == 'color="#aabbcc" background="#ddeeff"' From acf3f23c8cf7ccc1060698d4da17fc24faa4cbbe Mon Sep 17 00:00:00 2001 From: leonor-p Date: Wed, 13 May 2026 19:26:32 +0100 Subject: [PATCH 3/4] test: add unit tests for pygments short hex color fix --- fix_code_class_pygments_hex.patch | 45 +++++++++++++++++++------------ fix_staticmethod_python310.patch | 12 +++++++++ package-lock.json | 6 +++++ 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 fix_staticmethod_python310.patch create mode 100644 package-lock.json diff --git a/fix_code_class_pygments_hex.patch b/fix_code_class_pygments_hex.patch index f9c72c6a84..a56f8d781d 100644 --- a/fix_code_class_pygments_hex.patch +++ b/fix_code_class_pygments_hex.patch @@ -1,17 +1,28 @@ -diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py -index 91bfada8..ed4c8283 100644 ---- a/manimlib/mobject/svg/text_mobject.py -+++ b/manimlib/mobject/svg/text_mobject.py -@@ -454,6 +454,12 @@ class Code(MarkupText): - style=code_style - ) - markup = pygments.highlight(code, lexer, formatter) -+ # Pango does not support 3-digit hex colors generated by pygments >= 2.14 -+ markup = re.sub( -+ r'(?<=["\'])#([0-9a-fA-F]{3})(?=["\'])', -+ lambda m: '#' + ''.join(c * 2 for c in m.group(1)), -+ markup -+ ) - markup = re.sub(r"", "", markup) - super().__init__( - markup, +diff --git a/tests/test_code_class.py b/tests/test_code_class.py +new file mode 100644 +index 00000000..f310e667 +--- /dev/null ++++ b/tests/test_code_class.py +@@ -0,0 +1,22 @@ ++import re ++import pytest ++ ++ ++def expand_hex(markup): ++ return re.sub( ++ r'(?<=["\'])#([0-9a-fA-F]{3})(?=["\'])', ++ lambda m: '#' + ''.join(c * 2 for c in m.group(1)), ++ markup ++ ) ++ ++ ++def test_expand_3digit_hex(): ++ assert expand_hex('foreground="#abc"') == 'foreground="#aabbcc"' ++ assert expand_hex('foreground="#fff"') == 'foreground="#ffffff"' ++ assert expand_hex('foreground="#aabbcc"') == 'foreground="#aabbcc"' ++ ++ ++def test_expand_multiple_colors(): ++ markup = 'color="#abc" background="#def"' ++ result = expand_hex(markup) ++ assert result == 'color="#aabbcc" background="#ddeeff"' diff --git a/fix_staticmethod_python310.patch b/fix_staticmethod_python310.patch new file mode 100644 index 0000000000..2602daab66 --- /dev/null +++ b/fix_staticmethod_python310.patch @@ -0,0 +1,12 @@ +diff --git a/manimlib/window.py b/manimlib/window.py +index ad2a92d3..92810994 100644 +--- a/manimlib/window.py ++++ b/manimlib/window.py +@@ -143,7 +143,6 @@ class Window(PygletWindow): + super().swap_buffers() + self._has_undrawn_event = False + +- @staticmethod + def note_undrawn_event(func: Callable[..., T]) -> Callable[..., T]: + @wraps(func) + def wrapper(self, *args, **kwargs): diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000000..8205b1755e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "manim", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} From b9d1175c306848ceb6ce0204c6572db524f50ca9 Mon Sep 17 00:00:00 2001 From: Leonor Pinto <129208585+leonor-p@users.noreply.github.com> Date: Wed, 13 May 2026 21:43:52 +0100 Subject: [PATCH 4/4] Delete fix_staticmethod_python310.patch --- fix_staticmethod_python310.patch | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 fix_staticmethod_python310.patch diff --git a/fix_staticmethod_python310.patch b/fix_staticmethod_python310.patch deleted file mode 100644 index 2602daab66..0000000000 --- a/fix_staticmethod_python310.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/manimlib/window.py b/manimlib/window.py -index ad2a92d3..92810994 100644 ---- a/manimlib/window.py -+++ b/manimlib/window.py -@@ -143,7 +143,6 @@ class Window(PygletWindow): - super().swap_buffers() - self._has_undrawn_event = False - -- @staticmethod - def note_undrawn_event(func: Callable[..., T]) -> Callable[..., T]: - @wraps(func) - def wrapper(self, *args, **kwargs):