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
"http://orgmode.org/org-info.js")
70 (toc TOC
:table-of-contents
)
71 (mouse MOUSE_HINT
"underline")
73 (buttons VIEW_BUTTONS
"0")
76 (home LINK_HOME
:link-home
))
77 "JavaScript options, long form for script, default values.")
79 (defcustom org-infojs-options
80 (mapcar (lambda (x) (cons (car x
) (nth 2 x
)))
81 org-infojs-opts-table
)
82 "Options settings for the INFOJS Javascript.
83 Each of the options must have an entry in `org-export-html/infojs-opts-table'.
84 The value can either be a string that will be passed to the script, or
85 a property. This property is then assumed to be a property that is defined
86 by the Export/Publishing setup of Org."
90 (cons (symbol :tag
"Option")
91 (choice (symbol :tag
"Publishing/Export property")
92 (string :tag
"Value")))))
94 (defcustom org-infojs-template
95 "<script type=\"text/javascript\" language=\"JavaScript\" src=\"%SCRIPT_PATH\"></script>
96 <script type=\"text/javascript\" language=\"JavaScript\">
99 org_html_manager.setup(); // activate after the parameterd are set
102 "The template for the export style additions when org-info.js is used.
103 Option settings will replace the %MANAGER-OPTIONS cookie."
107 (defun org-infojs-handle-options (exp-plist)
108 "Analyze JavaScript options in INFO-PLIST and modify EXP-PLIST accordingly."
109 (if (or (not org-export-html-use-infojs
)
110 (and (eq org-export-html-use-infojs
'when-configured
)
111 (or (not (plist-get exp-plist
:infojs-opt
))
112 (string-match "\\<view:nil\\>"
113 (plist-get exp-plist
:infojs-opt
)))))
114 ;; We do not want to use the script
116 ;; We do want to use the script, set it up
117 (let ((template org-infojs-template
)
118 p1 s p v a1 tmp e opt var val table default
)
119 (setq v
(plist-get exp-plist
:infojs-opt
)
120 table org-infojs-opts-table
)
121 (while (setq e
(pop table
))
122 (setq opt
(car e
) var
(nth 1 e
)
123 default
(cdr (assoc opt org-infojs-options
)))
124 (and (symbolp default
) (not (memq default
'(t nil
)))
125 (setq default
(plist-get exp-plist default
)))
126 (if (string-match (format " %s:\\(\\S-+\\)" opt
) v
)
127 (setq val
(match-string 1 v
))
131 (and (string-match "%SCRIPT_PATH" template
)
132 (setq template
(replace-match val t t template
))))
136 ((or (eq val t
) (equal val
"t")) "1")
137 ((or (eq val nil
) (equal val
"nil")) "0")
139 (t (format "%s" val
))))
140 (push (cons var val
) s
))))
143 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
146 (when (and s
(> (length s
) 0))
147 (and (string-match "%MANAGER_OPTIONS" template
)
148 (setq s
(replace-match s t t template
))
152 (concat (or (plist-get exp-plist
:style
) "") "\n" s
)))))
153 ;; This script absolutely needs the table of contents, to we change that
155 (if (not (plist-get exp-plist
:table-of-contents
))
156 (setq exp-plist
(plist-put exp-plist
:table-of-contents t
)))
158 ;; Return the modified property list
161 (defun org-infojs-options-inbuffer-template ()
162 (format "#+INFOJS_OPT: view:%s toc:%s ltoc:%s runs:%s mouse:%s buttons:%s path:%s"
163 (if (eq t org-export-html-use-infojs
) (cdr (assoc 'view org-infojs-options
)) nil
)
164 (let ((a (cdr (assoc 'toc org-infojs-options
))))
165 (cond ((memq a
'(nil t
)) a
)
166 (t (plist-get (org-infile-export-plist) :table-of-contents
))))
167 (if (equal (cdr (assoc 'ltoc org-infojs-options
)) "1") t nil
)
168 (cdr (assoc 'runs org-infojs-options
))
169 (cdr (assoc 'mouse org-infojs-options
))
170 (cdr (assoc 'buttons org-infojs-options
))
171 (cdr (assoc 'path org-infojs-options
))))
173 (provide 'org-infojs
)
175 ;;; org-infojs.el ends here