├── LICENSE ├── .gitignore ├── NOTICE.txt ├── .yardopts ├── example ├── _members │ ├── alice.md │ └── python-alice.ipynb ├── ruby │ ├── index.md │ └── ruby.ipynb ├── _posts │ └── 2017-09-03-blog.md ├── _layouts │ └── default.html ├── index.md ├── Gemfile ├── _config.yml ├── python.ipynb ├── notebooks │ └── blog.ipynb └── python-raw.ipynb ├── Gemfile ├── lib ├── jekyll-jupyter-notebook │ ├── version.rb │ ├── tag.rb │ ├── generator.rb │ └── converter.rb └── jekyll-jupyter-notebook.rb ├── .github ├── dependabot.yml └── workflows │ └── release.yml ├── docs ├── 2017 │ └── 09 │ │ └── 03 │ │ └── blog.html ├── members │ └── alice.html ├── ruby │ └── index.html └── index.html ├── Rakefile ├── doc └── text │ ├── news.md │ └── apache-2.0.txt ├── jekyll-jupyter-notebook.gemspec └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | doc/text/apache-2.0.txt -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | /pkg/ 3 | /example/_site/ 4 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Jekyll Jupyter Notebook plugin 2 | Copyright 2017 Kouhei Sutou 3 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --output-dir doc/reference/en 2 | --markup markdown 3 | --markup-provider kramdown 4 | lib/**/*.rb 5 | - 6 | doc/text/**/* 7 | -------------------------------------------------------------------------------- /example/_members/alice.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | name: alice 4 | title: Alice 5 | --- 6 | 7 | ## Title 8 | 9 | {% jupyter_notebook "python-alice.ipynb" %} 10 | -------------------------------------------------------------------------------- /example/ruby/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Ruby 4 | --- 5 | 6 | ## IRuby kernel 7 | 8 | Here is a Jupyter Notebook with IRuby kernel: 9 | 10 | {::nomarkdown} 11 | {% jupyter_notebook "ruby.ipynb" %} 12 | {:/nomarkdown} 13 | -------------------------------------------------------------------------------- /example/_posts/2017-09-03-blog.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Blog title 4 | --- 5 | 6 | ## Blog title 7 | 8 | Here is a Jupyter Notebook on Blog using a string literal: 9 | 10 | {::nomarkdown} 11 | {% jupyter_notebook "/notebooks/blog.ipynb" %} 12 | {:/nomarkdown} 13 | 14 | Here is the same Jupyter Notebook on Blog using a variable: 15 | 16 | {::nomarkdown} 17 | {% assign notebook_path = "/notebooks/blog.ipynb" %} 18 | {% jupyter_notebook notebook_path %} 19 | {:/nomarkdown} 20 | -------------------------------------------------------------------------------- /example/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Jekyll Jupyter Notebook plugin example - {{ page.title }} 7 | 8 | 9 |
10 |

11 | Jekyll Jupyter Notebook plugin example 12 |

13 |
14 | {{ content }} 15 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /example/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Top 4 | --- 5 | 6 | ## Top page 7 | 8 | Here is a Jupyter Notebook: 9 | 10 | {% jupyter_notebook "python.ipynb" %} 11 | 12 | ### Raw rendered pages 13 | 14 | * [Raw IPython kernel](python-raw.html) 15 | 16 | ### Other kernels 17 | 18 | * [IRuby kernel](ruby/) 19 | 20 | ### Blog posts 21 | 22 | {% for post in site.posts %} 23 | * [{{ post.title }} ({{ post.date | date: "%Y-%m-%d" }})]({{ post.url }}) 24 | {% endfor %} 25 | 26 | ### Collection: members 27 | 28 | * [Alice]({% link _members/alice.md %}) 29 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | source "https://rubygems.org/" 16 | 17 | gemspec 18 | -------------------------------------------------------------------------------- /lib/jekyll-jupyter-notebook/version.rb: -------------------------------------------------------------------------------- 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 | VERSION = "0.0.7" 15 | end 16 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 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 | version: 2 14 | updates: 15 | - package-ecosystem: "github-actions" 16 | directory: "/" 17 | schedule: 18 | interval: "daily" 19 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | source "https://rubygems.org/" 16 | 17 | gem "base64" 18 | gem "bigdecimal" 19 | gem "csv" 20 | gem "jekyll" 21 | gem "jekyll-jupyter-notebook", path: ".." 22 | gem "webrick" 23 | -------------------------------------------------------------------------------- /lib/jekyll-jupyter-notebook.rb: -------------------------------------------------------------------------------- 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 | require "jekyll-jupyter-notebook/version" 14 | 15 | require "jekyll-jupyter-notebook/converter" 16 | require "jekyll-jupyter-notebook/generator" 17 | require "jekyll-jupyter-notebook/tag" 18 | -------------------------------------------------------------------------------- /example/_config.yml: -------------------------------------------------------------------------------- 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 | markdown: kramdown 14 | exclude: 15 | - "Gemfile" 16 | - "Gemfile.lock" 17 | plugins: 18 | - jekyll-jupyter-notebook 19 | collections: 20 | members: 21 | output: true 22 | permalink: /members/:path:output_ext 23 | -------------------------------------------------------------------------------- /docs/members/alice.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Jekyll Jupyter Notebook plugin example - Alice 7 | 8 | 9 |
10 |

