-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathob-wsdmode.el
68 lines (52 loc) · 2.3 KB
/
ob-wsdmode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;;; ob-wsdmode.el --- Org-babel integration for wsd-mode -*- lexical-binding: t; -*-
;; Copyright (C) 2015 Jostein Kjønigsen
;; Author: Jostein Kjønigsen <[email protected]>
;; Keywords: languages
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'ob)
(require 'wsd-core)
(defvar org-babel-default-header-args:wsd
'((:results . "file") (:exports . "results"))
"Default arguments for evaluating a wsd-mode source block.")
(defun org-babel-expand-body:wsd (body params &optional processed-params)
"Expand BODY according to PARAMS, return the expanded body." body)
(defun org-babel-execute:wsd (body params)
"Execute a block of wsd-mode code with org-babel.
This function is called by `org-babel-execute-src-block'."
(let* ((out-file (cdr (assoc :file params)))
(img-file (if out-file
out-file
(wsd-get-temp-filename)))
;; override preference based on whatever filename says.
(wsd-format (file-name-extension img-file))
(json (wsd-get-json body))
(image-url (wsd-get-image-url json))
(errors (wsd-get-errors json)))
(when (not (= 0 (length errors)))
(error "Errors reported from websequence-diagrams service!"))
(url-copy-file image-url img-file t)
;; org-babel :file is special cased. if provided by the document
;; any non-nil data we return will be written to that file.
;;
;; When not provided org will interpret our-return data as a file-name to
;; use.
;;
;; Therefore only return file-name when we have generated it. Otherwise
;, return nil.
(if out-file
nil
img-file)))
(provide 'ob-wsdmode)
;;; ob-wsdmode.el ends here