view lisp/org/org-jsinfo.el @ 100448:cea079b68b76

2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-refile): Avoid refiling to within the region to be refiled. * org-export-latex.el (org-export-latex-special-chars): Replace special characters also in tables. * org-agenda.el (org-agenda-change-all-lines): New argument FORCE-TAGS. (org-agenda-set-tags): Cet the new tags and pas them to `org-format-agenda-item'. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-export-latex.el (org-export-latex-classes): Add longable as a default package to all classes. (org-export-latex-tables): Handle the longtable attribute and the align attribute. * org-table.el (orgtbl-to-generic): Handle tables that start with a hline. * org-export-latex.el (org-export-latex-emphasis-alist): Switch to \verb for colde-like snippets. (org-export-as-latex): Fix issues with region export. * org.el (org-up-heading-safe): Speed up function by using a direct regexp search. (org-olpa): New variable. (org-get-outline-path): Speed-up path constructions in cases where this is possible because the entire hierarchy is scanned anyway. (org-refile-get-location): Don't compare the truenames of files, this is too slow. (org-goto-max-level): New option. (org-goto): Use `org-goto-max-level'. 2008-12-16 Tassilo Horn <tassilo@member.fsf.org> * org-gnus.el (org-gnus-article-link, org-gnus-article-link): Strip angle brackets from message-ids in the former and don't do it in the latter. (org-gnus-follow-link): Open summary reliable, even if the last messages were deleted, and handle empty groups, too. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-export-latex.el (org-export-latex-emphasis-alist): Use \verb instead of \texttt for the =...= and ~===~ emphasis environments. (org-export-as-latex): Remove any old :org-license-to-kill text properties. (org-export-as-latex): Pass RBEG to `org-export-latex-first-lines'. (org-export-latex-make-header): Add some hard space after the table of contents. (org-export-latex-first-lines): Accept RBEG argument. Mark exported text so that it will be excuded in further steps. * org-table.el (org-table-get-specials): Make @0 reference the last line in a table. (org-table-recalculate): Improve docstring. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-log-done): Fix docstring. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-html-format-image): Fix bugs. * org-export-latex.el (org-export-latex-tables) (org-export-latex-links): Implement attribute, label, and caption handling. * org-exp.el (org-export-html-style-default): Add style definitions for the figure div. (org-export-preprocess-string, org-export-as-html): Implement attribute, label, and caption handling. (org-export-attach-captions-and-attributes): New function. (org-export-html-format-image): New function. (org-format-org-table-html): Implement attribute, label, and caption handling. * org.el (org-find-text-property-in-string): New function. (org-extract-attributes): Use the property org-attr instead of org-attrobutes, because this property is now set with the #+ATTR lines. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-compat.el (org-substring-no-properties): Fix for XEmacs, for the case that FROM is nil. * org.el (org-before-first-heading-p): New function. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-as-html): Do not add a space before enforces line breaks. (org-export-as-html): Close paragraph before blockquote and verse tags. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-id.el (org-id-locations-file): Wrap file name with `convert-standard-filename'. (org-id-files): New variable. (org-id-use-hash): New option. (org-id-update-id-locations): Also search in all files current listed in `org-id-files'. Convert the resulting alist to a hash if the user customation says so. (org-id-locations-save): Handle he case if `org-id-locations' is a hash. (org-id-locations-load): Convert the alist to a hash. (org-id-add-location): Handle the hast case. (kill-emacs-hook): Make sure id locations are saved when Emacs is exited. (org-id-hash-to-alist, org-id-alist-to-hash) (org-id-paste-tracker): New functions.
author Carsten Dominik <dominik@science.uva.nl>
date Tue, 16 Dec 2008 13:28:37 +0000
parents c851df8e004e
children ba23e35d3eaf
line wrap: on
line source

;;; org-jsinfo.el --- Support for org-info.js Javascript in Org HTML export

;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.

;; Author: Carsten Dominik <carsten at orgmode dot org>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 6.15a
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs 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.

;; GNU Emacs 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 GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:

;; This file implements the support for Sebastian Rose's Javascript
;; org-info.js to display an org-mode file exported to HTML in an
;; Info-like way, or using folding similar to the outline structure
;; org org-mode itself.

;; Documentation for using this module is in the Org manual. The script
;; itself is documented by Sebastian Rose in a file distributed with
;; the script.  FIXME: Accurate pointers!

;; Org-mode loads this module by default - if this is not what you want,
;; configure the variable `org-modules'.