11 | Jekyll Jupyter Notebook plugin example 12 |

13 |
14 |

Title

15 | 16 |
17 |
18 | 19 |
20 |
21 | 22 | 23 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ruby/ruby.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "\"2.3.3\"" 14 | ] 15 | }, 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "RUBY_VERSION" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": { 29 | "collapsed": true 30 | }, 31 | "outputs": [], 32 | "source": [] 33 | } 34 | ], 35 | "metadata": { 36 | "kernelspec": { 37 | "display_name": "Ruby 2.3.3", 38 | "language": "ruby", 39 | "name": "ruby" 40 | }, 41 | "language_info": { 42 | "file_extension": ".rb", 43 | "mimetype": "application/x-ruby", 44 | "name": "ruby", 45 | "version": "2.3.3" 46 | } 47 | }, 48 | "nbformat": 4, 49 | "nbformat_minor": 2 50 | } 51 | -------------------------------------------------------------------------------- /example/python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)" 14 | ] 15 | }, 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "import sys\n", 23 | "sys.version_info" 24 | ] 25 | } 26 | ], 27 | "metadata": { 28 | "kernelspec": { 29 | "display_name": "Python 3", 30 | "language": "python", 31 | "name": "python3" 32 | }, 33 | "language_info": { 34 | "codemirror_mode": { 35 | "name": "ipython", 36 | "version": 3 37 | }, 38 | "file_extension": ".py", 39 | "mimetype": "text/x-python", 40 | "name": "python", 41 | "nbconvert_exporter": "python", 42 | "pygments_lexer": "ipython3", 43 | "version": "3.5.2" 44 | } 45 | }, 46 | "nbformat": 4, 47 | "nbformat_minor": 2 48 | } 49 | -------------------------------------------------------------------------------- /example/notebooks/blog.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "sys.version_info(major=3, minor=6, micro=2, releaselevel='final', serial=0)" 14 | ] 15 | }, 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "import sys\n", 23 | "sys.version_info" 24 | ] 25 | } 26 | ], 27 | "metadata": { 28 | "kernelspec": { 29 | "display_name": "Python 3", 30 | "language": "python", 31 | "name": "python3" 32 | }, 33 | "language_info": { 34 | "codemirror_mode": { 35 | "name": "ipython", 36 | "version": 3 37 | }, 38 | "file_extension": ".py", 39 | "mimetype": "text/x-python", 40 | "name": "python", 41 | "nbconvert_exporter": "python", 42 | "pygments_lexer": "ipython3", 43 | "version": "3.6.2" 44 | } 45 | }, 46 | "nbformat": 4, 47 | "nbformat_minor": 2 48 | } 49 | -------------------------------------------------------------------------------- /docs/ruby/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Jekyll Jupyter Notebook plugin example - Ruby 7 | 8 | 9 |
10 |

11 | Jekyll Jupyter Notebook plugin example 12 |

13 |
14 |

IRuby kernel

15 | 16 |

Here is a Jupyter Notebook with IRuby kernel:

