Skip to content

Commit 1bffb1d

Browse files
authored
Fix Code mobject wrong indentation (#2725)
1 parent bd631f7 commit 1bffb1d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

manim/mobject/text/code_mobject.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ def _gen_code_json(self):
404404
# print(self.default_color,self.background_color)
405405
for i in range(3, -1, -1):
406406
self.html_string = self.html_string.replace("</" + " " * i, "</")
407+
408+
# handle pygments bug
409+
# https://github.com/pygments/pygments/issues/961
410+
self.html_string = self.html_string.replace("<span></span>", "")
411+
407412
for i in range(10, -1, -1):
408413
self.html_string = self.html_string.replace(
409414
"</span>" + " " * i,

tests/test_code_mobject.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from manim.mobject.text.code_mobject import Code
2+
3+
4+
def test_code_indentation():
5+
co = Code(
6+
code="""\
7+
def test()
8+
print("Hi")
9+
""",
10+
language="Python",
11+
indentation_chars=" ",
12+
)
13+
14+
assert co.tab_spaces[0] == 1
15+
assert co.tab_spaces[1] == 2

0 commit comments

Comments
 (0)