jkitchin / ox-ipynb

org-mode exporter to Jupyter notebooks
175 stars 40 forks source link

Can ox-ipynb recognize jupyter-python src blocks? #19

Closed singletS closed 5 years ago

singletS commented 5 years ago

I've been trying out emacs-jupyter as an alternative to ob-ipython with good results. To export to ipynbs, I currently use a hackish ox-ipynb-preprocess-hook to replace all of the

+BEGIN_SRC jupyter-python

blocks to

+BEGIN_SRC ipython

Is there a simple way to get ox-ipynb to recognize source blocks with 'jupyter-python' as the language? I was thinking that

+OX-IPYNB-LANGUAGE: jupyter-python

should work, but ox-ipynb exports a malformed ipynb with no code blocks.

Minimal example:

#+PROPERTY: header-args:jupyter-python :session jpy
#+PROPERTY: header-args :exports both
* A emacs jupyter cell

#+BEGIN_SRC jupyter-python
print("hello")
#+END_SRC

Thanks

jkitchin commented 5 years ago

This works for me:

#+PROPERTY: header-args:jupyter-python :session jpy
#+PROPERTY: header-args :exports both

* A emacs jupyter cell

#+BEGIN_SRC jupyter-python
print("hello")
#+END_SRC

* setup                                                            :noexport:
#+BEGIN_SRC emacs-lisp
(add-to-list 'ox-ipynb-kernelspecs
         '(jupyter-python . (kernelspec . ((display_name . "Python 3")
                                              (language . "python")
                                              (name . "python3")))))

(add-to-list 'ox-ipynb-language-infos
         '(jupyter-python . (language_info . ((codemirror_mode . ((name . ipython)
                                      (version . 3)))
                          (file_extension . ".py")
                          (mimetype . "text/x-python")
                          (name . "python")
                          (nbconvert_exporter . "python")
                          (pygments_lexer . "ipython3")
                          (version . "3.5.2")))))
#+END_SRC
singletS commented 5 years ago

Thanks for the straightforward solution. Is it worth adding to ox-ipynb?