17 | 18 |
21 |
22 | 28 |
29 |
30 | 31 | 32 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /example/_members/python-alice.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)" 14 | ] 15 | }, 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "import sys\n", 23 | "sys.version_info" 24 | ] 25 | } 26 | ], 27 | "metadata": { 28 | "kernelspec": { 29 | "display_name": "Python 3", 30 | "language": "python", 31 | "name": "python3" 32 | }, 33 | "language_info": { 34 | "codemirror_mode": { 35 | "name": "ipython", 36 | "version": 3 37 | }, 38 | "file_extension": ".py", 39 | "mimetype": "text/x-python", 40 | "name": "python", 41 | "nbconvert_exporter": "python", 42 | "pygments_lexer": "ipython3", 43 | "version": "3.5.2" 44 | } 45 | }, 46 | "nbformat": 4, 47 | "nbformat_minor": 2 48 | } 49 | -------------------------------------------------------------------------------- /example/python-raw.ipynb: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | {% raw %} 4 | { 5 | "cells": [ 6 | { 7 | "cell_type": "code", 8 | "execution_count": 1, 9 | "metadata": { 10 | "collapsed": false 11 | }, 12 | "outputs": [ 13 | { 14 | "data": { 15 | "text/plain": [ 16 | "sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)" 17 | ] 18 | }, 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "output_type": "execute_result" 22 | } 23 | ], 24 | "source": [ 25 | "import sys\n", 26 | "sys.version_info" 27 | ] 28 | } 29 | ], 30 | "metadata": { 31 | "kernelspec": { 32 | "display_name": "Python 3", 33 | "language": "python", 34 | "name": "python3" 35 | }, 36 | "language_info": { 37 | "codemirror_mode": { 38 | "name": "ipython", 39 | "version": 3 40 | }, 41 | "file_extension": ".py", 42 | "mimetype": "text/x-python", 43 | "name": "python", 44 | "nbconvert_exporter": "python", 45 | "pygments_lexer": "ipython3", 46 | "version": "3.5.2" 47 | } 48 | }, 49 | "nbformat": 4, 50 | "nbformat_minor": 2 51 | } 52 | {% endraw %} 53 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | require "bundler/gem_helper" 16 | 17 | base_dir = File.join(File.dirname(__FILE__)) 18 | 19 | helper = Bundler::GemHelper.new(base_dir) 20 | def helper.version_tag 21 | version 22 | end 23 | 24 | helper.install 25 | spec = helper.gemspec 26 | 27 | # desc "Run tests" 28 | # task :test do 29 | # ruby("test/run-test.rb") 30 | # end 31 | 32 | # task default: :test 33 | 34 | desc "Update site" 35 | task :site do 36 | rm_rf("docs") 37 | cd("example") do 38 | sh("bundle", "exec", "jekyll", "build", "--destination", "../docs") 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Jekyll Jupyter Notebook plugin example - Top 7 | 8 | 9 |
10 |

11 | Jekyll Jupyter Notebook plugin example 12 |

13 |
14 |

Top page

15 | 16 |

Here is a Jupyter Notebook:

17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 |

Raw rendered pages

25 | 26 | 29 | 30 |

Other kernels

31 | 32 | 35 | 36 |

Blog posts

37 | 38 | 41 | 42 |

Collection: members