;;; Code:

(require 'org-exp)

(add-to-list 'org-export-inbuffer-options-extra '("INFOJS_OPT" :infojs-opt))
(add-hook 'org-export-options-filters 'org-infojs-handle-options)

(defgroup org-infojs nil
  "Options specific for using org-info.js in HTML export of Org-mode files."
  :tag "Org Export HTML INFOJS"
  :group 'org-export-html)

(defcustom org-export-html-use-infojs 'when-configured
  "Should Sebasian Rose's Java Script org-info.js be linked into HTML files?
This option can be nil or t to never or always use the script.  It can
also be the symbol `when-configured', meaning that the script will be
linked into the export file if and only if there is a \"#+INFOJS_OPT:\"
line in the buffer.  See also the variable `org-infojs-options'."
  :group 'org-export-html
  :group 'org-infojs
  :type '(choice
	  (const :tag "Never" nil)
	  (const :tag "When configured in buffer" when-configured)
	  (const :tag "Always" t)))

(defconst org-infojs-opts-table
  '((path PATH "http://orgmode.org/org-info.js")
    (view VIEW "info")
    (toc TOC :table-of-contents)
    (ftoc FIXED_TOC "0")
    (tdepth TOC_DEPTH "max")
    (sdepth SECTION_DEPTH "max")
    (mouse MOUSE_HINT "underline")
    (buttons VIEW_BUTTONS "0")
    (ltoc LOCAL_TOC "1")
    (up LINK_UP :link-up)
    (home LINK_HOME :link-home))
  "JavaScript options, long form for script, default values.")

