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-link-home
"HTML_LINK_HOME" nil org-html-link-home
)
117 (:html-link-up
"HTML_LINK_UP" nil org-html-link-up
)
118 (:html-mathjax
"HTML_MATHJAX" nil
"" space
)
119 (:html-postamble nil
"html-postamble" org-html-postamble
)
120 (:html-preamble nil
"html-preamble" org-html-preamble
)
121 (:html-head
"HTML_HEAD" nil org-html-head newline
)
122 (:html-style-include-default nil nil org-html-head-include-default-style
)
123 (:html-head-include-scripts nil nil org-html-head-include-scripts
)
124 (:html-table-tag nil nil org-html-table-tag
)
125 ;; Redefine regular options.
126 (:creator
"CREATOR" nil org-html-creator-string
)
127 (:with-latex nil
"tex" org-html-with-latex
)
128 ;; Leave room for "ox-infojs.el" extension.
129 (:infojs-opt
"INFOJS_OPT" nil nil
)))
133 ;;; Internal Variables
135 (defvar org-html-format-table-no-css
)
136 (defvar htmlize-buffer-places
) ; from htmlize.el
138 (defconst org-html-special-string-regexps
139 '(("\\\\-" .
"­") ; shy
140 ("---\\([^-]\\)" .
"—\\1") ; mdash
141 ("--\\([^-]\\)" .
"–\\1") ; ndash
142 ("\\.\\.\\." .
"…")) ; hellip
143 "Regular expressions for special string conversion.")
145 (defconst org-html-scripts
146 "<script type=\"text/javascript\">
148 @licstart The following is the entire license notice for the
149 JavaScript code in this tag.
151 Copyright (C) 2012 Free Software Foundation, Inc.
153 The JavaScript code in this tag is free software: you can
154 redistribute it and/or modify it under the terms of the GNU
155 General Public License (GNU GPL) as published by the Free Software
156 Foundation, either version 3 of the License, or (at your option)
157 any later version. The code is distributed WITHOUT ANY WARRANTY;
158 without even the implied warranty of MERCHANTABILITY or FITNESS
159 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
161 As additional permission under GNU GPL version 3 section 7, you
162 may distribute non-source (e.g., minimized or compacted) forms of
163 that code without the copy of the GNU GPL normally required by
164 section 4, provided you include this license notice and a URL
165 through which recipients can access the Corresponding Source.
168 @licend The above is the entire license notice
169 for the JavaScript code in this tag.
171 <!--/*--><![CDATA[/*><!--*/
172 function CodeHighlightOn(elem, id)
174 var target = document.getElementById(id);
176 elem.cacheClassElem = elem.className;
177 elem.cacheClassTarget = target.className;
178 target.className = \"code-highlighted\";
179 elem.className = \"code-highlighted\";
182 function CodeHighlightOff(elem, id)
184 var target = document.getElementById(id);
185 if(elem.cacheClassElem)
186 elem.className = elem.cacheClassElem;
187 if(elem.cacheClassTarget)
188 target.className = elem.cacheClassTarget;
192 "Basic JavaScript that is needed by HTML files produced by Org mode.")
194 (defconst org-html-style-default
195 "<style type=\"text/css\">
196 <!--/*--><![CDATA[/*><!--*/
197 html { font-family: Times, serif; font-size: 12pt; }
198 .title { text-align: center; }
199 .todo { color: red; }
200 .done { color: green; }
201 .tag { background-color: #add8e6; font-weight:normal }
203 .timestamp { color: #bebebe; }
204 .timestamp-kwd { color: #5f9ea0; }
205 .right {margin-left:auto; margin-right:0px; text-align:right;}
206 .left {margin-left:0px; margin-right:auto; text-align:left;}
207 .center {margin-left:auto; margin-right:auto; text-align:center;}
208 p.verse { margin-left: 3% }
210 border: 1pt solid #AEBDCC;
211 background-color: #F3F5F7;
213 font-family: courier, monospace;
217 table { border-collapse: collapse; }
218 td, th { vertical-align: top; }
219 th.right { text-align:center; }
220 th.left { text-align:center; }
221 th.center { text-align:center; }
222 td.right { text-align:right; }
223 td.left { text-align:left; }
224 td.center { text-align:center; }
225 dt { font-weight: bold; }
226 div.figure { padding: 0.5em; }
227 div.figure p { text-align: center; }
230 border:2px solid gray;
234 textarea { overflow-x: auto; }
235 .linenr { font-size:smaller }
236 .code-highlighted {background-color:#ffff00;}
237 .org-info-js_info-navigation { border-style:none; }
238 #org-info-js_console-label { font-size:10px; font-weight:bold;
239 white-space:nowrap; }
240 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
244 "The default style specification for exported HTML files.
245 You can use `org-html-head' and `org-html-head-extra' to add to
246 this style. If you don't want to include this default style,
247 customize `org-html-head-include-default-style'.")
251 ;;; User Configuration Variables
253 (defgroup org-export-html nil
254 "Options for exporting Org mode files to HTML."
255 :tag
"Org Export HTML"
261 (defvar org-html-infojs-opts-table
262 '((path PATH
"http://orgmode.org/org-info.js")
266 (tdepth TOC_DEPTH
"max")
267 (sdepth SECTION_DEPTH
"max")
268 (mouse MOUSE_HINT
"underline")
269 (buttons VIEW_BUTTONS
"0")
271 (up LINK_UP
:html-link-up
)
272 (home LINK_HOME
:html-link-home
))
273 "JavaScript options, long form for script, default values.")
275 (defcustom org-html-use-infojs
'when-configured
276 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
277 This option can be nil or t to never or always use the script.
278 It can also be the symbol `when-configured', meaning that the
279 script will be linked into the export file if and only if there
280 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
281 `org-html-infojs-options'."
282 :group
'org-export-html
284 :package-version
'(Org .
"8.0")
286 (const :tag
"Never" nil
)
287 (const :tag
"When configured in buffer" when-configured
)
288 (const :tag
"Always" t
)))
290 (defcustom org-html-infojs-options
291 (mapcar (lambda (x) (cons (car x
) (nth 2 x
))) org-html-infojs-opts-table
)
292 "Options settings for the INFOJS JavaScript.
293 Each of the options must have an entry in `org-html-infojs-opts-table'.
294 The value can either be a string that will be passed to the script, or
295 a property. This property is then assumed to be a property that is defined
296 by the Export/Publishing setup of Org.
297 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
298 means to use the maximum value consistent with other options."
299 :group
'org-export-html
301 :package-version
'(Org .
"8.0")
303 `(set :greedy t
:inline t
306 (list 'cons
(list 'const
(car x
))
308 (symbol :tag
"Publishing/Export property")
309 (string :tag
"Value"))))
310 org-html-infojs-opts-table
)))
312 (defcustom org-html-infojs-template
313 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
316 * @source: %SCRIPT_PATH
318 * @licstart The following is the entire license notice for the
319 * JavaScript code in %SCRIPT_PATH.
321 * Copyright (C) 2012-2013 Sebastian Rose
324 * The JavaScript code in this tag is free software: you can
325 * redistribute it and/or modify it under the terms of the GNU
326 * General Public License (GNU GPL) as published by the Free Software
327 * Foundation, either version 3 of the License, or (at your option)
328 * any later version. The code is distributed WITHOUT ANY WARRANTY;
329 * without even the implied warranty of MERCHANTABILITY or FITNESS
330 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
332 * As additional permission under GNU GPL version 3 section 7, you
333 * may distribute non-source (e.g., minimized or compacted) forms of
334 * that code without the copy of the GNU GPL normally required by
335 * section 4, provided you include this license notice and a URL
336 * through which recipients can access the Corresponding Source.
338 * @licend The above is the entire license notice
339 * for the JavaScript code in %SCRIPT_PATH.
344 <script type=\"text/javascript\">
347 @licstart The following is the entire license notice for the
348 JavaScript code in this tag.
350 Copyright (C) 2012-2013 Free Software Foundation, Inc.
352 The JavaScript code in this tag is free software: you can
353 redistribute it and/or modify it under the terms of the GNU
354 General Public License (GNU GPL) as published by the Free Software
355 Foundation, either version 3 of the License, or (at your option)
356 any later version. The code is distributed WITHOUT ANY WARRANTY;
357 without even the implied warranty of MERCHANTABILITY or FITNESS
358 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
360 As additional permission under GNU GPL version 3 section 7, you
361 may distribute non-source (e.g., minimized or compacted) forms of
362 that code without the copy of the GNU GPL normally required by
363 section 4, provided you include this license notice and a URL
364 through which recipients can access the Corresponding Source.
367 @licend The above is the entire license notice
368 for the JavaScript code in this tag.
371 <!--/*--><![CDATA[/*><!--*/
373 org_html_manager.setup(); // activate after the parameters are set
376 "The template for the export style additions when org-info.js is used.
377 Option settings will replace the %MANAGER-OPTIONS cookie."
378 :group
'org-export-html
380 :package-version
'(Org .
"8.0")
383 (defun org-html-infojs-install-script (exp-plist backend
)
384 "Install script in export options when appropriate.
385 EXP-PLIST is a plist containing export options. BACKEND is the
386 export back-end currently used."
387 (unless (or (not org-html-use-infojs
)
388 (and (eq org-html-use-infojs
'when-configured
)
389 (or (not (plist-get exp-plist
:infojs-opt
))
390 (string-match "\\<view:nil\\>"
391 (plist-get exp-plist
:infojs-opt
)))))
392 (let* ((template org-html-infojs-template
)
393 (ptoc (plist-get exp-plist
:with-toc
))
394 (hlevels (plist-get exp-plist
:headline-levels
))
396 (tdepth (if (integerp ptoc
) (min ptoc hlevels
) hlevels
))
397 (options (plist-get exp-plist
:infojs-opt
))
398 (table org-html-infojs-opts-table
)
400 (dolist (entry table
)
401 (let* ((opt (car entry
))
403 ;; Compute default values for script option OPT from
404 ;; `org-html-infojs-options' variable.
406 (let ((default (cdr (assq opt org-html-infojs-options
))))
407 (if (and (symbolp default
) (not (memq default
'(t nil
))))
408 (plist-get exp-plist default
)
410 ;; Value set through INFOJS_OPT keyword has precedence
411 ;; over the default one.
412 (val (if (and options
413 (string-match (format "\\<%s:\\(\\S-+\\)" opt
)
415 (match-string 1 options
)
419 (replace-regexp-in-string
420 "%SCRIPT_PATH" val template t t
)))
421 (sdepth (when (integerp (read val
))
422 (setq sdepth
(min (read val
) sdepth
))))
423 (tdepth (when (integerp (read val
))
424 (setq tdepth
(min (read val
) tdepth
))))
427 ((or (eq val t
) (equal val
"t")) "1")
428 ((or (eq val nil
) (equal val
"nil")) "0")
430 (t (format "%s" val
))))
431 (push (cons var val
) style
)))))
432 ;; Now we set the depth of the *generated* TOC to SDEPTH,
433 ;; because the toc will actually determine the splitting. How
434 ;; much of the toc will actually be displayed is governed by the
436 (setq exp-plist
(plist-put exp-plist
:with-toc sdepth
))
437 ;; The table of contents should not show more sections than we
439 (setq tdepth
(min tdepth sdepth
))
440 (push (cons "TOC_DEPTH" tdepth
) style
)
441 ;; Build style string.
442 (setq style
(mapconcat
443 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
447 (when (and style
(> (length style
) 0))
448 (and (string-match "%MANAGER_OPTIONS" template
)
449 (setq style
(replace-match style t t template
))
452 exp-plist
:html-head-extra
453 (concat (or (plist-get exp-plist
:html-head-extra
) "")
456 ;; This script absolutely needs the table of contents, so we
457 ;; change that setting.
458 (unless (plist-get exp-plist
:with-toc
)
459 (setq exp-plist
(plist-put exp-plist
:with-toc t
)))
460 ;; Return the modified property list.
466 (defcustom org-html-text-markup-alist
467 '((bold .
"<b>%s</b>")
468 (code .
"<code>%s</code>")
469 (italic .
"<i>%s</i>")
470 (strike-through .
"<del>%s</del>")
471 (underline .
"<span style=\"text-decoration:underline;\">%s</span>")
472 (verbatim .
"<code>%s</code>"))
473 "Alist of HTML expressions to convert text markup
475 The key must be a symbol among `bold', `code', `italic',
476 `strike-through', `underline' and `verbatim'. The value is
477 a formatting string to wrap fontified text with.
479 If no association can be found for a given markup, text will be
481 :group
'org-export-html
482 :type
'(alist :key-type
(symbol :tag
"Markup type")
483 :value-type
(string :tag
"Format string"))
484 :options
'(bold code italic strike-through underline verbatim
))
489 (defcustom org-html-pretty-output nil
490 "Enable this to generate pretty HTML."
491 :group
'org-export-html
497 (defcustom org-html-format-drawer-function nil
498 "Function called to format a drawer in HTML code.
500 The function must accept two parameters:
501 NAME the drawer name, like \"LOGBOOK\"
502 CONTENTS the contents of the drawer.
504 The function should return the string to be exported.
506 For example, the variable could be set to the following function
507 in order to mimic default behaviour:
509 \(defun org-html-format-drawer-default \(name contents\)
510 \"Format a drawer element for HTML export.\"
512 :group
'org-export-html
518 (defcustom org-html-footnotes-section
"<div id=\"footnotes\">
519 <h2 class=\"footnotes\">%s: </h2>
520 <div id=\"text-footnotes\">
524 "Format for the footnotes section.
525 Should contain a two instances of %s. The first will be replaced with the
526 language-specific word for \"Footnotes\", the second one will be replaced
527 by the footnotes themselves."
528 :group
'org-export-html
531 (defcustom org-html-footnote-format
"<sup>%s</sup>"
532 "The format for the footnote reference.
533 %s will be replaced by the footnote reference itself."
534 :group
'org-export-html
537 (defcustom org-html-footnote-separator
"<sup>, </sup>"
538 "Text used to separate footnotes."
539 :group
'org-export-html
545 (defcustom org-html-toplevel-hlevel
2
546 "The <H> level for level 1 headings in HTML export.
547 This is also important for the classes that will be wrapped around headlines
548 and outline structure. If this variable is 1, the top-level headlines will
549 be <h1>, and the corresponding classes will be outline-1, section-number-1,
550 and outline-text-1. If this is 2, all of these will get a 2 instead.
551 The default for this variable is 2, because we use <h1> for formatting the
553 :group
'org-export-html
556 (defcustom org-html-format-headline-function nil
557 "Function to format headline text.
559 This function will be called with 5 arguments:
560 TODO the todo keyword (string or nil).
561 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
562 PRIORITY the priority of the headline (integer or nil)
563 TEXT the main headline text (string).
564 TAGS the tags (string or nil).
566 The function result will be used in the section format string."
567 :group
'org-export-html
573 (defcustom org-html-allow-name-attribute-in-anchors t
574 "When nil, do not set \"name\" attribute in anchors.
575 By default, anchors are formatted with both \"id\" and \"name\"
576 attributes, when appropriate."
577 :group
'org-export-html
583 (defcustom org-html-format-inlinetask-function nil
584 "Function called to format an inlinetask in HTML code.
586 The function must accept six parameters:
587 TODO the todo keyword, as a string
588 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
589 PRIORITY the inlinetask priority, as a string
590 NAME the inlinetask name, as a string.
591 TAGS the inlinetask tags, as a list of strings.
592 CONTENTS the contents of the inlinetask, as a string.
594 The function should return the string to be exported."
595 :group
'org-export-html
601 (defcustom org-html-with-latex org-export-with-latex
602 "Non-nil means process LaTeX math snippets.
604 When set, the exporter will process LaTeX environments and
607 This option can also be set with the +OPTIONS line,
608 e.g. \"tex:mathjax\". Allowed values are:
610 nil Ignore math snippets.
611 `verbatim' Keep everything in verbatim
612 `dvipng' Process the LaTeX fragments to images. This will also
613 include processing of non-math environments.
614 `imagemagick' Convert the LaTeX fragments to pdf files and use
615 imagemagick to convert pdf files to png files.
616 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
618 t Synonym for `mathjax'."
619 :group
'org-export-html
621 (const :tag
"Do not process math in any way" nil
)
622 (const :tag
"Use dvipng to make images" dvipng
)
623 (const :tag
"Use imagemagick to make images" imagemagick
)
624 (const :tag
"Use MathJax to display math" mathjax
)
625 (const :tag
"Leave math verbatim" verbatim
)))
628 ;;;; Links :: Generic
630 (defcustom org-html-link-org-files-as-html t
631 "Non-nil means make file links to `file.org' point to `file.html'.
632 When org-mode is exporting an org-mode file to HTML, links to
633 non-html files are directly put into a href tag in HTML.
634 However, links to other Org-mode files (recognized by the
635 extension `.org.) should become links to the corresponding html
636 file, assuming that the linked org-mode file will also be
638 When nil, the links still point to the plain `.org' file."
639 :group
'org-export-html
643 ;;;; Links :: Inline images
645 (defcustom org-html-inline-images
'maybe
646 "Non-nil means inline images into exported HTML pages.
647 This is done using an <img> tag. When nil, an anchor with href is used to
648 link to the image. If this option is `maybe', then images in links with
649 an empty description will be inlined, while images with a description will
651 :group
'org-export-html
652 :type
'(choice (const :tag
"Never" nil
)
653 (const :tag
"Always" t
)
654 (const :tag
"When there is no description" maybe
)))
656 (defcustom org-html-inline-image-rules
657 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
658 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
659 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
660 "Rules characterizing image files that can be inlined into HTML.
662 A rule consists in an association whose key is the type of link
663 to consider, and value is a regexp that will be matched against
666 Note that, by default, the image extension *actually* allowed
667 depend on the way the HTML file is processed. When used with
668 pdflatex, pdf, jpg and png images are OK. When processing
669 through dvi to Postscript, only ps and eps are allowed. The
670 default we use here encompasses both."
671 :group
'org-export-html
672 :type
'(alist :key-type
(string :tag
"Type")
673 :value-type
(regexp :tag
"Path")))
678 (defcustom org-html-protect-char-alist
682 "Alist of characters to be converted by `org-html-protect'."
683 :group
'org-export-html
684 :type
'(repeat (cons (string :tag
"Character")
685 (string :tag
"HTML equivalent"))))
690 (defcustom org-html-htmlize-output-type
'inline-css
691 "Output type to be used by htmlize when formatting code snippets.
692 Choices are `css', to export the CSS selectors only, or `inline-css', to
693 export the CSS attribute values inline in the HTML. We use as default
694 `inline-css', in order to make the resulting HTML self-containing.
696 However, this will fail when using Emacs in batch mode for export, because
697 then no rich font definitions are in place. It will also not be good if
698 people with different Emacs setup contribute HTML files to a website,
699 because the fonts will represent the individual setups. In these cases,
700 it is much better to let Org/Htmlize assign classes only, and to use
701 a style file to define the look of these classes.
702 To get a start for your css file, start Emacs session and make sure that
703 all the faces you are interested in are defined, for example by loading files
704 in all modes you want. Then, use the command
705 \\[org-html-htmlize-generate-css] to extract class definitions."
706 :group
'org-export-html
707 :type
'(choice (const css
) (const inline-css
)))
709 (defcustom org-html-htmlize-font-prefix
"org-"
710 "The prefix for CSS class names for htmlize font specifications."
711 :group
'org-export-html
716 (defcustom org-html-table-tag
717 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
718 "The HTML tag that is used to start a table.
719 This must be a <table> tag, but you may change the options like
720 borders and spacing."
721 :group
'org-export-html
724 (defcustom org-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
725 "The opening tag for table header fields.
726 This is customizable so that alignment options can be specified.
727 The first %s will be filled with the scope of the field, either row or col.
728 The second %s will be replaced by a style entry to align the field.
729 See also the variable `org-html-table-use-header-tags-for-first-column'.
730 See also the variable `org-html-table-align-individual-fields'."
731 :group
'org-export-html
732 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
734 (defcustom org-html-table-data-tags
'("<td%s>" .
"</td>")
735 "The opening tag for table data fields.
736 This is customizable so that alignment options can be specified.
737 The first %s will be filled with the scope of the field, either row or col.
738 The second %s will be replaced by a style entry to align the field.
739 See also the variable `org-html-table-align-individual-fields'."
740 :group
'org-export-html
741 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
743 (defcustom org-html-table-row-tags
'("<tr>" .
"</tr>")
744 "The opening tag for table data fields.
745 This is customizable so that alignment options can be specified.
746 Instead of strings, these can be Lisp forms that will be evaluated
747 for each row in order to construct the table row tags. During evaluation,
748 the variable `head' will be true when this is a header line, nil when this
749 is a body line. And the variable `nline' will contain the line number,
750 starting from 1 in the first header line. For example
752 (setq org-html-table-row-tags
755 (if (= (mod nline 2) 1)
756 \"<tr class=\\\"tr-odd\\\">\"
757 \"<tr class=\\\"tr-even\\\">\"))
760 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
761 :group
'org-export-html
763 (choice :tag
"Opening tag"
764 (string :tag
"Specify")
766 (choice :tag
"Closing tag"
767 (string :tag
"Specify")
770 (defcustom org-html-table-align-individual-fields t
771 "Non-nil means attach style attributes for alignment to each table field.
772 When nil, alignment will only be specified in the column tags, but this
773 is ignored by some browsers (like Firefox, Safari). Opera does it right
775 :group
'org-export-html
778 (defcustom org-html-table-use-header-tags-for-first-column nil
779 "Non-nil means format column one in tables with header tags.
780 When nil, also column one will use data tags."
781 :group
'org-export-html
784 (defcustom org-html-table-caption-above t
785 "When non-nil, place caption string at the beginning of the table.
786 Otherwise, place it near the end."
787 :group
'org-export-html
793 (defcustom org-html-tag-class-prefix
""
794 "Prefix to class names for TODO keywords.
795 Each tag gets a class given by the tag itself, with this prefix.
796 The default prefix is empty because it is nice to just use the keyword
797 as a class name. But if you get into conflicts with other, existing
798 CSS classes, then this prefix can be very useful."
799 :group
'org-export-html
803 ;;;; Template :: Generic
805 (defcustom org-html-extension
"html"
806 "The extension for exported HTML files."
807 :group
'org-export-html
810 (defcustom org-html-xml-declaration
811 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
812 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
813 "The extension for exported HTML files.
814 %s will be replaced with the charset of the exported file.
815 This may be a string, or an alist with export extensions
816 and corresponding declarations."
817 :group
'org-export-html
819 (string :tag
"Single declaration")
820 (repeat :tag
"Dependent on extension"
821 (cons (string :tag
"Extension")
822 (string :tag
"Declaration")))))
824 (defcustom org-html-coding-system
'utf-8
825 "Coding system for HTML export.
826 Use utf-8 as the default value."
827 :group
'org-export-html
828 :type
'coding-system
)
830 (defcustom org-html-divs
'("preamble" "content" "postamble")
831 "The name of the main divs for HTML export.
832 This is a list of three strings, the first one for the preamble
833 DIV, the second one for the content DIV and the third one for the
835 :group
'org-export-html
837 (string :tag
" Div for the preamble:")
838 (string :tag
" Div for the content:")
839 (string :tag
"Div for the postamble:")))
842 ;;;; Template :: Mathjax
844 (defcustom org-html-mathjax-options
845 '((path "http://orgmode.org/mathjax/MathJax.js")
850 "Options for MathJax setup.
852 path The path where to find MathJax
853 scale Scaling for the HTML-CSS backend, usually between 100 and 133
854 align How to align display math: left, center, or right
855 indent If align is not center, how far from the left/right side?
856 mathml Should a MathML player be used if available?
857 This is faster and reduces bandwidth use, but currently
858 sometimes has lower spacing quality. Therefore, the default is
859 nil. When browsers get better, this switch can be flipped.
861 You can also customize this for each buffer, using something like
863 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
864 :group
'org-export-html
865 :type
'(list :greedy t
866 (list :tag
"path (the path from where to load MathJax.js)"
867 (const :format
" " path
) (string))
868 (list :tag
"scale (scaling for the displayed math)"
869 (const :format
" " scale
) (string))
870 (list :tag
"align (alignment of displayed equations)"
871 (const :format
" " align
) (string))
872 (list :tag
"indent (indentation with left or right alignment)"
873 (const :format
" " indent
) (string))
874 (list :tag
"mathml (should MathML display be used is possible)"
875 (const :format
" " mathml
) (boolean))))
877 (defcustom org-html-mathjax-template
878 "<script type=\"text/javascript\" src=\"%PATH\">
879 <!--/*--><![CDATA[/*><!--*/
881 // Only one of the two following lines, depending on user settings
882 // First allows browser-native MathML display, second forces HTML/CSS
883 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
884 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
885 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
886 \"TeX/noUndefined.js\"],
888 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
889 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
890 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
891 ignoreClass: \"tex2jax_ignore\",
892 processEscapes: false,
893 processEnvironments: true,
896 showProcessingMessages: true,
897 displayAlign: \"%ALIGN\",
898 displayIndent: \"%INDENT\",
902 availableFonts: [\"STIX\",\"TeX\"],
903 preferredFont: \"TeX\",
919 "The MathJax setup for XHTML files."
920 :group
'org-export-html
924 ;;;; Template :: Postamble
926 (defcustom org-html-postamble
'auto
927 "Non-nil means insert a postamble in HTML export.
929 When `t', insert a string as defined by the formatting string in
930 `org-html-postamble-format'. When set to a string, this
931 string overrides `org-html-postamble-format'. When set to
932 'auto, discard `org-html-postamble-format' and honor
933 `org-export-author/email/creator-info' variables. When set to a
934 function, apply this function and insert the returned string.
935 The function takes the property list of export options as its
938 Setting :html-postamble in publishing projects will take
939 precedence over this variable."
940 :group
'org-export-html
941 :type
'(choice (const :tag
"No postamble" nil
)
942 (const :tag
"Auto preamble" 'auto
)
943 (const :tag
"Default formatting string" t
)
944 (string :tag
"Custom formatting string")
945 (function :tag
"Function (must return a string)")))
947 (defcustom org-html-postamble-format
948 '(("en" "<p class=\"author\">Author: %a (%e)</p>
949 <p class=\"date\">Date: %d</p>
950 <p class=\"creator\">Generated by %c</p>
951 <p class=\"xhtml-validation\">%v</p>"))
952 "Alist of languages and format strings for the HTML postamble.
954 The first element of each list is the language code, as used for
955 the #+LANGUAGE keyword.
957 The second element of each list is a format string to format the
958 postamble itself. This format string can contain these elements:
960 %a stands for the author's name.
961 %e stands for the author's email.
962 %d stands for the date.
963 %c will be replaced by information about Org/Emacs versions.
964 %v will be replaced by `org-html-validation-link'.
966 If you need to use a \"%\" character, you need to escape it
968 :group
'org-export-html
969 :type
'(alist :key-type
(string :tag
"Language")
970 :value-type
(string :tag
"Format string")))
972 (defcustom org-html-validation-link
973 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
974 "Link to HTML validation service."
975 :group
'org-export-html
978 (defcustom org-html-creator-string
979 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
980 (if (fboundp 'org-version
) (org-version) "(Unknown)")
982 "String to insert at the end of the HTML document."
983 :group
'org-export-html
984 :type
'(string :tag
"Creator string"))
987 ;;;; Template :: Preamble
989 (defcustom org-html-preamble t
990 "Non-nil means insert a preamble in HTML export.
992 When `t', insert a string as defined by one of the formatting
993 strings in `org-html-preamble-format'. When set to a
994 string, this string overrides `org-html-preamble-format'.
995 When set to a function, apply this function and insert the
996 returned string. The function takes the property list of export
997 options as its only argument.
999 Setting :html-preamble in publishing projects will take
1000 precedence over this variable."
1001 :group
'org-export-html
1002 :type
'(choice (const :tag
"No preamble" nil
)
1003 (const :tag
"Default preamble" t
)
1004 (string :tag
"Custom formatting string")
1005 (function :tag
"Function (must return a string)")))
1007 (defcustom org-html-preamble-format
'(("en" ""))
1008 "Alist of languages and format strings for the HTML preamble.
1010 The first element of each list is the language code, as used for
1011 the #+LANGUAGE keyword.
1013 The second element of each list is a format string to format the
1014 preamble itself. This format string can contain these elements:
1016 %t stands for the title.
1017 %a stands for the author's name.
1018 %e stands for the author's email.
1019 %d stands for the date.
1021 If you need to use a \"%\" character, you need to escape it
1023 :group
'org-export-html
1024 :type
'(alist :key-type
(string :tag
"Language")
1025 :value-type
(string :tag
"Format string")))
1027 (defcustom org-html-link-up
""
1028 "Where should the \"UP\" link of exported HTML pages lead?"
1029 :group
'org-export-html
1030 :type
'(string :tag
"File or URL"))
1032 (defcustom org-html-link-home
""
1033 "Where should the \"HOME\" link of exported HTML pages lead?"
1034 :group
'org-export-html
1035 :type
'(string :tag
"File or URL"))
1037 (defcustom org-html-home
/up-format
1038 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
1039 <a accesskey=\"h\" href=\"%s\"> UP </a>
1041 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1043 "Snippet used to insert the HOME and UP links.
1044 This is a format string, the first %s will receive the UP link,
1045 the second the HOME link. If both `org-html-link-up' and
1046 `org-html-link-home' are empty, the entire snippet will be
1048 :group
'org-export-html
1052 ;;;; Template :: Scripts
1054 (define-obsolete-variable-alias
1055 'org-html-style-include-scripts
'org-html-head-include-scripts
"24.4")
1056 (defcustom org-html-head-include-scripts t
1057 "Non-nil means include the JavaScript snippets in exported HTML files.
1058 The actual script is defined in `org-html-scripts' and should
1060 :group
'org-export-html
1062 :package-version
'(Org .
"8.0")
1066 ;;;; Template :: Styles
1068 (define-obsolete-variable-alias
1069 'org-html-style-include-default
'org-html-head-include-default-style
"24.4")
1070 (defcustom org-html-head-include-default-style t
1071 "Non-nil means include the default style in exported HTML files.
1072 The actual style is defined in `org-html-style-default' and
1073 should not be modified. Use `org-html-head' to add your own
1075 :group
'org-export-html
1077 :package-version
'(Org .
"8.0")
1080 (put 'org-html-head-include-default-style
'safe-local-variable
'booleanp
)
1082 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
1083 (defcustom org-html-head
""
1084 "Org-wide head definitions for exported HTML files.
1086 This variable can contain the full HTML structure to provide a
1087 style, including the surrounding HTML tags. You can consider
1088 including definitions for the following classes: title, todo,
1089 done, timestamp, timestamp-kwd, tag, target.
1091 For example, a valid value would be:
1093 <style type=\"text/css\">
1095 p { font-weight: normal; color: gray; }
1096 h1 { color: black; }
1097 .title { text-align: center; }
1098 .todo, .timestamp-kwd { color: red; }
1099 .done { color: green; }
1103 If you want to refer to an external style, use something like
1105 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1107 As the value of this option simply gets inserted into the HTML
1108 <head> header, you can use it to add any arbitrary text to the
1110 :group
'org-export-html
1112 :package-version
'(Org .
"8.0")
1115 (put 'org-html-head
'safe-local-variable
'stringp
)
1119 (defcustom org-html-todo-kwd-class-prefix
""
1120 "Prefix to class names for TODO keywords.
1121 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1122 The default prefix is empty because it is nice to just use the keyword
1123 as a class name. But if you get into conflicts with other, existing
1124 CSS classes, then this prefix can be very useful."
1125 :group
'org-export-html
1128 (defcustom org-html-display-buffer-mode
'html-mode
1129 "Default mode when visiting the HTML output."
1130 :group
'org-export-html
1132 :package-version
'(Org .
"8.0")
1133 :type
'(choice (function 'html-mode
)
1134 (function 'nxml-mode
)
1135 (function :tag
"Other mode")))
1139 ;;; Internal Functions
1141 (defun org-html-format-inline-image (src &optional
1142 caption label attr standalone-p
)
1143 (let* ((id (if (not label
) ""
1144 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1147 ((string-match "\\<alt=" (or attr
"")) "")
1148 ((string-match "^ltxpng/" src
)
1149 (format " alt=\"%s\""
1150 (org-html-encode-plain-text
1151 (org-find-text-property-in-string
1152 'org-latex-src src
))))
1153 (t (format " alt=\"%s\""
1154 (file-name-nondirectory src
)))))))
1157 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1158 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1159 id
(format "\n<p>%s</p>" img
)
1160 (when caption
(format "\n<p>%s</p>" caption
)))))
1161 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1163 (defun org-html--textarea-block (element)
1164 "Transcode ELEMENT into a textarea block.
1165 ELEMENT is either a src block or an example block."
1166 (let ((code (car (org-export-unravel-code element
)))
1167 (attr (org-export-read-attribute :attr_html element
)))
1168 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
1169 (or (plist-get attr
:width
) 80)
1170 (or (plist-get attr
:height
) (org-count-lines code
))
1176 (defun org-html-bibliography ()
1177 "Find bibliography, cut it out and return it."
1179 (let (beg end
(cnt 1) bib
)
1181 (goto-char (point-min))
1182 (when (re-search-forward
1183 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1184 (setq beg
(match-beginning 0))
1185 (while (re-search-forward "</?div\\>" nil t
)
1186 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1188 (and (looking-at ">") (forward-char 1))
1189 (setq bib
(buffer-substring beg
(point)))
1190 (delete-region beg
(point))
1191 (throw 'exit bib
))))
1196 (defun org-html-splice-attributes (tag attributes
)
1197 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1198 (if (not attributes
)
1200 (let (oldatt newatt
)
1201 (setq oldatt
(org-extract-attributes-from-string tag
)
1203 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1205 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1206 (if (string-match ">" tag
)
1208 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1212 (defun org-export-splice-style (style extra
)
1213 "Splice EXTRA into STYLE, just before \"</style>\"."
1214 (if (and (stringp extra
)
1215 (string-match "\\S-" extra
)
1216 (string-match "</style>" style
))
1217 (concat (substring style
0 (match-beginning 0))
1219 (substring style
(match-beginning 0)))
1222 (defun org-html-htmlize-region-for-paste (beg end
)
1223 "Convert the region to HTML, using htmlize.el.
1224 This is much like `htmlize-region-for-paste', only that it uses
1225 the settings define in the org-... variables."
1226 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1227 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1228 (htmlbuf (htmlize-region beg end
)))
1230 (with-current-buffer htmlbuf
1231 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1232 (plist-get htmlize-buffer-places
'content-end
)))
1233 (kill-buffer htmlbuf
))))
1236 (defun org-html-htmlize-generate-css ()
1237 "Create the CSS for all font definitions in the current Emacs session.
1238 Use this to create face definitions in your CSS style file that can then
1239 be used by code snippets transformed by htmlize.
1240 This command just produces a buffer that contains class definitions for all
1241 faces used in the current Emacs session. You can copy and paste the ones you
1242 need into your CSS file.
1244 If you then set `org-html-htmlize-output-type' to `css', calls
1245 to the function `org-html-htmlize-region-for-paste' will
1246 produce code that uses these same face definitions."
1249 (and (get-buffer "*html*") (kill-buffer "*html*"))
1251 (let ((fl (face-list))
1252 (htmlize-css-name-prefix "org-")
1253 (htmlize-output-type 'css
)
1255 (while (setq f
(pop fl
)
1256 i
(and f
(face-attribute f
:inherit
)))
1257 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1258 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1259 (htmlize-region (point-min) (point-max))))
1260 (org-pop-to-buffer-same-window "*html*")
1261 (goto-char (point-min))
1262 (if (re-search-forward "<style" nil t
)
1263 (delete-region (point-min) (match-beginning 0)))
1264 (if (re-search-forward "</style>" nil t
)
1265 (delete-region (1+ (match-end 0)) (point-max)))
1266 (beginning-of-line 1)
1267 (if (looking-at " +") (replace-match ""))
1268 (goto-char (point-min)))
1270 (defun org-html--make-string (n string
)
1271 "Build a string by concatenating N times STRING."
1272 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1274 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1275 "Turn todo keyword into a valid class name.
1276 Replaces invalid characters with \"_\"."
1278 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1279 (setq kwd
(replace-match "_" t t kwd
))))
1282 (defun org-html-format-footnote-reference (n def refcnt
)
1283 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1284 (format org-html-footnote-format
1285 (let* ((id (format "fnr.%s%s" n extra
))
1286 (href (format " href=\"#fn.%s\"" n
))
1287 (attributes (concat " class=\"footref\"" href
)))
1288 (org-html--anchor id n attributes
)))))
1290 (defun org-html-format-footnotes-section (section-name definitions
)
1291 (if (not definitions
) ""
1292 (format org-html-footnotes-section section-name definitions
)))
1294 (defun org-html-format-footnote-definition (fn)
1295 (let ((n (car fn
)) (def (cdr fn
)))
1297 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1298 (format org-html-footnote-format
1299 (let* ((id (format "fn.%s" n
))
1300 (href (format " href=\"#fnr.%s\"" n
))
1301 (attributes (concat " class=\"footnum\"" href
)))
1302 (org-html--anchor id n attributes
)))
1305 (defun org-html-footnote-section (info)
1306 (let* ((fn-alist (org-export-collect-footnote-definitions
1307 (plist-get info
:parse-tree
) info
))
1310 (loop for
(n type raw
) in fn-alist collect
1311 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1312 (org-trim (org-export-data raw info
))
1314 (org-trim (org-export-data raw info
))))))))
1316 (org-html-format-footnotes-section
1317 (org-html--translate "Footnotes" info
)
1319 "<table>\n%s\n</table>\n"
1320 (mapconcat 'org-html-format-footnote-definition fn-alist
"\n"))))))
1326 (defun org-html--build-meta-info (info)
1327 "Return meta tags for exported document.
1328 INFO is a plist used as a communication channel."
1329 (let* ((title (org-export-data (plist-get info
:title
) info
))
1330 (author (and (plist-get info
:with-author
)
1331 (let ((auth (plist-get info
:author
)))
1332 (and auth
(org-export-data auth info
)))))
1333 (date (and (plist-get info
:with-date
)
1334 (let ((date (plist-get info
:date
)))
1335 (and date
(org-export-data date info
)))))
1336 (description (plist-get info
:description
))
1337 (keywords (plist-get info
:keywords
)))
1339 (format "<title>%s</title>\n" title
)
1341 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1342 (or (and org-html-coding-system
1343 (fboundp 'coding-system-get
)
1344 (coding-system-get org-html-coding-system
'mime-charset
))
1346 (format "<meta name=\"title\" content=\"%s\"/>\n" title
)
1347 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1348 (and date
(format "<meta name=\"generated\" content=\"%s\"/>\n" date
))
1349 (and author
(format "<meta name=\"author\" content=\"%s\"/>\n" author
))
1351 (format "<meta name=\"description\" content=\"%s\"/>\n" description
))
1353 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords
)))))
1355 (defun org-html--build-style (info)
1356 "Return style information for exported document.
1357 INFO is a plist used as a communication channel."
1358 (org-element-normalize-string
1360 (when (plist-get info
:html-style-include-default
)
1361 (org-element-normalize-string org-html-style-default
))
1362 (org-element-normalize-string (plist-get info
:html-style
))
1363 (when (and (plist-get info
:html-htmlized-css-url
)
1364 (eq org-html-htmlize-output-type
'css
))
1365 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1366 (plist-get info
:html-htmlized-css-url
)))
1367 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1369 (defun org-html--build-mathjax-config (info)
1370 "Insert the user setup into the mathjax template.
1371 INFO is a plist used as a communication channel."
1372 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1373 (org-element-map (plist-get info
:parse-tree
)
1374 '(latex-fragment latex-environment
) 'identity info t
))
1375 (let ((template org-html-mathjax-template
)
1376 (options org-html-mathjax-options
)
1377 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1378 name val
(yes " ") (no "// ") x
)
1381 (setq name
(car e
) val
(nth 1 e
))
1382 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1383 (setq val
(car (read-from-string
1384 (substring in-buffer
(match-end 0))))))
1385 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1386 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1387 (setq template
(replace-match val t t template
))))
1389 (setq val
(nth 1 (assq 'mathml options
)))
1390 (if (string-match (concat "\\<mathml:") in-buffer
)
1391 (setq val
(car (read-from-string
1392 (substring in-buffer
(match-end 0))))))
1393 ;; Exchange prefixes depending on mathml setting.
1394 (if (not val
) (setq x yes yes no no x
))
1395 ;; Replace cookies to turn on or off the config/jax lines.
1396 (if (string-match ":MMLYES:" template
)
1397 (setq template
(replace-match yes t t template
)))
1398 (if (string-match ":MMLNO:" template
)
1399 (setq template
(replace-match no t t template
)))
1400 ;; Return the modified template.
1401 (org-element-normalize-string template
))))
1403 (defun org-html--build-preamble (info)
1404 "Return document preamble as a string, or nil.
1405 INFO is a plist used as a communication channel."
1406 (let ((preamble (plist-get info
:html-preamble
)))
1408 (let ((preamble-contents
1409 (if (functionp preamble
) (funcall preamble info
)
1410 (let ((title (org-export-data (plist-get info
:title
) info
))
1411 (date (if (not (plist-get info
:with-date
)) ""
1412 (org-export-data (plist-get info
:date
) info
)))
1413 (author (if (not (plist-get info
:with-author
)) ""
1414 (org-export-data (plist-get info
:author
) info
)))
1415 (email (if (not (plist-get info
:with-email
)) ""
1416 (plist-get info
:email
))))
1417 (if (stringp preamble
)
1418 (format-spec preamble
1419 `((?t .
,title
) (?a .
,author
)
1420 (?d .
,date
) (?e .
,email
)))
1422 (or (cadr (assoc (plist-get info
:language
)
1423 org-html-preamble-format
))
1424 (cadr (assoc "en" org-html-preamble-format
)))
1425 `((?t .
,title
) (?a .
,author
)
1426 (?d .
,date
) (?e .
,email
))))))))
1427 (when (org-string-nw-p preamble-contents
)
1428 (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs
))
1429 (org-element-normalize-string preamble-contents
)
1432 (defun org-html--build-postamble (info)
1433 "Return document postamble as a string, or nil.
1434 INFO is a plist used as a communication channel."
1435 (let ((postamble (plist-get info
:html-postamble
)))
1437 (let ((postamble-contents
1438 (if (functionp postamble
) (funcall postamble info
)
1439 (let ((date (if (not (plist-get info
:with-date
)) ""
1440 (org-export-data (plist-get info
:date
) info
)))
1441 (author (let ((author (plist-get info
:author
)))
1442 (and author
(org-export-data author info
))))
1445 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1446 (split-string (plist-get info
:email
) ",+ *")
1448 (html-validation-link (or org-html-validation-link
""))
1449 (creator-info (plist-get info
:creator
)))
1450 (cond ((stringp postamble
)
1451 (format-spec postamble
1452 `((?a .
,author
) (?e .
,email
)
1453 (?d .
,date
) (?c .
,creator-info
)
1454 (?v .
,html-validation-link
))))
1455 ((eq postamble
'auto
)
1457 (when (plist-get info
:time-stamp-file
)
1458 (format "<p class=\"date\">%s: %s</p>\n"
1459 (org-html--translate "Date" info
)
1461 (when (and (plist-get info
:with-author
) author
)
1462 (format "<p class=\"author\">%s : %s</p>\n"
1463 (org-html--translate "Author" info
)
1465 (when (and (plist-get info
:with-email
) email
)
1466 (format "<p class=\"email\">%s </p>\n" email
))
1467 (when (plist-get info
:with-creator
)
1468 (format "<p class=\"creator\">%s</p>\n"
1470 html-validation-link
"\n"))
1472 (or (cadr (assoc (plist-get info
:language
)
1473 org-html-postamble-format
))
1474 (cadr (assoc "en" org-html-postamble-format
)))
1475 `((?a .
,author
) (?e .
,email
)
1476 (?d .
,date
) (?c .
,creator-info
)
1477 (?v .
,html-validation-link
)))))))))
1478 (when (org-string-nw-p postamble-contents
)
1480 (format "<div id=\"%s\">\n" (nth 2 org-html-divs
))
1481 (org-element-normalize-string postamble-contents
)
1484 (defun org-html-inner-template (contents info
)
1485 "Return body of document string after HTML conversion.
1486 CONTENTS is the transcoded contents string. INFO is a plist
1487 holding export options."
1489 (format "<div id=\"%s\">\n" (nth 1 org-html-divs
))
1491 (let ((title (plist-get info
:title
)))
1493 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data title info
))))
1494 ;; Table of contents.
1495 (let ((depth (plist-get info
:with-toc
)))
1496 (when depth
(org-html-toc depth info
)))
1497 ;; Document contents.
1499 ;; Footnotes section.
1500 (org-html-footnote-section info
)
1502 (org-html-bibliography)
1505 (defun org-html-template (contents info
)
1506 "Return complete document string after HTML conversion.
1507 CONTENTS is the transcoded contents string. INFO is a plist
1508 holding export options."
1511 (or (and (stringp org-html-xml-declaration
)
1512 org-html-xml-declaration
)
1513 (cdr (assoc (plist-get info
:html-extension
)
1514 org-html-xml-declaration
))
1515 (cdr (assoc "html" org-html-xml-declaration
))
1518 (or (and org-html-coding-system
1519 (fboundp 'coding-system-get
)
1520 (coding-system-get org-html-coding-system
'mime-charset
))
1523 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1524 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
1525 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1526 (plist-get info
:language
) (plist-get info
:language
))
1528 (org-html--build-meta-info info
)
1529 (org-html--build-style info
)
1530 (org-html--build-mathjax-config info
)
1533 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1534 (link-home (org-trim (plist-get info
:html-link-home
))))
1535 (unless (and (string= link-up
"") (string= link-up
""))
1536 (format org-html-home
/up-format
1537 (or link-up link-home
)
1538 (or link-home link-up
))))
1540 (org-html--build-preamble info
)
1541 ;; Document contents.
1544 (org-html--build-postamble info
)
1545 ;; Closing document.
1546 "</body>\n</html>"))
1548 (defun org-html--translate (s info
)
1549 "Translate string S according to specified language.
1550 INFO is a plist used as a communication channel."
1551 (org-export-translate s
:html info
))
1555 (defun org-html--anchor (&optional id desc attributes
)
1556 (let* ((name (and org-html-allow-name-attribute-in-anchors id
))
1557 (attributes (concat (and id
(format " id=\"%s\"" id
))
1558 (and name
(format " name=\"%s\"" name
))
1560 (format "<a%s>%s</a>" attributes
(or desc
""))))
1564 (defun org-html--todo (todo)
1566 (format "<span class=\"%s %s%s\">%s</span>"
1567 (if (member todo org-done-keywords
) "done" "todo")
1568 org-html-todo-kwd-class-prefix
(org-html-fix-class-name todo
)
1573 (defun org-html--tags (tags)
1575 (format "<span class=\"tag\">%s</span>"
1578 (format "<span class=\"%s\">%s</span>"
1579 (concat org-html-tag-class-prefix
1580 (org-html-fix-class-name tag
))
1586 (defun* org-html-format-headline
1587 (todo todo-type priority text tags
1588 &key level section-number headline-label
&allow-other-keys
)
1589 (let ((section-number
1590 (when section-number
1591 (format "<span class=\"section-number-%d\">%s</span> "
1592 level section-number
)))
1593 (todo (org-html--todo todo
))
1594 (tags (org-html--tags tags
)))
1595 (concat section-number todo
(and todo
" ") text
1596 (and tags
"   ") tags
)))
1600 (defun org-html-fontify-code (code lang
)
1601 "Color CODE with htmlize library.
1602 CODE is a string representing the source code to colorize. LANG
1603 is the language used for CODE, as a string, or nil."
1606 ;; Case 1: No lang. Possibly an example block.
1608 ;; Simple transcoding.
1609 (org-html-encode-plain-text code
))
1610 ;; Case 2: No htmlize or an inferior version of htmlize
1611 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1613 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1614 ;; Simple transcoding.
1615 (org-html-encode-plain-text code
))
1618 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1619 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1621 ;; Case 1: Language is not associated with any Emacs mode
1622 ((not (functionp lang-mode
))
1623 ;; Simple transcoding.
1624 (org-html-encode-plain-text code
))
1625 ;; Case 2: Default. Fontify code.
1628 (setq code
(with-temp-buffer
1629 ;; Switch to language-specific mode.
1633 (font-lock-fontify-buffer)
1634 ;; Remove formatting on newline characters.
1636 (let ((beg (point-min))
1639 (while (progn (end-of-line) (< (point) end
))
1640 (put-text-property (point) (1+ (point)) 'face nil
)
1643 (set-buffer-modified-p nil
)
1645 (org-html-htmlize-region-for-paste
1646 (point-min) (point-max))))
1647 ;; Strip any enclosing <pre></pre> tags.
1648 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1649 (end (and beg
(string-match "</pre>\\'" code
))))
1650 (if (and beg end
) (substring code beg end
) code
)))))))))
1652 (defun org-html-do-format-code
1653 (code &optional lang refs retain-labels num-start
)
1654 "Format CODE string as source code.
1655 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1656 respectively, the language of the source code, as a string, an
1657 alist between line numbers and references (as returned by
1658 `org-export-unravel-code'), a boolean specifying if labels should
1659 appear in the source code, and the number associated to the first
1661 (let* ((code-lines (org-split-string code
"\n"))
1662 (code-length (length code-lines
))
1666 (length (number-to-string (+ code-length num-start
))))))
1667 (code (org-html-fontify-code code lang
)))
1668 (org-export-format-code
1670 (lambda (loc line-num ref
)
1673 ;; Add line number, if needed.
1675 (format "<span class=\"linenr\">%s</span>"
1676 (format num-fmt line-num
)))
1677 ;; Transcoded src line.
1679 ;; Add label, if needed.
1680 (when (and ref retain-labels
) (format " (%s)" ref
))))
1681 ;; Mark transcoded line as an anchor, if needed.
1683 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1687 (defun org-html-format-code (element info
)
1688 "Format contents of ELEMENT as source code.
1689 ELEMENT is either an example block or a src block. INFO is
1690 a plist used as a communication channel."
1691 (let* ((lang (org-element-property :language element
))
1692 ;; Extract code and references.
1693 (code-info (org-export-unravel-code element
))
1694 (code (car code-info
))
1695 (refs (cdr code-info
))
1696 ;; Does the src block contain labels?
1697 (retain-labels (org-element-property :retain-labels element
))
1698 ;; Does it have line numbers?
1699 (num-start (case (org-element-property :number-lines element
)
1700 (continued (org-export-get-loc element info
))
1702 (org-html-do-format-code code lang refs retain-labels num-start
)))
1706 ;;; Tables of Contents
1708 (defun org-html-toc (depth info
)
1709 "Build a table of contents.
1710 DEPTH is an integer specifying the depth of the table. INFO is
1711 a plist used as a communication channel. Return the table of
1712 contents as a string, or nil if it is empty."
1714 (mapcar (lambda (headline)
1715 (cons (org-html--format-toc-headline headline info
)
1716 (org-export-get-relative-level headline info
)))
1717 (org-export-collect-headlines info depth
))))
1719 (concat "<div id=\"table-of-contents\">\n"
1720 (format "<h%d>%s</h%d>\n"
1721 org-html-toplevel-hlevel
1722 (org-html--translate "Table of Contents" info
)
1723 org-html-toplevel-hlevel
)
1724 "<div id=\"text-table-of-contents\">"
1725 (org-html--toc-text toc-entries
)
1729 (defun org-html--toc-text (toc-entries)
1730 "Return innards of a table of contents, as a string.
1731 TOC-ENTRIES is an alist where key is an entry title, as a string,
1732 and value is its relative level, as an integer."
1733 (let* ((prev-level (1- (cdar toc-entries
)))
1734 (start-level prev-level
))
1738 (let ((headline (car entry
))
1739 (level (cdr entry
)))
1741 (let* ((cnt (- level prev-level
))
1742 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1744 (setq prev-level level
)
1746 (org-html--make-string
1747 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1748 ((< cnt
0) "</li>\n</ul>\n")))
1749 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1752 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
1754 (defun org-html--format-toc-headline (headline info
)
1755 "Return an appropriate table of contents entry for HEADLINE.
1756 INFO is a plist used as a communication channel."
1757 (let* ((headline-number (org-export-get-headline-number headline info
))
1759 (and (not (org-export-low-level-p headline info
))
1760 (org-export-numbered-headline-p headline info
)
1761 (concat (mapconcat 'number-to-string headline-number
".") ". ")))
1762 (tags (and (eq (plist-get info
:with-tags
) t
)
1763 (org-export-get-tags headline info
))))
1764 (format "<a href=\"#%s\">%s</a>"
1766 (org-export-solidify-link-text
1767 (or (org-element-property :CUSTOM_ID headline
)
1768 (concat "sec-" (mapconcat 'number-to-string
1769 headline-number
"-"))))
1771 (concat section-number
1772 (org-export-data-with-translations
1773 (org-export-get-alt-title headline info
)
1774 ;; Ignore any footnote-reference, link,
1775 ;; radio-target and target in table of contents.
1777 '((footnote-reference . ignore
)
1778 (link .
(lambda (link desc i
) desc
))
1779 (radio-target .
(lambda (radio desc i
) desc
))
1781 (org-export-backend-translate-table 'html
))
1783 (and tags
"   ") (org-html--tags tags
)))))
1785 (defun org-html-list-of-listings (info)
1786 "Build a list of listings.
1787 INFO is a plist used as a communication channel. Return the list
1788 of listings as a string, or nil if it is empty."
1789 (let ((lol-entries (org-export-collect-listings info
)))
1791 (concat "<div id=\"list-of-listings\">\n"
1792 (format "<h%d>%s</h%d>\n"
1793 org-html-toplevel-hlevel
1794 (org-html--translate "List of Listings" info
)
1795 org-html-toplevel-hlevel
)
1796 "<div id=\"text-list-of-listings\">\n<ul>\n"
1798 (initial-fmt (org-html--translate "Listing %d:" info
)))
1801 (let ((label (org-element-property :name entry
))
1804 (or (org-export-get-caption entry t
)
1805 (org-export-get-caption entry
))
1810 (concat (format initial-fmt
(incf count
)) " " title
)
1811 (format "<a href=\"#%s\">%s %s</a>"
1812 (org-export-solidify-link-text label
)
1813 (format initial-fmt
(incf count
))
1817 "\n</ul>\n</div>\n</div>"))))
1819 (defun org-html-list-of-tables (info)
1820 "Build a list of tables.
1821 INFO is a plist used as a communication channel. Return the list
1822 of tables as a string, or nil if it is empty."
1823 (let ((lol-entries (org-export-collect-tables info
)))
1825 (concat "<div id=\"list-of-tables\">\n"
1826 (format "<h%d>%s</h%d>\n"
1827 org-html-toplevel-hlevel
1828 (org-html--translate "List of Tables" info
)
1829 org-html-toplevel-hlevel
)
1830 "<div id=\"text-list-of-tables\">\n<ul>\n"
1832 (initial-fmt (org-html--translate "Table %d:" info
)))
1835 (let ((label (org-element-property :name entry
))
1838 (or (org-export-get-caption entry t
)
1839 (org-export-get-caption entry
))
1844 (concat (format initial-fmt
(incf count
)) " " title
)
1845 (format "<a href=\"#%s\">%s %s</a>"
1846 (org-export-solidify-link-text label
)
1847 (format initial-fmt
(incf count
))
1851 "\n</ul>\n</div>\n</div>"))))
1855 ;;; Transcode Functions
1859 (defun org-html-bold (bold contents info
)
1860 "Transcode BOLD from Org to HTML.
1861 CONTENTS is the text with bold markup. INFO is a plist holding
1862 contextual information."
1863 (format (or (cdr (assq 'bold org-html-text-markup-alist
)) "%s")
1869 (defun org-html-center-block (center-block contents info
)
1870 "Transcode a CENTER-BLOCK element from Org to HTML.
1871 CONTENTS holds the contents of the block. INFO is a plist
1872 holding contextual information."
1873 (format "<div style=\"text-align: center\">\n%s</div>" contents
))
1878 (defun org-html-clock (clock contents info
)
1879 "Transcode a CLOCK element from Org to HTML.
1880 CONTENTS is nil. INFO is a plist used as a communication
1883 <span class=\"timestamp-wrapper\">
1884 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1889 (org-element-property :raw-value
1890 (org-element-property :value clock
)))
1891 (let ((time (org-element-property :duration clock
)))
1892 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
1897 (defun org-html-code (code contents info
)
1898 "Transcode CODE from Org to HTML.
1899 CONTENTS is nil. INFO is a plist holding contextual
1901 (format (or (cdr (assq 'code org-html-text-markup-alist
)) "%s")
1902 (org-element-property :value code
)))
1907 (defun org-html-drawer (drawer contents info
)
1908 "Transcode a DRAWER element from Org to HTML.
1909 CONTENTS holds the contents of the block. INFO is a plist
1910 holding contextual information."
1911 (if (functionp org-html-format-drawer-function
)
1912 (funcall org-html-format-drawer-function
1913 (org-element-property :drawer-name drawer
)
1915 ;; If there's no user defined function: simply
1916 ;; display contents of the drawer.
1922 (defun org-html-dynamic-block (dynamic-block contents info
)
1923 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1924 CONTENTS holds the contents of the block. INFO is a plist
1925 holding contextual information. See `org-export-data'."
1931 (defun org-html-entity (entity contents info
)
1932 "Transcode an ENTITY object from Org to HTML.
1933 CONTENTS are the definition itself. INFO is a plist holding
1934 contextual information."
1935 (org-element-property :html entity
))
1940 (defun org-html-example-block (example-block contents info
)
1941 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1942 CONTENTS is nil. INFO is a plist holding contextual
1944 (if (org-export-read-attribute :attr_html example-block
:textarea
)
1945 (org-html--textarea-block example-block
)
1946 (format "<pre class=\"example\">\n%s</pre>"
1947 (org-html-format-code example-block info
))))
1952 (defun org-html-export-snippet (export-snippet contents info
)
1953 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1954 CONTENTS is nil. INFO is a plist holding contextual
1956 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
1957 (org-element-property :value export-snippet
)))
1962 (defun org-html-export-block (export-block contents info
)
1963 "Transcode a EXPORT-BLOCK element from Org to HTML.
1964 CONTENTS is nil. INFO is a plist holding contextual information."
1965 (when (string= (org-element-property :type export-block
) "HTML")
1966 (org-remove-indentation (org-element-property :value export-block
))))
1971 (defun org-html-fixed-width (fixed-width contents info
)
1972 "Transcode a FIXED-WIDTH element from Org to HTML.
1973 CONTENTS is nil. INFO is a plist holding contextual information."
1974 (format "<pre class=\"example\">\n%s</pre>"
1975 (org-html-do-format-code
1976 (org-remove-indentation
1977 (org-element-property :value fixed-width
)))))
1980 ;;;; Footnote Reference
1982 (defun org-html-footnote-reference (footnote-reference contents info
)
1983 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1984 CONTENTS is nil. INFO is a plist holding contextual information."
1986 ;; Insert separator between two footnotes in a row.
1987 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1988 (when (eq (org-element-type prev
) 'footnote-reference
)
1989 org-html-footnote-separator
))
1991 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1992 (org-html-format-footnote-reference
1993 (org-export-get-footnote-number footnote-reference info
)
1995 ;; Inline definitions are secondary strings.
1996 ((eq (org-element-property :type footnote-reference
) 'inline
)
1997 (org-html-format-footnote-reference
1998 (org-export-get-footnote-number footnote-reference info
)
2000 ;; Non-inline footnotes definitions are full Org data.
2001 (t (org-html-format-footnote-reference
2002 (org-export-get-footnote-number footnote-reference info
)
2008 (defun org-html-format-headline--wrap
2009 (headline info
&optional format-function
&rest extra-keys
)
2010 "Transcode a HEADLINE element from Org to HTML.
2011 CONTENTS holds the contents of the headline. INFO is a plist
2012 holding contextual information."
2013 (let* ((level (+ (org-export-get-relative-level headline info
)
2014 (1- org-html-toplevel-hlevel
)))
2015 (headline-number (org-export-get-headline-number headline info
))
2016 (section-number (and (not (org-export-low-level-p headline info
))
2017 (org-export-numbered-headline-p headline info
)
2018 (mapconcat 'number-to-string
2019 headline-number
".")))
2020 (todo (and (plist-get info
:with-todo-keywords
)
2021 (let ((todo (org-element-property :todo-keyword headline
)))
2022 (and todo
(org-export-data todo info
)))))
2023 (todo-type (and todo
(org-element-property :todo-type headline
)))
2024 (priority (and (plist-get info
:with-priority
)
2025 (org-element-property :priority headline
)))
2026 (text (org-export-data (org-element-property :title headline
) info
))
2027 (tags (and (plist-get info
:with-tags
)
2028 (org-export-get-tags headline info
)))
2029 (headline-label (or (org-element-property :CUSTOM_ID headline
)
2030 (concat "sec-" (mapconcat 'number-to-string
2031 headline-number
"-"))))
2032 (format-function (cond
2033 ((functionp format-function
) format-function
)
2034 ((functionp org-html-format-headline-function
)
2036 (lambda (todo todo-type priority text tags
2038 (funcall org-html-format-headline-function
2039 todo todo-type priority text tags
))))
2040 (t 'org-html-format-headline
))))
2041 (apply format-function
2042 todo todo-type priority text tags
2043 :headline-label headline-label
:level level
2044 :section-number section-number extra-keys
)))
2046 (defun org-html-headline (headline contents info
)
2047 "Transcode a HEADLINE element from Org to HTML.
2048 CONTENTS holds the contents of the headline. INFO is a plist
2049 holding contextual information."
2051 (setq contents
(or contents
""))
2052 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2053 (level (org-export-get-relative-level headline info
))
2054 (text (org-export-data (org-element-property :title headline
) info
))
2055 (todo (and (plist-get info
:with-todo-keywords
)
2056 (let ((todo (org-element-property :todo-keyword headline
)))
2057 (and todo
(org-export-data todo info
)))))
2058 (todo-type (and todo
(org-element-property :todo-type headline
)))
2059 (tags (and (plist-get info
:with-tags
)
2060 (org-export-get-tags headline info
)))
2061 (priority (and (plist-get info
:with-priority
)
2062 (org-element-property :priority headline
)))
2063 (section-number (and (org-export-numbered-headline-p headline info
)
2064 (mapconcat 'number-to-string
2065 (org-export-get-headline-number
2066 headline info
) ".")))
2067 ;; Create the headline text.
2068 (full-text (org-html-format-headline--wrap headline info
)))
2070 ;; Case 1: This is a footnote section: ignore it.
2071 ((org-element-property :footnote-section-p headline
) nil
)
2072 ;; Case 2. This is a deep sub-tree: export it as a list item.
2073 ;; Also export as items headlines for which no section
2074 ;; format has been found.
2075 ((org-export-low-level-p headline info
)
2076 ;; Build the real contents of the sub-tree.
2077 (let* ((type (if numberedp
'ordered
'unordered
))
2078 (itemized-body (org-html-format-list-item
2079 contents type nil nil full-text
)))
2081 (and (org-export-first-sibling-p headline info
)
2082 (org-html-begin-plain-list type
))
2084 (and (org-export-last-sibling-p headline info
)
2085 (org-html-end-plain-list type
)))))
2086 ;; Case 3. Standard headline. Export it as a section.
2088 (let* ((section-number (mapconcat 'number-to-string
2089 (org-export-get-headline-number
2090 headline info
) "-"))
2092 (list (org-element-property :CUSTOM_ID headline
)
2093 (concat "sec-" section-number
)
2094 (org-element-property :ID headline
))))
2095 (preferred-id (car ids
))
2096 (extra-ids (cdr ids
))
2097 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2098 (level1 (+ level
(1- org-html-toplevel-hlevel
)))
2099 (first-content (car (org-element-contents headline
))))
2100 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2101 (format "outline-container-%s"
2102 (or (org-element-property :CUSTOM_ID headline
)
2104 (concat (format "outline-%d" level1
) (and extra-class
" ")
2106 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2111 (let ((id (org-export-solidify-link-text
2112 (if (org-uuidgen-p x
) (concat "ID-" x
)
2114 (org-html--anchor id
)))
2118 ;; When there is no section, pretend there is an empty
2119 ;; one to get the correct <div class="outline- ...>
2120 ;; which is needed by `org-info.js'.
2121 (if (not (eq (org-element-type first-content
) 'section
))
2122 (concat (org-html-section first-content
"" info
)
2127 ;;;; Horizontal Rule
2129 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2130 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2131 CONTENTS is nil. INFO is a plist holding contextual information."
2135 ;;;; Inline Src Block
2137 (defun org-html-inline-src-block (inline-src-block contents info
)
2138 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2139 CONTENTS holds the contents of the item. INFO is a plist holding
2140 contextual information."
2141 (let* ((org-lang (org-element-property :language inline-src-block
))
2142 (code (org-element-property :value inline-src-block
)))
2143 (error "Cannot export inline src block")))
2148 (defun org-html-format-section (text class
&optional id
)
2149 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2150 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2152 (defun org-html-inlinetask (inlinetask contents info
)
2153 "Transcode an INLINETASK element from Org to HTML.
2154 CONTENTS holds the contents of the block. INFO is a plist
2155 holding contextual information."
2157 ;; If `org-html-format-inlinetask-function' is provided, call it
2158 ;; with appropriate arguments.
2159 ((functionp org-html-format-inlinetask-function
)
2160 (let ((format-function
2162 (lambda (todo todo-type priority text tags
2163 &key contents
&allow-other-keys
)
2164 (funcall org-html-format-inlinetask-function
2165 todo todo-type priority text tags contents
)))))
2166 (org-html-format-headline--wrap
2167 inlinetask info format-function
:contents contents
)))
2168 ;; Otherwise, use a default template.
2169 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2170 (org-html-format-headline--wrap inlinetask info
)
2176 (defun org-html-italic (italic contents info
)
2177 "Transcode ITALIC from Org to HTML.
2178 CONTENTS is the text with italic markup. INFO is a plist holding
2179 contextual information."
2180 (format (or (cdr (assq 'italic org-html-text-markup-alist
)) "%s") contents
))
2185 (defun org-html-checkbox (checkbox)
2186 (case checkbox
(on "<code>[X]</code>")
2187 (off "<code>[ ]</code>")
2188 (trans "<code>[-]</code>")
2191 (defun org-html-format-list-item (contents type checkbox
2192 &optional term-counter-id
2194 (let ((checkbox (concat (org-html-checkbox checkbox
) (and checkbox
" "))))
2198 (let* ((counter term-counter-id
)
2199 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2201 (format "<li%s>" extra
)
2202 (when headline
(concat headline
"<br/>")))))
2204 (let* ((id term-counter-id
)
2205 (extra (if id
(format " id=\"%s\"" id
) "")))
2207 (format "<li%s>" extra
)
2208 (when headline
(concat headline
"<br/>")))))
2210 (let* ((term term-counter-id
))
2211 (setq term
(or term
"(no term)"))
2212 ;; Check-boxes in descriptive lists are associated to tag.
2213 (concat (format "<dt> %s </dt>"
2214 (concat checkbox term
))
2216 (unless (eq type
'descriptive
) checkbox
)
2221 (descriptive "</dd>")))))
2223 (defun org-html-item (item contents info
)
2224 "Transcode an ITEM element from Org to HTML.
2225 CONTENTS holds the contents of the item. INFO is a plist holding
2226 contextual information."
2227 (let* ((plain-list (org-export-get-parent item
))
2228 (type (org-element-property :type plain-list
))
2229 (counter (org-element-property :counter item
))
2230 (checkbox (org-element-property :checkbox item
))
2231 (tag (let ((tag (org-element-property :tag item
)))
2232 (and tag
(org-export-data tag info
)))))
2233 (org-html-format-list-item
2234 contents type checkbox
(or tag counter
))))
2239 (defun org-html-keyword (keyword contents info
)
2240 "Transcode a KEYWORD element from Org to HTML.
2241 CONTENTS is nil. INFO is a plist holding contextual information."
2242 (let ((key (org-element-property :key keyword
))
2243 (value (org-element-property :value keyword
)))
2245 ((string= key
"HTML") value
)
2246 ;; Invisible targets.
2247 ((string= key
"TARGET") nil
)
2248 ((string= key
"TOC")
2249 (let ((value (downcase value
)))
2251 ((string-match "\\<headlines\\>" value
)
2252 (let ((depth (or (and (string-match "[0-9]+" value
)
2253 (string-to-number (match-string 0 value
)))
2254 (plist-get info
:with-toc
))))
2255 (org-html-toc depth info
)))
2256 ((string= "listings" value
) (org-html-list-of-listings info
))
2257 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2260 ;;;; Latex Environment
2262 (defun org-html-format-latex (latex-frag processing-type
)
2263 "Format LaTeX fragments into HTML."
2264 (let ((cache-relpath "") (cache-dir "") bfn
)
2265 (unless (eq processing-type
'mathjax
)
2266 (setq bfn
(buffer-file-name)
2269 (file-name-sans-extension
2270 (file-name-nondirectory bfn
)))
2271 cache-dir
(file-name-directory bfn
)))
2274 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2275 nil nil processing-type
)
2278 (defun org-html-latex-environment (latex-environment contents info
)
2279 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2280 CONTENTS is nil. INFO is a plist holding contextual information."
2281 (let ((processing-type (plist-get info
:with-latex
))
2282 (latex-frag (org-remove-indentation
2283 (org-element-property :value latex-environment
)))
2284 (caption (org-export-data
2285 (org-export-get-caption latex-environment
) info
))
2287 (label (org-element-property :name latex-environment
)))
2289 ((memq processing-type
'(t mathjax
))
2290 (org-html-format-latex latex-frag
'mathjax
))
2291 ((eq processing-type
'dvipng
)
2292 (let* ((formula-link (org-html-format-latex
2293 latex-frag processing-type
)))
2294 (when (and formula-link
2295 (string-match "file:\\([^]]*\\)" formula-link
))
2296 (org-html-format-inline-image
2297 (match-string 1 formula-link
) caption label attr t
))))
2303 (defun org-html-latex-fragment (latex-fragment contents info
)
2304 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2305 CONTENTS is nil. INFO is a plist holding contextual information."
2306 (let ((latex-frag (org-element-property :value latex-fragment
))
2307 (processing-type (plist-get info
:with-latex
)))
2308 (case processing-type
2310 (org-html-format-latex latex-frag
'mathjax
))
2312 (let* ((formula-link (org-html-format-latex
2313 latex-frag processing-type
)))
2314 (when (and formula-link
2315 (string-match "file:\\([^]]*\\)" formula-link
))
2316 (org-html-format-inline-image
2317 (match-string 1 formula-link
)))))
2323 (defun org-html-line-break (line-break contents info
)
2324 "Transcode a LINE-BREAK object from Org to HTML.
2325 CONTENTS is nil. INFO is a plist holding contextual information."
2331 (defun org-html-link--inline-image (link desc info
)
2332 "Return HTML code for an inline image.
2333 LINK is the link pointing to the inline image. INFO is a plist
2334 used as a communication channel."
2335 (let* ((type (org-element-property :type link
))
2336 (raw-path (org-element-property :path link
))
2337 (path (cond ((member type
'("http" "https"))
2338 (concat type
":" raw-path
))
2339 ((file-name-absolute-p raw-path
)
2340 (expand-file-name raw-path
))
2342 (parent (org-export-get-parent-element link
))
2343 (caption (org-export-data (org-export-get-caption parent
) info
))
2344 (label (org-element-property :name parent
))
2345 (attr (mapconcat #'identity
(org-element-property :attr_html parent
) " ")))
2346 ;; Return proper string, depending on DISPOSITION.
2347 (org-html-format-inline-image
2348 path caption label attr
(org-html-standalone-image-p link info
))))
2350 (defvar org-html-standalone-image-predicate
)
2351 (defun org-html-standalone-image-p (element info
&optional predicate
)
2352 "Test if ELEMENT is a standalone image for the purpose HTML export.
2353 INFO is a plist holding contextual information.
2355 Return non-nil, if ELEMENT is of type paragraph and it's sole
2356 content, save for whitespaces, is a link that qualifies as an
2359 Return non-nil, if ELEMENT is of type link and it's containing
2360 paragraph has no other content save for leading and trailing
2363 Return nil, otherwise.
2365 Bind `org-html-standalone-image-predicate' to constrain
2366 paragraph further. For example, to check for only captioned
2367 standalone images, do the following.
2369 \(setq org-html-standalone-image-predicate
2370 \(lambda \(paragraph\)
2371 \(org-element-property :caption paragraph\)\)\)"
2372 (let ((paragraph (case (org-element-type element
)
2374 (link (and (org-export-inline-image-p
2375 element org-html-inline-image-rules
)
2376 (org-export-get-parent element
)))
2378 (when (eq (org-element-type paragraph
) 'paragraph
)
2379 (when (or (not (and (boundp 'org-html-standalone-image-predicate
)
2380 (functionp org-html-standalone-image-predicate
)))
2381 (funcall org-html-standalone-image-predicate paragraph
))
2382 (let ((contents (org-element-contents paragraph
)))
2383 (loop for x in contents
2384 with inline-image-count
= 0
2386 ((eq (org-element-type x
) 'plain-text
)
2387 (not (org-string-nw-p x
)))
2388 ((eq (org-element-type x
) 'link
)
2389 (when (org-export-inline-image-p
2390 x org-html-inline-image-rules
)
2391 (= (incf inline-image-count
) 1)))
2394 (defun org-html-link (link desc info
)
2395 "Transcode a LINK object from Org to HTML.
2397 DESC is the description part of the link, or the empty string.
2398 INFO is a plist holding contextual information. See
2400 (let* ((--link-org-files-as-html-maybe
2402 (lambda (raw-path info
)
2403 "Treat links to `file.org' as links to `file.html', if needed.
2404 See `org-html-link-org-files-as-html'."
2406 ((and org-html-link-org-files-as-html
2408 (downcase (file-name-extension raw-path
"."))))
2409 (concat (file-name-sans-extension raw-path
) "."
2410 (plist-get info
:html-extension
)))
2412 (type (org-element-property :type link
))
2413 (raw-path (org-element-property :path link
))
2414 ;; Ensure DESC really exists, or set it to nil.
2415 (desc (and (not (string= desc
"")) desc
))
2418 ((member type
'("http" "https" "ftp" "mailto"))
2419 (concat type
":" raw-path
))
2420 ((string= type
"file")
2421 ;; Treat links to ".org" files as ".html", if needed.
2423 (funcall --link-org-files-as-html-maybe raw-path info
))
2424 ;; If file path is absolute, prepend it with protocol
2425 ;; component - "file://".
2426 (when (file-name-absolute-p raw-path
)
2428 (concat "file://" (expand-file-name raw-path
))))
2429 ;; Add search option, if any. A search option can be
2430 ;; relative to a custom-id or a headline title. Any other
2431 ;; option is ignored.
2432 (let ((option (org-element-property :search-option link
)))
2433 (cond ((not option
) raw-path
)
2434 ((eq (aref option
0) ?
#) (concat raw-path option
))
2435 ;; External fuzzy link: try to resolve it if path
2436 ;; belongs to current project, if any.
2437 ((eq (aref option
0) ?
*)
2441 (org-publish-resolve-external-fuzzy-link
2442 (org-element-property :path link
) option
)))
2443 (and numbers
(concat "#sec-"
2444 (mapconcat 'number-to-string
2445 numbers
"-")))))))))
2447 attributes protocol
)
2448 ;; Extract attributes from parent's paragraph. HACK: Only do this
2449 ;; for the first link in parent. This is needed as long as
2450 ;; attributes cannot be set on a per link basis.
2451 (and (setq attributes
2452 (let ((parent (org-export-get-parent-element link
)))
2453 (if (not (eq (org-element-map parent
'link
'identity info t
)
2458 (let ((att (org-element-property :attr_html parent
)))
2459 (unless (and desc att
2460 (string-match (regexp-quote (car att
)) desc
))
2463 (unless (string= attributes
"")
2464 (setq attributes
(concat " " attributes
))))
2467 ((and (or (eq t org-html-inline-images
)
2468 (and org-html-inline-images
(not desc
)))
2469 (org-export-inline-image-p link org-html-inline-image-rules
))
2470 (org-html-link--inline-image link desc info
))
2471 ;; Radio target: Transcode target's contents and use them as
2472 ;; link's description.
2473 ((string= type
"radio")
2474 (let ((destination (org-export-resolve-radio-link link info
)))
2476 (format "<a href=\"#%s\"%s>%s</a>"
2477 (org-export-solidify-link-text path
)
2479 (org-export-data (org-element-contents destination
) info
)))))
2480 ;; Links pointing to a headline: Find destination and build
2481 ;; appropriate referencing command.
2482 ((member type
'("custom-id" "fuzzy" "id"))
2483 (let ((destination (if (string= type
"fuzzy")
2484 (org-export-resolve-fuzzy-link link info
)
2485 (org-export-resolve-id-link link info
))))
2486 (case (org-element-type destination
)
2487 ;; ID link points to an external file.
2489 (let ((fragment (concat "ID-" path
))
2490 ;; Treat links to ".org" files as ".html", if needed.
2491 (path (funcall --link-org-files-as-html-maybe
2493 (format "<a href=\"%s#%s\"%s>%s</a>"
2494 path fragment attributes
(or desc destination
))))
2495 ;; Fuzzy link points nowhere.
2500 (org-element-property :raw-link link
) info
))))
2501 ;; Fuzzy link points to an invisible target.
2503 ;; Link points to a headline.
2506 ;; What href to use?
2508 ;; Case 1: Headline is linked via it's CUSTOM_ID
2509 ;; property. Use CUSTOM_ID.
2510 ((string= type
"custom-id")
2511 (org-element-property :CUSTOM_ID destination
))
2512 ;; Case 2: Headline is linked via it's ID property
2513 ;; or through other means. Use the default href.
2514 ((member type
'("id" "fuzzy"))
2516 (mapconcat 'number-to-string
2517 (org-export-get-headline-number
2518 destination info
) "-")))
2519 (t (error "Shouldn't reach here"))))
2520 ;; What description to use?
2522 ;; Case 1: Headline is numbered and LINK has no
2523 ;; description or LINK's description matches
2524 ;; headline's title. Display section number.
2525 (if (and (org-export-numbered-headline-p destination info
)
2527 (string= desc
(org-element-property
2528 :raw-value destination
))))
2529 (mapconcat 'number-to-string
2530 (org-export-get-headline-number
2531 destination info
) ".")
2532 ;; Case 2: Either the headline is un-numbered or
2533 ;; LINK has a custom description. Display LINK's
2534 ;; description or headline's title.
2535 (or desc
(org-export-data (org-element-property
2536 :title destination
) info
)))))
2537 (format "<a href=\"#%s\"%s>%s</a>"
2538 (org-export-solidify-link-text href
) attributes desc
)))
2539 ;; Fuzzy link points to a target. Do as above.
2541 (let ((path (org-export-solidify-link-text path
)) number
)
2544 ((org-html-standalone-image-p destination info
)
2545 (org-export-get-ordinal
2546 (assoc 'link
(org-element-contents destination
))
2547 info
'link
'org-html-standalone-image-p
))
2548 (t (org-export-get-ordinal destination info
))))
2549 (setq desc
(when number
2550 (if (atom number
) (number-to-string number
)
2551 (mapconcat 'number-to-string number
".")))))
2552 (format "<a href=\"#%s\"%s>%s</a>"
2553 path attributes
(or desc
"No description for this link")))))))
2554 ;; Coderef: replace link with the reference name or the
2555 ;; equivalent line number.
2556 ((string= type
"coderef")
2557 (let ((fragment (concat "coderef-" path
)))
2558 (format "<a href=\"#%s\"%s%s>%s</a>"
2561 (format (concat "class=\"coderef\""
2562 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2563 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2566 (format (org-export-get-coderef-format path desc
)
2567 (org-export-resolve-coderef path info
)))))
2568 ;; Link type is handled by a special function.
2569 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2570 (funcall protocol
(org-link-unescape path
) desc
'html
))
2571 ;; External link with a description part.
2572 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2573 ;; External link without a description part.
2574 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2575 ;; No path, only description. Try to do something useful.
2576 (t (format "<i>%s</i>" desc
)))))
2581 (defun org-html-paragraph (paragraph contents info
)
2582 "Transcode a PARAGRAPH element from Org to HTML.
2583 CONTENTS is the contents of the paragraph, as a string. INFO is
2584 the plist used as a communication channel."
2585 (let* ((style nil
) ; FIXME
2586 (class (cdr (assoc style
'((footnote .
"footnote")
2588 (extra (if class
(format " class=\"%s\"" class
) ""))
2589 (parent (org-export-get-parent paragraph
)))
2591 ((and (eq (org-element-type parent
) 'item
)
2592 (= (org-element-property :begin paragraph
)
2593 (org-element-property :contents-begin parent
)))
2594 ;; leading paragraph in a list item have no tags
2596 ((org-html-standalone-image-p paragraph info
)
2599 (t (format "<p%s>\n%s</p>" extra contents
)))))
2604 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2605 ;; the correct value for the item counter
2606 (defun org-html-begin-plain-list (type &optional arg1
)
2607 "Insert the beginning of the HTML list depending on TYPE.
2608 When ARG1 is a string, use it as the start parameter for ordered
2612 (format "<ol class=\"org-ol\"%s>"
2613 (if arg1
(format " start=\"%d\"" arg1
) "")))
2614 (unordered "<ul class=\"org-ul\">")
2615 (descriptive "<dl class=\"org-dl\">")))
2617 (defun org-html-end-plain-list (type)
2618 "Insert the end of the HTML list depending on TYPE."
2622 (descriptive "</dl>")))
2624 (defun org-html-plain-list (plain-list contents info
)
2625 "Transcode a PLAIN-LIST element from Org to HTML.
2626 CONTENTS is the contents of the list. INFO is a plist holding
2627 contextual information."
2628 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2629 (type (org-element-property :type plain-list
)))
2631 (org-html-begin-plain-list type
)
2632 contents
(org-html-end-plain-list type
))))
2636 (defun org-html-convert-special-strings (string)
2637 "Convert special characters in STRING to HTML."
2638 (let ((all org-html-special-string-regexps
)
2640 (while (setq a
(pop all
))
2641 (setq re
(car a
) rpl
(cdr a
) start
0)
2642 (while (string-match re string start
)
2643 (setq string
(replace-match rpl t nil string
))))
2646 (defun org-html-encode-plain-text (text)
2647 "Convert plain text characters to HTML equivalent.
2648 Possible conversions are set in `org-export-html-protect-char-alist'."
2651 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2652 org-html-protect-char-alist
)
2655 (defun org-html-plain-text (text info
)
2656 "Transcode a TEXT string from Org to HTML.
2657 TEXT is the string to transcode. INFO is a plist holding
2658 contextual information."
2659 (let ((output text
))
2660 ;; Protect following characters: <, >, &.
2661 (setq output
(org-html-encode-plain-text output
))
2662 ;; Handle smart quotes. Be sure to provide original string since
2663 ;; OUTPUT may have been modified.
2664 (when (plist-get info
:with-smart-quotes
)
2665 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
2666 ;; Handle special strings.
2667 (when (plist-get info
:with-special-strings
)
2668 (setq output
(org-html-convert-special-strings output
)))
2669 ;; Handle break preservation if required.
2670 (when (plist-get info
:preserve-breaks
)
2672 (replace-regexp-in-string
2673 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output
)))
2680 (defun org-html-planning (planning contents info
)
2681 "Transcode a PLANNING element from Org to HTML.
2682 CONTENTS is nil. INFO is a plist used as a communication
2684 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2686 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2691 (let ((closed (org-element-property :closed planning
)))
2693 (format span-fmt org-closed-string
2695 (org-element-property :raw-value closed
)))))
2696 (let ((deadline (org-element-property :deadline planning
)))
2698 (format span-fmt org-deadline-string
2700 (org-element-property :raw-value deadline
)))))
2701 (let ((scheduled (org-element-property :scheduled planning
)))
2703 (format span-fmt org-scheduled-string
2705 (org-element-property :raw-value scheduled
)))))))
2709 ;;;; Property Drawer
2711 (defun org-html-property-drawer (property-drawer contents info
)
2712 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2713 CONTENTS is nil. INFO is a plist holding contextual
2715 ;; The property drawer isn't exported but we want separating blank
2716 ;; lines nonetheless.
2722 (defun org-html-quote-block (quote-block contents info
)
2723 "Transcode a QUOTE-BLOCK element from Org to HTML.
2724 CONTENTS holds the contents of the block. INFO is a plist
2725 holding contextual information."
2726 (format "<blockquote>\n%s</blockquote>" contents
))
2731 (defun org-html-quote-section (quote-section contents info
)
2732 "Transcode a QUOTE-SECTION element from Org to HTML.
2733 CONTENTS is nil. INFO is a plist holding contextual information."
2734 (let ((value (org-remove-indentation
2735 (org-element-property :value quote-section
))))
2736 (when value
(format "<pre>\n%s</pre>" value
))))
2741 (defun org-html-section (section contents info
)
2742 "Transcode a SECTION element from Org to HTML.
2743 CONTENTS holds the contents of the section. INFO is a plist
2744 holding contextual information."
2745 (let ((parent (org-export-get-parent-headline section
)))
2746 ;; Before first headline: no container, just return CONTENTS.
2747 (if (not parent
) contents
2748 ;; Get div's class and id references.
2749 (let* ((class-num (+ (org-export-get-relative-level parent info
)
2750 (1- org-html-toplevel-hlevel
)))
2754 (org-export-get-headline-number parent info
) "-")))
2755 ;; Build return value.
2756 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2758 (or (org-element-property :CUSTOM_ID parent
) section-number
)
2763 (defun org-html-radio-target (radio-target text info
)
2764 "Transcode a RADIO-TARGET object from Org to HTML.
2765 TEXT is the text of the target. INFO is a plist holding
2766 contextual information."
2767 (let ((id (org-export-solidify-link-text
2768 (org-element-property :value radio-target
))))
2769 (org-html--anchor id text
)))
2774 (defun org-html-special-block (special-block contents info
)
2775 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2776 CONTENTS holds the contents of the block. INFO is a plist
2777 holding contextual information."
2778 (format "<div class=\"%s\">\n%s\n</div>"
2779 (downcase (org-element-property :type special-block
))
2785 (defun org-html-src-block (src-block contents info
)
2786 "Transcode a SRC-BLOCK element from Org to HTML.
2787 CONTENTS holds the contents of the item. INFO is a plist holding
2788 contextual information."
2789 (if (org-export-read-attribute :attr_html src-block
:textarea
)
2790 (org-html--textarea-block src-block
)
2791 (let ((lang (org-element-property :language src-block
))
2792 (caption (org-export-get-caption src-block
))
2793 (code (org-html-format-code src-block info
))
2794 (label (let ((lbl (org-element-property :name src-block
)))
2796 (format " id=\"%s\""
2797 (org-export-solidify-link-text lbl
))))))
2798 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
2800 "<div class=\"org-src-container\">\n%s%s\n</div>"
2801 (if (not caption
) ""
2802 (format "<label class=\"org-src-name\">%s</label>"
2803 (org-export-data caption info
)))
2804 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
2807 ;;;; Statistics Cookie
2809 (defun org-html-statistics-cookie (statistics-cookie contents info
)
2810 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2811 CONTENTS is nil. INFO is a plist holding contextual information."
2812 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2813 (format "<code>%s</code>" cookie-value
)))
2818 (defun org-html-strike-through (strike-through contents info
)
2819 "Transcode STRIKE-THROUGH from Org to HTML.
2820 CONTENTS is the text with strike-through markup. INFO is a plist
2821 holding contextual information."
2822 (format (or (cdr (assq 'strike-through org-html-text-markup-alist
)) "%s")
2828 (defun org-html-subscript (subscript contents info
)
2829 "Transcode a SUBSCRIPT object from Org to HTML.
2830 CONTENTS is the contents of the object. INFO is a plist holding
2831 contextual information."
2832 (format "<sub>%s</sub>" contents
))
2837 (defun org-html-superscript (superscript contents info
)
2838 "Transcode a SUPERSCRIPT object from Org to HTML.
2839 CONTENTS is the contents of the object. INFO is a plist holding
2840 contextual information."
2841 (format "<sup>%s</sup>" contents
))
2846 (defun org-html-table-cell (table-cell contents info
)
2847 "Transcode a TABLE-CELL element from Org to HTML.
2848 CONTENTS is nil. INFO is a plist used as a communication
2850 (let* ((table-row (org-export-get-parent table-cell
))
2851 (table (org-export-get-parent-table table-cell
))
2853 (if (not org-html-table-align-individual-fields
) ""
2854 (format (if (and (boundp 'org-html-format-table-no-css
)
2855 org-html-format-table-no-css
)
2856 " align=\"%s\"" " class=\"%s\"")
2857 (org-export-table-cell-alignment table-cell info
)))))
2858 (when (or (not contents
) (string= "" (org-trim contents
)))
2859 (setq contents
" "))
2861 ((and (org-export-table-has-header-p table info
)
2862 (= 1 (org-export-table-row-group table-row info
)))
2863 (concat "\n" (format (car org-html-table-header-tags
) "col" cell-attrs
)
2864 contents
(cdr org-html-table-header-tags
)))
2865 ((and org-html-table-use-header-tags-for-first-column
2866 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2867 (concat "\n" (format (car org-html-table-header-tags
) "row" cell-attrs
)
2868 contents
(cdr org-html-table-header-tags
)))
2869 (t (concat "\n" (format (car org-html-table-data-tags
) cell-attrs
)
2870 contents
(cdr org-html-table-data-tags
))))))
2875 (defun org-html-table-row (table-row contents info
)
2876 "Transcode a TABLE-ROW element from Org to HTML.
2877 CONTENTS is the contents of the row. INFO is a plist used as a
2878 communication channel."
2879 ;; Rules are ignored since table separators are deduced from
2880 ;; borders of the current row.
2881 (when (eq (org-element-property :type table-row
) 'standard
)
2882 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info
)))
2885 ;; Case 1: Row belongs to second or subsequent rowgroups.
2886 ((not (= 1 (org-export-table-row-group table-row info
)))
2887 '("<tbody>" .
"\n</tbody>"))
2888 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2889 ((org-export-table-has-header-p
2890 (org-export-get-parent-table table-row
) info
)
2891 '("<thead>" .
"\n</thead>"))
2892 ;; Case 2: Row is from first and only row group.
2893 (t '("<tbody>" .
"\n</tbody>")))))
2895 ;; Begin a rowgroup?
2896 (when (org-export-table-row-starts-rowgroup-p table-row info
)
2897 (car rowgroup-tags
))
2899 (concat "\n" (eval (car org-html-table-row-tags
))
2902 (eval (cdr org-html-table-row-tags
)))
2904 (when (org-export-table-row-ends-rowgroup-p table-row info
)
2905 (cdr rowgroup-tags
))))))
2910 (defun org-html-table-first-row-data-cells (table info
)
2912 (org-element-map table
'table-row
2914 (unless (eq (org-element-property :type row
) 'rule
) row
))
2916 (special-column-p (org-export-table-has-special-column-p table
)))
2917 (if (not special-column-p
) (org-element-contents table-row
)
2918 (cdr (org-element-contents table-row
)))))
2920 (defun org-html-table--table.el-table
(table info
)
2921 (when (eq (org-element-property :type table
) 'table.el
)
2923 (let ((outbuf (with-current-buffer
2924 (get-buffer-create "*org-export-table*")
2925 (erase-buffer) (current-buffer))))
2927 (insert (org-element-property :value table
))
2929 (re-search-forward "^[ \t]*|[^|]" nil t
)
2930 (table-generate-source 'html outbuf
))
2931 (with-current-buffer outbuf
2932 (prog1 (org-trim (buffer-string))
2935 (defun org-html-table (table contents info
)
2936 "Transcode a TABLE element from Org to HTML.
2937 CONTENTS is the contents of the table. INFO is a plist holding
2938 contextual information."
2939 (case (org-element-property :type table
)
2940 ;; Case 1: table.el table. Convert it using appropriate tools.
2941 (table.el
(org-html-table--table.el-table table info
))
2942 ;; Case 2: Standard table.
2944 (let* ((label (org-element-property :name table
))
2945 (caption (org-export-get-caption table
))
2946 (attributes (mapconcat #'identity
2947 (org-element-property :attr_html table
)
2950 (if (and (boundp 'org-html-format-table-no-css
)
2951 org-html-format-table-no-css
)
2952 "align=\"%s\"" "class=\"%s\""))
2955 (lambda (table info
)
2957 (lambda (table-cell)
2958 (let ((alignment (org-export-table-cell-alignment
2961 ;; Begin a colgroup?
2962 (when (org-export-table-cell-starts-colgroup-p
2965 ;; Add a column. Also specify it's alignment.
2966 (format "\n<col %s/>" (format alignspec alignment
))
2968 (when (org-export-table-cell-ends-colgroup-p
2971 (org-html-table-first-row-data-cells table info
) "\n"))))
2973 (let ((table-tag (plist-get info
:html-table-tag
)))
2975 (and (string-match "<table\\(.*\\)>" table-tag
)
2976 (match-string 1 table-tag
))
2977 (and label
(format " id=\"%s\""
2978 (org-export-solidify-link-text label
)))
2979 (unless (string= attributes
"")
2980 (concat " " attributes
))))))
2981 ;; Remove last blank line.
2982 (setq contents
(substring contents
0 -
1))
2983 (format "<table%s>\n%s\n%s\n%s\n</table>"
2985 (if (not caption
) ""
2986 (format "<caption>%s</caption>"
2987 (org-export-data caption info
)))
2988 (funcall table-column-specs table info
)
2994 (defun org-html-target (target contents info
)
2995 "Transcode a TARGET object from Org to HTML.
2996 CONTENTS is nil. INFO is a plist holding contextual
2998 (let ((id (org-export-solidify-link-text
2999 (org-element-property :value target
))))
3000 (org-html--anchor id
)))
3005 (defun org-html-timestamp (timestamp contents info
)
3006 "Transcode a TIMESTAMP object from Org to HTML.
3007 CONTENTS is nil. INFO is a plist holding contextual
3009 (let ((value (org-html-plain-text
3010 (org-timestamp-translate timestamp
) info
)))
3011 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3012 (replace-regexp-in-string "--" "–" value
))))
3017 (defun org-html-underline (underline contents info
)
3018 "Transcode UNDERLINE from Org to HTML.
3019 CONTENTS is the text with underline markup. INFO is a plist
3020 holding contextual information."
3021 (format (or (cdr (assq 'underline org-html-text-markup-alist
)) "%s")
3027 (defun org-html-verbatim (verbatim contents info
)
3028 "Transcode VERBATIM from Org to HTML.
3029 CONTENTS is nil. INFO is a plist holding contextual
3031 (format (or (cdr (assq 'verbatim org-html-text-markup-alist
)) "%s")
3032 (org-element-property :value verbatim
)))
3037 (defun org-html-verse-block (verse-block contents info
)
3038 "Transcode a VERSE-BLOCK element from Org to HTML.
3039 CONTENTS is verse block contents. INFO is a plist holding
3040 contextual information."
3041 ;; Replace each newline character with line break. Also replace
3042 ;; each blank line with a line break.
3043 (setq contents
(replace-regexp-in-string
3044 "^ *\\\\\\\\$" "<br/>\n"
3045 (replace-regexp-in-string
3046 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3047 ;; Replace each white space at beginning of a line with a
3048 ;; non-breaking space.
3049 (while (string-match "^[ \t]+" contents
)
3050 (let* ((num-ws (length (match-string 0 contents
)))
3051 (ws (let (out) (dotimes (i num-ws out
)
3052 (setq out
(concat out
" "))))))
3053 (setq contents
(replace-match ws nil t contents
))))
3054 (format "<p class=\"verse\">\n%s</p>" contents
))
3058 ;;; Filter Functions
3060 (defun org-html-final-function (contents backend info
)
3061 (if (not org-html-pretty-output
) contents
3065 (indent-region (point-min) (point-max))
3066 (buffer-substring-no-properties (point-min) (point-max)))))
3070 ;;; End-user functions
3073 (defun org-html-export-as-html
3074 (&optional async subtreep visible-only body-only ext-plist
)
3075 "Export current buffer to an HTML buffer.
3077 If narrowing is active in the current buffer, only export its
3080 If a region is active, export that region.
3082 A non-nil optional argument ASYNC means the process should happen
3083 asynchronously. The resulting buffer should be accessible
3084 through the `org-export-stack' interface.
3086 When optional argument SUBTREEP is non-nil, export the sub-tree
3087 at point, extracting information from the headline properties
3090 When optional argument VISIBLE-ONLY is non-nil, don't export
3091 contents of hidden elements.
3093 When optional argument BODY-ONLY is non-nil, only write code
3094 between \"<body>\" and \"</body>\" tags.
3096 EXT-PLIST, when provided, is a property list with external
3097 parameters overriding Org default settings, but still inferior to
3098 file-local settings.
3100 Export is done in a buffer named \"*Org HTML Export*\", which
3101 will be displayed when `org-export-show-temporary-export-buffer'
3105 (org-export-async-start
3107 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3110 (goto-char (point-min))
3111 (funcall org-html-display-buffer-mode
)
3112 (org-export-add-to-stack (current-buffer) 'html
)))
3113 `(org-export-as 'html
,subtreep
,visible-only
,body-only
',ext-plist
))
3114 (let ((outbuf (org-export-to-buffer
3115 'html
"*Org HTML Export*"
3116 subtreep visible-only body-only ext-plist
)))
3118 (with-current-buffer outbuf
(funcall org-html-display-buffer-mode
))
3119 (when org-export-show-temporary-export-buffer
3120 (switch-to-buffer-other-window outbuf
)))))
3123 (defun org-html-export-to-html
3124 (&optional async subtreep visible-only body-only ext-plist
)
3125 "Export current buffer to a HTML file.
3127 If narrowing is active in the current buffer, only export its
3130 If a region is active, export that region.
3132 A non-nil optional argument ASYNC means the process should happen
3133 asynchronously. The resulting file should be accessible through
3134 the `org-export-stack' interface.
3136 When optional argument SUBTREEP is non-nil, export the sub-tree
3137 at point, extracting information from the headline properties
3140 When optional argument VISIBLE-ONLY is non-nil, don't export
3141 contents of hidden elements.
3143 When optional argument BODY-ONLY is non-nil, only write code
3144 between \"<body>\" and \"</body>\" tags.
3146 EXT-PLIST, when provided, is a property list with external
3147 parameters overriding Org default settings, but still inferior to
3148 file-local settings.
3150 Return output file's name."
3152 (let* ((extension (concat "." org-html-extension
))
3153 (file (org-export-output-file-name extension subtreep
))
3154 (org-export-coding-system org-html-coding-system
))
3156 (org-export-async-start
3157 (lambda (f) (org-export-add-to-stack f
'html
))
3158 (let ((org-export-coding-system org-html-coding-system
))
3161 'html
,file
,subtreep
,visible-only
,body-only
',ext-plist
))))
3162 (let ((org-export-coding-system org-html-coding-system
))
3164 'html file subtreep visible-only body-only ext-plist
)))))
3167 (defun org-html-publish-to-html (plist filename pub-dir
)
3168 "Publish an org file to HTML.
3170 FILENAME is the filename of the Org file to be published. PLIST
3171 is the property list for the given project. PUB-DIR is the
3172 publishing directory.
3174 Return output file name."
3175 (org-publish-org-to 'html filename
".html" plist pub-dir
))
3181 ;;;; org-format-table-html
3182 ;;;; org-format-org-table-html
3183 ;;;; org-format-table-table-html
3184 ;;;; org-table-number-fraction
3185 ;;;; org-table-number-regexp
3186 ;;;; org-html-table-caption-above
3187 ;;;; org-html-with-timestamp
3188 ;;;; org-html-html-helper-timestamp
3189 ;;;; org-html-inline-image-extensions
3190 ;;;; org-export-preferred-target-alist
3191 ;;;; class for anchors
3192 ;;;; org-export-with-section-numbers, body-only
3193 ;;;; org-export-mark-todo-in-toc
3194 ;;;; org-html-format-org-link
3195 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3196 ;;;; alt = (file-name-nondirectory path)
3201 ;; generated-autoload-file: "org-loaddefs.el"
3204 ;;; ox-html.el ends here