Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 119c81b

Browse files
committed
Use iframe to embed notebook
1 parent f4ee922 commit 119c81b

File tree

6 files changed

+55
-23
lines changed

6 files changed

+55
-23
lines changed

‎example/_posts/2017-09-03-blog.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ title: Blog
88
Here is a Jupyter Notebook on Blog:
99

1010
{::nomarkdown}
11-
{% jupyter_notebook blog.ipynb %}
11+
{% jupyter_notebook /notebooks/blog.ipynb %}
1212
{:/nomarkdown}
File renamed without changes.

‎lib/jekyll-jupyter-notebook.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
require "jekyll-jupyter-notebook/version"
1414

1515
require "jekyll-jupyter-notebook/converter"
16+
require "jekyll-jupyter-notebook/generator"
1617
require "jekyll-jupyter-notebook/tag"

‎lib/jekyll-jupyter-notebook/converter.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def matches(ext)
1818
ext == ".ipynb"
1919
end
2020

21-
def output_ext(_ext)
21+
def output_ext(ext)
2222
".html"
2323
end
2424

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
module JekyllJupyterNotebook
14+
module IFramePage
15+
def output_ext
16+
ext + super
17+
end
18+
end
19+
20+
class Generator < Jekyll::Generator
21+
def generate(site)
22+
site.static_files.reject! do |static_file|
23+
if static_file.extname == ".ipynb"
24+
base = static_file.instance_variable_get(:@base)
25+
dir = static_file.instance_variable_get(:@dir)
26+
name = static_file.name
27+
page = Jekyll::Page.new(site, base, dir, name)
28+
page.extend(IFramePage)
29+
site.pages << page
30+
true
31+
else
32+
false
33+
end
34+
end
35+
end
36+
end
37+
end

‎lib/jekyll-jupyter-notebook/tag.rb‎

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,21 @@ def syntax_example
2626
end
2727

2828
def render(context)
29-
dir = context["page"]["dir"] || File.dirname(context["page"]["path"])
30-
notebook_path = File.join(context["site"]["source"],
31-
dir,
32-
@notebook_path)
33-
Dir.mktmpdir do |output|
34-
system("jupyter",
35-
"nbconvert",
36-
"--to", "html",
37-
"--output-dir", output,
38-
notebook_path)
39-
html_path = Dir.glob("#{output}/*.html").first
40-
html = File.read(html_path)
41-
html.sub!(/\A.*?<\/title>/m, "")
42-
html.sub!(/<link.+?href="custom.css">/, "")
43-
html.sub!(/<\/head>/, "")
44-
html.sub!(/<body>/, "")
45-
html.sub!(/<\/body>.*?\z/m, "")
46-
<<-HTML
47-
<div class="jupyter-notebook">#{html}</div>
48-
HTML
49-
end
29+
notebook_html_path = "#{@notebook_path}.html"
30+
<<-HTML
31+
<div
32+
class="jupyter-notebook"
33+
style="position: relative; width: 100%; margin: 0 auto;">
34+
<div class="jupyter-notebook-iframe-container">
35+
<iframe
36+
src="#{CGI.escapeHTML(notebook_html_path)}"
37+
style="position: absolute; top: 0; left: 0; border-style: none;"
38+
width="100%"
39+
height="100%"
40+
onload="this.parentElement.style.paddingBottom = (this.contentWindow.document.documentElement.scrollHeight + 10) + 'px'"></iframe>
41+
</div>
42+
</div>
43+
HTML
5044
end
5145
end
5246
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /