Skip to content

Commit adfef5e

Browse files
naveen521kkpre-commit-ci[bot]behackl
authored
Add option to run examples directly with binder (#3427)
* Add option to run examples directly with binder The minified JS is from https://github.com/naveen521kk/manim-binder * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * slight style changes * update the js file to fix on chrome Signed-off-by: Naveen M K <[email protected]> * show the run button as an cursor * make the video to be 100% of the width * Update manim/utils/docbuild/manim_directive.py Co-authored-by: Benjamin Hackl <[email protected]> * Add a "Make interactive" button instead of "Run" button Clicking on the "Make interactive" button show the code-editor and "run" button * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update margin for run interactive button --------- Signed-off-by: Naveen M K <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent 20028ce commit adfef5e

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

docs/source/_static/custom.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,22 @@ h4, h5, h6{
8282
.sidebar-tree a.internal.reference {
8383
display: table-cell;
8484
}
85+
86+
.manim-binder-button {
87+
text-transform: capitalize;
88+
padding: 10px 20px;
89+
margin: 10px 0;
90+
}
91+
92+
.manim-binder-wrapper {
93+
background-color: var(--color-code-background);
94+
color: var(--color-code-foreground);
95+
}
96+
97+
.manim-binder-title {
98+
margin-top: 0;
99+
}
100+
101+
.manim-binder-button-wrapper {
102+
margin: 0px 10px;
103+
}

docs/source/_static/manim-binder.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*!
2+
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
3+
*
4+
* Copyright (c) 2014-2017, Jon Schlinkert.
5+
* Released under the MIT License.
6+
*/

docs/source/_static/manim-binder.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@
172172
"penwidth": 1,
173173
}
174174

175-
html_js_files = [
176-
"responsiveSvg.js",
177-
]
175+
html_js_files = ["responsiveSvg.js"]
178176

179177
graphviz_output_format = "svg"

manim/utils/docbuild/manim_directive.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def construct(self):
8585
import re
8686
import shutil
8787
import sys
88+
import textwrap
8889
from pathlib import Path
8990
from timeit import timeit
9091

@@ -94,6 +95,7 @@ def construct(self):
9495
from docutils.statemachine import StringList
9596

9697
from manim import QUALITIES
98+
from manim import __version__ as manim_version
9799

98100
classnamedict = {}
99101

@@ -168,16 +170,25 @@ def run(self):
168170
or self.state.document.settings.env.app.builder.name == "gettext"
169171
)
170172
if should_skip:
173+
clsname = self.arguments[0]
171174
node = SkipManimNode()
172175
self.state.nested_parse(
173176
StringList(
174177
[
175-
f"Placeholder block for ``{self.arguments[0]}``.",
178+
f"Placeholder block for ``{clsname}``.",
176179
"",
177180
".. code-block:: python",
178181
"",
179182
]
180183
+ [" " + line for line in self.content]
184+
+ [
185+
"",
186+
".. raw:: html",
187+
"",
188+
f' <pre data-manim-binder data-manim-classname="{clsname}">',
189+
]
190+
+ [" " + line for line in self.content]
191+
+ [" </pre>"],
181192
),
182193
self.content_offset,
183194
node,
@@ -235,6 +246,13 @@ def run(self):
235246
"",
236247
" from manim import *\n",
237248
*(" " + line for line in self.content),
249+
"",
250+
".. raw:: html",
251+
"",
252+
f' <pre data-manim-binder data-manim-classname="{clsname}">',
253+
*(" " + line for line in self.content),
254+
"",
255+
" </pre>",
238256
]
239257
source_block = "\n".join(source_block)
240258

@@ -380,6 +398,16 @@ def setup(app):
380398
app.connect("builder-inited", _delete_rendering_times)
381399
app.connect("build-finished", _log_rendering_times)
382400

401+
app.add_js_file("manim-binder.min.js")
402+
app.add_js_file(
403+
None,
404+
body=textwrap.dedent(
405+
f"""\
406+
window.initManimBinder({{branch: "v{manim_version}"}})
407+
"""
408+
).strip(),
409+
)
410+
383411
metadata = {"parallel_read_safe": False, "parallel_write_safe": True}
384412
return metadata
385413

0 commit comments

Comments
 (0)