1 ;;; ox-jsinfo.el --- Org HTML Export Extension for org-info.js
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;; This file implements the support for Sebastian Rose's JavaScript
28 ;; org-info.js to display an Org mode file exported to HTML in an
29 ;; Info-like way, or using folding similar to the outline structure of
32 ;; Documentation for using this module is in the Org manual. The
33 ;; script itself is documented by Sebastian Rose in a file distributed
34 ;; with the script. FIXME: Accurate pointers!
40 (add-to-list 'org-export-filter-options-functions
'org-infojs-install-script
)
42 (defgroup org-export-infojs nil
43 "Options specific for using org-info.js in HTML export."
44 :tag
"Org Export HTML INFOJS"
45 :group
'org-export-html
)
47 (defcustom org-export-html-use-infojs
'when-configured
48 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
49 This option can be nil or t to never or always use the script.
50 It can also be the symbol `when-configured', meaning that the
51 script will be linked into the export file if and only if there
52 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
53 `org-infojs-options'."
54 :group
'org-export-html
55 :group
'org-export-infojs
57 (const :tag
"Never" nil
)
58 (const :tag
"When configured in buffer" when-configured
)
59 (const :tag
"Always" t
)))
61 (defconst org-infojs-opts-table
62 '((path PATH
"http://orgmode.org/org-info.js")
66 (tdepth TOC_DEPTH
"max")
67 (sdepth SECTION_DEPTH
"max")
68 (mouse MOUSE_HINT
"underline")
69 (buttons VIEW_BUTTONS
"0")
71 (up LINK_UP
:html-link-up
)
72 (home LINK_HOME
:html-link-home
))
73 "JavaScript options, long form for script, default values.")
75 (defvar org-infojs-options
)
76 (when (and (boundp 'org-infojs-options
)
77 (assq 'runs org-infojs-options
))
78 (setq org-infojs-options
(delq (assq 'runs org-infojs-options
)
81 (defcustom org-infojs-options
82 (mapcar (lambda (x) (cons (car x
) (nth 2 x
))) org-infojs-opts-table
)
83 "Options settings for the INFOJS JavaScript.
84 Each of the options must have an entry in `org-export-html/infojs-opts-table'.
85 The value can either be a string that will be passed to the script, or
86 a property. This property is then assumed to be a property that is defined
87 by the Export/Publishing setup of Org.
88 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
89 means to use the maximum value consistent with other options."
90 :group
'org-export-infojs
92 `(set :greedy t
:inline t
95 (list 'cons
(list 'const
(car x
))
97 (symbol :tag
"Publishing/Export property")
98 (string :tag
"Value"))))
99 org-infojs-opts-table
)))
101 (defcustom org-infojs-template
102 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
105 * @source: %SCRIPT_PATH
107 * @licstart The following is the entire license notice for the
108 * JavaScript code in %SCRIPT_PATH.
110 * Copyright (C) 2012-2013 Sebastian Rose
113 * The JavaScript code in this tag is free software: you can
114 * redistribute it and/or modify it under the terms of the GNU
115 * General Public License (GNU GPL) as published by the Free Software
116 * Foundation, either version 3 of the License, or (at your option)
117 * any later version. The code is distributed WITHOUT ANY WARRANTY;
118 * without even the implied warranty of MERCHANTABILITY or FITNESS
119 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
121 * As additional permission under GNU GPL version 3 section 7, you
122 * may distribute non-source (e.g., minimized or compacted) forms of
123 * that code without the copy of the GNU GPL normally required by
124 * section 4, provided you include this license notice and a URL
125 * through which recipients can access the Corresponding Source.
127 * @licend The above is the entire license notice
128 * for the JavaScript code in %SCRIPT_PATH.
133 <script type=\"text/javascript\">
136 @licstart The following is the entire license notice for the
137 JavaScript code in this tag.
139 Copyright (C) 2012-2013 Free Software Foundation, Inc.
141 The JavaScript code in this tag is free software: you can
142 redistribute it and/or modify it under the terms of the GNU
143 General Public License (GNU GPL) as published by the Free Software
144 Foundation, either version 3 of the License, or (at your option)
145 any later version. The code is distributed WITHOUT ANY WARRANTY;
146 without even the implied warranty of MERCHANTABILITY or FITNESS
147 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
149 As additional permission under GNU GPL version 3 section 7, you
150 may distribute non-source (e.g., minimized or compacted) forms of
151 that code without the copy of the GNU GPL normally required by
152 section 4, provided you include this license notice and a URL
153 through which recipients can access the Corresponding Source.
156 @licend The above is the entire license notice
157 for the JavaScript code in this tag.
160 <!--/*--><![CDATA[/*><!--*/
162 org_html_manager.setup(); // activate after the parameters are set
165 "The template for the export style additions when org-info.js is used.
166 Option settings will replace the %MANAGER-OPTIONS cookie."
170 (defun org-infojs-install-script (exp-plist backend
)
171 "Install script in export options when appropriate.
172 EXP-PLIST is a plist containing export options. BACKEND is the
173 export back-end currently used."
174 (unless (or (not (org-export-derived-backend-p backend
'html
))
175 (not org-export-html-use-infojs
)
176 (and (eq org-export-html-use-infojs
'when-configured
)
177 (or (not (plist-get exp-plist
:infojs-opt
))
178 (string-match "\\<view:nil\\>"
179 (plist-get exp-plist
:infojs-opt
)))))
180 (let* ((template org-infojs-template
)
181 (ptoc (plist-get exp-plist
:with-toc
))
182 (hlevels (plist-get exp-plist
:headline-levels
))
184 (tdepth (if (integerp ptoc
) (min ptoc hlevels
) hlevels
))
185 (options (plist-get exp-plist
:infojs-opt
))
186 (table org-infojs-opts-table
)
188 (dolist (entry table
)
189 (let* ((opt (car entry
))
191 ;; Compute default values for script option OPT from
192 ;; `org-infojs-options' variable.
194 (let ((default (cdr (assq opt org-infojs-options
))))
195 (if (and (symbolp default
) (not (memq default
'(t nil
))))
196 (plist-get exp-plist default
)
198 ;; Value set through INFOJS_OPT keyword has precedence
199 ;; over the default one.
200 (val (if (and options
201 (string-match (format "\\<%s:\\(\\S-+\\)" opt
)
203 (match-string 1 options
)
207 (replace-regexp-in-string
208 "%SCRIPT_PATH" val template t t
)))
209 (sdepth (when (integerp (read val
))
210 (setq sdepth
(min (read val
) sdepth
))))
211 (tdepth (when (integerp (read val
))
212 (setq tdepth
(min (read val
) tdepth
))))
215 ((or (eq val t
) (equal val
"t")) "1")
216 ((or (eq val nil
) (equal val
"nil")) "0")
218 (t (format "%s" val
))))
219 (push (cons var val
) style
)))))
220 ;; Now we set the depth of the *generated* TOC to SDEPTH,
221 ;; because the toc will actually determine the splitting. How
222 ;; much of the toc will actually be displayed is governed by the
224 (setq exp-plist
(plist-put exp-plist
:with-toc sdepth
))
225 ;; The table of contents should not show more sections than we
227 (setq tdepth
(min tdepth sdepth
))
228 (push (cons "TOC_DEPTH" tdepth
) style
)
229 ;; Build style string.
230 (setq style
(mapconcat
231 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
235 (when (and style
(> (length style
) 0))
236 (and (string-match "%MANAGER_OPTIONS" template
)
237 (setq style
(replace-match style t t template
))
240 exp-plist
:html-style-extra
241 (concat (or (plist-get exp-plist
:html-style-extra
) "")
244 ;; This script absolutely needs the table of contents, so we
245 ;; change that setting.
246 (unless (plist-get exp-plist
:with-toc
)
247 (setq exp-plist
(plist-put exp-plist
:with-toc t
)))
248 ;; Return the modified property list.
257 ;; generated-autoload-file: "org-loaddefs.el"
260 ;;; ox-jsinfo.el ends here