Skip to content

Commit da78c8c

Browse files
committed
jupyter-org-result: Refactor
1 parent 24fa006 commit da78c8c

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

jupyter-org-client.el

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -936,14 +936,13 @@ will be inserted by calling `org-element-interpret-data' first.
936936
The returned result should be a representation of a MIME type's
937937
CONTENT. CONTENT is a property list like
938938
939-
'(:data ... :metadata ...)
939+
'(:data DATA :metadata METADATA)
940940
941-
that contains the data/metadata of the mime type.
941+
that contains the DATA/METADATA of the mime type. As an example,
942+
if MIME is `:text/markdown', then DATA should be the markdown
943+
string. The returned result in this case will be
942944
943-
As an example, if DATA only contains the mimetype
944-
`:text/markdown', then the returned results is
945-
946-
(jupyter-org-export-block \"markdown\" data)"
945+
(jupyter-org-export-block \"markdown\" DATA)"
947946
(ignore))
948947

949948
(defun jupyter-org--find-mime-types (req-types)
@@ -993,27 +992,28 @@ If the source block parameters have a value for the :display
993992
header argument, like \"image/png html plain\", then loop over
994993
those mime types instead."
995994
(cl-assert plist json-plist)
996-
(org-with-point-at (jupyter-org-request-marker req)
997-
(let* ((params (jupyter-org-request-block-params req))
998-
(display-mime-types (jupyter-org--find-mime-types
999-
(alist-get :display params))))
1000-
;; Push :file back into PARAMS if it was present in
1001-
;; `org-babel-execute:jupyter'. That function removes it because
1002-
;; we don't want `org-babel-insert-result' to handle it.
1003-
(when (jupyter-org-request-file req)
1004-
(push (cons :file (jupyter-org-request-file req)) params))
1005-
(cond
1006-
((jupyter-map-mime-bundle (or display-mime-types jupyter-org-mime-types)
1007-
(jupyter-normalize-data plist metadata)
1008-
(lambda (mime content)
1009-
(jupyter-org-result mime content params))))
1010-
(t
995+
(let* ((params (jupyter-org-request-block-params req))
996+
(display (alist-get :display params))
997+
(mime-types (or (jupyter-org--find-mime-types display)
998+
jupyter-org-mime-types)))
999+
;; Push :file back into PARAMS if it was present in
1000+
;; `org-babel-execute:jupyter'. That function removes it because
1001+
;; we don't want `org-babel-insert-result' to handle it.
1002+
(when (jupyter-org-request-file req)
1003+
(push (cons :file (jupyter-org-request-file req)) params))
1004+
(or (org-with-point-at
1005+
(jupyter-org-request-marker req)
1006+
(jupyter-map-mime-bundle mime-types
1007+
(jupyter-normalize-data plist metadata)
1008+
(lambda (mime content)
1009+
(jupyter-org-result mime content params))))
10111010
(let ((warning
10121011
(format
10131012
"%s did not return requested mimetype(s): %s"
10141013
(jupyter-message-type (jupyter-request-last-message req))
1015-
(or display-mime-types jupyter-org-mime-types))))
1016-
(display-warning 'jupyter warning)))))))
1014+
mime-types)))
1015+
(display-warning 'jupyter warning)
1016+
nil))))
10171017

10181018
(cl-defmethod jupyter-org-result ((_mime (eql :application/vnd.jupyter.widget-view+json)) _content _params)
10191019
;; TODO: Clickable text to open up a browser

0 commit comments

Comments
 (0)