Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix Code mobject wrong indentation (#2725)

nyabkun1bffb1d7a7cf
diff --git a/manim/mobject/text/code_mobject.py b/manim/mobject/text/code_mobject.py
index 5a710396f..e39cecadb 100644
--- a/manim/mobject/text/code_mobject.py
+++ b/manim/mobject/text/code_mobject.py
@@ -404,6 +404,11 @@ class Code(VGroup):
# print(self.default_color,self.background_color)
for i in range(3, -1, -1):
self.html_string = self.html_string.replace("</" + " " * i, "</")
+
+ # handle pygments bug
+ # https://github.com/pygments/pygments/issues/961
+ self.html_string = self.html_string.replace("<span></span>", "")
+
for i in range(10, -1, -1):
self.html_string = self.html_string.replace(
"</span>" + " " * i,
diff --git a/tests/test_code_mobject.py b/tests/test_code_mobject.py
new file mode 100644
index 000000000..b4b522a10
--- /dev/null
+++ b/tests/test_code_mobject.py
@@ -0,0 +1,15 @@
+from manim.mobject.text.code_mobject import Code
+
+
+def test_code_indentation():
+ co = Code(
+ code="""\
+ def test()
+ print("Hi")
+ """,
+ language="Python",
+ indentation_chars=" ",
+ )
+
+ assert co.tab_spaces[0] == 1
+ assert co.tab_spaces[1] == 2