43 | 44 | 47 | 48 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /doc/text/news.md: -------------------------------------------------------------------------------- 1 | # News 2 | 3 | ## 0.0.6 - 2024-04-08 4 | 5 | ### Improvements 6 | 7 | * Added `prompt` option that controls whether `In [N]`/`Out[N]` prompts are shown or not. 8 | * GH-9 9 | * Reported by Julian Hatzky 10 | 11 | ### Thanks 12 | 13 | * Julian Hatzky 14 | 15 | ## 0.0.5 - 2022-08-20 16 | 17 | ### Improvements 18 | 19 | * Added support for collection. 20 | [GitHub#8][Reported by Jeremy Lloyd Conlin] 21 | 22 | ### Thanks 23 | 24 | * Jeremy Lloyd Conlin 25 | 26 | ## 0.0.4 - 2018-08-08 27 | 28 | ### Improvements 29 | 30 | * Added support for variable for notebook path. Now, notebook path 31 | must be string literal such as `"sample.ipynb"` not 32 | `sample.ipynb`. `sample.ipynb` is still supported for backward 33 | compatibility but it's obsoleted. 34 | [GitHub#7][Patch by Josh Hills] 35 | 36 | ### Thanks 37 | 38 | * Josh Hills 39 | 40 | ## 0.0.3 - 2018-03-31 41 | 42 | ### Improvements 43 | 44 | * Improved install document. 45 | [GitHub#5][Patch by Jake VanCampen] 46 | 47 | * Changed to use `iframe` instead of embedding `nbconvert`-ed HTML directory. 48 | It required JavaScript. 49 | 50 | ### Thanks 51 | 52 | * Jake VanCampen 53 | 54 | ## 0.0.2 - 2017-09-03 55 | 56 | ### Improvements 57 | 58 | * Disabled unused `test` task. [GitHub#2][Reported by Yang Bo] 59 | 60 | * Added `_posts/` support. 61 | [GitHub#3][Reported by Diego Ferigo][Reported by Li-Pin Juan] 62 | 63 | ### Thanks 64 | 65 | * Yang Bo 66 | 67 | * Diego Ferigo 68 | 69 | * Li-Pin Juan 70 | 71 | ## 0.0.1 - 2017-04-28 72 | 73 | Initial release!!! 74 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 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 | name: Release 14 | on: 15 | push: 16 | tags: 17 | - "*" 18 | jobs: 19 | github: 20 | name: GitHub 21 | runs-on: ubuntu-latest 22 | timeout-minutes: 10 23 | steps: 24 | - uses: actions/checkout@v6 25 | - name: Extract release note 26 | run: | 27 | ruby \ 28 | -e 'print("## Jekyll Jupyter Notebook "); \ 29 | puts(ARGF.read.split(/^## /)[1]. \ 30 | gsub(/ {.+?}/, ""). \ 31 | gsub(/\[(.+?)\]\[.+?\]/) {$1})' \ 32 | doc/text/news.md > release-note.md 33 | - name: Upload to release 34 | run: | 35 | title=$(head -n1 release-note.md | sed -e 's/^## //') 36 | tail -n +2 release-note.md > release-note-without-version.md 37 | gh release create ${GITHUB_REF_NAME} \ 38 | --discussion-category Announcements \ 39 | --notes-file release-note-without-version.md \ 40 | --title "${title}" 41 | env: 42 | GH_TOKEN: ${{ github.token }} 43 | -------------------------------------------------------------------------------- /docs/2017/09/03/blog.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Jekyll Jupyter Notebook plugin example - Blog title 7 | 8 | 9 |
10 |

11 | Jekyll Jupyter Notebook plugin example 12 |

13 |
14 |

Blog title

15 | 16 |

Here is a Jupyter Notebook on Blog using a string literal:

17 | 18 |
21 |
22 | 28 |
29 |
30 | 31 | 32 |

Here is the same Jupyter Notebook on Blog using a variable:

