Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions fix_code_class_pygments_hex.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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"'
6 changes: 6 additions & 0 deletions manimlib/mobject/svg/text_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"</?tt>", "", markup)
super().__init__(
markup,
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test_code_fix.py
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 22 additions & 0 deletions tests/test_code_class.py
Original file line number Diff line number Diff line change
@@ -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"'