jkitchin / ox-ipynb

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

[enhancement] `ox-ipynb-get-language` should warn when language is not in `ox-ipynb-kernelspecs` #47

Open ed9w2in6 opened 1 year ago

ed9w2in6 commented 1 year ago

I have met the issue #42 and I think ox-ipynb-get-language should at least warn when the result does not match any of ox-ipynb-kernelspecs such that the user will know what is wrong.

This is because it is not immediately clear whether the issue on jupyter, the org file, or ox-ipynb.

Something like this:

(defun ox-ipynb-get-language ()
  (let ((lang
         (intern
          (or (cdr
               (assoc
                "OX-IPYNB-LANGUAGE"
                (org-element-map
                 (org-element-parse-buffer) 'keyword
                 (lambda (key)
                   (cons
                    (org-element-property :key key)
                    (org-element-property :value key))))))
              (org-element-map
               (org-element-parse-buffer) 'src-block
               (lambda (src)
                 (unless (string=
                          "none"
                          (cdr
                           (assq
                            :exports
                            (org-babel-parse-header-arguments
                             (org-element-property
                              :parameters src)))))
                   (org-element-property :language src)))
               nil t)
              "ipython"))))

    (progn
      (unless (member lang (mapcar #'car ox-ipynb-kernelspecs))
        (display-warning
         'ox-ipynb
         (format "Language \"%s\" not defined in ox-ipynb-kernelspecs."
                 lang)
         :warning))
      lang)))

Or maybe it should fail.

This should be clearer that the problem is on the config of ox-ipynb, thus reducing the amount of time needed to debug and search online until they found issue #42.

ed9w2in6 commented 1 year ago

I can submit a pull request if there is no need for automated testing.

jkitchin commented 1 year ago

I will be traveling for the next week. I would consider a pull request for this, or I can work on adding it when I get back in July.