Function: org-html-infojs-install-script

org-html-infojs-install-script is a byte-compiled function defined in ox-html.el.gz.

Signature

(org-html-infojs-install-script EXP-PLIST BACKEND)

Documentation

Install script in export options when appropriate.

EXP-PLIST is a plist containing export options. BACKEND is the export back-end currently used.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-html.el.gz
(defun org-html-infojs-install-script (exp-plist _backend)
  "Install script in export options when appropriate.
EXP-PLIST is a plist containing export options.  BACKEND is the
export back-end currently used."
  (unless (or (memq 'body-only (plist-get exp-plist :export-options))
	      (not (plist-get exp-plist :html-use-infojs))
	      (and (eq (plist-get exp-plist :html-use-infojs) 'when-configured)
		   (let ((opt (plist-get exp-plist :infojs-opt)))
		     (or (not opt)
			 (string= "" opt)
			 (string-match "\\<view:nil\\>" opt)))))
    (let* ((template (plist-get exp-plist :html-infojs-template))
	   (ptoc (plist-get exp-plist :with-toc))
	   (hlevels (plist-get exp-plist :headline-levels))
	   (sdepth hlevels)
	   (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
	   (options (plist-get exp-plist :infojs-opt))
	   (infojs-opt (plist-get exp-plist :html-infojs-options))
	   (table org-html-infojs-opts-table)
	   style)
      (dolist (entry table)
	(let* ((opt (car entry))
	       (var (nth 1 entry))
	       ;; Compute default values for script option OPT from
	       ;; `org-html-infojs-options' variable.
	       (default
		 (let ((default (cdr (assq opt infojs-opt))))
		   (if (and (symbolp default) (not (memq default '(t nil))))
		       (plist-get exp-plist default)
		     default)))
	       ;; Value set through INFOJS_OPT keyword has precedence
	       ;; over the default one.
	       (val (if (and options
			     (string-match (format "\\<%s:\\(\\S-+\\)" opt)
					   options))
			(match-string 1 options)
		      default)))
	  (pcase opt
	    (`path (setq template
			 (replace-regexp-in-string
			  "%SCRIPT_PATH" val template t t)))
	    (`sdepth (when (integerp (read val))
		       (setq sdepth (min (read val) sdepth))))
	    (`tdepth (when (integerp (read val))
		       (setq tdepth (min (read val) tdepth))))
	    (_ (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) style)))))
      ;; 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 :with-toc sdepth))
      ;; The table of contents should not show more sections than we
      ;; generate.
      (setq tdepth (min tdepth sdepth))
      (push (cons "TOC_DEPTH" tdepth) style)
      ;; Build style string.
      (setq style (mapconcat
		   (lambda (x)
		     (format "org_html_manager.set(\"%s\", \"%s\");"
			     (car x) (cdr x)))
		   style "\n"))
      (when (and style (> (length style) 0))
	(and (string-match "%MANAGER_OPTIONS" template)
	     (setq style (replace-match style t t template))
	     (setq exp-plist
		   (plist-put
		    exp-plist :html-head-extra
		    (concat (or (plist-get exp-plist :html-head-extra) "")
			    "\n"
			    style)))))
      ;; This script absolutely needs the table of contents, so we
      ;; change that setting.
      (unless (plist-get exp-plist :with-toc)
	(setq exp-plist (plist-put exp-plist :with-toc t)))
      ;; Return the modified property list.
      exp-plist)))