1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; M-x org-export-as-html
29 ;; in an Org mode buffer. See ox.el for more details on how this
38 (require 'format-spec
)
39 (eval-when-compile (require 'cl
) (require 'table
))
43 ;;; Function Declarations
45 (declare-function org-id-find-id-file
"org-id" (id))
46 (declare-function htmlize-region
"ext:htmlize" (beg end
))
47 (declare-function org-pop-to-buffer-same-window
48 "org-compat" (&optional buffer-or-name norecord label
))
53 (org-export-define-backend html
54 ((bold . org-html-bold
)
55 (center-block . org-html-center-block
)
56 (clock . org-html-clock
)
57 (code . org-html-code
)
58 (drawer . org-html-drawer
)
59 (dynamic-block . org-html-dynamic-block
)
60 (entity . org-html-entity
)
61 (example-block . org-html-example-block
)
62 (export-block . org-html-export-block
)
63 (export-snippet . org-html-export-snippet
)
64 (fixed-width . org-html-fixed-width
)
65 (footnote-definition . org-html-footnote-definition
)
66 (footnote-reference . org-html-footnote-reference
)
67 (headline . org-html-headline
)
68 (horizontal-rule . org-html-horizontal-rule
)
69 (inline-src-block . org-html-inline-src-block
)
70 (inlinetask . org-html-inlinetask
)
71 (inner-template . org-html-inner-template
)
72 (italic . org-html-italic
)
73 (item . org-html-item
)
74 (keyword . org-html-keyword
)
75 (latex-environment . org-html-latex-environment
)
76 (latex-fragment . org-html-latex-fragment
)
77 (line-break . org-html-line-break
)
78 (link . org-html-link
)
79 (paragraph . org-html-paragraph
)
80 (plain-list . org-html-plain-list
)
81 (plain-text . org-html-plain-text
)
82 (planning . org-html-planning
)
83 (property-drawer . org-html-property-drawer
)
84 (quote-block . org-html-quote-block
)
85 (quote-section . org-html-quote-section
)
86 (radio-target . org-html-radio-target
)
87 (section . org-html-section
)
88 (special-block . org-html-special-block
)
89 (src-block . org-html-src-block
)
90 (statistics-cookie . org-html-statistics-cookie
)
91 (strike-through . org-html-strike-through
)
92 (subscript . org-html-subscript
)
93 (superscript . org-html-superscript
)
94 (table . org-html-table
)
95 (table-cell . org-html-table-cell
)
96 (table-row . org-html-table-row
)
97 (target . org-html-target
)
98 (template . org-html-template
)
99 (timestamp . org-html-timestamp
)
100 (underline . org-html-underline
)
101 (verbatim . org-html-verbatim
)
102 (verse-block . org-html-verse-block
))
104 :filters-alist
((:filter-options . org-html-infojs-install-script
)
105 (:filter-final-output . org-html-final-function
))
108 ((?H
"As HTML buffer" org-html-export-as-html
)
109 (?h
"As HTML file" org-html-export-to-html
)
110 (?o
"As HTML file and open"
112 (if a
(org-html-export-to-html t s v b
)
113 (org-open-file (org-html-export-to-html nil s v b
)))))))
115 ((:html-extension nil nil org-html-extension
)
116 (:html-doctype
"HTML_DOCTYPE" nil org-html-doctype
)
117 (:html-container
"HTML_CONTAINER" nil org-html-container-element
)
118 (:html-link-home
"HTML_LINK_HOME" nil org-html-link-home
)
119 (:html-link-up
"HTML_LINK_UP" nil org-html-link-up
)
120 (:html-mathjax
"HTML_MATHJAX" nil
"" space
)
121 (:html-postamble nil
"html-postamble" org-html-postamble
)
122 (:html-preamble nil
"html-preamble" org-html-preamble
)
123 (:html-head
"HTML_HEAD" nil org-html-head newline
)
124 (:html-head-extra
"HTML_HEAD_EXTRA" nil org-html-head-extra newline
)
125 (:html-head-include-default-style
"HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline
)
126 (:html-head-include-scripts
"HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline
)
127 (:html-table-tag nil nil org-html-table-tag
)
128 ;; Redefine regular options.
129 (:creator
"CREATOR" nil org-html-creator-string
)
130 (:with-latex nil
"tex" org-html-with-latex
)
131 ;; Leave room for "ox-infojs.el" extension.
132 (:infojs-opt
"INFOJS_OPT" nil nil
)))
136 ;;; Internal Variables
138 (defvar org-html-format-table-no-css
)
139 (defvar htmlize-buffer-places
) ; from htmlize.el
141 (defconst org-html-special-string-regexps
142 '(("\\\\-" .
"­") ; shy
143 ("---\\([^-]\\)" .
"—\\1") ; mdash
144 ("--\\([^-]\\)" .
"–\\1") ; ndash
145 ("\\.\\.\\." .
"…")) ; hellip
146 "Regular expressions for special string conversion.")
148 (defconst org-html-scripts
149 "<script type=\"text/javascript\">
151 @licstart The following is the entire license notice for the
152 JavaScript code in this tag.
154 Copyright (C) 2012 Free Software Foundation, Inc.
156 The JavaScript code in this tag is free software: you can
157 redistribute it and/or modify it under the terms of the GNU
158 General Public License (GNU GPL) as published by the Free Software
159 Foundation, either version 3 of the License, or (at your option)
160 any later version. The code is distributed WITHOUT ANY WARRANTY;
161 without even the implied warranty of MERCHANTABILITY or FITNESS
162 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
164 As additional permission under GNU GPL version 3 section 7, you
165 may distribute non-source (e.g., minimized or compacted) forms of
166 that code without the copy of the GNU GPL normally required by
167 section 4, provided you include this license notice and a URL
168 through which recipients can access the Corresponding Source.
171 @licend The above is the entire license notice
172 for the JavaScript code in this tag.
174 <!--/*--><![CDATA[/*><!--*/
175 function CodeHighlightOn(elem, id)
177 var target = document.getElementById(id);
179 elem.cacheClassElem = elem.className;
180 elem.cacheClassTarget = target.className;
181 target.className = \"code-highlighted\";
182 elem.className = \"code-highlighted\";
185 function CodeHighlightOff(elem, id)
187 var target = document.getElementById(id);
188 if(elem.cacheClassElem)
189 elem.className = elem.cacheClassElem;
190 if(elem.cacheClassTarget)
191 target.className = elem.cacheClassTarget;
195 "Basic JavaScript that is needed by HTML files produced by Org mode.")
197 (defconst org-html-style-default
198 "<style type=\"text/css\">
199 <!--/*--><![CDATA[/*><!--*/
200 .title { text-align: center; }
201 .todo { font-family: monospace; color: red; }
202 .done { color: green; }
203 .tag { background-color: #eee; font-family: monospace;
204 padding: 2px; font-size: 80%; font-weight: normal; }
205 .timestamp { color: #bebebe; }
206 .timestamp-kwd { color: #5f9ea0; }
207 .right { margin-left: auto; margin-right: 0px; text-align: right; }
208 .left { margin-left: 0px; margin-right: auto; text-align: left; }
209 .center { margin-left: auto; margin-right: auto; text-align: center; }
210 #content { margin: 3em; }
211 #postamble p, a { font-size: 90%; margin: .2em; }
212 p.verse { margin-left: 3%; }
214 border: 1px solid #ccc;
215 box-shadow: 3px 3px 3px #eee;
217 font-family: monospace;
229 background-color: white;
233 border: 1px solid black;
235 pre.src:hover:before { display: inline;}
236 pre.src-sh:before { content: 'sh'; }
237 pre.src-bash:before { content: 'sh'; }
238 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
239 pre.src-R:before { content: 'R'; }
240 pre.src-perl:before { content: 'Perl'; }
241 pre.src-java:before { content: 'Java'; }
242 pre.src-sql:before { content: 'SQL'; }
244 table { border-collapse:collapse; }
245 td, th { vertical-align:top; }
246 th.right { text-align:center; }
247 th.left { text-align:center; }
248 th.center { text-align:center; }
249 td.right { text-align:right; }
250 td.left { text-align:left; }
251 td.center { text-align:center; }
252 dt { font-weight: bold; }
253 div.figure { padding:1em; }
254 div.figure p { text-align:center; }
257 border:2px solid gray;
261 textarea { overflow-x:auto; }
262 .linenr { font-size:smaller }
263 .code-highlighted { background-color:#ffff00; }
264 .org-info-js_info-navigation { border-style:none; }
265 #org-info-js_console-label
266 { font-size:10px; font-weight:bold; white-space:nowrap; }
267 .org-info-js_search-highlight
268 { background-color:#ffff00; color:#000000; font-weight:bold; }
271 "The default style specification for exported HTML files.
272 You can use `org-html-head' and `org-html-head-extra' to add to
273 this style. If you don't want to include this default style,
274 customize `org-html-head-include-default-style'.")
278 ;;; User Configuration Variables
280 (defgroup org-export-html nil
281 "Options for exporting Org mode files to HTML."
282 :tag
"Org Export HTML"
288 (defvar org-html-infojs-opts-table
289 '((path PATH
"http://orgmode.org/org-info.js")
293 (tdepth TOC_DEPTH
"max")
294 (sdepth SECTION_DEPTH
"max")
295 (mouse MOUSE_HINT
"underline")
296 (buttons VIEW_BUTTONS
"0")
298 (up LINK_UP
:html-link-up
)
299 (home LINK_HOME
:html-link-home
))
300 "JavaScript options, long form for script, default values.")
302 (defcustom org-html-use-infojs
'when-configured
303 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
304 This option can be nil or t to never or always use the script.
305 It can also be the symbol `when-configured', meaning that the
306 script will be linked into the export file if and only if there
307 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
308 `org-html-infojs-options'."
309 :group
'org-export-html
311 :package-version
'(Org .
"8.0")
313 (const :tag
"Never" nil
)
314 (const :tag
"When configured in buffer" when-configured
)
315 (const :tag
"Always" t
)))
317 (defcustom org-html-infojs-options
318 (mapcar (lambda (x) (cons (car x
) (nth 2 x
))) org-html-infojs-opts-table
)
319 "Options settings for the INFOJS JavaScript.
320 Each of the options must have an entry in `org-html-infojs-opts-table'.
321 The value can either be a string that will be passed to the script, or
322 a property. This property is then assumed to be a property that is defined
323 by the Export/Publishing setup of Org.
324 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
325 means to use the maximum value consistent with other options."
326 :group
'org-export-html
328 :package-version
'(Org .
"8.0")
330 `(set :greedy t
:inline t
333 (list 'cons
(list 'const
(car x
))
335 (symbol :tag
"Publishing/Export property")
336 (string :tag
"Value"))))
337 org-html-infojs-opts-table
)))
339 (defcustom org-html-infojs-template
340 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
343 * @source: %SCRIPT_PATH
345 * @licstart The following is the entire license notice for the
346 * JavaScript code in %SCRIPT_PATH.
348 * Copyright (C) 2012-2013 Sebastian Rose
351 * The JavaScript code in this tag is free software: you can
352 * redistribute it and/or modify it under the terms of the GNU
353 * General Public License (GNU GPL) as published by the Free Software
354 * Foundation, either version 3 of the License, or (at your option)
355 * any later version. The code is distributed WITHOUT ANY WARRANTY;
356 * without even the implied warranty of MERCHANTABILITY or FITNESS
357 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
359 * As additional permission under GNU GPL version 3 section 7, you
360 * may distribute non-source (e.g., minimized or compacted) forms of
361 * that code without the copy of the GNU GPL normally required by
362 * section 4, provided you include this license notice and a URL
363 * through which recipients can access the Corresponding Source.
365 * @licend The above is the entire license notice
366 * for the JavaScript code in %SCRIPT_PATH.
371 <script type=\"text/javascript\">
374 @licstart The following is the entire license notice for the
375 JavaScript code in this tag.
377 Copyright (C) 2012-2013 Free Software Foundation, Inc.
379 The JavaScript code in this tag is free software: you can
380 redistribute it and/or modify it under the terms of the GNU
381 General Public License (GNU GPL) as published by the Free Software
382 Foundation, either version 3 of the License, or (at your option)
383 any later version. The code is distributed WITHOUT ANY WARRANTY;
384 without even the implied warranty of MERCHANTABILITY or FITNESS
385 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
387 As additional permission under GNU GPL version 3 section 7, you
388 may distribute non-source (e.g., minimized or compacted) forms of
389 that code without the copy of the GNU GPL normally required by
390 section 4, provided you include this license notice and a URL
391 through which recipients can access the Corresponding Source.
394 @licend The above is the entire license notice
395 for the JavaScript code in this tag.
398 <!--/*--><![CDATA[/*><!--*/
400 org_html_manager.setup(); // activate after the parameters are set
403 "The template for the export style additions when org-info.js is used.
404 Option settings will replace the %MANAGER-OPTIONS cookie."
405 :group
'org-export-html
407 :package-version
'(Org .
"8.0")
410 (defun org-html-infojs-install-script (exp-plist backend
)
411 "Install script in export options when appropriate.
412 EXP-PLIST is a plist containing export options. BACKEND is the
413 export back-end currently used."
414 (unless (or (memq 'body-only
(plist-get exp-plist
:export-options
))
415 (not org-html-use-infojs
)
416 (and (eq org-html-use-infojs
'when-configured
)
417 (or (not (plist-get exp-plist
:infojs-opt
))
418 (string-match "\\<view:nil\\>"
419 (plist-get exp-plist
:infojs-opt
)))))
420 (let* ((template org-html-infojs-template
)
421 (ptoc (plist-get exp-plist
:with-toc
))
422 (hlevels (plist-get exp-plist
:headline-levels
))
424 (tdepth (if (integerp ptoc
) (min ptoc hlevels
) hlevels
))
425 (options (plist-get exp-plist
:infojs-opt
))
426 (table org-html-infojs-opts-table
)
428 (dolist (entry table
)
429 (let* ((opt (car entry
))
431 ;; Compute default values for script option OPT from
432 ;; `org-html-infojs-options' variable.
434 (let ((default (cdr (assq opt org-html-infojs-options
))))
435 (if (and (symbolp default
) (not (memq default
'(t nil
))))
436 (plist-get exp-plist default
)
438 ;; Value set through INFOJS_OPT keyword has precedence
439 ;; over the default one.
440 (val (if (and options
441 (string-match (format "\\<%s:\\(\\S-+\\)" opt
)
443 (match-string 1 options
)
447 (replace-regexp-in-string
448 "%SCRIPT_PATH" val template t t
)))
449 (sdepth (when (integerp (read val
))
450 (setq sdepth
(min (read val
) sdepth
))))
451 (tdepth (when (integerp (read val
))
452 (setq tdepth
(min (read val
) tdepth
))))
455 ((or (eq val t
) (equal val
"t")) "1")
456 ((or (eq val nil
) (equal val
"nil")) "0")
458 (t (format "%s" val
))))
459 (push (cons var val
) style
)))))
460 ;; Now we set the depth of the *generated* TOC to SDEPTH,
461 ;; because the toc will actually determine the splitting. How
462 ;; much of the toc will actually be displayed is governed by the
464 (setq exp-plist
(plist-put exp-plist
:with-toc sdepth
))
465 ;; The table of contents should not show more sections than we
467 (setq tdepth
(min tdepth sdepth
))
468 (push (cons "TOC_DEPTH" tdepth
) style
)
469 ;; Build style string.
470 (setq style
(mapconcat
471 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
475 (when (and style
(> (length style
) 0))
476 (and (string-match "%MANAGER_OPTIONS" template
)
477 (setq style
(replace-match style t t template
))
480 exp-plist
:html-head-extra
481 (concat (or (plist-get exp-plist
:html-head-extra
) "")
484 ;; This script absolutely needs the table of contents, so we
485 ;; change that setting.
486 (unless (plist-get exp-plist
:with-toc
)
487 (setq exp-plist
(plist-put exp-plist
:with-toc t
)))
488 ;; Return the modified property list.
494 (defcustom org-html-text-markup-alist
495 '((bold .
"<b>%s</b>")
496 (code .
"<code>%s</code>")
497 (italic .
"<i>%s</i>")
498 (strike-through .
"<del>%s</del>")
499 (underline .
"<span style=\"text-decoration:underline;\">%s</span>")
500 (verbatim .
"<code>%s</code>"))
501 "Alist of HTML expressions to convert text markup.
503 The key must be a symbol among `bold', `code', `italic',
504 `strike-through', `underline' and `verbatim'. The value is
505 a formatting string to wrap fontified text with.
507 If no association can be found for a given markup, text will be
509 :group
'org-export-html
510 :type
'(alist :key-type
(symbol :tag
"Markup type")
511 :value-type
(string :tag
"Format string"))
512 :options
'(bold code italic strike-through underline verbatim
))
514 (defcustom org-html-pretty-output nil
515 "Enable this to generate pretty HTML."
516 :group
'org-export-html
518 :package-version
'(Org .
"8.0")
523 (defcustom org-html-format-drawer-function nil
524 "Function called to format a drawer in HTML code.
526 The function must accept two parameters:
527 NAME the drawer name, like \"LOGBOOK\"
528 CONTENTS the contents of the drawer.
530 The function should return the string to be exported.
532 For example, the variable could be set to the following function
533 in order to mimic default behaviour:
535 \(defun org-html-format-drawer-default \(name contents\)
536 \"Format a drawer element for HTML export.\"
538 :group
'org-export-html
544 (defcustom org-html-footnotes-section
"<div id=\"footnotes\">
545 <h2 class=\"footnotes\">%s: </h2>
546 <div id=\"text-footnotes\">
550 "Format for the footnotes section.
551 Should contain a two instances of %s. The first will be replaced with the
552 language-specific word for \"Footnotes\", the second one will be replaced
553 by the footnotes themselves."
554 :group
'org-export-html
557 (defcustom org-html-footnote-format
"<sup>%s</sup>"
558 "The format for the footnote reference.
559 %s will be replaced by the footnote reference itself."
560 :group
'org-export-html
563 (defcustom org-html-footnote-separator
"<sup>, </sup>"
564 "Text used to separate footnotes."
565 :group
'org-export-html
571 (defcustom org-html-toplevel-hlevel
2
572 "The <H> level for level 1 headings in HTML export.
573 This is also important for the classes that will be wrapped around headlines
574 and outline structure. If this variable is 1, the top-level headlines will
575 be <h1>, and the corresponding classes will be outline-1, section-number-1,
576 and outline-text-1. If this is 2, all of these will get a 2 instead.
577 The default for this variable is 2, because we use <h1> for formatting the
579 :group
'org-export-html
582 (defcustom org-html-format-headline-function nil
583 "Function to format headline text.
585 This function will be called with 5 arguments:
586 TODO the todo keyword (string or nil).
587 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
588 PRIORITY the priority of the headline (integer or nil)
589 TEXT the main headline text (string).
590 TAGS the tags (string or nil).
592 The function result will be used in the section format string."
593 :group
'org-export-html
599 (defcustom org-html-allow-name-attribute-in-anchors t
600 "When nil, do not set \"name\" attribute in anchors.
601 By default, anchors are formatted with both \"id\" and \"name\"
602 attributes, when appropriate."
603 :group
'org-export-html
605 :package-version
'(Org .
"8.0")
611 (defcustom org-html-format-inlinetask-function nil
612 "Function called to format an inlinetask in HTML code.
614 The function must accept six parameters:
615 TODO the todo keyword, as a string
616 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
617 PRIORITY the inlinetask priority, as a string
618 NAME the inlinetask name, as a string.
619 TAGS the inlinetask tags, as a list of strings.
620 CONTENTS the contents of the inlinetask, as a string.
622 The function should return the string to be exported."
623 :group
'org-export-html
629 (defcustom org-html-with-latex org-export-with-latex
630 "Non-nil means process LaTeX math snippets.
632 When set, the exporter will process LaTeX environments and
635 This option can also be set with the +OPTIONS line,
636 e.g. \"tex:mathjax\". Allowed values are:
638 nil Ignore math snippets.
639 `verbatim' Keep everything in verbatim
640 `dvipng' Process the LaTeX fragments to images. This will also
641 include processing of non-math environments.
642 `imagemagick' Convert the LaTeX fragments to pdf files and use
643 imagemagick to convert pdf files to png files.
644 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
646 t Synonym for `mathjax'."
647 :group
'org-export-html
649 :package-version
'(Org .
"8.0")
651 (const :tag
"Do not process math in any way" nil
)
652 (const :tag
"Use dvipng to make images" dvipng
)
653 (const :tag
"Use imagemagick to make images" imagemagick
)
654 (const :tag
"Use MathJax to display math" mathjax
)
655 (const :tag
"Leave math verbatim" verbatim
)))
658 ;;;; Links :: Generic
660 (defcustom org-html-link-org-files-as-html t
661 "Non-nil means make file links to `file.org' point to `file.html'.
662 When `org-mode' is exporting an `org-mode' file to HTML, links to
663 non-html files are directly put into a href tag in HTML.
664 However, links to other Org-mode files (recognized by the
665 extension `.org.) should become links to the corresponding html
666 file, assuming that the linked `org-mode' file will also be
668 When nil, the links still point to the plain `.org' file."
669 :group
'org-export-html
673 ;;;; Links :: Inline images
675 (defcustom org-html-inline-images
'maybe
676 "Non-nil means inline images into exported HTML pages.
677 This is done using an <img> tag. When nil, an anchor with href is used to
678 link to the image. If this option is `maybe', then images in links with
679 an empty description will be inlined, while images with a description will
681 :group
'org-export-html
682 :type
'(choice (const :tag
"Never" nil
)
683 (const :tag
"Always" t
)
684 (const :tag
"When there is no description" maybe
)))
686 (defcustom org-html-inline-image-rules
687 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
688 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
689 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
690 "Rules characterizing image files that can be inlined into HTML.
692 A rule consists in an association whose key is the type of link
693 to consider, and value is a regexp that will be matched against
696 Note that, by default, the image extension *actually* allowed
697 depend on the way the HTML file is processed. When used with
698 pdflatex, pdf, jpg and png images are OK. When processing
699 through dvi to Postscript, only ps and eps are allowed. The
700 default we use here encompasses both."
701 :group
'org-export-html
703 :package-version
'(Org .
"8.0")
704 :type
'(alist :key-type
(string :tag
"Type")
705 :value-type
(regexp :tag
"Path")))
710 (defcustom org-html-protect-char-alist
714 "Alist of characters to be converted by `org-html-protect'."
715 :group
'org-export-html
716 :type
'(repeat (cons (string :tag
"Character")
717 (string :tag
"HTML equivalent"))))
722 (defcustom org-html-htmlize-output-type
'inline-css
723 "Output type to be used by htmlize when formatting code snippets.
724 Choices are `css', to export the CSS selectors only, or `inline-css', to
725 export the CSS attribute values inline in the HTML. We use as default
726 `inline-css', in order to make the resulting HTML self-containing.
728 However, this will fail when using Emacs in batch mode for export, because
729 then no rich font definitions are in place. It will also not be good if
730 people with different Emacs setup contribute HTML files to a website,
731 because the fonts will represent the individual setups. In these cases,
732 it is much better to let Org/Htmlize assign classes only, and to use
733 a style file to define the look of these classes.
734 To get a start for your css file, start Emacs session and make sure that
735 all the faces you are interested in are defined, for example by loading files
736 in all modes you want. Then, use the command
737 \\[org-html-htmlize-generate-css] to extract class definitions."
738 :group
'org-export-html
739 :type
'(choice (const css
) (const inline-css
)))
741 (defcustom org-html-htmlize-font-prefix
"org-"
742 "The prefix for CSS class names for htmlize font specifications."
743 :group
'org-export-html
748 (defcustom org-html-table-tag
749 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
750 "The HTML tag that is used to start a table.
751 This must be a <table> tag, but you may change the options like
752 borders and spacing."
753 :group
'org-export-html
756 (defcustom org-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
757 "The opening tag for table header fields.
758 This is customizable so that alignment options can be specified.
759 The first %s will be filled with the scope of the field, either row or col.
760 The second %s will be replaced by a style entry to align the field.
761 See also the variable `org-html-table-use-header-tags-for-first-column'.
762 See also the variable `org-html-table-align-individual-fields'."
763 :group
'org-export-html
764 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
766 (defcustom org-html-table-data-tags
'("<td%s>" .
"</td>")
767 "The opening tag for table data fields.
768 This is customizable so that alignment options can be specified.
769 The first %s will be filled with the scope of the field, either row or col.
770 The second %s will be replaced by a style entry to align the field.
771 See also the variable `org-html-table-align-individual-fields'."
772 :group
'org-export-html
773 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
775 (defcustom org-html-table-row-tags
'("<tr>" .
"</tr>")
776 "The opening tag for table data fields.
777 This is customizable so that alignment options can be specified.
778 Instead of strings, these can be Lisp forms that will be evaluated
779 for each row in order to construct the table row tags. During evaluation,
780 the variable `head' will be true when this is a header line, nil when this
781 is a body line. And the variable `nline' will contain the line number,
782 starting from 1 in the first header line. For example
784 (setq org-html-table-row-tags
787 (if (= (mod nline 2) 1)
788 \"<tr class=\\\"tr-odd\\\">\"
789 \"<tr class=\\\"tr-even\\\">\"))
792 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
793 :group
'org-export-html
795 (choice :tag
"Opening tag"
796 (string :tag
"Specify")
798 (choice :tag
"Closing tag"
799 (string :tag
"Specify")
802 (defcustom org-html-table-align-individual-fields t
803 "Non-nil means attach style attributes for alignment to each table field.
804 When nil, alignment will only be specified in the column tags, but this
805 is ignored by some browsers (like Firefox, Safari). Opera does it right
807 :group
'org-export-html
810 (defcustom org-html-table-use-header-tags-for-first-column nil
811 "Non-nil means format column one in tables with header tags.
812 When nil, also column one will use data tags."
813 :group
'org-export-html
816 (defcustom org-html-table-caption-above t
817 "When non-nil, place caption string at the beginning of the table.
818 Otherwise, place it near the end."
819 :group
'org-export-html
825 (defcustom org-html-tag-class-prefix
""
826 "Prefix to class names for TODO keywords.
827 Each tag gets a class given by the tag itself, with this prefix.
828 The default prefix is empty because it is nice to just use the keyword
829 as a class name. But if you get into conflicts with other, existing
830 CSS classes, then this prefix can be very useful."
831 :group
'org-export-html
835 ;;;; Template :: Generic
837 (defcustom org-html-extension
"html"
838 "The extension for exported HTML files."
839 :group
'org-export-html
842 (defcustom org-html-xml-declaration
843 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
844 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
845 "The extension for exported HTML files.
846 %s will be replaced with the charset of the exported file.
847 This may be a string, or an alist with export extensions
848 and corresponding declarations."
849 :group
'org-export-html
851 (string :tag
"Single declaration")
852 (repeat :tag
"Dependent on extension"
853 (cons (string :tag
"Extension")
854 (string :tag
"Declaration")))))
856 (defcustom org-html-coding-system
'utf-8
857 "Coding system for HTML export.
858 Use utf-8 as the default value."
859 :group
'org-export-html
861 :package-version
'(Org .
"8.0")
862 :type
'coding-system
)
864 (defcustom org-html-doctype
865 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
866 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
867 "Document type definition to use for exported HTML files.
868 Can be set with the in-buffer HTML_DOCTYPE property or for
869 publishing, with :html-doctype."
870 :group
'org-export-html
872 :package-version
'(Org .
"8.0")
875 (defcustom org-html-container-element
"div"
876 "Container class to use for wrapping top level sections.
877 Can be set with the in-buffer HTML_CONTAINER property or for
878 publishing, with :html-container."
879 :group
'org-export-html
881 :package-version
'(Org .
"8.0")
884 (defcustom org-html-divs
885 '((preamble "div" "preamble")
886 (content "div" "content")
887 (postamble "div" "postamble"))
888 "Alist of the threed section elements for HTML export.
889 The car of each entry is one of 'preamble, 'content or 'postamble.
890 The cdrs of each entry are the ELEMENT_TYPE and ID for each
891 section of the exported document."
892 :group
'org-export-html
894 :package-version
'(Org .
"8.0")
895 :type
'(list :greedy t
896 (list :tag
"Preamble"
897 (const :format
"" preamble
)
898 (string :tag
"element") (string :tag
" id"))
900 (const :format
"" content
)
901 (string :tag
"element") (string :tag
" id"))
902 (list :tag
"Postamble" (const :format
"" postamble
)
903 (string :tag
" id") (string :tag
"element"))))
905 ;;;; Template :: Mathjax
907 (defcustom org-html-mathjax-options
908 '((path "http://orgmode.org/mathjax/MathJax.js")
913 "Options for MathJax setup.
915 path The path where to find MathJax
916 scale Scaling for the HTML-CSS backend, usually between 100 and 133
917 align How to align display math: left, center, or right
918 indent If align is not center, how far from the left/right side?
919 mathml Should a MathML player be used if available?
920 This is faster and reduces bandwidth use, but currently
921 sometimes has lower spacing quality. Therefore, the default is
922 nil. When browsers get better, this switch can be flipped.
924 You can also customize this for each buffer, using something like
926 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
927 :group
'org-export-html
928 :type
'(list :greedy t
929 (list :tag
"path (the path from where to load MathJax.js)"
930 (const :format
" " path
) (string))
931 (list :tag
"scale (scaling for the displayed math)"
932 (const :format
" " scale
) (string))
933 (list :tag
"align (alignment of displayed equations)"
934 (const :format
" " align
) (string))
935 (list :tag
"indent (indentation with left or right alignment)"
936 (const :format
" " indent
) (string))
937 (list :tag
"mathml (should MathML display be used is possible)"
938 (const :format
" " mathml
) (boolean))))
940 (defcustom org-html-mathjax-template
941 "<script type=\"text/javascript\" src=\"%PATH\">
942 <!--/*--><![CDATA[/*><!--*/
944 // Only one of the two following lines, depending on user settings
945 // First allows browser-native MathML display, second forces HTML/CSS
946 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
947 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
948 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
949 \"TeX/noUndefined.js\"],
951 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
952 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
953 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
954 ignoreClass: \"tex2jax_ignore\",
955 processEscapes: false,
956 processEnvironments: true,
959 showProcessingMessages: true,
960 displayAlign: \"%ALIGN\",
961 displayIndent: \"%INDENT\",
965 availableFonts: [\"STIX\",\"TeX\"],
966 preferredFont: \"TeX\",
982 "The MathJax setup for XHTML files."
983 :group
'org-export-html
987 ;;;; Template :: Postamble
989 (defcustom org-html-postamble
'auto
990 "Non-nil means insert a postamble in HTML export.
992 When set to 'auto, check against the
993 `org-export-with-author/email/creator/date' variables to set the
994 content of the postamble. When set to a string, use this string
995 as the postamble. When t, insert a string as defined by the
996 formatting string in `org-html-postamble-format'.
998 When set to a function, apply this function and insert the
999 returned string. The function takes the property list of export
1000 options as its only argument.
1002 Setting :html-postamble in publishing projects will take
1003 precedence over this variable."
1004 :group
'org-export-html
1005 :type
'(choice (const :tag
"No postamble" nil
)
1006 (const :tag
"Auto postamble" 'auto
)
1007 (const :tag
"Default formatting string" t
)
1008 (string :tag
"Custom formatting string")
1009 (function :tag
"Function (must return a string)")))
1011 (defcustom org-html-postamble-format
1012 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1013 <p class=\"date\">Date: %d</p>
1014 <p class=\"creator\">Generated by %c</p>
1015 <p class=\"xhtml-validation\">%v</p>"))
1016 "Alist of languages and format strings for the HTML postamble.
1018 The first element of each list is the language code, as used for
1019 the #+LANGUAGE keyword.
1021 The second element of each list is a format string to format the
1022 postamble itself. This format string can contain these elements:
1024 %a stands for the author's name.
1025 %e stands for the author's email.
1026 %d stands for the date.
1027 %c will be replaced by information about Org/Emacs versions.
1028 %v will be replaced by `org-html-validation-link'.
1030 If you need to use a \"%\" character, you need to escape it
1032 :group
'org-export-html
1033 :type
'(alist :key-type
(string :tag
"Language")
1034 :value-type
(string :tag
"Format string")))
1036 (defcustom org-html-validation-link
1037 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1038 "Link to HTML validation service."
1039 :group
'org-export-html
1042 (defcustom org-html-creator-string
1043 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
1044 (if (fboundp 'org-version
) (org-version) "(Unknown)")
1046 "String to insert at the end of the HTML document."
1047 :group
'org-export-html
1048 :type
'(string :tag
"Creator string"))
1051 ;;;; Template :: Preamble
1053 (defcustom org-html-preamble t
1054 "Non-nil means insert a preamble in HTML export.
1056 When t, insert a string as defined by the formatting string in
1057 `org-html-preamble-format'. When set to a string, use this
1058 formatting string instead (see `org-html-postamble-format' for an
1059 example of such a formatting string).
1061 When set to a function, apply this function and insert the
1062 returned string. The function takes the property list of export
1063 options as its only argument.
1065 Setting :html-preamble in publishing projects will take
1066 precedence over this variable."
1067 :group
'org-export-html
1068 :type
'(choice (const :tag
"No preamble" nil
)
1069 (const :tag
"Default preamble" t
)
1070 (string :tag
"Custom formatting string")
1071 (function :tag
"Function (must return a string)")))
1073 (defcustom org-html-preamble-format
'(("en" ""))
1074 "Alist of languages and format strings for the HTML preamble.
1076 The first element of each list is the language code, as used for
1077 the #+LANGUAGE keyword.
1079 The second element of each list is a format string to format the
1080 preamble itself. This format string can contain these elements:
1082 %t stands for the title.
1083 %a stands for the author's name.
1084 %e stands for the author's email.
1085 %d stands for the date.
1087 If you need to use a \"%\" character, you need to escape it
1090 See the default value of `org-html-postamble-format' for an
1092 :group
'org-export-html
1093 :type
'(alist :key-type
(string :tag
"Language")
1094 :value-type
(string :tag
"Format string")))
1096 (defcustom org-html-link-up
""
1097 "Where should the \"UP\" link of exported HTML pages lead?"
1098 :group
'org-export-html
1099 :type
'(string :tag
"File or URL"))
1101 (defcustom org-html-link-home
""
1102 "Where should the \"HOME\" link of exported HTML pages lead?"
1103 :group
'org-export-html
1104 :type
'(string :tag
"File or URL"))
1106 (defcustom org-html-home
/up-format
1107 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
1108 <a accesskey=\"h\" href=\"%s\"> UP </a>
1110 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1112 "Snippet used to insert the HOME and UP links.
1113 This is a format string, the first %s will receive the UP link,
1114 the second the HOME link. If both `org-html-link-up' and
1115 `org-html-link-home' are empty, the entire snippet will be
1117 :group
'org-export-html
1121 ;;;; Template :: Scripts
1123 (define-obsolete-variable-alias
1124 'org-html-style-include-scripts
'org-html-head-include-scripts
"24.4")
1125 (defcustom org-html-head-include-scripts t
1126 "Non-nil means include the JavaScript snippets in exported HTML files.
1127 The actual script is defined in `org-html-scripts' and should
1129 :group
'org-export-html
1131 :package-version
'(Org .
"8.0")
1135 ;;;; Template :: Styles
1137 (define-obsolete-variable-alias
1138 'org-html-style-include-default
'org-html-head-include-default-style
"24.4")
1139 (defcustom org-html-head-include-default-style t
1140 "Non-nil means include the default style in exported HTML files.
1141 The actual style is defined in `org-html-style-default' and
1142 should not be modified. Use `org-html-head' to use your own
1144 :group
'org-export-html
1146 :package-version
'(Org .
"8.0")
1149 (put 'org-html-head-include-default-style
'safe-local-variable
'booleanp
)
1151 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
1152 (defcustom org-html-head
""
1153 "Org-wide head definitions for exported HTML files.
1155 This variable can contain the full HTML structure to provide a
1156 style, including the surrounding HTML tags. You can consider
1157 including definitions for the following classes: title, todo,
1158 done, timestamp, timestamp-kwd, tag, target.
1160 For example, a valid value would be:
1162 <style type=\"text/css\">
1164 p { font-weight: normal; color: gray; }
1165 h1 { color: black; }
1166 .title { text-align: center; }
1167 .todo, .timestamp-kwd { color: red; }
1168 .done { color: green; }
1172 If you want to refer to an external style, use something like
1174 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1176 As the value of this option simply gets inserted into the HTML
1177 <head> header, you can use it to add any arbitrary text to the
1180 You can set this on a per-file basis using #+HTML_HEAD:,
1181 or for publication projects using the :html-head property."
1182 :group
'org-export-html
1184 :package-version
'(Org .
"8.0")
1187 (put 'org-html-head
'safe-local-variable
'stringp
)
1190 (defcustom org-html-head-extra
""
1191 "More head information to add in the HTML output.
1193 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1194 or for publication projects using the :html-head-extra property."
1195 :group
'org-export-html
1197 :package-version
'(Org .
"8.0")
1200 (put 'org-html-head-extra
'safe-local-variable
'stringp
)
1204 (defcustom org-html-todo-kwd-class-prefix
""
1205 "Prefix to class names for TODO keywords.
1206 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1207 The default prefix is empty because it is nice to just use the keyword
1208 as a class name. But if you get into conflicts with other, existing
1209 CSS classes, then this prefix can be very useful."
1210 :group
'org-export-html
1214 ;;; Internal Functions
1216 (defun org-html-format-inline-image (src &optional
1217 caption label attr standalone-p
)
1218 "Format an inline image from SRC.
1219 CAPTION, LABEL and ATTR are optional arguments providing the
1220 caption, the label and the attribute of the image.
1221 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1222 (let* ((id (if (not label
) ""
1223 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1226 ((string-match "\\<alt=" (or attr
"")) "")
1227 ((string-match "^ltxpng/" src
)
1228 (format " alt=\"%s\""
1229 (org-html-encode-plain-text
1230 (org-find-text-property-in-string
1231 'org-latex-src src
))))
1232 (t (format " alt=\"%s\""
1233 (file-name-nondirectory src
)))))))
1236 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1237 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1238 id
(format "\n<p>%s</p>" img
)
1239 (when (and caption
(not (string= caption
"")))
1240 (format "\n<p>%s</p>" caption
)))))
1241 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1243 (defun org-html--textarea-block (element)
1244 "Transcode ELEMENT into a textarea block.
1245 ELEMENT is either a src block or an example block."
1246 (let* ((code (car (org-export-unravel-code element
)))
1247 (attr (org-export-read-attribute :attr_html element
)))
1248 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1249 (or (plist-get attr
:width
) 80)
1250 (or (plist-get attr
:height
) (org-count-lines code
))
1256 (defun org-html-bibliography ()
1257 "Find bibliography, cut it out and return it."
1259 (let (beg end
(cnt 1) bib
)
1261 (goto-char (point-min))
1262 (when (re-search-forward
1263 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1264 (setq beg
(match-beginning 0))
1265 (while (re-search-forward "</?div\\>" nil t
)
1266 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1268 (and (looking-at ">") (forward-char 1))
1269 (setq bib
(buffer-substring beg
(point)))
1270 (delete-region beg
(point))
1271 (throw 'exit bib
))))
1276 (defun org-html-splice-attributes (tag attributes
)
1277 "Return a HTML TAG edited wrt ATTRIBUTES."
1278 (if (not attributes
)
1280 (let (oldatt newatt
)
1281 (setq oldatt
(org-extract-attributes-from-string tag
)
1283 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1285 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1286 (if (string-match ">" tag
)
1288 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1292 (defun org-export-splice-style (style extra
)
1293 "Return STYLE updated wrt EXTRA."
1294 (if (and (stringp extra
)
1295 (string-match "\\S-" extra
)
1296 (string-match "</style>" style
))
1297 (concat (substring style
0 (match-beginning 0))
1299 (substring style
(match-beginning 0)))
1302 (defun org-html-htmlize-region-for-paste (beg end
)
1303 "Convert the region between BEG and END to HTML, using htmlize.el.
1304 This is much like `htmlize-region-for-paste', only that it uses
1305 the settings define in the org-... variables."
1306 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1307 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1308 (htmlbuf (htmlize-region beg end
)))
1310 (with-current-buffer htmlbuf
1311 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1312 (plist-get htmlize-buffer-places
'content-end
)))
1313 (kill-buffer htmlbuf
))))
1316 (defun org-html-htmlize-generate-css ()
1317 "Create the CSS for all font definitions in the current Emacs session.
1318 Use this to create face definitions in your CSS style file that can then
1319 be used by code snippets transformed by htmlize.
1320 This command just produces a buffer that contains class definitions for all
1321 faces used in the current Emacs session. You can copy and paste the ones you
1322 need into your CSS file.
1324 If you then set `org-html-htmlize-output-type' to `css', calls
1325 to the function `org-html-htmlize-region-for-paste' will
1326 produce code that uses these same face definitions."
1329 (and (get-buffer "*html*") (kill-buffer "*html*"))
1331 (let ((fl (face-list))
1332 (htmlize-css-name-prefix "org-")
1333 (htmlize-output-type 'css
)
1335 (while (setq f
(pop fl
)
1336 i
(and f
(face-attribute f
:inherit
)))
1337 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1338 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1339 (htmlize-region (point-min) (point-max))))
1340 (org-pop-to-buffer-same-window "*html*")
1341 (goto-char (point-min))
1342 (if (re-search-forward "<style" nil t
)
1343 (delete-region (point-min) (match-beginning 0)))
1344 (if (re-search-forward "</style>" nil t
)
1345 (delete-region (1+ (match-end 0)) (point-max)))
1346 (beginning-of-line 1)
1347 (if (looking-at " +") (replace-match ""))
1348 (goto-char (point-min)))
1350 (defun org-html--make-string (n string
)
1351 "Build a string by concatenating N times STRING."
1352 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1354 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1355 "Turn todo keyword KWD into a valid class name.
1356 Replaces invalid characters with \"_\"."
1358 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1359 (setq kwd
(replace-match "_" t t kwd
))))
1362 (defun org-html-format-footnote-reference (n def refcnt
)
1363 "Format footnote reference N with definition DEF into HTML."
1364 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1365 (format org-html-footnote-format
1366 (let* ((id (format "fnr.%s%s" n extra
))
1367 (href (format " href=\"#fn.%s\"" n
))
1368 (attributes (concat " class=\"footref\"" href
)))
1369 (org-html--anchor id n attributes
)))))
1371 (defun org-html-format-footnotes-section (section-name definitions
)
1372 "Format footnotes section SECTION-NAME."
1373 (if (not definitions
) ""
1374 (format org-html-footnotes-section section-name definitions
)))
1376 (defun org-html-format-footnote-definition (fn)
1377 "Format the footnote definition FN."
1378 (let ((n (car fn
)) (def (cdr fn
)))
1381 (format org-html-footnote-format
1382 (let* ((id (format "fn.%s" n
))
1383 (href (format " href=\"#fnr.%s\"" n
))
1384 (attributes (concat " class=\"footnum\"" href
)))
1385 (org-html--anchor id n attributes
)))
1388 (defun org-html-footnote-section (info)
1389 "Format the footnote section.
1390 INFO is a plist used as a communication channel."
1391 (let* ((fn-alist (org-export-collect-footnote-definitions
1392 (plist-get info
:parse-tree
) info
))
1395 (loop for
(n type raw
) in fn-alist collect
1396 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1397 (org-trim (org-export-data raw info
))
1399 (org-trim (org-export-data raw info
))))))))
1401 (org-html-format-footnotes-section
1402 (org-html--translate "Footnotes" info
)
1405 (mapconcat 'org-html-format-footnote-definition fn-alist
"\n"))))))
1411 (defun org-html--build-meta-info (info)
1412 "Return meta tags for exported document.
1413 INFO is a plist used as a communication channel."
1414 (let* ((title (org-export-data (plist-get info
:title
) info
))
1415 (author (and (plist-get info
:with-author
)
1416 (let ((auth (plist-get info
:author
)))
1417 (and auth
(org-export-data auth info
)))))
1418 (date (and (plist-get info
:with-date
)
1419 (let ((date (plist-get info
:date
)))
1420 (and date
(org-export-data date info
)))))
1421 (description (plist-get info
:description
))
1422 (keywords (plist-get info
:keywords
)))
1424 (format "<title>%s</title>\n" title
)
1426 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1427 (or (and org-html-coding-system
1428 (fboundp 'coding-system-get
)
1429 (coding-system-get org-html-coding-system
'mime-charset
))
1431 (format "<meta name=\"title\" content=\"%s\"/>\n" title
)
1432 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1433 (and date
(format "<meta name=\"generated\" content=\"%s\"/>\n" date
))
1434 (and author
(format "<meta name=\"author\" content=\"%s\"/>\n" author
))
1436 (format "<meta name=\"description\" content=\"%s\"/>\n" description
))
1438 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords
)))))
1440 (defun org-html--build-head (info)
1441 "Return information for the <head>..</head> of the HTML output.
1442 INFO is a plist used as a communication channel."
1443 (org-element-normalize-string
1445 (when (plist-get info
:html-head-include-default-style
)
1446 (org-element-normalize-string org-html-style-default
))
1447 (org-element-normalize-string (plist-get info
:html-head
))
1448 (org-element-normalize-string (plist-get info
:html-head-extra
))
1449 (when (and (plist-get info
:html-htmlized-css-url
)
1450 (eq org-html-htmlize-output-type
'css
))
1451 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1452 (plist-get info
:html-htmlized-css-url
)))
1453 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1455 (defun org-html--build-mathjax-config (info)
1456 "Insert the user setup into the mathjax template.
1457 INFO is a plist used as a communication channel."
1458 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1459 (org-element-map (plist-get info
:parse-tree
)
1460 '(latex-fragment latex-environment
) 'identity info t
))
1461 (let ((template org-html-mathjax-template
)
1462 (options org-html-mathjax-options
)
1463 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1464 name val
(yes " ") (no "// ") x
)
1467 (setq name
(car e
) val
(nth 1 e
))
1468 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1469 (setq val
(car (read-from-string
1470 (substring in-buffer
(match-end 0))))))
1471 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1472 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1473 (setq template
(replace-match val t t template
))))
1475 (setq val
(nth 1 (assq 'mathml options
)))
1476 (if (string-match (concat "\\<mathml:") in-buffer
)
1477 (setq val
(car (read-from-string
1478 (substring in-buffer
(match-end 0))))))
1479 ;; Exchange prefixes depending on mathml setting.
1480 (if (not val
) (setq x yes yes no no x
))
1481 ;; Replace cookies to turn on or off the config/jax lines.
1482 (if (string-match ":MMLYES:" template
)
1483 (setq template
(replace-match yes t t template
)))
1484 (if (string-match ":MMLNO:" template
)
1485 (setq template
(replace-match no t t template
)))
1486 ;; Return the modified template.
1487 (org-element-normalize-string template
))))
1489 (defun org-html--build-preamble (info)
1490 "Return document preamble as a string, or nil.
1491 INFO is a plist used as a communication channel."
1492 (let ((preamble (plist-get info
:html-preamble
)))
1494 (let ((preamble-contents
1495 (if (functionp preamble
) (funcall preamble info
)
1496 (let ((title (org-export-data (plist-get info
:title
) info
))
1497 (date (if (not (plist-get info
:with-date
)) ""
1498 (org-export-data (plist-get info
:date
) info
)))
1499 (author (if (not (plist-get info
:with-author
)) ""
1500 (org-export-data (plist-get info
:author
) info
)))
1501 (email (if (not (plist-get info
:with-email
)) ""
1502 (plist-get info
:email
))))
1503 (if (stringp preamble
)
1504 (format-spec preamble
1505 `((?t .
,title
) (?a .
,author
)
1506 (?d .
,date
) (?e .
,email
)))
1508 (or (cadr (assoc (plist-get info
:language
)
1509 org-html-preamble-format
))
1510 (cadr (assoc "en" org-html-preamble-format
)))
1511 `((?t .
,title
) (?a .
,author
)
1512 (?d .
,date
) (?e .
,email
))))))))
1513 (when (org-string-nw-p preamble-contents
)
1514 (concat (format "<%s id=\"%s\">\n"
1515 (nth 1 (assq 'preamble org-html-divs
))
1516 (nth 2 (assq 'preamble org-html-divs
)))
1517 (org-element-normalize-string preamble-contents
)
1518 (format "</%s>\n" (nth 1 (assq 'preamble org-html-divs
)))))))))
1520 (defun org-html--build-postamble (info)
1521 "Return document postamble as a string, or nil.
1522 INFO is a plist used as a communication channel."
1523 (let ((postamble (plist-get info
:html-postamble
)))
1525 (let ((postamble-contents
1526 (if (functionp postamble
) (funcall postamble info
)
1527 (let ((date (if (not (plist-get info
:with-date
)) ""
1528 (org-export-data (plist-get info
:date
) info
)))
1529 (author (let ((author (plist-get info
:author
)))
1530 (and author
(org-export-data author info
))))
1533 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1534 (split-string (plist-get info
:email
) ",+ *")
1536 (html-validation-link (or org-html-validation-link
""))
1537 (creator-info (plist-get info
:creator
)))
1538 (cond ((stringp postamble
)
1539 (format-spec postamble
1540 `((?a .
,author
) (?e .
,email
)
1541 (?d .
,date
) (?c .
,creator-info
)
1542 (?v .
,html-validation-link
))))
1543 ((eq postamble
'auto
)
1545 (when (plist-get info
:time-stamp-file
)
1546 (format "<p class=\"date\">%s: %s</p>\n"
1547 (org-html--translate "Date" info
)
1549 (when (and (plist-get info
:with-author
) author
)
1550 (format "<p class=\"author\">%s : %s</p>\n"
1551 (org-html--translate "Author" info
)
1553 (when (and (plist-get info
:with-email
) email
)
1554 (format "<p class=\"email\">%s </p>\n" email
))
1555 (when (plist-get info
:with-creator
)
1556 (format "<p class=\"creator\">%s</p>\n"
1558 html-validation-link
"\n"))
1560 (or (cadr (assoc (plist-get info
:language
)
1561 org-html-postamble-format
))
1562 (cadr (assoc "en" org-html-postamble-format
)))
1563 `((?a .
,author
) (?e .
,email
)
1564 (?d .
,date
) (?c .
,creator-info
)
1565 (?v .
,html-validation-link
)))))))))
1566 (when (org-string-nw-p postamble-contents
)
1568 (format "<%s id=\"%s\">\n"
1569 (nth 1 (assq 'postamble org-html-divs
))
1570 (nth 2 (assq 'postamble org-html-divs
)))
1571 (org-element-normalize-string postamble-contents
)
1572 (format "</%s>\n" (nth 1 (assq 'postamble org-html-divs
)))))))))
1574 (defun org-html-inner-template (contents info
)
1575 "Return body of document string after HTML conversion.
1576 CONTENTS is the transcoded contents string. INFO is a plist
1577 holding export options."
1579 ;; Table of contents.
1580 (let ((depth (plist-get info
:with-toc
)))
1581 (when depth
(org-html-toc depth info
)))
1582 ;; Document contents.
1584 ;; Footnotes section.
1585 (org-html-footnote-section info
)
1587 (org-html-bibliography)))
1589 (defun org-html-template (contents info
)
1590 "Return complete document string after HTML conversion.
1591 CONTENTS is the transcoded contents string. INFO is a plist
1592 holding export options."
1595 (or (and (stringp org-html-xml-declaration
)
1596 org-html-xml-declaration
)
1597 (cdr (assoc (plist-get info
:html-extension
)
1598 org-html-xml-declaration
))
1599 (cdr (assoc "html" org-html-xml-declaration
))
1602 (or (and org-html-coding-system
1603 (fboundp 'coding-system-get
)
1604 (coding-system-get org-html-coding-system
'mime-charset
))
1607 (plist-get info
:html-doctype
)
1609 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1610 (plist-get info
:language
) (plist-get info
:language
))
1612 (org-html--build-meta-info info
)
1613 (org-html--build-head info
)
1614 (org-html--build-mathjax-config info
)
1617 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1618 (link-home (org-trim (plist-get info
:html-link-home
))))
1619 (unless (and (string= link-up
"") (string= link-up
""))
1620 (format org-html-home
/up-format
1621 (or link-up link-home
)
1622 (or link-home link-up
))))
1624 (org-html--build-preamble info
)
1625 ;; Document contents.
1626 (format "<%s id=\"%s\">\n"
1627 (nth 1 (assq 'content org-html-divs
))
1628 (nth 2 (assq 'content org-html-divs
)))
1630 (let ((title (plist-get info
:title
)))
1631 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title
"") info
)))
1634 (nth 1 (assq 'content org-html-divs
)))
1636 (org-html--build-postamble info
)
1637 ;; Closing document.
1638 "</body>\n</html>"))
1640 (defun org-html--translate (s info
)
1641 "Translate string S according to specified language.
1642 INFO is a plist used as a communication channel."
1643 (org-export-translate s
:html info
))
1647 (defun org-html--anchor (&optional id desc attributes
)
1648 "Format a HTML anchor."
1649 (let* ((name (and org-html-allow-name-attribute-in-anchors id
))
1650 (attributes (concat (and id
(format " id=\"%s\"" id
))
1651 (and name
(format " name=\"%s\"" name
))
1653 (format "<a%s>%s</a>" attributes
(or desc
""))))
1657 (defun org-html--todo (todo)
1658 "Format TODO keywords into HTML."
1660 (format "<span class=\"%s %s%s\">%s</span>"
1661 (if (member todo org-done-keywords
) "done" "todo")
1662 org-html-todo-kwd-class-prefix
(org-html-fix-class-name todo
)
1667 (defun org-html--tags (tags)
1668 "Format TAGS into HTML."
1670 (format "<span class=\"tag\">%s</span>"
1673 (format "<span class=\"%s\">%s</span>"
1674 (concat org-html-tag-class-prefix
1675 (org-html-fix-class-name tag
))
1681 (defun* org-html-format-headline
1682 (todo todo-type priority text tags
1683 &key level section-number headline-label
&allow-other-keys
)
1684 "Format a headline in HTML."
1685 (let ((section-number
1686 (when section-number
1687 (format "<span class=\"section-number-%d\">%s</span> "
1688 level section-number
)))
1689 (todo (org-html--todo todo
))
1690 (tags (org-html--tags tags
)))
1691 (concat section-number todo
(and todo
" ") text
1692 (and tags
"   ") tags
)))
1696 (defun org-html-fontify-code (code lang
)
1697 "Color CODE with htmlize library.
1698 CODE is a string representing the source code to colorize. LANG
1699 is the language used for CODE, as a string, or nil."
1702 ;; Case 1: No lang. Possibly an example block.
1704 ;; Simple transcoding.
1705 (org-html-encode-plain-text code
))
1706 ;; Case 2: No htmlize or an inferior version of htmlize
1707 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1709 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1710 ;; Simple transcoding.
1711 (org-html-encode-plain-text code
))
1714 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1715 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1717 ;; Case 1: Language is not associated with any Emacs mode
1718 ((not (functionp lang-mode
))
1719 ;; Simple transcoding.
1720 (org-html-encode-plain-text code
))
1721 ;; Case 2: Default. Fontify code.
1724 (setq code
(with-temp-buffer
1725 ;; Switch to language-specific mode.
1729 (font-lock-fontify-buffer)
1730 ;; Remove formatting on newline characters.
1732 (let ((beg (point-min))
1735 (while (progn (end-of-line) (< (point) end
))
1736 (put-text-property (point) (1+ (point)) 'face nil
)
1739 (set-buffer-modified-p nil
)
1741 (org-html-htmlize-region-for-paste
1742 (point-min) (point-max))))
1743 ;; Strip any enclosing <pre></pre> tags.
1744 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1745 (end (and beg
(string-match "</pre>\\'" code
))))
1746 (if (and beg end
) (substring code beg end
) code
)))))))))
1748 (defun org-html-do-format-code
1749 (code &optional lang refs retain-labels num-start
)
1750 "Format CODE string as source code.
1751 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1752 respectively, the language of the source code, as a string, an
1753 alist between line numbers and references (as returned by
1754 `org-export-unravel-code'), a boolean specifying if labels should
1755 appear in the source code, and the number associated to the first
1757 (let* ((code-lines (org-split-string code
"\n"))
1758 (code-length (length code-lines
))
1762 (length (number-to-string (+ code-length num-start
))))))
1763 (code (org-html-fontify-code code lang
)))
1764 (org-export-format-code
1766 (lambda (loc line-num ref
)
1769 ;; Add line number, if needed.
1771 (format "<span class=\"linenr\">%s</span>"
1772 (format num-fmt line-num
)))
1773 ;; Transcoded src line.
1775 ;; Add label, if needed.
1776 (when (and ref retain-labels
) (format " (%s)" ref
))))
1777 ;; Mark transcoded line as an anchor, if needed.
1779 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1783 (defun org-html-format-code (element info
)
1784 "Format contents of ELEMENT as source code.
1785 ELEMENT is either an example block or a src block. INFO is
1786 a plist used as a communication channel."
1787 (let* ((lang (org-element-property :language element
))
1788 ;; Extract code and references.
1789 (code-info (org-export-unravel-code element
))
1790 (code (car code-info
))
1791 (refs (cdr code-info
))
1792 ;; Does the src block contain labels?
1793 (retain-labels (org-element-property :retain-labels element
))
1794 ;; Does it have line numbers?
1795 (num-start (case (org-element-property :number-lines element
)
1796 (continued (org-export-get-loc element info
))
1798 (org-html-do-format-code code lang refs retain-labels num-start
)))
1802 ;;; Tables of Contents
1804 (defun org-html-toc (depth info
)
1805 "Build a table of contents.
1806 DEPTH is an integer specifying the depth of the table. INFO is a
1807 plist used as a communication channel. Return the table of
1808 contents as a string, or nil if it is empty."
1810 (mapcar (lambda (headline)
1811 (cons (org-html--format-toc-headline headline info
)
1812 (org-export-get-relative-level headline info
)))
1813 (org-export-collect-headlines info depth
))))
1815 (concat "<div id=\"table-of-contents\">\n"
1816 (format "<h%d>%s</h%d>\n"
1817 org-html-toplevel-hlevel
1818 (org-html--translate "Table of Contents" info
)
1819 org-html-toplevel-hlevel
)
1820 "<div id=\"text-table-of-contents\">"
1821 (org-html--toc-text toc-entries
)
1825 (defun org-html--toc-text (toc-entries)
1826 "Return innards of a table of contents, as a string.
1827 TOC-ENTRIES is an alist where key is an entry title, as a string,
1828 and value is its relative level, as an integer."
1829 (let* ((prev-level (1- (cdar toc-entries
)))
1830 (start-level prev-level
))
1834 (let ((headline (car entry
))
1835 (level (cdr entry
)))
1837 (let* ((cnt (- level prev-level
))
1838 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1840 (setq prev-level level
)
1842 (org-html--make-string
1843 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1844 ((< cnt
0) "</li>\n</ul>\n")))
1845 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1848 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
1850 (defun org-html--format-toc-headline (headline info
)
1851 "Return an appropriate table of contents entry for HEADLINE.
1852 INFO is a plist used as a communication channel."
1853 (let* ((headline-number (org-export-get-headline-number headline info
))
1855 (and (not (org-export-low-level-p headline info
))
1856 (org-export-numbered-headline-p headline info
)
1857 (concat (mapconcat 'number-to-string headline-number
".") ". ")))
1858 (tags (and (eq (plist-get info
:with-tags
) t
)
1859 (org-export-get-tags headline info
))))
1860 (format "<a href=\"#%s\">%s</a>"
1862 (org-export-solidify-link-text
1863 (or (org-element-property :CUSTOM_ID headline
)
1864 (concat "sec-" (mapconcat 'number-to-string
1865 headline-number
"-"))))
1867 (concat section-number
1868 (org-export-data-with-translations
1869 (org-export-get-alt-title headline info
)
1870 ;; Ignore any footnote-reference, link,
1871 ;; radio-target and target in table of contents.
1873 '((footnote-reference . ignore
)
1874 (link .
(lambda (link desc i
) desc
))
1875 (radio-target .
(lambda (radio desc i
) desc
))
1877 (org-export-backend-translate-table 'html
))
1879 (and tags
"   ") (org-html--tags tags
)))))
1881 (defun org-html-list-of-listings (info)
1882 "Build a list of listings.
1883 INFO is a plist used as a communication channel. Return the list
1884 of listings as a string, or nil if it is empty."
1885 (let ((lol-entries (org-export-collect-listings info
)))
1887 (concat "<div id=\"list-of-listings\">\n"
1888 (format "<h%d>%s</h%d>\n"
1889 org-html-toplevel-hlevel
1890 (org-html--translate "List of Listings" info
)
1891 org-html-toplevel-hlevel
)
1892 "<div id=\"text-list-of-listings\">\n<ul>\n"
1894 (initial-fmt (org-html--translate "Listing %d:" info
)))
1897 (let ((label (org-element-property :name entry
))
1900 (or (org-export-get-caption entry t
)
1901 (org-export-get-caption entry
))
1906 (concat (format initial-fmt
(incf count
)) " " title
)
1907 (format "<a href=\"#%s\">%s %s</a>"
1908 (org-export-solidify-link-text label
)
1909 (format initial-fmt
(incf count
))
1913 "\n</ul>\n</div>\n</div>"))))
1915 (defun org-html-list-of-tables (info)
1916 "Build a list of tables.
1917 INFO is a plist used as a communication channel. Return the list
1918 of tables as a string, or nil if it is empty."
1919 (let ((lol-entries (org-export-collect-tables info
)))
1921 (concat "<div id=\"list-of-tables\">\n"
1922 (format "<h%d>%s</h%d>\n"
1923 org-html-toplevel-hlevel
1924 (org-html--translate "List of Tables" info
)
1925 org-html-toplevel-hlevel
)
1926 "<div id=\"text-list-of-tables\">\n<ul>\n"
1928 (initial-fmt (org-html--translate "Table %d:" info
)))
1931 (let ((label (org-element-property :name entry
))
1934 (or (org-export-get-caption entry t
)
1935 (org-export-get-caption entry
))
1940 (concat (format initial-fmt
(incf count
)) " " title
)
1941 (format "<a href=\"#%s\">%s %s</a>"
1942 (org-export-solidify-link-text label
)
1943 (format initial-fmt
(incf count
))
1947 "\n</ul>\n</div>\n</div>"))))
1951 ;;; Transcode Functions
1955 (defun org-html-bold (bold contents info
)
1956 "Transcode BOLD from Org to HTML.
1957 CONTENTS is the text with bold markup. INFO is a plist holding
1958 contextual information."
1959 (format (or (cdr (assq 'bold org-html-text-markup-alist
)) "%s")
1965 (defun org-html-center-block (center-block contents info
)
1966 "Transcode a CENTER-BLOCK element from Org to HTML.
1967 CONTENTS holds the contents of the block. INFO is a plist
1968 holding contextual information."
1969 (format "<div style=\"text-align: center\">\n%s</div>" contents
))
1974 (defun org-html-clock (clock contents info
)
1975 "Transcode a CLOCK element from Org to HTML.
1976 CONTENTS is nil. INFO is a plist used as a communication
1979 <span class=\"timestamp-wrapper\">
1980 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1985 (org-element-property :raw-value
1986 (org-element-property :value clock
)))
1987 (let ((time (org-element-property :duration clock
)))
1988 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
1993 (defun org-html-code (code contents info
)
1994 "Transcode CODE from Org to HTML.
1995 CONTENTS is nil. INFO is a plist holding contextual
1997 (format (or (cdr (assq 'code org-html-text-markup-alist
)) "%s")
1998 (org-html-plain-text (org-element-property :value code
) info
)))
2003 (defun org-html-drawer (drawer contents info
)
2004 "Transcode a DRAWER element from Org to HTML.
2005 CONTENTS holds the contents of the block. INFO is a plist
2006 holding contextual information."
2007 (if (functionp org-html-format-drawer-function
)
2008 (funcall org-html-format-drawer-function
2009 (org-element-property :drawer-name drawer
)
2011 ;; If there's no user defined function: simply
2012 ;; display contents of the drawer.
2018 (defun org-html-dynamic-block (dynamic-block contents info
)
2019 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2020 CONTENTS holds the contents of the block. INFO is a plist
2021 holding contextual information. See `org-export-data'."
2027 (defun org-html-entity (entity contents info
)
2028 "Transcode an ENTITY object from Org to HTML.
2029 CONTENTS are the definition itself. INFO is a plist holding
2030 contextual information."
2031 (org-element-property :html entity
))
2036 (defun org-html-example-block (example-block contents info
)
2037 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2038 CONTENTS is nil. INFO is a plist holding contextual
2040 (if (org-export-read-attribute :attr_html example-block
:textarea
)
2041 (org-html--textarea-block example-block
)
2042 (format "<pre class=\"example\">\n%s</pre>"
2043 (org-html-format-code example-block info
))))
2048 (defun org-html-export-snippet (export-snippet contents info
)
2049 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2050 CONTENTS is nil. INFO is a plist holding contextual
2052 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
2053 (org-element-property :value export-snippet
)))
2058 (defun org-html-export-block (export-block contents info
)
2059 "Transcode a EXPORT-BLOCK element from Org to HTML.
2060 CONTENTS is nil. INFO is a plist holding contextual information."
2061 (when (string= (org-element-property :type export-block
) "HTML")
2062 (org-remove-indentation (org-element-property :value export-block
))))
2067 (defun org-html-fixed-width (fixed-width contents info
)
2068 "Transcode a FIXED-WIDTH element from Org to HTML.
2069 CONTENTS is nil. INFO is a plist holding contextual information."
2070 (format "<pre class=\"example\">\n%s</pre>"
2071 (org-html-do-format-code
2072 (org-remove-indentation
2073 (org-element-property :value fixed-width
)))))
2076 ;;;; Footnote Reference
2078 (defun org-html-footnote-reference (footnote-reference contents info
)
2079 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2080 CONTENTS is nil. INFO is a plist holding contextual information."
2082 ;; Insert separator between two footnotes in a row.
2083 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2084 (when (eq (org-element-type prev
) 'footnote-reference
)
2085 org-html-footnote-separator
))
2087 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2088 (org-html-format-footnote-reference
2089 (org-export-get-footnote-number footnote-reference info
)
2091 ;; Inline definitions are secondary strings.
2092 ((eq (org-element-property :type footnote-reference
) 'inline
)
2093 (org-html-format-footnote-reference
2094 (org-export-get-footnote-number footnote-reference info
)
2096 ;; Non-inline footnotes definitions are full Org data.
2097 (t (org-html-format-footnote-reference
2098 (org-export-get-footnote-number footnote-reference info
)
2104 (defun org-html-format-headline--wrap
2105 (headline info
&optional format-function
&rest extra-keys
)
2106 "Transcode a HEADLINE element from Org to HTML.
2107 CONTENTS holds the contents of the headline. INFO is a plist
2108 holding contextual information."
2109 (let* ((level (+ (org-export-get-relative-level headline info
)
2110 (1- org-html-toplevel-hlevel
)))
2111 (headline-number (org-export-get-headline-number headline info
))
2112 (section-number (and (not (org-export-low-level-p headline info
))
2113 (org-export-numbered-headline-p headline info
)
2114 (mapconcat 'number-to-string
2115 headline-number
".")))
2116 (todo (and (plist-get info
:with-todo-keywords
)
2117 (let ((todo (org-element-property :todo-keyword headline
)))
2118 (and todo
(org-export-data todo info
)))))
2119 (todo-type (and todo
(org-element-property :todo-type headline
)))
2120 (priority (and (plist-get info
:with-priority
)
2121 (org-element-property :priority headline
)))
2122 (text (org-export-data (org-element-property :title headline
) info
))
2123 (tags (and (plist-get info
:with-tags
)
2124 (org-export-get-tags headline info
)))
2125 (headline-label (or (org-element-property :CUSTOM_ID headline
)
2126 (concat "sec-" (mapconcat 'number-to-string
2127 headline-number
"-"))))
2128 (format-function (cond
2129 ((functionp format-function
) format-function
)
2130 ((functionp org-html-format-headline-function
)
2132 (lambda (todo todo-type priority text tags
2134 (funcall org-html-format-headline-function
2135 todo todo-type priority text tags
))))
2136 (t 'org-html-format-headline
))))
2137 (apply format-function
2138 todo todo-type priority text tags
2139 :headline-label headline-label
:level level
2140 :section-number section-number extra-keys
)))
2142 (defun org-html-headline (headline contents info
)
2143 "Transcode a HEADLINE element from Org to HTML.
2144 CONTENTS holds the contents of the headline. INFO is a plist
2145 holding contextual information."
2147 (setq contents
(or contents
""))
2148 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2149 (level (org-export-get-relative-level headline info
))
2150 (text (org-export-data (org-element-property :title headline
) info
))
2151 (todo (and (plist-get info
:with-todo-keywords
)
2152 (let ((todo (org-element-property :todo-keyword headline
)))
2153 (and todo
(org-export-data todo info
)))))
2154 (todo-type (and todo
(org-element-property :todo-type headline
)))
2155 (tags (and (plist-get info
:with-tags
)
2156 (org-export-get-tags headline info
)))
2157 (priority (and (plist-get info
:with-priority
)
2158 (org-element-property :priority headline
)))
2159 (section-number (and (org-export-numbered-headline-p headline info
)
2160 (mapconcat 'number-to-string
2161 (org-export-get-headline-number
2162 headline info
) ".")))
2163 ;; Create the headline text.
2164 (full-text (org-html-format-headline--wrap headline info
)))
2166 ;; Case 1: This is a footnote section: ignore it.
2167 ((org-element-property :footnote-section-p headline
) nil
)
2168 ;; Case 2. This is a deep sub-tree: export it as a list item.
2169 ;; Also export as items headlines for which no section
2170 ;; format has been found.
2171 ((org-export-low-level-p headline info
)
2172 ;; Build the real contents of the sub-tree.
2173 (let* ((type (if numberedp
'ordered
'unordered
))
2174 (itemized-body (org-html-format-list-item
2175 contents type nil nil full-text
)))
2177 (and (org-export-first-sibling-p headline info
)
2178 (org-html-begin-plain-list type
))
2180 (and (org-export-last-sibling-p headline info
)
2181 (org-html-end-plain-list type
)))))
2182 ;; Case 3. Standard headline. Export it as a section.
2184 (let* ((section-number (mapconcat 'number-to-string
2185 (org-export-get-headline-number
2186 headline info
) "-"))
2188 (list (org-element-property :CUSTOM_ID headline
)
2189 (concat "sec-" section-number
)
2190 (org-element-property :ID headline
))))
2191 (preferred-id (car ids
))
2192 (extra-ids (cdr ids
))
2193 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2194 (level1 (+ level
(1- org-html-toplevel-hlevel
)))
2195 (first-content (car (org-element-contents headline
))))
2196 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2197 (if (= 1 (org-export-get-relative-level headline info
))
2198 (plist-get info
:html-container
)
2200 (format "outline-container-%s"
2201 (or (org-element-property :CUSTOM_ID headline
)
2203 (concat (format "outline-%d" level1
) (and extra-class
" ")
2205 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2210 (let ((id (org-export-solidify-link-text
2211 (if (org-uuidgen-p x
) (concat "ID-" x
)
2213 (org-html--anchor id
)))
2217 ;; When there is no section, pretend there is an empty
2218 ;; one to get the correct <div class="outline- ...>
2219 ;; which is needed by `org-info.js'.
2220 (if (not (eq (org-element-type first-content
) 'section
))
2221 (concat (org-html-section first-content
"" info
)
2224 (if (= 1 (org-export-get-relative-level headline info
))
2225 (plist-get info
:html-container
)
2229 ;;;; Horizontal Rule
2231 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2232 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2233 CONTENTS is nil. INFO is a plist holding contextual information."
2237 ;;;; Inline Src Block
2239 (defun org-html-inline-src-block (inline-src-block contents info
)
2240 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2241 CONTENTS holds the contents of the item. INFO is a plist holding
2242 contextual information."
2243 (let* ((org-lang (org-element-property :language inline-src-block
))
2244 (code (org-element-property :value inline-src-block
)))
2245 (error "Cannot export inline src block")))
2250 (defun org-html-format-section (text class
&optional id
)
2251 "Format a section with TEXT into a HTML div with CLASS and ID."
2252 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2253 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2255 (defun org-html-inlinetask (inlinetask contents info
)
2256 "Transcode an INLINETASK element from Org to HTML.
2257 CONTENTS holds the contents of the block. INFO is a plist
2258 holding contextual information."
2260 ;; If `org-html-format-inlinetask-function' is provided, call it
2261 ;; with appropriate arguments.
2262 ((functionp org-html-format-inlinetask-function
)
2263 (let ((format-function
2265 (lambda (todo todo-type priority text tags
2266 &key contents
&allow-other-keys
)
2267 (funcall org-html-format-inlinetask-function
2268 todo todo-type priority text tags contents
)))))
2269 (org-html-format-headline--wrap
2270 inlinetask info format-function
:contents contents
)))
2271 ;; Otherwise, use a default template.
2272 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2273 (org-html-format-headline--wrap inlinetask info
)
2279 (defun org-html-italic (italic contents info
)
2280 "Transcode ITALIC from Org to HTML.
2281 CONTENTS is the text with italic markup. INFO is a plist holding
2282 contextual information."
2283 (format (or (cdr (assq 'italic org-html-text-markup-alist
)) "%s") contents
))
2288 (defun org-html-checkbox (checkbox)
2289 "Format CHECKBOX into HTML."
2290 (case checkbox
(on "<code>[X]</code>")
2291 (off "<code>[ ]</code>")
2292 (trans "<code>[-]</code>")
2295 (defun org-html-format-list-item (contents type checkbox
2296 &optional term-counter-id
2298 "Format a list item into HTML."
2299 (let ((checkbox (concat (org-html-checkbox checkbox
) (and checkbox
" "))))
2303 (let* ((counter term-counter-id
)
2304 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2306 (format "<li%s>" extra
)
2307 (when headline
(concat headline
"<br/>")))))
2309 (let* ((id term-counter-id
)
2310 (extra (if id
(format " id=\"%s\"" id
) "")))
2312 (format "<li%s>" extra
)
2313 (when headline
(concat headline
"<br/>")))))
2315 (let* ((term term-counter-id
))
2316 (setq term
(or term
"(no term)"))
2317 ;; Check-boxes in descriptive lists are associated to tag.
2318 (concat (format "<dt> %s </dt>"
2319 (concat checkbox term
))
2321 (unless (eq type
'descriptive
) checkbox
)
2326 (descriptive "</dd>")))))
2328 (defun org-html-item (item contents info
)
2329 "Transcode an ITEM element from Org to HTML.
2330 CONTENTS holds the contents of the item. INFO is a plist holding
2331 contextual information."
2332 (let* ((plain-list (org-export-get-parent item
))
2333 (type (org-element-property :type plain-list
))
2334 (counter (org-element-property :counter item
))
2335 (checkbox (org-element-property :checkbox item
))
2336 (tag (let ((tag (org-element-property :tag item
)))
2337 (and tag
(org-export-data tag info
)))))
2338 (org-html-format-list-item
2339 contents type checkbox
(or tag counter
))))
2344 (defun org-html-keyword (keyword contents info
)
2345 "Transcode a KEYWORD element from Org to HTML.
2346 CONTENTS is nil. INFO is a plist holding contextual information."
2347 (let ((key (org-element-property :key keyword
))
2348 (value (org-element-property :value keyword
)))
2350 ((string= key
"HTML") value
)
2351 ;; Invisible targets.
2352 ((string= key
"TARGET") nil
)
2353 ((string= key
"TOC")
2354 (let ((value (downcase value
)))
2356 ((string-match "\\<headlines\\>" value
)
2357 (let ((depth (or (and (string-match "[0-9]+" value
)
2358 (string-to-number (match-string 0 value
)))
2359 (plist-get info
:with-toc
))))
2360 (org-html-toc depth info
)))
2361 ((string= "listings" value
) (org-html-list-of-listings info
))
2362 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2365 ;;;; Latex Environment
2367 (defun org-html-format-latex (latex-frag processing-type
)
2368 "Format the LaTeX fragment LATEX-FRAG into HTML."
2369 (let ((cache-relpath "") (cache-dir "") bfn
)
2370 (unless (eq processing-type
'mathjax
)
2371 (setq bfn
(buffer-file-name)
2374 (file-name-sans-extension
2375 (file-name-nondirectory bfn
)))
2376 cache-dir
(file-name-directory bfn
)))
2379 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2380 nil nil processing-type
)
2383 (defun org-html-latex-environment (latex-environment contents info
)
2384 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2385 CONTENTS is nil. INFO is a plist holding contextual information."
2386 (let ((processing-type (plist-get info
:with-latex
))
2387 (latex-frag (org-remove-indentation
2388 (org-element-property :value latex-environment
)))
2389 (caption (org-export-data
2390 (org-export-get-caption latex-environment
) info
))
2392 (label (org-element-property :name latex-environment
)))
2394 ((memq processing-type
'(t mathjax
))
2395 (org-html-format-latex latex-frag
'mathjax
))
2396 ((eq processing-type
'dvipng
)
2397 (let* ((formula-link (org-html-format-latex
2398 latex-frag processing-type
)))
2399 (when (and formula-link
2400 (string-match "file:\\([^]]*\\)" formula-link
))
2401 (org-html-format-inline-image
2402 (match-string 1 formula-link
) caption label attr t
))))
2408 (defun org-html-latex-fragment (latex-fragment contents info
)
2409 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2410 CONTENTS is nil. INFO is a plist holding contextual information."
2411 (let ((latex-frag (org-element-property :value latex-fragment
))
2412 (processing-type (plist-get info
:with-latex
)))
2413 (case processing-type
2415 (org-html-format-latex latex-frag
'mathjax
))
2417 (let* ((formula-link (org-html-format-latex
2418 latex-frag processing-type
)))
2419 (when (and formula-link
2420 (string-match "file:\\([^]]*\\)" formula-link
))
2421 (org-html-format-inline-image
2422 (match-string 1 formula-link
)))))
2428 (defun org-html-line-break (line-break contents info
)
2429 "Transcode a LINE-BREAK object from Org to HTML.
2430 CONTENTS is nil. INFO is a plist holding contextual information."
2436 (defun org-html-link--inline-image (link desc info
)
2437 "Return HTML code for an inline image.
2438 LINK is the link pointing to the inline image. INFO is a plist
2439 used as a communication channel."
2440 (let* ((type (org-element-property :type link
))
2441 (raw-path (org-element-property :path link
))
2442 (path (cond ((member type
'("http" "https"))
2443 (concat type
":" raw-path
))
2444 ((file-name-absolute-p raw-path
)
2445 (expand-file-name raw-path
))
2447 (parent (org-export-get-parent-element link
))
2448 (caption (org-export-data (org-export-get-caption parent
) info
))
2449 (label (org-element-property :name parent
))
2450 (attr (mapconcat #'identity
(org-element-property :attr_html parent
) " ")))
2451 ;; Return proper string, depending on DISPOSITION.
2452 (org-html-format-inline-image
2453 path caption label attr
(org-html-standalone-image-p link info
))))
2455 (defvar org-html-standalone-image-predicate
)
2456 (defun org-html-standalone-image-p (element info
&optional predicate
)
2457 "Test if ELEMENT is a standalone image for the purpose HTML export.
2458 INFO is a plist holding contextual information.
2460 Return non-nil, if ELEMENT is of type paragraph and it's sole
2461 content, save for whitespaces, is a link that qualifies as an
2464 Return non-nil, if ELEMENT is of type link and it's containing
2465 paragraph has no other content save for leading and trailing
2468 Return nil, otherwise.
2470 Bind `org-html-standalone-image-predicate' to constrain
2471 paragraph further. For example, to check for only captioned
2472 standalone images, do the following.
2474 \(setq org-html-standalone-image-predicate
2475 \(lambda \(paragraph\)
2476 \(org-element-property :caption paragraph\)\)\)"
2477 (let ((paragraph (case (org-element-type element
)
2479 (link (and (org-export-inline-image-p
2480 element org-html-inline-image-rules
)
2481 (org-export-get-parent element
)))
2483 (when (eq (org-element-type paragraph
) 'paragraph
)
2484 (when (or (not (and (boundp 'org-html-standalone-image-predicate
)
2485 (functionp org-html-standalone-image-predicate
)))
2486 (funcall org-html-standalone-image-predicate paragraph
))
2487 (let ((contents (org-element-contents paragraph
)))
2488 (loop for x in contents
2489 with inline-image-count
= 0
2491 ((eq (org-element-type x
) 'plain-text
)
2492 (not (org-string-nw-p x
)))
2493 ((eq (org-element-type x
) 'link
)
2494 (when (org-export-inline-image-p
2495 x org-html-inline-image-rules
)
2496 (= (incf inline-image-count
) 1)))
2499 (defun org-html-link (link desc info
)
2500 "Transcode a LINK object from Org to HTML.
2502 DESC is the description part of the link, or the empty string.
2503 INFO is a plist holding contextual information. See
2505 (let* ((--link-org-files-as-html-maybe
2507 (lambda (raw-path info
)
2508 "Treat links to `file.org' as links to `file.html', if needed.
2509 See `org-html-link-org-files-as-html'."
2511 ((and org-html-link-org-files-as-html
2513 (downcase (file-name-extension raw-path
"."))))
2514 (concat (file-name-sans-extension raw-path
) "."
2515 (plist-get info
:html-extension
)))
2517 (type (org-element-property :type link
))
2518 (raw-path (org-element-property :path link
))
2519 ;; Ensure DESC really exists, or set it to nil.
2520 (desc (and (not (string= desc
"")) desc
))
2523 ((member type
'("http" "https" "ftp" "mailto"))
2524 (concat type
":" raw-path
))
2525 ((string= type
"file")
2526 ;; Treat links to ".org" files as ".html", if needed.
2528 (funcall --link-org-files-as-html-maybe raw-path info
))
2529 ;; If file path is absolute, prepend it with protocol
2530 ;; component - "file://".
2531 (when (file-name-absolute-p raw-path
)
2533 (concat "file://" (expand-file-name raw-path
))))
2534 ;; Add search option, if any. A search option can be
2535 ;; relative to a custom-id or a headline title. Any other
2536 ;; option is ignored.
2537 (let ((option (org-element-property :search-option link
)))
2538 (cond ((not option
) raw-path
)
2539 ((eq (aref option
0) ?
#) (concat raw-path option
))
2540 ;; External fuzzy link: try to resolve it if path
2541 ;; belongs to current project, if any.
2542 ((eq (aref option
0) ?
*)
2546 (org-publish-resolve-external-fuzzy-link
2547 (org-element-property :path link
) option
)))
2548 (and numbers
(concat "#sec-"
2549 (mapconcat 'number-to-string
2550 numbers
"-")))))))))
2552 attributes protocol
)
2553 ;; Extract attributes from parent's paragraph. HACK: Only do this
2554 ;; for the first link in parent. This is needed as long as
2555 ;; attributes cannot be set on a per link basis.
2556 (and (setq attributes
2557 (let ((parent (org-export-get-parent-element link
)))
2558 (if (not (eq (org-element-map parent
'link
'identity info t
)
2563 (let ((att (org-element-property :attr_html parent
)))
2564 (unless (and desc att
2565 (string-match (regexp-quote (car att
)) desc
))
2568 (unless (string= attributes
"")
2569 (setq attributes
(concat " " attributes
))))
2572 ((and (or (eq t org-html-inline-images
)
2573 (and org-html-inline-images
(not desc
)))
2574 (org-export-inline-image-p link org-html-inline-image-rules
))
2575 (org-html-link--inline-image link desc info
))
2576 ;; Radio target: Transcode target's contents and use them as
2577 ;; link's description.
2578 ((string= type
"radio")
2579 (let ((destination (org-export-resolve-radio-link link info
)))
2581 (format "<a href=\"#%s\"%s>%s</a>"
2582 (org-export-solidify-link-text path
)
2584 (org-export-data (org-element-contents destination
) info
)))))
2585 ;; Links pointing to a headline: Find destination and build
2586 ;; appropriate referencing command.
2587 ((member type
'("custom-id" "fuzzy" "id"))
2588 (let ((destination (if (string= type
"fuzzy")
2589 (org-export-resolve-fuzzy-link link info
)
2590 (org-export-resolve-id-link link info
))))
2591 (case (org-element-type destination
)
2592 ;; ID link points to an external file.
2594 (let ((fragment (concat "ID-" path
))
2595 ;; Treat links to ".org" files as ".html", if needed.
2596 (path (funcall --link-org-files-as-html-maybe
2598 (format "<a href=\"%s#%s\"%s>%s</a>"
2599 path fragment attributes
(or desc destination
))))
2600 ;; Fuzzy link points nowhere.
2605 (org-element-property :raw-link link
) info
))))
2606 ;; Fuzzy link points to an invisible target.
2608 ;; Link points to a headline.
2611 ;; What href to use?
2613 ;; Case 1: Headline is linked via it's CUSTOM_ID
2614 ;; property. Use CUSTOM_ID.
2615 ((string= type
"custom-id")
2616 (org-element-property :CUSTOM_ID destination
))
2617 ;; Case 2: Headline is linked via it's ID property
2618 ;; or through other means. Use the default href.
2619 ((member type
'("id" "fuzzy"))
2621 (mapconcat 'number-to-string
2622 (org-export-get-headline-number
2623 destination info
) "-")))
2624 (t (error "Shouldn't reach here"))))
2625 ;; What description to use?
2627 ;; Case 1: Headline is numbered and LINK has no
2628 ;; description or LINK's description matches
2629 ;; headline's title. Display section number.
2630 (if (and (org-export-numbered-headline-p destination info
)
2632 (string= desc
(org-element-property
2633 :raw-value destination
))))
2634 (mapconcat 'number-to-string
2635 (org-export-get-headline-number
2636 destination info
) ".")
2637 ;; Case 2: Either the headline is un-numbered or
2638 ;; LINK has a custom description. Display LINK's
2639 ;; description or headline's title.
2640 (or desc
(org-export-data (org-element-property
2641 :title destination
) info
)))))
2642 (format "<a href=\"#%s\"%s>%s</a>"
2643 (org-export-solidify-link-text href
) attributes desc
)))
2644 ;; Fuzzy link points to a target. Do as above.
2646 (let ((path (org-export-solidify-link-text path
)) number
)
2649 ((org-html-standalone-image-p destination info
)
2650 (org-export-get-ordinal
2651 (assoc 'link
(org-element-contents destination
))
2652 info
'link
'org-html-standalone-image-p
))
2653 (t (org-export-get-ordinal destination info
))))
2654 (setq desc
(when number
2655 (if (atom number
) (number-to-string number
)
2656 (mapconcat 'number-to-string number
".")))))
2657 (format "<a href=\"#%s\"%s>%s</a>"
2658 path attributes
(or desc
"No description for this link")))))))
2659 ;; Coderef: replace link with the reference name or the
2660 ;; equivalent line number.
2661 ((string= type
"coderef")
2662 (let ((fragment (concat "coderef-" path
)))
2663 (format "<a href=\"#%s\"%s%s>%s</a>"
2666 (format (concat "class=\"coderef\""
2667 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2668 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2671 (format (org-export-get-coderef-format path desc
)
2672 (org-export-resolve-coderef path info
)))))
2673 ;; Link type is handled by a special function.
2674 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2675 (funcall protocol
(org-link-unescape path
) desc
'html
))
2676 ;; External link with a description part.
2677 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2678 ;; External link without a description part.
2679 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2680 ;; No path, only description. Try to do something useful.
2681 (t (format "<i>%s</i>" desc
)))))
2686 (defun org-html-paragraph (paragraph contents info
)
2687 "Transcode a PARAGRAPH element from Org to HTML.
2688 CONTENTS is the contents of the paragraph, as a string. INFO is
2689 the plist used as a communication channel."
2690 (let* ((parent (org-export-get-parent paragraph
))
2691 (parent-type (org-element-type parent
))
2692 (style '((footnote-definition
2693 " style=\"display:inline;\" class=\"footnote\""
2695 (extra (or (cadr (assoc parent-type style
)) ""))
2696 (after (or (nth 1 (cdr (assoc parent-type style
))) "")))
2698 ((and (eq (org-element-type parent
) 'item
)
2699 (= (org-element-property :begin paragraph
)
2700 (org-element-property :contents-begin parent
)))
2701 ;; leading paragraph in a list item have no tags
2703 ((org-html-standalone-image-p paragraph info
)
2706 (t (format "<p%s>\n%s</p>%s" extra contents after
)))))
2711 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2712 ;; the correct value for the item counter
2713 (defun org-html-begin-plain-list (type &optional arg1
)
2714 "Insert the beginning of the HTML list depending on TYPE.
2715 When ARG1 is a string, use it as the start parameter for ordered
2719 (format "<ol class=\"org-ol\"%s>"
2720 (if arg1
(format " start=\"%d\"" arg1
) "")))
2721 (unordered "<ul class=\"org-ul\">")
2722 (descriptive "<dl class=\"org-dl\">")))
2724 (defun org-html-end-plain-list (type)
2725 "Insert the end of the HTML list depending on TYPE."
2729 (descriptive "</dl>")))
2731 (defun org-html-plain-list (plain-list contents info
)
2732 "Transcode a PLAIN-LIST element from Org to HTML.
2733 CONTENTS is the contents of the list. INFO is a plist holding
2734 contextual information."
2735 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2736 (type (org-element-property :type plain-list
)))
2738 (org-html-begin-plain-list type
)
2739 contents
(org-html-end-plain-list type
))))
2743 (defun org-html-convert-special-strings (string)
2744 "Convert special characters in STRING to HTML."
2745 (let ((all org-html-special-string-regexps
)
2747 (while (setq a
(pop all
))
2748 (setq re
(car a
) rpl
(cdr a
) start
0)
2749 (while (string-match re string start
)
2750 (setq string
(replace-match rpl t nil string
))))
2753 (defun org-html-encode-plain-text (text)
2754 "Convert plain text characters from TEXT to HTML equivalent.
2755 Possible conversions are set in `org-html-protect-char-alist'."
2758 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2759 org-html-protect-char-alist
)
2762 (defun org-html-plain-text (text info
)
2763 "Transcode a TEXT string from Org to HTML.
2764 TEXT is the string to transcode. INFO is a plist holding
2765 contextual information."
2766 (let ((output text
))
2767 ;; Protect following characters: <, >, &.
2768 (setq output
(org-html-encode-plain-text output
))
2769 ;; Handle smart quotes. Be sure to provide original string since
2770 ;; OUTPUT may have been modified.
2771 (when (plist-get info
:with-smart-quotes
)
2772 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
2773 ;; Handle special strings.
2774 (when (plist-get info
:with-special-strings
)
2775 (setq output
(org-html-convert-special-strings output
)))
2776 ;; Handle break preservation if required.
2777 (when (plist-get info
:preserve-breaks
)
2779 (replace-regexp-in-string
2780 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output
)))
2787 (defun org-html-planning (planning contents info
)
2788 "Transcode a PLANNING element from Org to HTML.
2789 CONTENTS is nil. INFO is a plist used as a communication
2791 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2793 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2798 (let ((closed (org-element-property :closed planning
)))
2800 (format span-fmt org-closed-string
2802 (org-element-property :raw-value closed
)))))
2803 (let ((deadline (org-element-property :deadline planning
)))
2805 (format span-fmt org-deadline-string
2807 (org-element-property :raw-value deadline
)))))
2808 (let ((scheduled (org-element-property :scheduled planning
)))
2810 (format span-fmt org-scheduled-string
2812 (org-element-property :raw-value scheduled
)))))))
2816 ;;;; Property Drawer
2818 (defun org-html-property-drawer (property-drawer contents info
)
2819 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2820 CONTENTS is nil. INFO is a plist holding contextual
2822 ;; The property drawer isn't exported but we want separating blank
2823 ;; lines nonetheless.
2829 (defun org-html-quote-block (quote-block contents info
)
2830 "Transcode a QUOTE-BLOCK element from Org to HTML.
2831 CONTENTS holds the contents of the block. INFO is a plist
2832 holding contextual information."
2833 (format "<blockquote>\n%s</blockquote>" contents
))
2838 (defun org-html-quote-section (quote-section contents info
)
2839 "Transcode a QUOTE-SECTION element from Org to HTML.
2840 CONTENTS is nil. INFO is a plist holding contextual information."
2841 (let ((value (org-remove-indentation
2842 (org-element-property :value quote-section
))))
2843 (when value
(format "<pre>\n%s</pre>" value
))))
2848 (defun org-html-section (section contents info
)
2849 "Transcode a SECTION element from Org to HTML.
2850 CONTENTS holds the contents of the section. INFO is a plist
2851 holding contextual information."
2852 (let ((parent (org-export-get-parent-headline section
)))
2853 ;; Before first headline: no container, just return CONTENTS.
2854 (if (not parent
) contents
2855 ;; Get div's class and id references.
2856 (let* ((class-num (+ (org-export-get-relative-level parent info
)
2857 (1- org-html-toplevel-hlevel
)))
2861 (org-export-get-headline-number parent info
) "-")))
2862 ;; Build return value.
2863 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2865 (or (org-element-property :CUSTOM_ID parent
) section-number
)
2870 (defun org-html-radio-target (radio-target text info
)
2871 "Transcode a RADIO-TARGET object from Org to HTML.
2872 TEXT is the text of the target. INFO is a plist holding
2873 contextual information."
2874 (let ((id (org-export-solidify-link-text
2875 (org-element-property :value radio-target
))))
2876 (org-html--anchor id text
)))
2881 (defun org-html-special-block (special-block contents info
)
2882 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2883 CONTENTS holds the contents of the block. INFO is a plist
2884 holding contextual information."
2885 (format "<div class=\"%s\">\n%s\n</div>"
2886 (downcase (org-element-property :type special-block
))
2892 (defun org-html-src-block (src-block contents info
)
2893 "Transcode a SRC-BLOCK element from Org to HTML.
2894 CONTENTS holds the contents of the item. INFO is a plist holding
2895 contextual information."
2896 (if (org-export-read-attribute :attr_html src-block
:textarea
)
2897 (org-html--textarea-block src-block
)
2898 (let ((lang (org-element-property :language src-block
))
2899 (caption (org-export-get-caption src-block
))
2900 (code (org-html-format-code src-block info
))
2901 (label (let ((lbl (org-element-property :name src-block
)))
2903 (format " id=\"%s\""
2904 (org-export-solidify-link-text lbl
))))))
2905 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
2907 "<div class=\"org-src-container\">\n%s%s\n</div>"
2908 (if (not caption
) ""
2909 (format "<label class=\"org-src-name\">%s</label>"
2910 (org-export-data caption info
)))
2911 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
2914 ;;;; Statistics Cookie
2916 (defun org-html-statistics-cookie (statistics-cookie contents info
)
2917 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2918 CONTENTS is nil. INFO is a plist holding contextual information."
2919 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2920 (format "<code>%s</code>" cookie-value
)))
2925 (defun org-html-strike-through (strike-through contents info
)
2926 "Transcode STRIKE-THROUGH from Org to HTML.
2927 CONTENTS is the text with strike-through markup. INFO is a plist
2928 holding contextual information."
2929 (format (or (cdr (assq 'strike-through org-html-text-markup-alist
)) "%s")
2935 (defun org-html-subscript (subscript contents info
)
2936 "Transcode a SUBSCRIPT object from Org to HTML.
2937 CONTENTS is the contents of the object. INFO is a plist holding
2938 contextual information."
2939 (format "<sub>%s</sub>" contents
))
2944 (defun org-html-superscript (superscript contents info
)
2945 "Transcode a SUPERSCRIPT object from Org to HTML.
2946 CONTENTS is the contents of the object. INFO is a plist holding
2947 contextual information."
2948 (format "<sup>%s</sup>" contents
))
2953 (defun org-html-table-cell (table-cell contents info
)
2954 "Transcode a TABLE-CELL element from Org to HTML.
2955 CONTENTS is nil. INFO is a plist used as a communication
2957 (let* ((table-row (org-export-get-parent table-cell
))
2958 (table (org-export-get-parent-table table-cell
))
2960 (if (not org-html-table-align-individual-fields
) ""
2961 (format (if (and (boundp 'org-html-format-table-no-css
)
2962 org-html-format-table-no-css
)
2963 " align=\"%s\"" " class=\"%s\"")
2964 (org-export-table-cell-alignment table-cell info
)))))
2965 (when (or (not contents
) (string= "" (org-trim contents
)))
2966 (setq contents
" "))
2968 ((and (org-export-table-has-header-p table info
)
2969 (= 1 (org-export-table-row-group table-row info
)))
2970 (concat "\n" (format (car org-html-table-header-tags
) "col" cell-attrs
)
2971 contents
(cdr org-html-table-header-tags
)))
2972 ((and org-html-table-use-header-tags-for-first-column
2973 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2974 (concat "\n" (format (car org-html-table-header-tags
) "row" cell-attrs
)
2975 contents
(cdr org-html-table-header-tags
)))
2976 (t (concat "\n" (format (car org-html-table-data-tags
) cell-attrs
)
2977 contents
(cdr org-html-table-data-tags
))))))
2982 (defun org-html-table-row (table-row contents info
)
2983 "Transcode a TABLE-ROW element from Org to HTML.
2984 CONTENTS is the contents of the row. INFO is a plist used as a
2985 communication channel."
2986 ;; Rules are ignored since table separators are deduced from
2987 ;; borders of the current row.
2988 (when (eq (org-element-property :type table-row
) 'standard
)
2989 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info
)))
2992 ;; Case 1: Row belongs to second or subsequent rowgroups.
2993 ((not (= 1 (org-export-table-row-group table-row info
)))
2994 '("<tbody>" .
"\n</tbody>"))
2995 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2996 ((org-export-table-has-header-p
2997 (org-export-get-parent-table table-row
) info
)
2998 '("<thead>" .
"\n</thead>"))
2999 ;; Case 2: Row is from first and only row group.
3000 (t '("<tbody>" .
"\n</tbody>")))))
3002 ;; Begin a rowgroup?
3003 (when (org-export-table-row-starts-rowgroup-p table-row info
)
3004 (car rowgroup-tags
))
3006 (concat "\n" (eval (car org-html-table-row-tags
))
3009 (eval (cdr org-html-table-row-tags
)))
3011 (when (org-export-table-row-ends-rowgroup-p table-row info
)
3012 (cdr rowgroup-tags
))))))
3017 (defun org-html-table-first-row-data-cells (table info
)
3018 "Transcode the first row of TABLE.
3019 INFO is a plist used as a communication channel."
3021 (org-element-map table
'table-row
3023 (unless (eq (org-element-property :type row
) 'rule
) row
))
3025 (special-column-p (org-export-table-has-special-column-p table
)))
3026 (if (not special-column-p
) (org-element-contents table-row
)
3027 (cdr (org-element-contents table-row
)))))
3029 (defun org-html-table--table.el-table
(table info
)
3030 "Format table.el tables into HTML.
3031 INFO is a plist used as a communication channel."
3032 (when (eq (org-element-property :type table
) 'table.el
)
3034 (let ((outbuf (with-current-buffer
3035 (get-buffer-create "*org-export-table*")
3036 (erase-buffer) (current-buffer))))
3038 (insert (org-element-property :value table
))
3040 (re-search-forward "^[ \t]*|[^|]" nil t
)
3041 (table-generate-source 'html outbuf
))
3042 (with-current-buffer outbuf
3043 (prog1 (org-trim (buffer-string))
3046 (defun org-html-table (table contents info
)
3047 "Transcode a TABLE element from Org to HTML.
3048 CONTENTS is the contents of the table. INFO is a plist holding
3049 contextual information."
3050 (case (org-element-property :type table
)
3051 ;; Case 1: table.el table. Convert it using appropriate tools.
3052 (table.el
(org-html-table--table.el-table table info
))
3053 ;; Case 2: Standard table.
3055 (let* ((label (org-element-property :name table
))
3056 (caption (org-export-get-caption table
))
3057 (attributes (mapconcat #'identity
3058 (org-element-property :attr_html table
)
3061 (if (and (boundp 'org-html-format-table-no-css
)
3062 org-html-format-table-no-css
)
3063 "align=\"%s\"" "class=\"%s\""))
3066 (lambda (table info
)
3068 (lambda (table-cell)
3069 (let ((alignment (org-export-table-cell-alignment
3072 ;; Begin a colgroup?
3073 (when (org-export-table-cell-starts-colgroup-p
3076 ;; Add a column. Also specify it's alignment.
3077 (format "\n<col %s/>" (format alignspec alignment
))
3079 (when (org-export-table-cell-ends-colgroup-p
3082 (org-html-table-first-row-data-cells table info
) "\n"))))
3084 (let ((table-tag (plist-get info
:html-table-tag
)))
3086 (and (string-match "<table\\(.*\\)>" table-tag
)
3087 (match-string 1 table-tag
))
3088 (and label
(format " id=\"%s\""
3089 (org-export-solidify-link-text label
)))
3090 (unless (string= attributes
"")
3091 (concat " " attributes
))))))
3092 ;; Remove last blank line.
3093 (setq contents
(substring contents
0 -
1))
3094 (format "<table%s>\n%s\n%s\n%s\n</table>"
3096 (if (not caption
) ""
3097 (format "<caption>%s</caption>"
3098 (org-export-data caption info
)))
3099 (funcall table-column-specs table info
)
3105 (defun org-html-target (target contents info
)
3106 "Transcode a TARGET object from Org to HTML.
3107 CONTENTS is nil. INFO is a plist holding contextual
3109 (let ((id (org-export-solidify-link-text
3110 (org-element-property :value target
))))
3111 (org-html--anchor id
)))
3116 (defun org-html-timestamp (timestamp contents info
)
3117 "Transcode a TIMESTAMP object from Org to HTML.
3118 CONTENTS is nil. INFO is a plist holding contextual
3120 (let ((value (org-html-plain-text
3121 (org-timestamp-translate timestamp
) info
)))
3122 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3123 (replace-regexp-in-string "--" "–" value
))))
3128 (defun org-html-underline (underline contents info
)
3129 "Transcode UNDERLINE from Org to HTML.
3130 CONTENTS is the text with underline markup. INFO is a plist
3131 holding contextual information."
3132 (format (or (cdr (assq 'underline org-html-text-markup-alist
)) "%s")
3138 (defun org-html-verbatim (verbatim contents info
)
3139 "Transcode VERBATIM from Org to HTML.
3140 CONTENTS is nil. INFO is a plist holding contextual
3142 (format (or (cdr (assq 'verbatim org-html-text-markup-alist
)) "%s")
3143 (org-html-plain-text (org-element-property :value verbatim
) info
)))
3148 (defun org-html-verse-block (verse-block contents info
)
3149 "Transcode a VERSE-BLOCK element from Org to HTML.
3150 CONTENTS is verse block contents. INFO is a plist holding
3151 contextual information."
3152 ;; Replace each newline character with line break. Also replace
3153 ;; each blank line with a line break.
3154 (setq contents
(replace-regexp-in-string
3155 "^ *\\\\\\\\$" "<br/>\n"
3156 (replace-regexp-in-string
3157 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3158 ;; Replace each white space at beginning of a line with a
3159 ;; non-breaking space.
3160 (while (string-match "^[ \t]+" contents
)
3161 (let* ((num-ws (length (match-string 0 contents
)))
3162 (ws (let (out) (dotimes (i num-ws out
)
3163 (setq out
(concat out
" "))))))
3164 (setq contents
(replace-match ws nil t contents
))))
3165 (format "<p class=\"verse\">\n%s</p>" contents
))
3169 ;;; Filter Functions
3171 (defun org-html-final-function (contents backend info
)
3172 "Filter to prettify the HTML output.
3173 Prettifying happens if `org-html-pretty-output' is t."
3174 (if (not org-html-pretty-output
) contents
3178 (indent-region (point-min) (point-max))
3179 (buffer-substring-no-properties (point-min) (point-max)))))
3183 ;;; End-user functions
3186 (defun org-html-export-as-html
3187 (&optional async subtreep visible-only body-only ext-plist
)
3188 "Export current buffer to an HTML buffer.
3190 If narrowing is active in the current buffer, only export its
3193 If a region is active, export that region.
3195 A non-nil optional argument ASYNC means the process should happen
3196 asynchronously. The resulting buffer should be accessible
3197 through the `org-export-stack' interface.
3199 When optional argument SUBTREEP is non-nil, export the sub-tree
3200 at point, extracting information from the headline properties
3203 When optional argument VISIBLE-ONLY is non-nil, don't export
3204 contents of hidden elements.
3206 When optional argument BODY-ONLY is non-nil, only write code
3207 between \"<body>\" and \"</body>\" tags.
3209 EXT-PLIST, when provided, is a property list with external
3210 parameters overriding Org default settings, but still inferior to
3211 file-local settings.
3213 Export is done in a buffer named \"*Org HTML Export*\", which
3214 will be displayed when `org-export-show-temporary-export-buffer'
3218 (org-export-async-start
3220 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3223 (goto-char (point-min))
3225 (org-export-add-to-stack (current-buffer) 'html
)))
3226 `(org-export-as 'html
,subtreep
,visible-only
,body-only
',ext-plist
))
3227 (let ((outbuf (org-export-to-buffer
3228 'html
"*Org HTML Export*"
3229 subtreep visible-only body-only ext-plist
)))
3231 (with-current-buffer outbuf
(set-auto-mode t
))
3232 (when org-export-show-temporary-export-buffer
3233 (switch-to-buffer-other-window outbuf
)))))
3236 (defun org-html-export-to-html
3237 (&optional async subtreep visible-only body-only ext-plist
)
3238 "Export current buffer to a HTML file.
3240 If narrowing is active in the current buffer, only export its
3243 If a region is active, export that region.
3245 A non-nil optional argument ASYNC means the process should happen
3246 asynchronously. The resulting file should be accessible through
3247 the `org-export-stack' interface.
3249 When optional argument SUBTREEP is non-nil, export the sub-tree
3250 at point, extracting information from the headline properties
3253 When optional argument VISIBLE-ONLY is non-nil, don't export
3254 contents of hidden elements.
3256 When optional argument BODY-ONLY is non-nil, only write code
3257 between \"<body>\" and \"</body>\" tags.
3259 EXT-PLIST, when provided, is a property list with external
3260 parameters overriding Org default settings, but still inferior to
3261 file-local settings.
3263 Return output file's name."
3265 (let* ((extension (concat "." org-html-extension
))
3266 (file (org-export-output-file-name extension subtreep
))
3267 (org-export-coding-system org-html-coding-system
))
3269 (org-export-async-start
3270 (lambda (f) (org-export-add-to-stack f
'html
))
3271 (let ((org-export-coding-system org-html-coding-system
))
3274 'html
,file
,subtreep
,visible-only
,body-only
',ext-plist
))))
3275 (let ((org-export-coding-system org-html-coding-system
))
3277 'html file subtreep visible-only body-only ext-plist
)))))
3280 (defun org-html-publish-to-html (plist filename pub-dir
)
3281 "Publish an org file to HTML.
3283 FILENAME is the filename of the Org file to be published. PLIST
3284 is the property list for the given project. PUB-DIR is the
3285 publishing directory.
3287 Return output file name."
3288 (org-publish-org-to 'html filename
".html" plist pub-dir
))
3294 ;;;; org-format-table-html
3295 ;;;; org-format-org-table-html
3296 ;;;; org-format-table-table-html
3297 ;;;; org-table-number-fraction
3298 ;;;; org-table-number-regexp
3299 ;;;; org-html-table-caption-above
3300 ;;;; org-html-inline-image-extensions
3301 ;;;; org-export-preferred-target-alist
3302 ;;;; class for anchors
3303 ;;;; org-export-with-section-numbers, body-only
3304 ;;;; org-export-mark-todo-in-toc
3305 ;;;; org-html-format-org-link
3306 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3307 ;;;; alt = (file-name-nondirectory path)
3312 ;; generated-autoload-file: "org-loaddefs.el"
3315 ;;; ox-html.el ends here