33 | 34 | 35 |
38 |
39 | 45 |
46 |
47 | 48 | 49 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /jekyll-jupyter-notebook.gemspec: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | clean_white_space = lambda do |entry| 16 | entry.gsub(/(\A\n+|\n+\z)/, '') + "\n" 17 | end 18 | 19 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib")) 20 | require "jekyll-jupyter-notebook/version" 21 | 22 | Gem::Specification.new do |spec| 23 | spec.name = "jekyll-jupyter-notebook" 24 | spec.version = JekyllJupyterNotebook::VERSION 25 | spec.homepage = "https://github.com/red-data-tools/jekyll-jupyter-notebook" 26 | spec.authors = ["Kouhei Sutou"] 27 | spec.email = ["kou@clear-code.com"] 28 | 29 | readme = File.read("README.md") 30 | readme.force_encoding("UTF-8") 31 | entries = readme.split(/^\#\#\s(.*)$/) 32 | clean_white_space.call(entries[entries.index("Description") + 1]) 33 | description = clean_white_space.call(entries[entries.index("Description") + 1]) 34 | spec.summary, spec.description, = description.split(/\n\n+/, 3) 35 | spec.license = "Apache-2.0" 36 | spec.files = ["README.md", "Rakefile", "Gemfile", "#{spec.name}.gemspec"] 37 | spec.files += [".yardopts"] 38 | spec.files += Dir.glob("lib/**/*.rb") 39 | spec.files += Dir.glob("doc/text/*") 40 | spec.test_files += Dir.glob("test/**/*") 41 | 42 | spec.add_runtime_dependency("jekyll") 43 | 44 | spec.add_development_dependency("bundler") 45 | spec.add_development_dependency("rake") 46 | spec.add_development_dependency("kramdown") 47 | end 48 | -------------------------------------------------------------------------------- /lib/jekyll-jupyter-notebook/tag.rb: -------------------------------------------------------------------------------- 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 | require "tmpdir" 14 | 15 | module JekyllJupyterNotebook 16 | class Tag < Liquid::Tag 17 | Liquid::Template.register_tag("jupyter_notebook", self) 18 | 19 | def initialize(tag_name, markup, parse_context) 20 | super 21 | end 22 | 23 | def syntax_example 24 | "{% #{@tag_name} \"filename.ipynb\" %}" 25 | end 26 | 27 | def render(context) 28 | variable = Liquid::Variable.new(@markup, @parse_context) 29 | notebook_path = variable.render(context) 30 | if notebook_path.nil? 31 | Jekyll.logger.warn("Warning:", 32 | "Jupyter Notebook path be string literal: " + 33 | "<#{@markup.strip.inspect}>") 34 | notebook_path = @markup.strip # For backward compatibility 35 | end 36 | notebook_html_path = "#{notebook_path}.html" 37 | <<-HTML 38 |
41 |
42 | 48 |
49 |
50 | HTML 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/jekyll-jupyter-notebook/generator.rb: -------------------------------------------------------------------------------- 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 IFramable 15 | def output_ext 16 | extname + super 17 | end 18 | end 19 | 20 | class Generator < Jekyll::Generator 21 | def generate(site) 22 | generate_site_static_files(site) 23 | site.collections.each_value do |collection| 24 | generate_collection_filtered_entries(collection) 25 | end 26 | end 27 | 28 | private 29 | def generate_site_static_files(site) 30 | site.static_files.reject! do |static_file| 31 | next false unless static_file.extname == ".ipynb" 32 | 33 | base = static_file.instance_variable_get(:@base) 34 | dir = static_file.instance_variable_get(:@dir) 35 | name = static_file.name 36 | page = Jekyll::Page.new(site, base, dir, name) 37 | page.extend(IFramable) 38 | site.pages << page 39 | true 40 | end 41 | end 42 | 43 | def generate_collection_filtered_entries(collection) 44 | collection.filtered_entries.reject! do |file_path| 45 | full_path = collection.collection_dir(file_path) 46 | next false unless File.extname(file_path) == ".ipynb" 47 | next false if Jekyll::Utils.has_yaml_header?(full_path) 48 | 49 | document = Jekyll::Document.new(full_path, 50 | site: collection.site, 51 | collection: collection) 52 | document.extend(IFramable) 53 | document.read 54 | collection.docs << document 55 | true 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /lib/jekyll-jupyter-notebook/converter.rb: -------------------------------------------------------------------------------- 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 | require "tempfile" 14 | 15 | module JekyllJupyterNotebook 16 | class Converter < Jekyll::Converter 17 | def matches(ext) 18 | ext == ".ipynb" 19 | end 20 | 21 | def output_ext(ext) 22 | ".html" 23 | end 24 | 25 | def convert(content) 26 | config = @config["jupyter_notebook"] || {} 27 | 28 | html = convert_notebook(content, config) 29 | html.sub!(//, "") 30 | case config["content"] || "html" 31 | when "html" 32 | when "body" 33 | html.sub!(/\A.*?<\/title>/m, "") 34 | html.sub!(/<\/head>/, "") 35 | html.sub!(//, "") 36 | html.sub!(/<\/body>.*?\z/m, "") 37 | when "body-without-style" 38 | html.sub!(/\A.*?/m, "") 39 | html.sub!(/<\/body>.*?\z/m, "") 40 | end 41 | html 42 | end 43 | 44 | private 45 | def convert_notebook(content, config) 46 | notebook = Tempfile.new(["jekyll-jupyter-notebook", ".ipynb"]) 47 | notebook.print(content) 48 | notebook.close 49 | IO.pipe do |input, output| 50 | command_line = [ 51 | "jupyter", 52 | "nbconvert", 53 | "--to", "html", 54 | "--stdout", 55 | ] 56 | command_line << "--no-input" unless config.fetch("input", true) 57 | command_line << "--no-prompt" unless config.fetch("prompt", true) 58 | command_line << notebook.path 59 | pid = spawn(*command_line, out: output) 60 | begin 61 | output.close 62 | html = nil 63 | read_thread = Thread.new do 64 | html = input.read 65 | end 66 | read_thread.join 67 | html 68 | ensure 69 | Process.waitpid(pid) 70 | end 71 | end 72 | end 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | ## Name 4 | 5 | Jekyll Jupyter Notebook plugin 6 | 7 | ## Description 8 | 9 | Jekyll Jupyter Notebook plugin adds [Jupyter](http://jupyter.org/) Notebook support to Jekyll. You can embed Jupyter Notebooks into your texts. 10 | 11 | ## Install 12 | 13 | Add the following line to your site's `Gemfile`: 14 | 15 | ```ruby 16 | gem "jekyll-jupyter-notebook" 17 | ``` 18 | 19 | Run the following command line to make the gem available: 20 | 21 | ```console 22 | % bundle install 23 | ``` 24 | 25 | Add the following line to your site's `_config.yml`: 26 | 27 | ```yaml 28 | plugins: 29 | - jekyll-jupyter-notebook 30 | ``` 31 | 32 | ## Usage 33 | 34 | Put a Jupyter Notebook (`sample.ipynb`) to the directory that has the target text (`my-text.md`) like the following: 35 | 36 | ```text 37 | . 38 | |-- my-text.md 39 | `-- sample.ipynb 40 | ``` 41 | 42 | Put the following tag into the target text: 43 | 44 | ```markdown 45 | {% jupyter_notebook "sample.ipynb" %} 46 | ``` 47 | 48 | If you use kramdown as Markdown parser and get strange result, try to surround `{% jupyter_notebook ...%}` with `{::nomarkdown}` and `{:/nomarkdown}` like the following: 49 | 50 | ```markdown 51 | {::nomarkdown} 52 | {% jupyter_notebook "sample.ipynb" %} 53 | {:/nomarkdown} 54 | ``` 55 | 56 | ## Configurations 57 | 58 | You can customize `.ipynb` to `.html` conversion by `jupyter_notebook` in `_config.yml`: 59 | 60 | ```yaml 61 | jupyter_notebook: 62 | # ... 63 | ``` 64 | 65 | ### `prompt` 66 | 67 | You can control whether a converted `.html` includes `In [N]`/`Out[N]` prompts or not by `prompt`: 68 | 69 | ```yaml 70 | jupyter_notebook: 71 | prompt: true 72 | ``` 73 | 74 | The default value is `true`. It means that `In [N]`/`Out[N]` are shown. 75 | 76 | You can remove them by using `false`: 77 | 78 | ```yaml 79 | jupyter_notebook: 80 | prompt: false 81 | ``` 82 | 83 | ### `input` 84 | 85 | Similar to how `prompt` works, you can also control whether a converted `.html` includes code inputs or not by using `input`: 86 | 87 | ```yaml 88 | jupyter_notebook: 89 | input: true 90 | ``` 91 | 92 | The default value is `true`. It means that input code blocks are shown. 93 | 94 | You can remove them by using `false`: 95 | 96 | ```yaml 97 | jupyter_notebook: 98 | input: false 99 | ``` 100 | 101 | ## Authors 102 | 103 | * Kouhei Sutou \ 104 | 105 | ## License 106 | 107 | Apache License 2.0. See doc/text/apache-2.0.txt and NOTICE.txt for details. 108 | 109 | (Kouhei Sutou has a right to change the license including contributed patches.) 110 | -------------------------------------------------------------------------------- /doc/text/apache-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------