Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to run examples directly with binder #3427

Merged
merged 12 commits into from
Nov 10, 2023
Merged
19 changes: 19 additions & 0 deletions docs/source/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,22 @@ h4, h5, h6{
.sidebar-tree a.internal.reference {
display: table-cell;
}

.manim-binder-button {
text-transform: capitalize;
padding: 10px 20px;
margin: 10px 0;
}

.manim-binder-wrapper {
background-color: var(--color-code-background);
color: var(--color-code-foreground);
}

.manim-binder-title {
margin-top: 0;
}

.manim-binder-button-wrapper {
margin: 0px 10px;
}
3 changes: 3 additions & 0 deletions docs/source/_static/manim-binder.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions docs/source/_static/manim-binder.min.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
1 change: 1 addition & 0 deletions docs/source/_static/manim-binder.min.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@
"penwidth": 1,
}

html_js_files = [
"responsiveSvg.js",
]
html_js_files = ["responsiveSvg.js"]

graphviz_output_format = "svg"
30 changes: 29 additions & 1 deletion manim/utils/docbuild/manim_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def construct(self):
import re
import shutil
import sys
import textwrap
from pathlib import Path
from timeit import timeit

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

from manim import QUALITIES
from manim import __version__ as manim_version

classnamedict = {}

Expand Down Expand Up @@ -168,16 +170,25 @@ def run(self):
or self.state.document.settings.env.app.builder.name == "gettext"
)
if should_skip:
clsname = self.arguments[0]
node = SkipManimNode()
self.state.nested_parse(
StringList(
[
f"Placeholder block for ``{self.arguments[0]}``.",
f"Placeholder block for ``{clsname}``.",
"",
".. code-block:: python",
"",
]
+ [" " + line for line in self.content]
+ [
"",
".. raw:: html",
"",
f' <pre data-manim-binder data-manim-classname="{clsname}">',
]
+ [" " + line for line in self.content]
+ [" </pre>"],
),
self.content_offset,
node,
Expand Down Expand Up @@ -235,6 +246,13 @@ def run(self):
"",
" from manim import *\n",
*(" " + line for line in self.content),
"",
".. raw:: html",
"",
f' <pre data-manim-binder data-manim-classname="{clsname}">',
*(" " + line for line in self.content),
"",
" </pre>",
]
source_block = "\n".join(source_block)

Expand Down Expand Up @@ -380,6 +398,16 @@ def setup(app):
app.connect("builder-inited", _delete_rendering_times)
app.connect("build-finished", _log_rendering_times)

app.add_js_file("manim-binder.min.js")
app.add_js_file(
None,
body=textwrap.dedent(
f"""\
window.initManimBinder({{branch: "v{manim_version}"}})
"""
).strip(),
)

metadata = {"parallel_read_safe": False, "parallel_write_safe": True}
return metadata

Expand Down
Loading