You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Kouhei Sutou (JIRA)" <ji...@apache.org> on 2017/04/26 14:51:04 UTC
[jira] [Commented] (ARROW-896) [Docs] Add Jekyll plugin for
including rendered Jupyter notebooks on website
[ https://issues.apache.org/jira/browse/ARROW-896?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15984943#comment-15984943 ]
Kouhei Sutou commented on ARROW-896:
------------------------------------
Yes. I can write a Jekyll liquid tag plugin. Here is a simple implementation:
{noformat}
diff --git a/site/_plugins/notebook.rb b/site/_plugins/notebook.rb
new file mode 100644
index 0000000..4e6e22b
--- /dev/null
+++ b/site/_plugins/notebook.rb
@@ -0,0 +1,34 @@
+require "tmpdir"
+
+class JekyllNotebookTag < Liquid::Tag
+ def initialize(tag_name, markup, tokens)
+ super
+ @notebook_path = markup.strip
+ end
+
+ def syntax_example
+ "{% #{@tag_name} filename.ipynb %}"
+ end
+
+ def render(context)
+ Dir.mktmpdir do |output|
+ system("jupyter",
+ "nbconvert",
+ "--to", "html",
+ "--output-dir", output,
+ @notebook_path)
+ html_path = Dir.glob("#{output}/*.html").first
+ html = File.read(html_path)
+ html.gsub!(/\A.*?<\/title>/m, "")
+ html.gsub!(/<link.+?href="custom.css">/, "")
+ html.gsub!(/<\/head>/, "")
+ html.gsub!(/<body>/, "")
+ html.gsub!(/<\/body>.*\z/m, "")
+ <<-HTML
+<div class="notebook">#{html}</div>
+ HTML
+ end
+ end
+end
+
+Liquid::Template.register_tag("notebook", JekyllNotebookTag)
{noformat}
It works for https://github.com/jupyter/nbconvert/blob/master/docs/source/example.ipynb .
If you need to support more complex notebook and you can provide notebook files that you want to show, I may be able to improve the implementation.
> [Docs] Add Jekyll plugin for including rendered Jupyter notebooks on website
> ----------------------------------------------------------------------------
>
> Key: ARROW-896
> URL: https://issues.apache.org/jira/browse/ARROW-896
> Project: Apache Arrow
> Issue Type: Improvement
> Components: Documentation
> Reporter: Wes McKinney
>
> This would help with writing blog posts and other documentation about Arrow.
> [~kou] do you have any experience writing Jekyll liquid tag plugins in Ruby? Under the hood, we would convert .ipynb to Markdown using https://github.com/jupyter/nbconvert. We would need to add some notebook-related CSS to make the output look nice.
> Here is a Jekyll-like plugin that does this for the Pelican platform: https://github.com/getpelican/pelican-plugins/blob/master/liquid_tags/notebook.py
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)