(defvar org-infojs-options)
(when (and (boundp 'org-infojs-options)
	   (assq 'runs org-infojs-options))
  (setq org-infojs-options (delq (assq 'runs org-infojs-options)
				 org-infojs-options)))

(defcustom org-infojs-options
  (mapcar (lambda (x) (cons (car x) (nth 2 x)))
	  org-infojs-opts-table)
  "Options settings for the INFOJS Javascript.
Each of the options must have an entry in `org-export-html/infojs-opts-table'.
The value can either be a string that will be passed to the script, or
a property.  This property is then assumed to be a property that is defined
by the Export/Publishing setup of Org.
The `sdepth' and `tdepth' parameters can also be set to \"max\", which
means to use the maximum value consistent with other options."
  :group 'org-infojs
  :type
  `(set :greedy t :inline t
	,@(mapcar
	   (lambda (x)
	     (list 'cons (list 'const (car x))
		   '(choice
			    (symbol :tag "Publishing/Export property")
			    (string :tag "Value"))))
	   org-infojs-opts-table)))

(defcustom org-infojs-template
  "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\"></script>
<script type=\"text/javascript\" >
<!--/*--><![CDATA[/*><!--*/
%MANAGER_OPTIONS
org_html_manager.setup();  // activate after the parameterd are set
/*]]>*/-->
</script>"
  "The template for the export style additions when org-info.js is used.
Option settings will replace the %MANAGER-OPTIONS cookie."
  :group 'org-infojs
  :type 'string)

(defun org-infojs-handle-options (exp-plist)
  "Analyze JavaScript options in INFO-PLIST and modify EXP-PLIST accordingly."
  (if (or (not org-export-html-use-infojs)
	  (and (eq org-export-html-use-infojs 'when-configured)
	       (or (not (plist-get exp-plist :infojs-opt))
		   (string-match "\\<view:nil\\>"
				 (plist-get exp-plist :infojs-opt)))))
      ;; We do not want to use the script
      exp-plist
    ;; We do want to use the script, set it up
    (let ((template org-infojs-template)
	(ptoc (plist-get exp-plist :table-of-contents))
	(hlevels (plist-get exp-plist :headline-levels))
	tdepth sdepth p1 s p v a1 tmp e opt var val table default)
    (setq sdepth hlevels
	  tdepth hlevels)
    (if (integerp ptoc) (setq tdepth (min ptoc tdepth)))
    (setq v (plist-get exp-plist :infojs-opt)
	  table org-infojs-opts-table)
    (while (setq e (pop table))
      (setq opt (car e) var (nth 1 e)
	    default (cdr (assoc opt org-infojs-options)))
      (and (symbolp default) (not (memq default '(t nil)))
	   (setq default (plist-get exp-plist default)))
      (if (string-match (format " %s:\\(\\S-+\\)" opt) v)
	  (setq val (match-string 1 v))
	(setq val default))
      (cond
       ((eq opt 'path)
	(and (string-match "%SCRIPT_PATH" template)
	     (setq template (replace-match val t t template))))
       ((eq opt 'sdepth)
	(if (integerp (read val))
	    (setq sdepth (min (read val) hlevels))))
       ((eq opt 'tdepth)
	(if (integerp (read val))
	    (setq tdepth (min (read val) hlevels))))
       (t
	(setq val
	      (cond
	       ((or (eq val t) (equal val "t")) "1")
	       ((or (eq val nil) (equal val "nil")) "0")
	       ((stringp val) val)
	       (t (format "%s" val))))
	(push (cons var val) s))))

    ;; Now we set the depth of the *generated* TOC to SDEPTH, because the
    ;; toc will actually determine the splitting.  How much of the toc will
    ;; actually be displayed is governed by the TDEPTH option.
    (setq exp-plist (plist-put exp-plist :table-of-contents sdepth))

    ;; The table of contents should ot show more sections then we generate
    (setq tdepth (min tdepth sdepth))
    (push (cons "TOC_DEPTH" tdepth) s)

    (setq s (mapconcat
	     (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
				 (car x) (cdr x)))
	     s "\n"))
    (when (and s (> (length s) 0))
      (and (string-match "%MANAGER_OPTIONS" template)
	   (setq s (replace-match s t t template))
	   (setq exp-plist
		 (plist-put
		  exp-plist :style-extra
		  (concat (or (plist-get exp-plist :style-extra) "") "\n" s)))))
    ;; This script absolutely needs the table of contents, to we change that
    ;; setting
    (if (not (plist-get exp-plist :table-of-contents))
	(setq exp-plist (plist-put exp-plist :table-of-contents t)))
    ;; Return the modified property list
    exp-plist)))

(defun org-infojs-options-inbuffer-template ()
  (format "#+INFOJS_OPT: view:%s toc:%s ltoc:%s mouse:%s buttons:%s path:%s"
	  (if (eq t org-export-html-use-infojs) (cdr (assoc 'view org-infojs-options)) nil)
	  (let ((a (cdr (assoc 'toc org-infojs-options))))
	    (cond ((memq a '(nil t)) a)
		  (t (plist-get (org-infile-export-plist) :table-of-contents))))
	  (if (equal (cdr (assoc 'ltoc org-infojs-options)) "1") t nil)
	  (cdr (assoc 'mouse org-infojs-options))
	  (cdr (assoc 'buttons org-infojs-options))
	  (cdr (assoc 'path org-infojs-options))))

(provide 'org-infojs)
(provide 'org-jsinfo)

;; arch-tag: c71d1d85-3337-4817-a066-725e74ac9eac

;;; org-jsinfo.el ends here