;;; ox-html.el --- HTML Back-End for Org Export Engine
;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
;; Author: Carsten Dominik
;; Jambunathan K
;; Keywords: outlines, hypermedia, calendar, wp
;; 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 .
;;; Commentary:
;; This library implements a HTML back-end for Org generic exporter.
;; See Org manual for more information.
;;; Code:
;;; Dependencies
(require 'ox)
(require 'ox-publish)
(require 'format-spec)
(eval-when-compile (require 'cl) (require 'table nil 'noerror))
;;; Function Declarations
(declare-function org-id-find-id-file "org-id" (id))
(declare-function htmlize-region "ext:htmlize" (beg end))
(declare-function org-pop-to-buffer-same-window
"org-compat" (&optional buffer-or-name norecord label))
(declare-function mm-url-decode-entities "mm-url" ())
;;; Define Back-End
(org-export-define-backend 'html
'((bold . org-html-bold)
(center-block . org-html-center-block)
(clock . org-html-clock)
(code . org-html-code)
(drawer . org-html-drawer)
(dynamic-block . org-html-dynamic-block)
(entity . org-html-entity)
(example-block . org-html-example-block)
(export-block . org-html-export-block)
(export-snippet . org-html-export-snippet)
(fixed-width . org-html-fixed-width)
(footnote-definition . org-html-footnote-definition)
(footnote-reference . org-html-footnote-reference)
(headline . org-html-headline)
(horizontal-rule . org-html-horizontal-rule)
(inline-src-block . org-html-inline-src-block)
(inlinetask . org-html-inlinetask)
(inner-template . org-html-inner-template)
(italic . org-html-italic)
(item . org-html-item)
(keyword . org-html-keyword)
(latex-environment . org-html-latex-environment)
(latex-fragment . org-html-latex-fragment)
(line-break . org-html-line-break)
(link . org-html-link)
(node-property . org-html-node-property)
(paragraph . org-html-paragraph)
(plain-list . org-html-plain-list)
(plain-text . org-html-plain-text)
(planning . org-html-planning)
(property-drawer . org-html-property-drawer)
(quote-block . org-html-quote-block)
(radio-target . org-html-radio-target)
(section . org-html-section)
(special-block . org-html-special-block)
(src-block . org-html-src-block)
(statistics-cookie . org-html-statistics-cookie)
(strike-through . org-html-strike-through)
(subscript . org-html-subscript)
(superscript . org-html-superscript)
(table . org-html-table)
(table-cell . org-html-table-cell)
(table-row . org-html-table-row)
(target . org-html-target)
(template . org-html-template)
(timestamp . org-html-timestamp)
(underline . org-html-underline)
(verbatim . org-html-verbatim)
(verse-block . org-html-verse-block))
:export-block "HTML"
:filters-alist '((:filter-options . org-html-infojs-install-script)
(:filter-final-output . org-html-final-function))
:menu-entry
'(?h "Export to HTML"
((?H "As HTML buffer" org-html-export-as-html)
(?h "As HTML file" org-html-export-to-html)
(?o "As HTML file and open"
(lambda (a s v b)
(if a (org-html-export-to-html t s v b)
(org-open-file (org-html-export-to-html nil s v b)))))))
:options-alist
'((:creator "CREATOR" nil org-html-creator-string)
(:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
(:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
(:html-link-up "HTML_LINK_UP" nil org-html-link-up)
(:html-head "HTML_HEAD" nil org-html-head newline)
(:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
(:html-container "HTML_CONTAINER" nil org-html-container-element)
(:html-mathjax "HTML_MATHJAX" nil "" space)
(:infojs-opt "INFOJS_OPT" nil nil)
;; Retrieve LaTeX header for fragments.
(:latex-header "LATEX_HEADER" nil nil newline)
(:html-extension nil nil org-html-extension)
(:html-link-org-as-html nil nil org-html-link-org-files-as-html)
(:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
(:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
(:html-postamble nil "html-postamble" org-html-postamble)
(:html-preamble nil "html-preamble" org-html-preamble)
(:html-head-include-default-style nil "html-style" org-html-head-include-default-style)
(:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
(:html-table-attributes nil nil org-html-table-default-attributes)
(:html-table-row-tags nil nil org-html-table-row-tags)
(:html-xml-declaration nil nil org-html-xml-declaration)
(:html-inline-images nil nil org-html-inline-images)
(:with-latex nil "tex" org-html-with-latex)))
;;; Internal Variables
(defvar org-html-format-table-no-css)
(defvar htmlize-buffer-places) ; from htmlize.el
(defvar org-html--pre/postamble-class "status"
"CSS class used for pre/postamble")
(defconst org-html-doctype-alist
'(("html4-strict" . "")
("html4-transitional" . "")
("html4-frameset" . "")
("xhtml-strict" . "")
("xhtml-transitional" . "")
("xhtml-frameset" . "")
("xhtml-11" . "")
("html5" . "")
("xhtml5" . ""))
"An alist mapping (x)html flavors to specific doctypes.")
(defconst org-html-html5-elements
'("article" "aside" "audio" "canvas" "details" "figcaption"
"figure" "footer" "header" "menu" "meter" "nav" "output"
"progress" "section" "video")
"New elements in html5.
For blocks that should contain headlines, use the HTML_CONTAINER
property on the headline itself.")
(defconst org-html-special-string-regexps
'(("\\\\-" . "") ; shy
("---\\([^-]\\)" . "—\\1") ; mdash
("--\\([^-]\\)" . "–\\1") ; ndash
("\\.\\.\\." . "…")) ; hellip
"Regular expressions for special string conversion.")
(defconst org-html-scripts
""
"Basic JavaScript that is needed by HTML files produced by Org mode.")
(defconst org-html-style-default
""
"The default style specification for exported HTML files.
You can use `org-html-head' and `org-html-head-extra' to add to
this style. If you don't want to include this default style,
customize `org-html-head-include-default-style'.")
;;; User Configuration Variables
(defgroup org-export-html nil
"Options for exporting Org mode files to HTML."
:tag "Org Export HTML"
:group 'org-export)
;;;; Handle infojs
(defvar org-html-infojs-opts-table
'((path PATH "http://orgmode.org/org-info.js")
(view VIEW "info")
(toc TOC :with-toc)
(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 :html-link-up)
(home LINK_HOME :html-link-home))
"JavaScript options, long form for script, default values.")
(defcustom org-html-use-infojs 'when-configured
"Non-nil when Sebastian Rose's Java Script org-info.js should be active.
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-html-infojs-options'."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type '(choice
(const :tag "Never" nil)
(const :tag "When configured in buffer" when-configured)
(const :tag "Always" t)))
(defcustom org-html-infojs-options
(mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
"Options settings for the INFOJS JavaScript.
Each of the options must have an entry in `org-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-export-html
:version "24.4"
:package-version '(Org . "8.0")
: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-html-infojs-opts-table)))
(defcustom org-html-infojs-template
"
"
"The template for the export style additions when org-info.js is used.
Option settings will replace the %MANAGER-OPTIONS cookie."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'string)
(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 org-html-use-infojs)
(and (eq org-html-use-infojs 'when-configured)
(or (not (plist-get exp-plist :infojs-opt))
(string-match "\\"
(plist-get exp-plist :infojs-opt)))))
(let* ((template org-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))
(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 org-html-infojs-options))))
(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)))
(case 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))))
(otherwise (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)))
;;;; Bold, etc.
(defcustom org-html-text-markup-alist
'((bold . "%s")
(code . "%s")
(italic . "%s")
(strike-through . "%s")
(underline . "%s")
(verbatim . "%s"))
"Alist of HTML expressions to convert text markup.
The key must be a symbol among `bold', `code', `italic',
`strike-through', `underline' and `verbatim'. The value is
a formatting string to wrap fontified text with.
If no association can be found for a given markup, text will be
returned as-is."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type '(alist :key-type (symbol :tag "Markup type")
:value-type (string :tag "Format string"))
:options '(bold code italic strike-through underline verbatim))
(defcustom org-html-indent nil
"Non-nil means to indent the generated HTML.
Warning: non-nil may break indentation of source code blocks."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'boolean)
(defcustom org-html-use-unicode-chars nil
"Non-nil means to use unicode characters instead of HTML entities."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'boolean)
;;;; Drawers
(defcustom org-html-format-drawer-function
(lambda (name contents) contents)
"Function called to format a drawer in HTML code.
The function must accept two parameters:
NAME the drawer name, like \"LOGBOOK\"
CONTENTS the contents of the drawer.
The function should return the string to be exported.
For example, the variable could be set to the following function
in order to mimic default behaviour:
The default value simply returns the value of CONTENTS."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'function)
;;;; Footnotes
(defcustom org-html-footnotes-section "
%s:
%s
"
"Format for the footnotes section.
Should contain a two instances of %s. The first will be replaced with the
language-specific word for \"Footnotes\", the second one will be replaced
by the footnotes themselves."
:group 'org-export-html
:type 'string)
(defcustom org-html-footnote-format "%s"
"The format for the footnote reference.
%s will be replaced by the footnote reference itself."
:group 'org-export-html
:type 'string)
(defcustom org-html-footnote-separator ", "
"Text used to separate footnotes."
:group 'org-export-html
:type 'string)
;;;; Headline
(defcustom org-html-toplevel-hlevel 2
"The level for level 1 headings in HTML export.
This is also important for the classes that will be wrapped around headlines
and outline structure. If this variable is 1, the top-level headlines will
be
, and the corresponding classes will be outline-1, section-number-1,
and outline-text-1. If this is 2, all of these will get a 2 instead.
The default for this variable is 2, because we use
for formatting the
document title."
:group 'org-export-html
:type 'integer)
(defcustom org-html-format-headline-function 'ignore
"Function to format headline text.
This function will be called with 5 arguments:
TODO the todo keyword (string or nil).
TODO-TYPE the type of todo (symbol: `todo', `done', nil)
PRIORITY the priority of the headline (integer or nil)
TEXT the main headline text (string).
TAGS the tags (string or nil).
The function result will be used in the section format string."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'function)
;;;; HTML-specific
(defcustom org-html-allow-name-attribute-in-anchors nil
"When nil, do not set \"name\" attribute in anchors.
By default, when appropriate, anchors are formatted with \"id\"
but without \"name\" attribute."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'boolean)
;;;; Inlinetasks
(defcustom org-html-format-inlinetask-function 'ignore
"Function called to format an inlinetask in HTML code.
The function must accept six parameters:
TODO the todo keyword, as a string
TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
PRIORITY the inlinetask priority, as a string
NAME the inlinetask name, as a string.
TAGS the inlinetask tags, as a list of strings.
CONTENTS the contents of the inlinetask, as a string.
The function should return the string to be exported."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'function)
;;;; LaTeX
(defcustom org-html-with-latex org-export-with-latex
"Non-nil means process LaTeX math snippets.
When set, the exporter will process LaTeX environments and
fragments.
This option can also be set with the +OPTIONS line,
e.g. \"tex:mathjax\". Allowed values are:
nil Ignore math snippets.
`verbatim' Keep everything in verbatim
`dvipng' Process the LaTeX fragments to images. This will also
include processing of non-math environments.
`imagemagick' Convert the LaTeX fragments to pdf files and use
imagemagick to convert pdf files to png files.
`mathjax' Do MathJax preprocessing and arrange for MathJax.js to
be loaded.
t Synonym for `mathjax'."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type '(choice
(const :tag "Do not process math in any way" nil)
(const :tag "Use dvipng to make images" dvipng)
(const :tag "Use imagemagick to make images" imagemagick)
(const :tag "Use MathJax to display math" mathjax)
(const :tag "Leave math verbatim" verbatim)))
;;;; Links :: Generic
(defcustom org-html-link-org-files-as-html t
"Non-nil means make file links to `file.org' point to `file.html'.
When `org-mode' is exporting an `org-mode' file to HTML, links to
non-html files are directly put into a href tag in HTML.
However, links to other Org-mode files (recognized by the
extension `.org.) should become links to the corresponding html
file, assuming that the linked `org-mode' file will also be
converted to HTML.
When nil, the links still point to the plain `.org' file."
:group 'org-export-html
:type 'boolean)
;;;; Links :: Inline images
(defcustom org-html-inline-images t
"Non-nil means inline images into exported HTML pages.
This is done using an tag. When nil, an anchor with href is used to
link to the image."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.1")
:type 'boolean)
(defcustom org-html-inline-image-rules
'(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
"Rules characterizing image files that can be inlined into HTML.
A rule consists in an association whose key is the type of link
to consider, and value is a regexp that will be matched against
link's path."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type '(alist :key-type (string :tag "Type")
:value-type (regexp :tag "Path")))
;;;; Plain Text
(defcustom org-html-protect-char-alist
'(("&" . "&")
("<" . "<")
(">" . ">"))
"Alist of characters to be converted by `org-html-protect'."
:group 'org-export-html
:type '(repeat (cons (string :tag "Character")
(string :tag "HTML equivalent"))))
;;;; Src Block
(defcustom org-html-htmlize-output-type 'inline-css
"Output type to be used by htmlize when formatting code snippets.
Choices are `css' to export the CSS selectors only,`inline-css'
to export the CSS attribute values inline in the HTML or `nil' to
export plain text. We use as default `inline-css', in order to
make the resulting HTML self-containing.
However, this will fail when using Emacs in batch mode for export, because
then no rich font definitions are in place. It will also not be good if
people with different Emacs setup contribute HTML files to a website,
because the fonts will represent the individual setups. In these cases,
it is much better to let Org/Htmlize assign classes only, and to use
a style file to define the look of these classes.
To get a start for your css file, start Emacs session and make sure that
all the faces you are interested in are defined, for example by loading files
in all modes you want. Then, use the command
\\[org-html-htmlize-generate-css] to extract class definitions."
:group 'org-export-html
:type '(choice (const css) (const inline-css) (const nil)))
(defcustom org-html-htmlize-font-prefix "org-"
"The prefix for CSS class names for htmlize font specifications."
:group 'org-export-html
:type 'string)
;;;; Table
(defcustom org-html-table-default-attributes
'(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
"Default attributes and values which will be used in table tags.
This is a plist where attributes are symbols, starting with
colons, and values are strings.
When exporting to HTML5, these values will be disregarded."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type '(plist :key-type (symbol :tag "Property")
:value-type (string :tag "Value")))
(defcustom org-html-table-header-tags '("
" . "
")
"The opening and ending tags for table header fields.
This is customizable so that alignment options can be specified.
The first %s will be filled with the scope of the field, either row or col.
The second %s will be replaced by a style entry to align the field.
See also the variable `org-html-table-use-header-tags-for-first-column'.
See also the variable `org-html-table-align-individual-fields'."
:group 'org-export-html
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
(defcustom org-html-table-data-tags '("
" . "
")
"The opening and ending tags for table data fields.
This is customizable so that alignment options can be specified.
The first %s will be filled with the scope of the field, either row or col.
The second %s will be replaced by a style entry to align the field.
See also the variable `org-html-table-align-individual-fields'."
:group 'org-export-html
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
(defcustom org-html-table-row-tags '("
" . "
")
"The opening and ending tags for table rows.
This is customizable so that alignment options can be specified.
Instead of strings, these can be Lisp forms that will be
evaluated for each row in order to construct the table row tags.
During evaluation, these variables will be dynamically bound so that
you can reuse them:
`row-number': row number (0 is the first row)
`rowgroup-number': group number of current row
`start-rowgroup-p': non-nil means the row starts a group
`end-rowgroup-p': non-nil means the row ends a group
`top-row-p': non-nil means this is the top row
`bottom-row-p': non-nil means this is the bottom row
For example:
\(setq org-html-table-row-tags
(cons '(cond (top-row-p \"
\")
(bottom-row-p \"
\")
(t (if (= (mod row-number 2) 1)
\"
\"
\"
\")))
\"
\"))
will use the \"tr-top\" and \"tr-bottom\" classes for the top row
and the bottom row, and otherwise alternate between \"tr-odd\" and
\"tr-even\" for odd and even rows."
:group 'org-export-html
:type '(cons
(choice :tag "Opening tag"
(string :tag "Specify")
(sexp))
(choice :tag "Closing tag"
(string :tag "Specify")
(sexp))))
(defcustom org-html-table-align-individual-fields t
"Non-nil means attach style attributes for alignment to each table field.
When nil, alignment will only be specified in the column tags, but this
is ignored by some browsers (like Firefox, Safari). Opera does it right
though."
:group 'org-export-html
:type 'boolean)
(defcustom org-html-table-use-header-tags-for-first-column nil
"Non-nil means format column one in tables with header tags.
When nil, also column one will use data tags."
:group 'org-export-html
:type 'boolean)
(defcustom org-html-table-caption-above t
"When non-nil, place caption string at the beginning of the table.
Otherwise, place it near the end."
:group 'org-export-html
:type 'boolean)
;;;; Tags
(defcustom org-html-tag-class-prefix ""
"Prefix to class names for TODO keywords.
Each tag gets a class given by the tag itself, with this prefix.
The default prefix is empty because it is nice to just use the keyword
as a class name. But if you get into conflicts with other, existing
CSS classes, then this prefix can be very useful."
:group 'org-export-html
:type 'string)
;;;; Template :: Generic
(defcustom org-html-extension "html"
"The extension for exported HTML files."
:group 'org-export-html
:type 'string)
(defcustom org-html-xml-declaration
'(("html" . "")
("php" . "\"; ?>"))
"The extension for exported HTML files.
%s will be replaced with the charset of the exported file.
This may be a string, or an alist with export extensions
and corresponding declarations.
This declaration only applies when exporting to XHTML."
:group 'org-export-html
:type '(choice
(string :tag "Single declaration")
(repeat :tag "Dependent on extension"
(cons (string :tag "Extension")
(string :tag "Declaration")))))
(defcustom org-html-coding-system 'utf-8
"Coding system for HTML export.
Use utf-8 as the default value."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'coding-system)
(defcustom org-html-doctype "xhtml-strict"
"Document type definition to use for exported HTML files.
Can be set with the in-buffer HTML_DOCTYPE property or for
publishing, with :html-doctype."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type (append
'(choice)
(mapcar (lambda (x) `(const ,(car x))) org-html-doctype-alist)
'((string :tag "Custom doctype" ))))
(defcustom org-html-html5-fancy nil
"Non-nil means using new HTML5 elements.
This variable is ignored for anything other than HTML5 export.
For compatibility with Internet Explorer, it's probably a good
idea to download some form of the html5shiv (for instance
https://code.google.com/p/html5shiv/) and add it to your
HTML_HEAD_EXTRA, so that your pages don't break for users of IE
versions 8 and below."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'boolean)
(defcustom org-html-container-element "div"
"HTML element to use for wrapping top level sections.
Can be set with the in-buffer HTML_CONTAINER property or for
publishing, with :html-container.
Note that changing the default will prevent you from using
org-info.js for your website."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'string)
(defcustom org-html-divs
'((preamble "div" "preamble")
(content "div" "content")
(postamble "div" "postamble"))
"Alist of the three section elements for HTML export.
The car of each entry is one of 'preamble, 'content or 'postamble.
The cdrs of each entry are the ELEMENT_TYPE and ID for each
section of the exported document.
Note that changing the default will prevent you from using
org-info.js for your website."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type '(list :greedy t
(list :tag "Preamble"
(const :format "" preamble)
(string :tag "element") (string :tag " id"))
(list :tag "Content"
(const :format "" content)
(string :tag "element") (string :tag " id"))
(list :tag "Postamble" (const :format "" postamble)
(string :tag " id") (string :tag "element"))))
(defconst org-html-checkbox-types
'((unicode .
((on . "☑") (off . "☐") (trans . "☐")))
(ascii .
((on . "[X]")
(off . "[ ]")
(trans . "[-]")))
(html .
((on . "")
(off . "")
(trans . ""))))
"Alist of checkbox types.
The cdr of each entry is an alist list three checkbox types for
HTML export: `on', `off' and `trans'.
The choices are:
`unicode' Unicode characters (HTML entities)
`ascii' ASCII characters
`html' HTML checkboxes
Note that only the ascii characters implement tri-state
checkboxes. The other two use the `off' checkbox for `trans'.")
(defcustom org-html-checkbox-type 'ascii
"The type of checkboxes to use for HTML export.
See `org-html-checkbox-types' for for the values used for each
option."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type '(choice
(const :tag "ASCII characters" ascii)
(const :tag "Unicode characters" unicode)
(const :tag "HTML checkboxes" html)))
(defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
"Format used for timestamps in preamble, postamble and metadata.
See `format-time-string' for more information on its components."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'string)
;;;; Template :: Mathjax
(defcustom org-html-mathjax-options
'((path "http://orgmode.org/mathjax/MathJax.js")
(scale "100")
(align "center")
(indent "2em")
(mathml nil))
"Options for MathJax setup.
path The path where to find MathJax
scale Scaling for the HTML-CSS backend, usually between 100 and 133
align How to align display math: left, center, or right
indent If align is not center, how far from the left/right side?
mathml Should a MathML player be used if available?
This is faster and reduces bandwidth use, but currently
sometimes has lower spacing quality. Therefore, the default is
nil. When browsers get better, this switch can be flipped.
You can also customize this for each buffer, using something like
#+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
:group 'org-export-html
:type '(list :greedy t
(list :tag "path (the path from where to load MathJax.js)"
(const :format " " path) (string))
(list :tag "scale (scaling for the displayed math)"
(const :format " " scale) (string))
(list :tag "align (alignment of displayed equations)"
(const :format " " align) (string))
(list :tag "indent (indentation with left or right alignment)"
(const :format " " indent) (string))
(list :tag "mathml (should MathML display be used is possible)"
(const :format " " mathml) (boolean))))
(defcustom org-html-mathjax-template
"
"
"The MathJax setup for XHTML files."
:group 'org-export-html
:type 'string)
;;;; Template :: Postamble
(defcustom org-html-postamble 'auto
"Non-nil means insert a postamble in HTML export.
When set to 'auto, check against the
`org-export-with-author/email/creator/date' variables to set the
content of the postamble. When set to a string, use this string
as the postamble. When t, insert a string as defined by the
formatting string in `org-html-postamble-format'.
When set to a function, apply this function and insert the
returned string. The function takes the property list of export
options as its only argument.
Setting :html-postamble in publishing projects will take
precedence over this variable."
:group 'org-export-html
:type '(choice (const :tag "No postamble" nil)
(const :tag "Auto postamble" auto)
(const :tag "Default formatting string" t)
(string :tag "Custom formatting string")
(function :tag "Function (must return a string)")))
(defcustom org-html-postamble-format
'(("en" "
Author: %a (%e)
Date: %d
%c
%v
"))
"Alist of languages and format strings for the HTML postamble.
The first element of each list is the language code, as used for
the LANGUAGE keyword. See `org-export-default-language'.
The second element of each list is a format string to format the
postamble itself. This format string can contain these elements:
%t stands for the title.
%a stands for the author's name.
%e stands for the author's email.
%d stands for the date.
%c will be replaced by `org-html-creator-string'.
%v will be replaced by `org-html-validation-link'.
%T will be replaced by the export time.
%C will be replaced by the last modification time.
If you need to use a \"%\" character, you need to escape it
like that: \"%%\"."
:group 'org-export-html
:type '(repeat
(list (string :tag "Language")
(string :tag "Format string"))))
(defcustom org-html-validation-link
"Validate"
"Link to HTML validation service."
:group 'org-export-html
:type 'string)
(defcustom org-html-creator-string
(format "Emacs %s (Org mode %s)"
emacs-version
(if (fboundp 'org-version) (org-version) "unknown version"))
"Information about the creator of the HTML document.
This option can also be set on with the CREATOR keyword."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type '(string :tag "Creator string"))
;;;; Template :: Preamble
(defcustom org-html-preamble t
"Non-nil means insert a preamble in HTML export.
When t, insert a string as defined by the formatting string in
`org-html-preamble-format'. When set to a string, use this
formatting string instead (see `org-html-postamble-format' for an
example of such a formatting string).
When set to a function, apply this function and insert the
returned string. The function takes the property list of export
options as its only argument.
Setting :html-preamble in publishing projects will take
precedence over this variable."
:group 'org-export-html
:type '(choice (const :tag "No preamble" nil)
(const :tag "Default preamble" t)
(string :tag "Custom formatting string")
(function :tag "Function (must return a string)")))
(defcustom org-html-preamble-format '(("en" ""))
"Alist of languages and format strings for the HTML preamble.
The first element of each list is the language code, as used for
the LANGUAGE keyword. See `org-export-default-language'.
The second element of each list is a format string to format the
preamble itself. This format string can contain these elements:
%t stands for the title.
%a stands for the author's name.
%e stands for the author's email.
%d stands for the date.
%c will be replaced by `org-html-creator-string'.
%v will be replaced by `org-html-validation-link'.
%T will be replaced by the export time.
%C will be replaced by the last modification time.
If you need to use a \"%\" character, you need to escape it
like that: \"%%\".
See the default value of `org-html-postamble-format' for an
example."
:group 'org-export-html
:type '(repeat
(list (string :tag "Language")
(string :tag "Format string"))))
(defcustom org-html-link-up ""
"Where should the \"UP\" link of exported HTML pages lead?"
:group 'org-export-html
:type '(string :tag "File or URL"))
(defcustom org-html-link-home ""
"Where should the \"HOME\" link of exported HTML pages lead?"
:group 'org-export-html
:type '(string :tag "File or URL"))
(defcustom org-html-link-use-abs-url nil
"Should we prepend relative links with HTML_LINK_HOME?"
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.1")
:type 'boolean)
(defcustom org-html-home/up-format
"
"
"Snippet used to insert the HOME and UP links.
This is a format string, the first %s will receive the UP link,
the second the HOME link. If both `org-html-link-up' and
`org-html-link-home' are empty, the entire snippet will be
ignored."
:group 'org-export-html
:type 'string)
;;;; Template :: Scripts
(define-obsolete-variable-alias
'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
(defcustom org-html-head-include-scripts t
"Non-nil means include the JavaScript snippets in exported HTML files.
The actual script is defined in `org-html-scripts' and should
not be modified."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'boolean)
;;;; Template :: Styles
(define-obsolete-variable-alias
'org-html-style-include-default 'org-html-head-include-default-style "24.4")
(defcustom org-html-head-include-default-style t
"Non-nil means include the default style in exported HTML files.
The actual style is defined in `org-html-style-default' and
should not be modified. Use `org-html-head' to use your own
style information."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'boolean)
;;;###autoload
(put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
(define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
(defcustom org-html-head ""
"Org-wide head definitions for exported HTML files.
This variable can contain the full HTML structure to provide a
style, including the surrounding HTML tags. You can consider
including definitions for the following classes: title, todo,
done, timestamp, timestamp-kwd, tag, target.
For example, a valid value would be:
If you want to refer to an external style, use something like
As the value of this option simply gets inserted into the HTML
header, you can use it to add any arbitrary text to the
header.
You can set this on a per-file basis using #+HTML_HEAD:,
or for publication projects using the :html-head property."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'string)
;;;###autoload
(put 'org-html-head 'safe-local-variable 'stringp)
(defcustom org-html-head-extra ""
"More head information to add in the HTML output.
You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
or for publication projects using the :html-head-extra property."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
:type 'string)
;;;###autoload
(put 'org-html-head-extra 'safe-local-variable 'stringp)
;;;; Todos
(defcustom org-html-todo-kwd-class-prefix ""
"Prefix to class names for TODO keywords.
Each TODO keyword gets a class given by the keyword itself, with this prefix.
The default prefix is empty because it is nice to just use the keyword
as a class name. But if you get into conflicts with other, existing
CSS classes, then this prefix can be very useful."
:group 'org-export-html
:type 'string)
;;; Internal Functions
(defun org-html-xhtml-p (info)
(let ((dt (downcase (plist-get info :html-doctype))))
(string-match-p "xhtml" dt)))
(defun org-html-html5-p (info)
(let ((dt (downcase (plist-get info :html-doctype))))
(member dt '("html5" "xhtml5" ""))))
(defun org-html-close-tag (tag attr info)
(concat "<" tag " " attr
(if (org-html-xhtml-p info) " />" ">")))
(defun org-html-doctype (info)
"Return correct html doctype tag from `org-html-doctype-alist',
or the literal value of :html-doctype from INFO if :html-doctype
is not found in the alist.
INFO is a plist used as a communication channel."
(let ((dt (plist-get info :html-doctype)))
(or (cdr (assoc dt org-html-doctype-alist)) dt)))
(defun org-html--make-attribute-string (attributes)
"Return a list of attributes, as a string.
ATTRIBUTES is a plist where values are either strings or nil. An
attributes with a nil value will be omitted from the result."
(let (output)
(dolist (item attributes (mapconcat 'identity (nreverse output) " "))
(cond ((null item) (pop output))
((symbolp item) (push (substring (symbol-name item) 1) output))
(t (let ((key (car output))
(value (replace-regexp-in-string
"\"" """ (org-html-encode-plain-text item))))
(setcar output (format "%s=\"%s\"" key value))))))))
(defun org-html--wrap-image (contents info &optional caption label)
"Wrap CONTENTS string within an appropriate environment for images.
INFO is a plist used as a communication channel. When optional
arguments CAPTION and LABEL are given, use them for caption and
\"id\" attribute."
(let ((html5-fancy (and (org-html-html5-p info)
(plist-get info :html-html5-fancy))))
(format (if html5-fancy "\n"
"\n
")
caption)))))
(defun org-html--format-image (source attributes info)
"Return \"img\" tag with given SOURCE and ATTRIBUTES.
SOURCE is a string specifying the location of the image.
ATTRIBUTES is a plist, as returned by
`org-export-read-attribute'. INFO is a plist used as
a communication channel."
(if (string= "svg" (file-name-extension source))
(org-html--svg-image source attributes info)
(org-html-close-tag
"img"
(org-html--make-attribute-string
(org-combine-plists
(list :src source
:alt (if (string-match-p "^ltxpng/" source)
(org-html-encode-plain-text
(org-find-text-property-in-string 'org-latex-src source))
(file-name-nondirectory source)))
attributes))
info)))
(defun org-html--svg-image (source attributes info)
"Return \"object\" appropriate for embedding svg file SOURCE
with assoicated ATTRIBUTES. INFO is a plist used as a
communication channel.
The special attribute \"fallback\" can be used to specify a fallback
image file to use if the object embedding is not supported."
(let ((fallback (plist-get attributes :fallback))
(attrs (org-html--make-attribute-string
(plist-put attributes :fallback nil))))
(format ""
source attrs
(if fallback
(org-html-close-tag
"img" (format "src=\"%s\" %s" fallback attrs) info)
"Sorry, your browser does not support SVG."))))
(defun org-html--textarea-block (element)
"Transcode ELEMENT into a textarea block.
ELEMENT is either a src block or an example block."
(let* ((code (car (org-export-unravel-code element)))
(attr (org-export-read-attribute :attr_html element)))
(format "
\n\n
"
(or (plist-get attr :width) 80)
(or (plist-get attr :height) (org-count-lines code))
code)))
(defun org-html--has-caption-p (element &optional info)
"Non-nil when ELEMENT has a caption affiliated keyword.
INFO is a plist used as a communication channel. This function
is meant to be used as a predicate for `org-export-get-ordinal' or
a value to `org-html-standalone-image-predicate'."
(org-element-property :caption element))
;;;; Table
(defun org-html-htmlize-region-for-paste (beg end)
"Convert the region between BEG and END to HTML, using htmlize.el.
This is much like `htmlize-region-for-paste', only that it uses
the settings define in the org-... variables."
(let* ((htmlize-output-type org-html-htmlize-output-type)
(htmlize-css-name-prefix org-html-htmlize-font-prefix)
(htmlbuf (htmlize-region beg end)))
(unwind-protect
(with-current-buffer htmlbuf
(buffer-substring (plist-get htmlize-buffer-places 'content-start)
(plist-get htmlize-buffer-places 'content-end)))
(kill-buffer htmlbuf))))
;;;###autoload
(defun org-html-htmlize-generate-css ()
"Create the CSS for all font definitions in the current Emacs session.
Use this to create face definitions in your CSS style file that can then
be used by code snippets transformed by htmlize.
This command just produces a buffer that contains class definitions for all
faces used in the current Emacs session. You can copy and paste the ones you
need into your CSS file.
If you then set `org-html-htmlize-output-type' to `css', calls
to the function `org-html-htmlize-region-for-paste' will
produce code that uses these same face definitions."
(interactive)
(require 'htmlize)
(and (get-buffer "*html*") (kill-buffer "*html*"))
(with-temp-buffer
(let ((fl (face-list))
(htmlize-css-name-prefix "org-")
(htmlize-output-type 'css)
f i)
(while (setq f (pop fl)
i (and f (face-attribute f :inherit)))
(when (and (symbolp f) (or (not i) (not (listp i))))
(insert (org-add-props (copy-sequence "1") nil 'face f))))
(htmlize-region (point-min) (point-max))))
(org-pop-to-buffer-same-window "*html*")
(goto-char (point-min))
(if (re-search-forward "