1 ;;; org-infojs.el --- Support for org-info.js Javascript in Org HTML export
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; This file implements the support for Sebastian Rose's Javascript
31 ;; org-info.js to display an org-mode file exported to HTML in an
32 ;; Info-like way, or using folding similar to the outline structure
33 ;; org org-mode itself.
35 ;; Documentation for using this module is in the Org manual. The script
36 ;; itself is documented by Sebastian Rose in a file distributed with
37 ;; the script. FIXME: Accurate pointers!
39 ;; Org-mode loads this module by default - if this is not what you want,
40 ;; configure the variable `org-modules'.
46 (add-to-list 'org-export-inbuffer-options-extra
'("INFOJS_OPT" :infojs-opt
))
47 (add-hook 'org-export-options-filters
'org-infojs-handle-options
)
49 (defgroup org-infojs nil
50 "Options specific for using org-info.js in HTML export of Org-mode files."
51 :tag
"Org Export HTML INFOJS"
52 :group
'org-export-html
)
54 (defcustom org-export-html-use-infojs
'when-configured
55 "Should Sebasian Rose's Java Script org-info.js be linked into HTML files?
56 This option can be nil or t to never or always use the script. It can
57 also be the symbol `when-configured', meaning that the script will be
58 linked into the export file if and only if there is a \"#+INFOJS_OPT:\"
59 line in the buffer. See also the variable `org-infojs-options'."
60 :group
'org-export-html
63 (const :tag
"Never" nil
)
64 (const :tag
"When configured in buffer" when-configured
)
65 (const :tag
"Always" t
)))
67 (defconst org-infojs-opts-table
68 '((path PATH
"org-info.js")
70 (toc TOC
:table-of-contents
)
71 (mouse MOUSE_HINT
"underline")
73 (buttons VIEW_BUTTONS
"0")
75 (home LINK_HOME
:link-home
))
76 "JavaScript options, long form for script, default values.")
78 (defcustom org-infojs-options
79 (mapcar (lambda (x) (cons (car x
) (nth 2 x
)))
80 org-infojs-opts-table
)
81 "Options settings for the INFOJS Javascript.
82 Each of the options must have an entry in `org-export-html/infojs-opts-table'.
83 The value can either be a string that will be passed to the script, or
84 a property. This property is then assumed to be a property that is defined
85 by the Export/Publishing setup of Org."
89 (cons (symbol :tag
"Option")
90 (choice (symbol :tag
"Publishing/Export property")
91 (string :tag
"Value")))))
93 (defcustom org-infojs-template
94 "<script type=\"text/javascript\" language=\"JavaScript\" src=\"%SCRIPT_PATH\"></script>
95 <script type=\"text/javascript\" language=\"JavaScript\">
98 org_html_manager.setup(); // activate after the parameterd are set
101 "The template for the export style additions when org-info.js is used.
102 Option settings will replace the %MANAGER-OPTIONS cookie."
106 (defun org-infojs-handle-options (exp-plist)
107 "Analyze JavaScript options in INFO-PLIST and modify EXP-PLIST accordingly."
108 (if (or (not org-export-html-use-infojs
)
109 (and (eq org-export-html-use-infojs
'when-configured
)
110 (not (plist-get exp-plist
:infojs-opt
))))
111 ;; We do not want to use the script
113 ;; We do want to use the script, set it up
114 (let ((template org-infojs-template
)
115 p1 s p v a1 tmp e opt var val table default
)
116 (setq v
(plist-get exp-plist
:infojs-opt
)
117 table org-infojs-opts-table
)
118 (while (setq e
(pop table
))
119 (setq opt
(car e
) var
(nth 1 e
)
120 default
(cdr (assoc opt org-infojs-options
)))
121 (and (symbolp default
) (not (memq default
'(t nil
)))
122 (setq default
(plist-get exp-plist default
)))
123 (if (string-match (format " %s:\\(\\S-+\\)" opt
) v
)
124 (setq val
(match-string 1 v
))
128 (and (string-match "%SCRIPT_PATH" template
)
129 (setq template
(replace-match val t t template
))))
133 ((or (eq val t
) (equal val
"t")) "1")
134 ((or (eq val nil
) (equal val
"nil")) "0")
136 (t (format "%s" val
))))
137 (push (cons var val
) s
))))
140 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
143 (when (and s
(> (length s
) 0))
144 (and (string-match "%MANAGER_OPTIONS" template
)
145 (setq s
(replace-match s t t template
))
149 (concat (or (plist-get exp-plist
:style
) "") "\n" s
)))))
152 (provide 'org-infojs
)
154 ;;; org-infojs.el ends here