1 ;;; org-e-html.el --- HTML Back-End For Org Export Engine
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program 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 ;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; M-: (org-export-to-buffer 'e-html "*Test e-HTML*") RET
29 ;; in an org-mode buffer then switch to the buffer to see the HTML
30 ;; export. See contrib/lisp/org-export.el for more details on how
31 ;; this exporter works.
33 ;; It introduces three new buffer keywords: "LATEX_CLASS",
34 ;; "LATEX_CLASS_OPTIONS" and "LATEX_HEADER".
40 (defvar org-e-html-debug nil
)
41 (defvar org-e-html-pp nil
)
43 (defun org-e-html-debug (fmt &rest args
)
44 (when org-e-html-debug
45 (with-current-buffer (get-buffer "*debug*")
46 (insert "\n" (apply 'format fmt args
)))))
48 (defun org-element-debug (header text
)
49 (insert "\n" "===== [" header
"] =====")
50 (insert "\n" (pp-to-string text
)))
52 (defun org-elements-debug (args)
53 (with-current-buffer "*debug*"
54 (insert "\n\n\n\n\n-------------------------\n")
56 (let* ((header (pop args
))
58 (org-element-debug (format "%s" header
) text
)))
59 (insert "\n--------------------------\n")))
61 (defvar org-elements-debug-depth
0)
62 (defmacro org-e-html-pp
(&rest args
)
67 (setq newargs
(append newargs
(list e
(eval e
))))))
68 ;; (pp-eval-expression 'newargs)
70 `(org-elements-debug (quote ,newargs
)))
74 (require 'format-spec
)
75 (eval-when-compile (require 'cl
) (require 'table
))
77 (declare-function org-id-find-id-file
"org-id" (id))
78 (declare-function htmlize-region
"ext:htmlize" (beg end
))
79 (declare-function org-pop-to-buffer-same-window
80 "org-compat" (&optional buffer-or-name norecord label
))
82 (defgroup org-export-e-html nil
83 "Options specific for HTML export of Org-mode files."
84 :tag
"Org Export HTML"
87 (defconst org-export-e-html-special-string-regexps
89 ("---\\([^-]\\)" .
"—\\1")
90 ("--\\([^-]\\)" .
"–\\1")
91 ("\\.\\.\\." .
"…"))
92 "Regular expressions for special string conversion.")
94 (defcustom org-export-e-html-footnotes-section
"<div id=\"footnotes\">
95 <h2 class=\"footnotes\">%s: </h2>
96 <div id=\"text-footnotes\">
100 "Format for the footnotes section.
101 Should contain a two instances of %s. The first will be replaced with the
102 language-specific word for \"Footnotes\", the second one will be replaced
103 by the footnotes themselves."
104 :group
'org-export-e-html
107 (defcustom org-export-e-html-footnote-format
"<sup>%s</sup>"
108 "The format for the footnote reference.
109 %s will be replaced by the footnote reference itself."
110 :group
'org-export-e-html
114 (defcustom org-export-e-html-footnote-separator
"<sup>, </sup>"
115 "Text used to separate footnotes."
116 :group
'org-export-e-html
119 (defcustom org-export-e-html-coding-system nil
120 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
121 :group
'org-export-e-html
122 :type
'coding-system
)
124 (defcustom org-export-e-html-extension
"html"
125 "The extension for exported HTML files."
126 :group
'org-export-e-html
129 (defcustom org-export-e-html-xml-declaration
130 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
131 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
132 "The extension for exported HTML files.
133 %s will be replaced with the charset of the exported file.
134 This may be a string, or an alist with export extensions
135 and corresponding declarations."
136 :group
'org-export-e-html
138 (string :tag
"Single declaration")
139 (repeat :tag
"Dependent on extension"
140 (cons (string :tag
"Extension")
141 (string :tag
"Declaration")))))
143 (defcustom org-export-e-html-style-include-scripts t
144 "Non-nil means include the JavaScript snippets in exported HTML files.
145 The actual script is defined in `org-export-e-html-scripts' and should
147 :group
'org-export-e-html
150 (defconst org-export-e-html-scripts
151 "<script type=\"text/javascript\">
152 <!--/*--><![CDATA[/*><!--*/
153 function CodeHighlightOn(elem, id)
155 var target = document.getElementById(id);
157 elem.cacheClassElem = elem.className;
158 elem.cacheClassTarget = target.className;
159 target.className = \"code-highlighted\";
160 elem.className = \"code-highlighted\";
163 function CodeHighlightOff(elem, id)
165 var target = document.getElementById(id);
166 if(elem.cacheClassElem)
167 elem.className = elem.cacheClassElem;
168 if(elem.cacheClassTarget)
169 target.className = elem.cacheClassTarget;
173 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
175 (defconst org-export-e-html-style-default
176 "<style type=\"text/css\">
177 <!--/*--><![CDATA[/*><!--*/
178 html { font-family: Times, serif; font-size: 12pt; }
179 .title { text-align: center; }
180 .todo { color: red; }
181 .done { color: green; }
182 .tag { background-color: #add8e6; font-weight:normal }
184 .timestamp { color: #bebebe; }
185 .timestamp-kwd { color: #5f9ea0; }
186 .right {margin-left:auto; margin-right:0px; text-align:right;}
187 .left {margin-left:0px; margin-right:auto; text-align:left;}
188 .center {margin-left:auto; margin-right:auto; text-align:center;}
189 p.verse { margin-left: 3% }
191 border: 1pt solid #AEBDCC;
192 background-color: #F3F5F7;
194 font-family: courier, monospace;
198 table { border-collapse: collapse; }
199 td, th { vertical-align: top; }
200 th.right { text-align:center; }
201 th.left { text-align:center; }
202 th.center { text-align:center; }
203 td.right { text-align:right; }
204 td.left { text-align:left; }
205 td.center { text-align:center; }
206 dt { font-weight: bold; }
207 div.figure { padding: 0.5em; }
208 div.figure p { text-align: center; }
211 border:2px solid gray;
215 textarea { overflow-x: auto; }
216 .linenr { font-size:smaller }
217 .code-highlighted {background-color:#ffff00;}
218 .org-info-js_info-navigation { border-style:none; }
219 #org-info-js_console-label { font-size:10px; font-weight:bold;
220 white-space:nowrap; }
221 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
225 "The default style specification for exported HTML files.
226 Please use the variables `org-export-e-html-style' and
227 `org-export-e-html-style-extra' to add to this style. If you wish to not
228 have the default style included, customize the variable
229 `org-export-e-html-style-include-default'.")
231 (defcustom org-export-e-html-style-include-default t
232 "Non-nil means include the default style in exported HTML files.
233 The actual style is defined in `org-export-e-html-style-default' and should
234 not be modified. Use the variables `org-export-e-html-style' to add
235 your own style information."
236 :group
'org-export-e-html
239 (put 'org-export-e-html-style-include-default
'safe-local-variable
'booleanp
)
241 (defcustom org-export-e-html-style
""
242 "Org-wide style definitions for exported HTML files.
244 This variable needs to contain the full HTML structure to provide a style,
245 including the surrounding HTML tags. If you set the value of this variable,
246 you should consider to include definitions for the following classes:
247 title, todo, done, timestamp, timestamp-kwd, tag, target.
249 For example, a valid value would be:
251 <style type=\"text/css\">
253 p { font-weight: normal; color: gray; }
255 .title { text-align: center; }
256 .todo, .timestamp-kwd { color: red; }
257 .done { color: green; }
261 If you'd like to refer to an external style file, use something like
263 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
265 As the value of this option simply gets inserted into the HTML <head> header,
266 you can \"misuse\" it to add arbitrary text to the header.
267 See also the variable `org-export-e-html-style-extra'."
268 :group
'org-export-e-html
271 (put 'org-export-e-html-style
'safe-local-variable
'stringp
)
273 (defcustom org-export-e-html-style-extra
""
274 "Additional style information for HTML export.
275 The value of this variable is inserted into the HTML buffer right after
276 the value of `org-export-e-html-style'. Use this variable for per-file
277 settings of style information, and do not forget to surround the style
278 settings with <style>...</style> tags."
279 :group
'org-export-e-html
282 (put 'org-export-e-html-style-extra
'safe-local-variable
'stringp
)
284 (defcustom org-export-e-html-mathjax-options
285 '((path "http://orgmode.org/mathjax/MathJax.js")
290 "Options for MathJax setup.
292 path The path where to find MathJax
293 scale Scaling for the HTML-CSS backend, usually between 100 and 133
294 align How to align display math: left, center, or right
295 indent If align is not center, how far from the left/right side?
296 mathml Should a MathML player be used if available?
297 This is faster and reduces bandwidth use, but currently
298 sometimes has lower spacing quality. Therefore, the default is
299 nil. When browsers get better, this switch can be flipped.
301 You can also customize this for each buffer, using something like
303 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
304 :group
'org-export-e-html
305 :type
'(list :greedy t
306 (list :tag
"path (the path from where to load MathJax.js)"
307 (const :format
" " path
) (string))
308 (list :tag
"scale (scaling for the displayed math)"
309 (const :format
" " scale
) (string))
310 (list :tag
"align (alignment of displayed equations)"
311 (const :format
" " align
) (string))
312 (list :tag
"indent (indentation with left or right alignment)"
313 (const :format
" " indent
) (string))
314 (list :tag
"mathml (should MathML display be used is possible)"
315 (const :format
" " mathml
) (boolean))))
317 (defun org-export-e-html-mathjax-config (template options in-buffer
)
318 "Insert the user setup into the matchjax template."
319 (let (name val
(yes " ") (no "// ") x
)
322 (setq name
(car e
) val
(nth 1 e
))
323 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
324 (setq val
(car (read-from-string
325 (substring in-buffer
(match-end 0))))))
326 (if (not (stringp val
)) (setq val
(format "%s" val
)))
327 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
328 (setq template
(replace-match val t t template
))))
330 (setq val
(nth 1 (assq 'mathml options
)))
331 (if (string-match (concat "\\<mathml:") in-buffer
)
332 (setq val
(car (read-from-string
333 (substring in-buffer
(match-end 0))))))
334 ;; Exchange prefixes depending on mathml setting
335 (if (not val
) (setq x yes yes no no x
))
336 ;; Replace cookies to turn on or off the config/jax lines
337 (if (string-match ":MMLYES:" template
)
338 (setq template
(replace-match yes t t template
)))
339 (if (string-match ":MMLNO:" template
)
340 (setq template
(replace-match no t t template
)))
341 ;; Return the modified template
344 (defcustom org-export-e-html-mathjax-template
345 "<script type=\"text/javascript\" src=\"%PATH\">
346 <!--/*--><![CDATA[/*><!--*/
348 // Only one of the two following lines, depending on user settings
349 // First allows browser-native MathML display, second forces HTML/CSS
350 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
351 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
352 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
353 \"TeX/noUndefined.js\"],
355 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
356 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
357 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
358 ignoreClass: \"tex2jax_ignore\",
359 processEscapes: false,
360 processEnvironments: true,
363 showProcessingMessages: true,
364 displayAlign: \"%ALIGN\",
365 displayIndent: \"%INDENT\",
369 availableFonts: [\"STIX\",\"TeX\"],
370 preferredFont: \"TeX\",
386 "The MathJax setup for XHTML files."
387 :group
'org-export-e-html
390 (defcustom org-export-e-html-tag-class-prefix
""
391 "Prefix to class names for TODO keywords.
392 Each tag gets a class given by the tag itself, with this prefix.
393 The default prefix is empty because it is nice to just use the keyword
394 as a class name. But if you get into conflicts with other, existing
395 CSS classes, then this prefix can be very useful."
396 :group
'org-export-e-html
399 (defcustom org-export-e-html-todo-kwd-class-prefix
""
400 "Prefix to class names for TODO keywords.
401 Each TODO keyword gets a class given by the keyword itself, with this prefix.
402 The default prefix is empty because it is nice to just use the keyword
403 as a class name. But if you get into conflicts with other, existing
404 CSS classes, then this prefix can be very useful."
405 :group
'org-export-e-html
408 (defcustom org-export-e-html-preamble t
409 "Non-nil means insert a preamble in HTML export.
411 When `t', insert a string as defined by one of the formatting
412 strings in `org-export-e-html-preamble-format'. When set to a
413 string, this string overrides `org-export-e-html-preamble-format'.
414 When set to a function, apply this function and insert the
415 returned string. The function takes the property list of export
416 options as its only argument.
418 Setting :html-preamble in publishing projects will take
419 precedence over this variable."
420 :group
'org-export-e-html
421 :type
'(choice (const :tag
"No preamble" nil
)
422 (const :tag
"Default preamble" t
)
423 (string :tag
"Custom formatting string")
424 (function :tag
"Function (must return a string)")))
426 (defcustom org-export-e-html-preamble-format
'(("en" ""))
427 "The format for the HTML preamble.
429 %t stands for the title.
430 %a stands for the author's name.
431 %e stands for the author's email.
432 %d stands for the date.
434 If you need to use a \"%\" character, you need to escape it
436 :group
'org-export-e-html
439 (defcustom org-export-e-html-postamble
'auto
440 "Non-nil means insert a postamble in HTML export.
442 When `t', insert a string as defined by the formatting string in
443 `org-export-e-html-postamble-format'. When set to a string, this
444 string overrides `org-export-e-html-postamble-format'. When set to
445 'auto, discard `org-export-e-html-postamble-format' and honor
446 `org-export-author/email/creator-info' variables. When set to a
447 function, apply this function and insert the returned string.
448 The function takes the property list of export options as its
451 Setting :html-postamble in publishing projects will take
452 precedence over this variable."
453 :group
'org-export-e-html
454 :type
'(choice (const :tag
"No postamble" nil
)
455 (const :tag
"Auto preamble" 'auto
)
456 (const :tag
"Default formatting string" t
)
457 (string :tag
"Custom formatting string")
458 (function :tag
"Function (must return a string)")))
460 (defcustom org-export-e-html-postamble-format
461 '(("en" "<p class=\"author\">Author: %a (%e)</p>
462 <p class=\"date\">Date: %d</p>
463 <p class=\"creator\">Generated by %c</p>
464 <p class=\"xhtml-validation\">%v</p>
466 "The format for the HTML postamble.
468 %a stands for the author's name.
469 %e stands for the author's email.
470 %d stands for the date.
471 %c will be replaced by information about Org/Emacs versions.
472 %v will be replaced by `org-export-e-html-validation-link'.
474 If you need to use a \"%\" character, you need to escape it
476 :group
'org-export-e-html
479 (defcustom org-export-e-html-home
/up-format
480 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
481 <a accesskey=\"h\" href=\"%s\"> UP </a>
483 <a accesskey=\"H\" href=\"%s\"> HOME </a>
485 "Snippet used to insert the HOME and UP links.
486 This is a format string, the first %s will receive the UP link,
487 the second the HOME link. If both `org-export-e-html-link-up' and
488 `org-export-e-html-link-home' are empty, the entire snippet will be
490 :group
'org-export-e-html
493 (defcustom org-export-e-html-toplevel-hlevel
2
494 "The <H> level for level 1 headings in HTML export.
495 This is also important for the classes that will be wrapped around headlines
496 and outline structure. If this variable is 1, the top-level headlines will
497 be <h1>, and the corresponding classes will be outline-1, section-number-1,
498 and outline-text-1. If this is 2, all of these will get a 2 instead.
499 The default for this variable is 2, because we use <h1> for formatting the
501 :group
'org-export-e-html
504 (defcustom org-export-e-html-link-org-files-as-html t
505 "Non-nil means make file links to `file.org' point to `file.html'.
506 When org-mode is exporting an org-mode file to HTML, links to
507 non-html files are directly put into a href tag in HTML.
508 However, links to other Org-mode files (recognized by the
509 extension `.org.) should become links to the corresponding html
510 file, assuming that the linked org-mode file will also be
512 When nil, the links still point to the plain `.org' file."
513 :group
'org-export-e-html
516 (defcustom org-export-e-html-inline-images
'maybe
517 "Non-nil means inline images into exported HTML pages.
518 This is done using an <img> tag. When nil, an anchor with href is used to
519 link to the image. If this option is `maybe', then images in links with
520 an empty description will be inlined, while images with a description will
522 :group
'org-export-e-html
523 :type
'(choice (const :tag
"Never" nil
)
524 (const :tag
"Always" t
)
525 (const :tag
"When there is no description" maybe
)))
527 (defcustom org-export-e-html-inline-image-extensions
528 '("png" "jpeg" "jpg" "gif" "svg")
529 "Extensions of image files that can be inlined into HTML."
530 :group
'org-export-e-html
531 :type
'(repeat (string :tag
"Extension")))
533 (defcustom org-export-e-html-table-tag
534 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
535 "The HTML tag that is used to start a table.
536 This must be a <table> tag, but you may change the options like
537 borders and spacing."
538 :group
'org-export-e-html
541 (defcustom org-export-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
542 "The opening tag for table header fields.
543 This is customizable so that alignment options can be specified.
544 The first %s will be filled with the scope of the field, either row or col.
545 The second %s will be replaced by a style entry to align the field.
546 See also the variable `org-export-e-html-table-use-header-tags-for-first-column'.
547 See also the variable `org-export-e-html-table-align-individual-fields'."
548 :group
'org-export-tables
549 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
551 (defcustom org-export-table-data-tags
'("<td%s>" .
"</td>")
552 "The opening tag for table data fields.
553 This is customizable so that alignment options can be specified.
554 The first %s will be filled with the scope of the field, either row or col.
555 The second %s will be replaced by a style entry to align the field.
556 See also the variable `org-export-e-html-table-align-individual-fields'."
557 :group
'org-export-tables
558 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
560 (defcustom org-export-table-row-tags
'("<tr>" .
"</tr>")
561 "The opening tag for table data fields.
562 This is customizable so that alignment options can be specified.
563 Instead of strings, these can be Lisp forms that will be evaluated
564 for each row in order to construct the table row tags. During evaluation,
565 the variable `head' will be true when this is a header line, nil when this
566 is a body line. And the variable `nline' will contain the line number,
567 starting from 1 in the first header line. For example
569 (setq org-export-table-row-tags
572 (if (= (mod nline 2) 1)
573 \"<tr class=\\\"tr-odd\\\">\"
574 \"<tr class=\\\"tr-even\\\">\"))
577 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
578 :group
'org-export-tables
580 (choice :tag
"Opening tag"
581 (string :tag
"Specify")
583 (choice :tag
"Closing tag"
584 (string :tag
"Specify")
587 (defcustom org-export-e-html-table-align-individual-fields t
588 "Non-nil means attach style attributes for alignment to each table field.
589 When nil, alignment will only be specified in the column tags, but this
590 is ignored by some browsers (like Firefox, Safari). Opera does it right
592 :group
'org-export-tables
595 (defcustom org-export-e-html-table-use-header-tags-for-first-column nil
596 "Non-nil means format column one in tables with header tags.
597 When nil, also column one will use data tags."
598 :group
'org-export-tables
601 (defcustom org-export-e-html-validation-link
602 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
603 "Link to HTML validation service."
604 :group
'org-export-e-html
607 ;; FIXME Obsolete since Org 7.7
608 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
609 (defvar org-export-e-html-with-timestamp nil
610 "If non-nil, write container for HTML-helper-mode timestamp.")
612 ;; FIXME Obsolete since Org 7.7
613 (defvar org-export-e-html-html-helper-timestamp
614 "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
615 "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
617 (defcustom org-export-e-html-protect-char-alist
621 "Alist of characters to be converted by `org-e-html-protect'."
622 :group
'org-export-e-html
623 :type
'(repeat (cons (string :tag
"Character")
624 (string :tag
"HTML equivalent"))))
626 (defgroup org-export-e-htmlize nil
627 "Options for processing examples with htmlize.el."
628 :tag
"Org Export Htmlize"
629 :group
'org-export-e-html
)
631 (defcustom org-export-e-htmlize-output-type
'inline-css
632 "Output type to be used by htmlize when formatting code snippets.
633 Choices are `css', to export the CSS selectors only, or `inline-css', to
634 export the CSS attribute values inline in the HTML. We use as default
635 `inline-css', in order to make the resulting HTML self-containing.
637 However, this will fail when using Emacs in batch mode for export, because
638 then no rich font definitions are in place. It will also not be good if
639 people with different Emacs setup contribute HTML files to a website,
640 because the fonts will represent the individual setups. In these cases,
641 it is much better to let Org/Htmlize assign classes only, and to use
642 a style file to define the look of these classes.
643 To get a start for your css file, start Emacs session and make sure that
644 all the faces you are interested in are defined, for example by loading files
645 in all modes you want. Then, use the command
646 \\[org-export-e-htmlize-generate-css] to extract class definitions."
647 :group
'org-export-e-htmlize
648 :type
'(choice (const css
) (const inline-css
)))
650 (defcustom org-export-e-htmlize-css-font-prefix
"org-"
651 "The prefix for CSS class names for htmlize font specifications."
652 :group
'org-export-e-htmlize
655 (defcustom org-export-e-htmlized-org-css-url nil
656 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
657 Normally when creating an htmlized version of an Org buffer, htmlize will
658 create CSS to define the font colors. However, this does not work when
659 converting in batch mode, and it also can look bad if different people
660 with different fontification setup work on the same website.
661 When this variable is non-nil, creating an htmlized version of an Org buffer
662 using `org-export-as-org' will remove the internal CSS section and replace it
663 with a link to this URL."
664 :group
'org-export-e-htmlize
666 (const :tag
"Keep internal css" nil
)
667 (string :tag
"URL or local href")))
669 ;; FIXME: The following variable is obsolete since Org 7.7 but is
670 ;; still declared and checked within code for compatibility reasons.
671 ;; Use the custom variables `org-export-e-html-divs' instead.
672 (defvar org-export-e-html-content-div
"content"
673 "The name of the container DIV that holds all the page contents.
675 This variable is obsolete since Org version 7.7.
676 Please set `org-export-e-html-divs' instead.")
678 (defcustom org-export-e-html-divs
'("preamble" "content" "postamble")
679 "The name of the main divs for HTML export.
680 This is a list of three strings, the first one for the preamble
681 DIV, the second one for the content DIV and the third one for the
683 :group
'org-export-e-html
685 (string :tag
" Div for the preamble:")
686 (string :tag
" Div for the content:")
687 (string :tag
"Div for the postamble:")))
691 (defvar org-export-e-html-after-blockquotes-hook nil
692 "Hook run during HTML export, after blockquote, verse, center are done.")
694 (defvar org-export-e-html-final-hook nil
695 "Hook run at the end of HTML export, in the new buffer.")
697 (defun org-export-e-html-preprocess-latex-fragments ()
698 (when (equal org-lparse-backend
'html
)
699 (org-export-e-html-do-preprocess-latex-fragments)))
701 (defvar org-lparse-opt-plist
) ; bound during org-do-lparse
702 (defun org-export-e-html-do-preprocess-latex-fragments ()
703 "Convert HTML fragments to images."
704 (let* ((latex-frag-opt (plist-get org-lparse-opt-plist
:HTML-fragments
))
705 (latex-frag-opt-1 ; massage the options
707 ((eq latex-frag-opt
'verbatim
) 'verbatim
)
708 ((eq latex-frag-opt
'mathjax
) 'mathjax
)
709 ((eq latex-frag-opt t
) 'mathjax
)
710 ((eq latex-frag-opt
'dvipng
) 'dvipng
)
712 (when (and org-current-export-file latex-frag-opt
)
714 (concat "ltxpng/" (file-name-sans-extension
715 (file-name-nondirectory
716 org-current-export-file
)))
717 org-current-export-dir nil
"Creating HTML image %s"
718 nil nil latex-frag-opt-1
))))
720 (defun org-export-e-html-preprocess-label-references ()
721 (goto-char (point-min))
723 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
724 (org-if-unprotected-at (match-beginning 1)
725 (setq label
(match-string 1))
727 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
728 (setq l1
(substring label
(match-beginning 1)))
730 (replace-match (format "[[#%s][%s]]" label l1
) t t
)))))
732 (defun org-export-e-html-preprocess (parameters)
733 (org-export-e-html-preprocess-label-references))
735 ;; Process latex fragments as part of
736 ;; `org-export-preprocess-after-blockquote-hook'. Note that this hook
737 ;; is the one that is closest and well before the call to
738 ;; `org-export-attach-captions-and-attributes' in
739 ;; `org-export-preprocess-stirng'. The above arrangement permits
740 ;; captions, labels and attributes to be attached to png images
741 ;; generated out of latex equations.
742 (add-hook 'org-export-preprocess-after-blockquote-hook
743 'org-export-e-html-preprocess-latex-fragments
)
745 (defvar html-table-tag nil
) ; dynamically scoped into this.
748 ;; FIXME: it already exists in org-e-html.el
749 (defconst org-e-html-cvt-link-fn
751 "Function to convert link URLs to exportable URLs.
752 Takes two arguments, TYPE and PATH.
753 Returns exportable url as (TYPE PATH), or nil to signal that it
754 didn't handle this case.
755 Intended to be locally bound around a call to `org-export-as-html'." )
758 ;; FIXME: it already exists in org-e-html.el
759 (defun org-e-html-cvt-org-as-html (opt-plist type path
)
760 "Convert an org filename to an equivalent html filename.
761 If TYPE is not file, just return `nil'.
762 See variable `org-export-e-html-link-org-files-as-html'"
766 org-export-e-html-link-org-files-as-html
767 (string= type
"file")
768 (string-match "\\.org$" path
)
773 (substring path
0 (match-beginning 0))
775 (plist-get opt-plist
:html-extension
)))))))
777 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
780 OPT-PLIST is an options list.
781 TYPE is the device-type of the link (THIS://foo.html).
782 PATH is the path of the link (http://THIS#location).
783 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
784 DESC is the link description, if any.
785 ATTR is a string of other attributes of the \"a\" element."
786 (declare (special org-lparse-par-open
))
788 (when (string= type-1
"coderef")
789 (let ((ref fragment
))
790 (setq desc
(format (org-export-get-coderef-format ref
(and descp desc
))
791 (cdr (assoc ref org-export-code-refs
)))
792 fragment
(concat "coderef-" ref
)
793 attr
(format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
794 fragment fragment
))))
796 (and (member type-1
'("http" "https" "file"))
797 (org-lparse-should-inline-p path descp
)
799 (type (if (equal type-1
"id") "file" type-1
))
801 ;;First pass. Just sanity stuff.
804 ((string= type
"file")
807 ;;Substitute just if original path was absolute.
808 ;;(Otherwise path must remain relative)
809 (if (file-name-absolute-p path
)
810 (concat "file://" (expand-file-name path
))
814 (t (list type path
))))
816 ;;Second pass. Components converted so they can refer
820 (and org-e-html-cvt-link-fn
821 (apply org-e-html-cvt-link-fn
822 opt-plist components-1
))
823 (apply #'org-e-html-cvt-org-as-html
824 opt-plist components-1
)
826 (type (first components-2
))
827 (thefile (second components-2
)))
830 ;;Third pass. Build final link except for leading type
835 (string= type
"http")
836 (string= type
"https")
837 (string= type
"file")
838 (string= type
"coderef"))
840 (setq thefile
(concat thefile
"#" fragment
))))
844 ;;Final URL-build, for all types.
847 ((str (org-xml-format-href thefile
)))
848 (if (and type
(not (or (string= "file" type
)
849 (string= "coderef" type
))))
850 (concat type
":" str
)
854 (org-e-html-format-image thefile
)
856 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
858 (defun org-e-html-format-inline-image (path &optional caption label attr
)
859 ;; FIXME: alt text missing here?
860 (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
861 path
(file-name-nondirectory path
))))
862 (if (not label
) inline-image
863 (org-e-html-format-section inline-image
"figure" label
))))
865 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
866 (defvar org-lparse-link-description-is-image
)
868 (defun org-e-html-format-image (src)
869 "Create image tag with source and attributes."
871 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
872 (attr (org-find-text-property-in-string 'org-attributes src
))
873 (label (org-find-text-property-in-string 'org-label src
))
874 (caption (and caption
(org-xml-encode-org-text caption
)))
875 (img-extras (if (string-match "^ltxpng/" src
)
876 (format " alt=\"%s\""
877 (org-find-text-property-in-string
879 (if (string-match "\\<alt=" (or attr
""))
881 (concat " " attr
" alt=\"" src
"\""))))
882 (img (format "<img src=\"%s\"%s />" src img-extras
))
885 (format "id=\"%s\" " (org-solidify-link-text label
)))
886 "class=\"figure\"")))
889 (with-org-lparse-preserve-paragraph-state
892 '("<div %s>" .
"\n</div>")
894 (org-lparse-format '("\n<p>" .
"</p>") img
)
895 (org-lparse-format '("\n<p>" .
"</p>") caption
))
900 (defun org-export-e-html-get-bibliography ()
901 "Find bibliography, cut it out and return it."
903 (let (beg end
(cnt 1) bib
)
905 (goto-char (point-min))
906 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
907 (setq beg
(match-beginning 0))
908 (while (re-search-forward "</?div\\>" nil t
)
909 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
911 (and (looking-at ">") (forward-char 1))
912 (setq bib
(buffer-substring beg
(point)))
913 (delete-region beg
(point))
917 (defmacro with-org-lparse-backend
(backend &rest body
)
918 `(let* ((org-lparse-backend ,backend
)
919 (org-lparse-entity-control-callbacks-alist
920 (org-lparse-get 'ENTITY-CONTROL
))
921 (org-lparse-entity-format-callbacks-alist
922 (org-lparse-get 'ENTITY-FORMAT
)))
925 (defun org-e-html-format-table (lines olines
)
926 (let ((org-e-html-format-table-no-css nil
))
927 (org-lparse-format-table lines olines
)))
929 ;; Following variable is defined for native tables i.e., when
930 ;; `org-lparse-table-is-styled' evals to t.
931 (defvar org-e-html-format-table-no-css
)
932 (defvar org-table-number-regexp
) ; defined in org-table.el
934 (defun org-format-table-html (lines olines
&optional no-css
)
935 "Find out which HTML converter to use and return the HTML code.
936 NO-CSS is passed to the exporter."
937 (with-org-lparse-backend
938 'html
(let* ((org-e-html-format-table-no-css no-css
))
939 (org-lparse-format-table lines olines
))))
941 (defun org-format-org-table-html (lines &optional splice no-css
)
942 (with-org-lparse-backend
943 'html
(let* ((org-e-html-format-table-no-css no-css
))
944 (org-lparse-format-org-table lines splice
))))
946 (defun org-export-splice-attributes (tag attributes
)
947 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
951 (setq oldatt
(org-extract-attributes-from-string tag
)
953 newatt
(cdr (org-extract-attributes-from-string attributes
)))
955 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
956 (if (string-match ">" tag
)
958 (replace-match (concat (org-attributes-to-string oldatt
) ">")
962 (defun org-format-table-table-html (lines)
963 (with-org-lparse-backend
964 'html
(org-lparse-format-table-table lines
)))
966 (defun org-export-splice-style (style extra
)
967 "Splice EXTRA into STYLE, just before \"</style>\"."
968 (if (and (stringp extra
)
969 (string-match "\\S-" extra
)
970 (string-match "</style>" style
))
971 (concat (substring style
0 (match-beginning 0))
973 (substring style
(match-beginning 0)))
976 (defvar htmlize-buffer-places
) ; from htmlize.el
977 (defun org-export-e-htmlize-region-for-paste (beg end
)
978 "Convert the region to HTML, using htmlize.el.
979 This is much like `htmlize-region-for-paste', only that it uses
980 the settings define in the org-... variables."
981 (let* ((htmlize-output-type org-export-e-htmlize-output-type
)
982 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix
)
983 (htmlbuf (htmlize-region beg end
)))
985 (with-current-buffer htmlbuf
986 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
987 (plist-get htmlize-buffer-places
'content-end
)))
988 (kill-buffer htmlbuf
))))
991 (defun org-export-e-htmlize-generate-css ()
992 "Create the CSS for all font definitions in the current Emacs session.
993 Use this to create face definitions in your CSS style file that can then
994 be used by code snippets transformed by htmlize.
995 This command just produces a buffer that contains class definitions for all
996 faces used in the current Emacs session. You can copy and paste the ones you
997 need into your CSS file.
999 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1000 the function `org-export-e-htmlize-region-for-paste' will produce code
1001 that uses these same face definitions."
1004 (and (get-buffer "*html*") (kill-buffer "*html*"))
1006 (let ((fl (face-list))
1007 (htmlize-css-name-prefix "org-")
1008 (htmlize-output-type 'css
)
1010 (while (setq f
(pop fl
)
1011 i
(and f
(face-attribute f
:inherit
)))
1012 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1013 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1014 (htmlize-region (point-min) (point-max))))
1015 (org-pop-to-buffer-same-window "*html*")
1016 (goto-char (point-min))
1017 (if (re-search-forward "<style" nil t
)
1018 (delete-region (point-min) (match-beginning 0)))
1019 (if (re-search-forward "</style>" nil t
)
1020 (delete-region (1+ (match-end 0)) (point-max)))
1021 (beginning-of-line 1)
1022 (if (looking-at " +") (replace-match ""))
1023 (goto-char (point-min)))
1025 (defvar body-only
) ; dynamically scoped into this.
1027 ;; Following variable is let bound when `org-do-lparse' is in
1028 ;; progress. See org-lparse.el.
1030 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
1031 (defvar org-lparse-toc
)
1032 (defvar org-lparse-footnote-definitions
)
1033 (defvar org-lparse-dyn-first-heading-pos
)
1035 (defun org-e-html-end-export ()
1036 ;; insert the table of contents
1037 (when (and org-export-with-toc
(not body-only
) org-lparse-toc
)
1038 (org-e-html-insert-toc org-lparse-toc
))
1040 ;; remove empty paragraphs
1041 (goto-char (point-min))
1042 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
1045 ;; Convert whitespace place holders
1046 (goto-char (point-min))
1048 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1049 (setq n
(get-text-property beg
'org-whitespace
)
1050 end
(next-single-property-change beg
'org-whitespace
))
1052 (delete-region beg end
)
1053 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1054 (make-string n ?x
)))))
1056 ;; Remove empty lines at the beginning of the file.
1057 (goto-char (point-min))
1058 (when (looking-at "\\s-+\n") (replace-match ""))
1060 ;; Remove display properties
1061 (remove-text-properties (point-min) (point-max) '(display t
))
1064 (run-hooks 'org-export-e-html-final-hook
))
1066 (defun org-e-html-format-toc-entry (snumber todo headline tags href
)
1067 (setq headline
(concat
1068 (and org-export-with-section-numbers
1069 (concat snumber
" "))
1073 (org-lparse-format 'SPACES
3)
1074 (org-lparse-format 'FONTIFY tags
"tag")))))
1076 (setq headline
(org-lparse-format 'FONTIFY headline
"todo")))
1077 (org-lparse-format 'LINK headline
(concat "#" href
)))
1079 (defun org-e-html-format-toc-item (toc-entry level org-last-level
)
1080 (when (> level org-last-level
)
1081 (let ((cnt (- level org-last-level
)))
1082 (while (>= (setq cnt
(1- cnt
)) 0)
1083 (org-lparse-begin-list 'unordered
)
1084 (org-lparse-begin-list-item 'unordered
))))
1085 (when (< level org-last-level
)
1086 (let ((cnt (- org-last-level level
)))
1087 (while (>= (setq cnt
(1- cnt
)) 0)
1088 (org-lparse-end-list-item-1)
1089 (org-lparse-end-list 'unordered
))))
1091 (org-lparse-end-list-item-1)
1092 (org-lparse-begin-list-item 'unordered
)
1095 (defun org-e-html-begin-toc (lang-specific-heading max-level
)
1096 (org-lparse-insert-tag "<div id=\"table-of-contents\">")
1098 (org-lparse-format 'HEADING lang-specific-heading
1099 (or (org-lparse-get 'TOPLEVEL-HLEVEL
) 1)))
1100 (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
1101 (org-lparse-begin-list 'unordered
)
1102 (org-lparse-begin-list-item 'unordered
))
1104 (defun org-e-html-end-toc ()
1105 (while (> org-last-level
(1- org-min-level
))
1106 (setq org-last-level
(1- org-last-level
))
1107 (org-lparse-end-list-item-1)
1108 (org-lparse-end-list 'unordered
))
1109 (org-lparse-insert-tag "</div>")
1110 (org-lparse-insert-tag "</div>")
1112 ;; cleanup empty list items in toc
1113 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t
)
1114 (replace-match "")))
1117 ;; (defun org-export-as-html-and-open (arg)
1118 ;; "Export the outline as HTML and immediately open it with a browser.
1119 ;; If there is an active region, export only the region.
1120 ;; The prefix ARG specifies how many levels of the outline should become
1121 ;; headlines. The default is 3. Lower levels will become bulleted lists."
1122 ;; (interactive "P")
1123 ;; (org-lparse-and-open "html" "html" arg))
1126 ;; (defun org-export-as-html-batch ()
1127 ;; "Call the function `org-lparse-batch'.
1128 ;; This function can be used in batch processing as:
1130 ;; --load=$HOME/lib/emacs/org.el
1131 ;; --eval \"(setq org-export-headline-levels 2)\"
1132 ;; --visit=MyFile --funcall org-export-as-html-batch"
1133 ;; (org-lparse-batch "html"))
1136 ;; (defun org-export-as-html-to-buffer (arg)
1137 ;; "Call `org-lparse-to-buffer` with output to a temporary buffer.
1138 ;; No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
1139 ;; (interactive "P")
1140 ;; (org-lparse-to-buffer "html" arg))
1143 ;; (defun org-replace-region-by-html (beg end)
1144 ;; "Assume the current region has org-mode syntax, and convert it to HTML.
1145 ;; This can be used in any buffer. For example, you could write an
1146 ;; itemized list in org-mode syntax in an HTML buffer and then use this
1147 ;; command to convert it."
1148 ;; (interactive "r")
1149 ;; (org-replace-region-by "html" beg end))
1152 ;; (defun org-export-region-as-html (beg end &optional body-only buffer)
1153 ;; "Convert region from BEG to END in `org-mode' buffer to HTML.
1154 ;; If prefix arg BODY-ONLY is set, omit file header, footer, and table of
1155 ;; contents, and only produce the region of converted text, useful for
1156 ;; cut-and-paste operations.
1157 ;; If BUFFER is a buffer or a string, use/create that buffer as a target
1158 ;; of the converted HTML. If BUFFER is the symbol `string', return the
1159 ;; produced HTML as a string and leave not buffer behind. For example,
1160 ;; a Lisp program could call this function in the following way:
1162 ;; (setq html (org-export-region-as-html beg end t 'string))
1164 ;; When called interactively, the output buffer is selected, and shown
1165 ;; in a window. A non-interactive call will only return the buffer."
1166 ;; (interactive "r\nP")
1167 ;; (org-lparse-region "html" beg end body-only buffer))
1169 ;;; org-export-as-html
1171 ;; (defun org-export-as-html (arg &optional hidden ext-plist
1172 ;; to-buffer body-only pub-dir)
1173 ;; "Export the outline as a pretty HTML file.
1174 ;; Use `org-lparse' internally to perform the actual export. This
1175 ;; routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
1176 ;; of `org-lparse' to \"html\"."
1177 ;; (interactive "P")
1178 ;; (org-lparse "html" "html" arg hidden ext-plist to-buffer body-only pub-dir))
1180 (defvar org-e-html-entity-control-callbacks-alist
1182 .
(org-e-html-begin-export org-e-html-end-export
))
1184 .
(org-e-html-begin-document-content org-e-html-end-document-content
))
1186 .
(org-e-html-begin-document-body org-e-html-end-document-body
))
1188 .
(org-e-html-begin-toc org-e-html-end-toc
))
1190 .
(org-e-html-begin-environment org-e-html-end-environment
))
1191 (FOOTNOTE-DEFINITION
1192 .
(org-e-html-begin-footnote-definition org-e-html-end-footnote-definition
))
1194 .
(org-e-html-begin-table org-e-html-end-table
))
1196 .
(org-e-html-begin-table-rowgroup org-e-html-end-table-rowgroup
))
1198 .
(org-e-html-begin-list org-e-html-end-list
))
1200 .
(org-e-html-begin-list-item org-e-html-end-list-item
))
1202 .
(org-e-html-begin-outline org-e-html-end-outline
))
1204 .
(org-e-html-begin-outline-text org-e-html-end-outline-text
))
1206 .
(org-e-html-begin-paragraph org-e-html-end-paragraph
)))
1207 "Alist of control callbacks registered with the exporter.
1208 Each element is of the form (ENTITY . (BEGIN-ENTITY-FUNCTION
1209 END-ENTITY-FUNCTION)). ENTITY is one of PARAGRAPH, LIST etc as
1210 seen above. BEGIN-ENTITY-FUNCTION and END-ENTITY-FUNCTION are
1211 functions that get called when the exporter needs to begin or end
1212 an entity in the currently exported file. The signatures of
1213 these callbacks are specific to the ENTITY being emitted. These
1214 callbacks always get called with exported file as the current
1215 buffer and need to insert the appropriate tags into the current
1216 buffer. For example, `org-e-html-begin-paragraph' inserts <p> and
1217 `org-e-html-end-paragraph' inserts </p> in to the current buffer.
1218 These callbacks are invoked via `org-lparse-begin' and
1221 (defvar org-e-html-entity-format-callbacks-alist
1222 `((EXTRA-TARGETS . org-lparse-format-extra-targets
)
1223 (ORG-TAGS . org-lparse-format-org-tags
)
1224 (SECTION-NUMBER . org-lparse-format-section-number
)
1225 (HEADLINE . org-e-html-format-headline
)
1226 (TOC-ENTRY . org-e-html-format-toc-entry
)
1227 (TOC-ITEM . org-e-html-format-toc-item
)
1228 (TAGS . org-e-html-format-tags
)
1229 (SPACES . org-e-html-format-spaces
)
1230 (TABS . org-e-html-format-tabs
)
1231 (LINE-BREAK . org-e-html-format-line-break
)
1232 (FONTIFY . org-e-html-format-fontify
)
1233 (TODO . org-lparse-format-todo
)
1234 (ORG-LINK . org-e-html-format-org-link
)
1235 (LINK . org-e-html-format-link
)
1236 (INLINE-IMAGE . org-e-html-format-inline-image
)
1237 (HEADING . org-e-html-format-heading
)
1238 (ANCHOR . org-e-html-format-anchor
)
1239 (TABLE . org-e-html-format-table
)
1240 (TABLE-ROW . org-e-html-format-table-row
)
1241 (TABLE-CELL . org-e-html-format-table-cell
)
1242 (FOOTNOTES-SECTION . org-e-html-format-footnotes-section
)
1243 (FOOTNOTE-REFERENCE . org-e-html-format-footnote-reference
)
1244 (HORIZONTAL-LINE . org-e-html-format-horizontal-line
)
1245 (LINE . org-e-html-format-line
)
1246 (COMMENT . org-e-html-format-comment
)
1247 (ORG-ENTITY . org-e-html-format-org-entity
))
1248 "Alist of format callbacks registered with the exporter.
1249 Each element is of the form (ENTITY . ENTITY-FORMAT-FUNCTION).
1250 ENTITY is one of LINE, HEADING, COMMENT, LINK, TABLE-ROW etc as
1251 seen above. ENTITY-FORMAT-FUNCTION is a functions that gets
1252 called when the exporter needs to format a string in `org-mode'
1253 buffer in a backend specific way. The signatures of the
1254 formatting callback is specific to the ENTITY being passed in.
1255 These callbacks always need to encode the incoming entity in
1256 backend specific way and return the same. These callbacks do not
1257 make any modifications to the exporter file. For example,
1258 `org-e-html-format-table-row' encloses incoming entity in <tr>
1259 </tr> tags and returns it. See also `org-lparse-format'.")
1261 (defun org-e-html-unload-function ()
1262 (org-lparse-unregister-backend 'html
)
1263 (remove-hook 'org-export-preprocess-after-blockquote-hook
1264 'org-export-e-html-preprocess-latex-fragments
)
1267 (defun org-e-html-begin-body (info)
1270 (defun org-e-html-begin-document-content (info)
1273 (defun org-e-html-end-document-content ()
1276 (defun org-e-html-begin-outline (level1 snumber title tags
1277 target extra-targets extra-class
)
1278 (let* ((class (format "outline-%d" level1
))
1279 (class (if extra-class
(concat class
" " extra-class
) class
))
1280 (id (format "outline-container-%s"
1281 (org-lparse-suffix-from-snumber snumber
)))
1282 (extra (concat (when id
(format " id=\"%s\"" id
))
1283 (when class
(format " class=\"%s\"" class
)))))
1284 (org-lparse-insert-tag "<div%s>" extra
)
1286 (org-lparse-format 'HEADING
1288 'HEADLINE title extra-targets tags snumber level1
)
1291 (defun org-e-html-end-outline ()
1292 (org-lparse-insert-tag "</div>"))
1295 ;; (defun org-e-html-format-heading (text level &optional id)
1296 ;; (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
1297 ;; (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
1299 (defun org-e-html-suffix-from-snumber (snumber)
1300 (let* ((snu (replace-regexp-in-string "\\." "-" snumber
))
1301 (href (cdr (assoc (concat "sec-" snu
)
1302 org-export-preferred-target-alist
))))
1303 (org-solidify-link-text (or href snu
))))
1305 (defun org-e-html-format-outline (contents level1 snumber title
1306 tags target extra-targets extra-class
)
1307 (let* ((class (format "outline-%d" level1
))
1308 (class (if extra-class
(concat class
" " extra-class
) class
))
1309 (id (and snumber
;; FIXME
1310 (format "outline-container-%s"
1311 (org-e-html-suffix-from-snumber snumber
))))
1312 (extra (concat (when id
(format " id=\"%s\"" id
))
1313 (when class
(format " class=\"%s\"" class
)))))
1315 (format "<div%s>\n" extra
)
1316 (org-e-html-format-heading
1317 (org-e-html-format-headline title extra-targets tags snumber level1
)
1324 (defun org-e-html-begin-outline-text (level1 snumber extra-class
)
1325 (let* ((class (format "outline-text-%d" level1
))
1326 (class (if extra-class
(concat class
" " extra-class
) class
))
1327 (id (format "text-%s" (org-lparse-suffix-from-snumber snumber
)))
1328 (extra (concat (when id
(format " id=\"%s\"" id
))
1329 (when class
(format " class=\"%s\"" class
)))))
1330 (org-lparse-insert-tag "<div%s>" extra
)))
1332 (defun org-e-html-end-outline-text ()
1333 (org-lparse-insert-tag "</div>"))
1335 (defun org-e-html-begin-paragraph (&optional style
)
1336 (let* ((class (cdr (assoc style
'((footnote .
"footnote")
1338 (extra (if class
(format " class=\"%s\"" class
) "")))
1339 (org-lparse-insert-tag "<p%s>" extra
)))
1341 (defun org-e-html-end-paragraph ()
1344 (defun org-e-html-format-environment (style beg-end
)
1345 (assert (memq style
'(blockquote center verse fixedwidth quote native
)) t
)
1350 (org-lparse-end-paragraph)
1351 (insert "<blockquote>\n")
1352 (org-lparse-begin-paragraph))
1354 (org-lparse-end-paragraph)
1355 (insert "\n</blockquote>\n")
1356 (org-lparse-begin-paragraph))))
1360 (org-lparse-end-paragraph)
1361 (insert "\n<p class=\"verse\">\n")
1362 (setq org-lparse-par-open t
))
1365 (setq org-lparse-par-open nil
)
1366 (org-lparse-begin-paragraph))))
1370 (org-lparse-end-paragraph)
1371 (insert "\n<div style=\"text-align: center\">")
1372 (org-lparse-begin-paragraph))
1374 (org-lparse-end-paragraph)
1376 (org-lparse-begin-paragraph))))
1380 (org-lparse-end-paragraph)
1381 (insert "<pre class=\"example\">\n"))
1384 (org-lparse-begin-paragraph))))
1388 (org-lparse-end-paragraph)
1392 (org-lparse-begin-paragraph))))
1395 (BEGIN (org-lparse-end-paragraph))
1396 (END (org-lparse-begin-paragraph))))
1397 (t (error "Unknown environment %s" style
))))
1399 (defun org-e-html-begin-environment (style env-options-plist
)
1400 (org-e-html-format-environment style
'BEGIN
))
1402 (defun org-e-html-end-environment (style env-options-plist
)
1403 (org-e-html-format-environment style
'END
))
1405 (defun org-e-html-begin-list (ltype)
1406 (setq ltype
(or (org-lparse-html-list-type-to-canonical-list-type ltype
)
1409 (ordered (let* ((arg1 nil
)
1410 (extra (if arg1
(format " start=\"%d\"" arg1
) "")))
1411 (org-lparse-insert-tag "<ol%s>" extra
)))
1412 (unordered (org-lparse-insert-tag "<ul>"))
1413 (description (org-lparse-insert-tag "<dl>"))
1414 (t (error "Unknown list type: %s" ltype
))))
1416 (defun org-e-html-end-list (ltype)
1417 (setq ltype
(or (org-lparse-html-list-type-to-canonical-list-type ltype
)
1420 (org-lparse-insert-tag
1424 (description "</dl>")
1425 (t (error "Unknown list type: %s" ltype
)))))
1427 (defun org-e-html-begin-list-item (ltype &optional arg headline
)
1428 (setq ltype
(or (org-lparse-html-list-type-to-canonical-list-type ltype
)
1432 (assert (not headline
) t
)
1433 (let* ((counter arg
)
1434 (extra (if counter
(format " value=\"%s\"" counter
) "")))
1435 (org-lparse-insert-tag "<li%s>" extra
)))
1438 (extra (if id
(format " id=\"%s\"" id
) "")))
1439 (org-lparse-insert-tag "<li%s>" extra
)
1441 (insert headline
(org-lparse-format 'LINE-BREAK
) "\n"))))
1443 (assert (not headline
) t
)
1444 (let* ((desc-tag (or arg
"(no term)")))
1446 (org-e-html-format-tags '("<dt>" .
"</dt>") desc-tag
))
1447 (org-lparse-insert-tag "<dd>")))
1448 (t (error "Unknown list type"))))
1450 (defun org-e-html-end-list-item (ltype)
1451 (setq ltype
(or (org-lparse-html-list-type-to-canonical-list-type ltype
)
1454 (ordered (org-lparse-insert-tag "</li>"))
1455 (unordered (org-lparse-insert-tag "</li>"))
1456 (description (org-lparse-insert-tag "</dd>"))
1457 (t (error "Unknown list type"))))
1459 ;; Following variables are let bound when table emission is in
1460 ;; progress. See org-lparse.el.
1462 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
1463 (defvar org-lparse-table-begin-marker
)
1464 (defvar org-lparse-table-ncols
)
1465 (defvar org-lparse-table-rowgrp-open
)
1466 (defvar org-lparse-table-rownum
)
1467 (defvar org-lparse-table-cur-rowgrp-is-hdr
)
1468 (defvar org-lparse-table-is-styled
)
1469 (defvar org-lparse-table-rowgrp-info
)
1470 (defvar org-lparse-table-colalign-vector
)
1471 (defvar org-lparse-table-num-numeric-items-per-column
)
1473 (defun org-e-html-begin-footnote-definition (n)
1474 (org-lparse-begin-paragraph 'footnote
)
1477 (format org-export-e-html-footnote-format
1478 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1481 (defun org-e-html-end-footnote-definition (n)
1482 (org-lparse-end-paragraph))
1485 (defun org-e-html-format-footnote-definition (contents n
)
1488 (format org-export-e-html-footnote-format
1489 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1494 ;; (defun org-e-html-format-spaces (n)
1495 ;; (let ((space (or (and org-lparse-encode-pending "\\nbsp") " ")) out)
1497 ;; (setq out (concat out space))
1498 ;; (setq n (1- n))) out))
1500 (defun org-e-html-format-tabs (&optional n
)
1503 (defun org-e-html-format-line-break ()
1504 (org-e-html-format-tags "<br/>" ""))
1506 (defun org-e-html-format-horizontal-line ()
1507 (concat "\n" "<hr/>" "\n"))
1509 (defun org-e-html-format-line (line)
1510 (case org-lparse-dyn-current-environment
1511 ((quote fixedwidth
) (concat (org-e-html-encode-plain-text line
) "\n"))
1512 (t (concat line
"\n"))))
1514 (defun org-e-html-format-comment (fmt &rest args
)
1515 (let ((comment (apply 'format fmt args
)))
1516 (format "\n<!-- %s -->\n" comment
)))
1518 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1519 "Turn todo keyword into a valid class name.
1520 Replaces invalid characters with \"_\"."
1522 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1523 (setq kwd
(replace-match "_" t t kwd
))))
1526 (defun org-e-html-format-fontify (text style
&optional id
)
1527 (let (class extra how
)
1529 ((eq style
'underline
)
1530 (setq extra
" style=\"text-decoration:underline;\"" ))
1531 ((setq how
(cdr (assoc style
1532 '((bold .
("<b>" .
"</b>"))
1533 (emphasis .
("<i>" .
"</i>"))
1534 (code .
("<code>" .
"</code>"))
1535 (verbatim .
("<code>" .
"</code>"))
1536 (strike .
("<del>" .
"</del>"))
1537 (subscript .
("<sub>" .
"</sub>"))
1538 (superscript .
("<sup>" .
"</sup>")))))))
1540 (setq class
(mapconcat 'identity style
" ")))
1543 (t (error "Unknown style %S" style
)))
1545 (setq extra
(concat (when class
(format " class=\"%s\"" class
))
1546 (when id
(format " id=\"%s\"" id
))
1549 (let ((tags (or how
'("<span%s>" .
"</span>"))))
1550 (concat (format (car tags
) extra
) text
(cdr tags
)))))
1552 (defun org-e-html-format-link (text href
&optional extra
)
1553 (let ((extra (concat (format " href=\"%s\"" href
)
1554 (and extra
(concat " " extra
)))))
1555 (format "<a%s>%s</a>" extra text
)))
1557 (defun org-e-html-format-internal-link (text href
&optional extra
)
1558 (org-e-html-format-link text
(concat "#" href
) extra
))
1560 (defun org-e-html-format-heading (text level
&optional id
)
1561 (let* ((extra (concat (when id
(format " id=\"%s\"" id
)))))
1562 (concat (format "<h%d%s>" level extra
) text
(format "</h%d>" level
))))
1564 ;; (defun org-e-html-format-headline (title extra-targets tags
1565 ;; &optional snumber level)
1567 ;; (org-lparse-format 'EXTRA-TARGETS extra-targets)
1568 ;; (concat (org-lparse-format 'SECTION-NUMBER snumber level) " ")
1570 ;; (and tags (concat (org-lparse-format 'SPACES 3)
1571 ;; (org-lparse-format 'ORG-TAGS tags)))))
1573 (defun org-e-html-format-anchor (text name
&optional class
)
1576 (when name
(format " name=\"%s\"" name
))
1577 (when id
(format " id=\"%s\"" id
))
1578 (when class
(format " class=\"%s\"" class
)))))
1579 (format "<a%s>%s</a>" extra text
)))
1581 (defun org-e-html-format-extra-targets (extra-targets)
1582 (if (not extra-targets
) ""
1583 (mapconcat (lambda (x)
1585 (setq x
(org-solidify-link-text
1586 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
1587 (org-e-html-format-anchor "" x
))) extra-targets
"")))
1589 (defun org-e-html-format-spaces (n)
1590 (let (out) (dotimes (i n out
) (setq out
(concat out
" ")))))
1592 (defun org-e-html-format-org-tags (tags)
1594 (org-e-html-format-fontify
1597 (org-e-html-format-fontify
1598 x
(concat org-export-e-html-tag-class-prefix
1599 (org-e-html-fix-class-name x
))))
1600 (org-split-string tags
":")
1601 (org-e-html-format-spaces 1)) "tag")))
1603 (defun org-e-html-format-section-number (&optional snumber level
)
1605 (and org-export-with-section-numbers
1606 ;; (not org-lparse-body-only)
1608 (org-e-html-format-fontify snumber
(format "section-number-%d" level
))))
1610 (defun org-e-html-format-headline (title extra-targets tags
1611 &optional snumber level
)
1613 (org-e-html-format-extra-targets extra-targets
)
1614 (concat (org-e-html-format-section-number snumber level
) " ")
1616 (and tags
(concat (org-e-html-format-spaces 3)
1617 (org-e-html-format-org-tags tags
)))))
1619 (defun org-e-html-format-footnote-reference (n def refcnt
)
1620 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1621 (format org-export-e-html-footnote-format
1623 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1626 (defun org-e-html-format-footnotes-section (section-name definitions
)
1627 (if (not definitions
) ""
1628 (format org-export-e-html-footnotes-section section-name definitions
)))
1630 (defun org-e-html-format-org-entity (wd)
1631 (org-entity-get-representation wd
'html
))
1633 (defun org-e-html-format-tags (tag text
&rest args
)
1634 (let ((prefix (when org-lparse-encode-pending
"@"))
1635 (suffix (when org-lparse-encode-pending
"@")))
1636 (apply 'org-lparse-format-tags tag text prefix suffix args
)))
1638 (defun org-e-html-get (what &optional opt-plist
)
1643 (CLEANUP-METHOD nil
)
1645 ;; ;; There is a provision to register a per-backend converter and
1646 ;; ;; output formats. Refer `org-lparse-get-converter' and
1647 ;; ;; `org-lparse-get-other-backends'.
1649 ;; ;; The default behaviour is to use `org-lparse-convert-process'
1650 ;; ;; and `org-lparse-convert-capabilities'.
1653 ;; ;; See note above
1655 (EXPORT-DIR (org-export-directory :html opt-plist
))
1656 (FILE-NAME-EXTENSION (plist-get opt-plist
:html-extension
))
1657 (EXPORT-BUFFER-NAME "*Org HTML Export*")
1658 (ENTITY-CONTROL org-e-html-entity-control-callbacks-alist
)
1659 (ENTITY-FORMAT org-e-html-entity-format-callbacks-alist
)
1660 (TOPLEVEL-HLEVEL org-export-e-html-toplevel-hlevel
)
1661 (SPECIAL-STRING-REGEXPS org-export-e-html-special-string-regexps
)
1662 (CODING-SYSTEM-FOR-WRITE org-export-e-html-coding-system
)
1663 (CODING-SYSTEM-FOR-SAVE org-export-e-html-coding-system
)
1664 (INLINE-IMAGES org-export-e-html-inline-images
)
1665 (INLINE-IMAGE-EXTENSIONS org-export-e-html-inline-image-extensions
)
1666 (PLAIN-TEXT-MAP org-export-e-html-protect-char-alist
)
1667 (TABLE-FIRST-COLUMN-AS-LABELS
1668 org-export-e-html-table-use-header-tags-for-first-column
)
1669 (TODO-KWD-CLASS-PREFIX org-export-e-html-todo-kwd-class-prefix
)
1670 (TAG-CLASS-PREFIX org-export-e-html-tag-class-prefix
)
1671 (FOOTNOTE-SEPARATOR org-export-e-html-footnote-separator
)
1672 (t (error "Unknown property: %s" what
))))
1674 (defun org-e-html-get-coding-system-for-write ()
1675 (or org-export-e-html-coding-system
1676 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1678 (defun org-e-html-get-coding-system-for-save ()
1679 (or org-export-e-html-coding-system
1680 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1682 (defun org-e-html-insert-toc (toc)
1683 ;; locate where toc needs to be inserted
1684 (goto-char (point-min))
1686 ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1687 (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t
))
1688 (goto-char (match-beginning 0))
1691 (org-lparse-dyn-first-heading-pos
1692 (goto-char org-lparse-dyn-first-heading-pos
)
1693 (when (looking-at "\\s-*</p>")
1694 (goto-char (match-end 0))
1699 (defun org-e-html-format-date (info)
1700 (let ((date (plist-get info
:date
)))
1702 ((and date
(string-match "%" date
))
1703 (format-time-string date
))
1705 (t (format-time-string "%Y-%m-%d %T %Z")))))
1707 (defun org-e-html-footnote-section (info)
1708 (when org-e-html-footnotes-alist
1709 ;; (setq org-e-html-footnotes-alist
1710 ;; (sort org-e-html-footnotes-alist
1711 ;; (lambda (n1 n2) (< (or (nth 1 n1) most-positive-fixnum)
1712 ;; (or (nth 1 n2) most-positive-fixnum)))))
1714 ;; (setq org-e-html-footnote-alist (nreverse org-e-html-footnotes-alist))
1716 (setq org-e-html-footnotes-alist
(nreverse org-e-html-footnotes-alist
))
1717 (org-e-html-format-footnotes-section
1718 (nth 4 (or (assoc (plist-get info
:language
)
1719 org-export-language-setup
)
1720 (assoc "en" org-export-language-setup
)))
1723 <table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">
1739 (format org-export-e-html-footnote-format
1740 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1742 org-e-html-footnotes-alist
"\n")
1747 (defun org-e-html-bibliography ()
1748 (org-export-e-html-get-bibliography))
1750 (defun org-e-html-expand (s)
1751 (with-org-lparse-backend 'html
(org-xml-encode-org-text-skip-links s
)))
1753 (defun org-e-html-protect (s)
1754 (with-org-lparse-backend 'html
(org-e-html-encode-plain-text s
)))
1756 (defun org-e-html-do-expand (s)
1757 (with-org-lparse-backend 'html
(org-xml-encode-org-text s
)))
1759 (defun org-export-e-html-format-href (s)
1760 (org-xml-format-href s
))
1762 (defun org-export-e-html-format-desc (s)
1763 (org-xml-format-desc s
))
1765 (eval-when-compile (require 'cl
))
1768 (defvar org-export-latex-default-packages-alist
)
1769 (defvar org-export-latex-packages-alist
)
1771 (declare-function org-element-get-property
"org-element" (property element
))
1772 (declare-function org-element-normalize-string
"org-element" (s))
1773 (declare-function org-element-parse-secondary-string
1774 "org-element" (string restriction
&optional buffer
))
1775 (defvar org-element-string-restrictions
)
1777 (declare-function org-export-clean-table
"org-export" (table specialp
))
1778 (declare-function org-export-data
"org-export" (data backend info
))
1779 (declare-function org-export-directory
"org-export" (type plist
))
1780 (declare-function org-export-expand-macro
"org-export" (macro info
))
1781 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
1782 (declare-function org-export-footnote-first-reference-p
"org-export"
1783 (footnote-reference info
))
1784 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
1785 (declare-function org-export-get-footnote-definition
"org-export"
1786 (footnote-reference info
))
1787 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
1788 (declare-function org-export-get-previous-element
"org-export" (blob info
))
1789 (declare-function org-export-get-relative-level
"org-export" (headline info
))
1790 (declare-function org-export-handle-code
1791 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
1792 (declare-function org-export-included-file
"org-export" (keyword backend info
))
1793 (declare-function org-export-inline-image-p
"org-export"
1794 (link &optional extensions
))
1795 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
1796 (declare-function org-export-low-level-p
"org-export" (headline info
))
1797 (declare-function org-export-output-file-name
1798 "org-export" (extension &optional subtreep pub-dir
))
1799 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
1800 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
1801 (declare-function org-export-secondary-string
"org-export"
1802 (secondary backend info
))
1803 (declare-function org-export-solidify-link-text
"org-export" (s))
1804 (declare-function org-export-table-format-info
"org-export" (table))
1806 org-export-to-buffer
"org-export"
1807 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
1809 org-export-to-file
"org-export"
1810 (backend file
&optional subtreep visible-only body-only ext-plist
))
1814 ;;; Internal Variables
1816 ;; (defconst org-e-html-option-alist
1817 ;; '((:date "DATE" nil org-e-html-date-format t)
1818 ;; (:latex-class "LATEX_CLASS" nil org-e-html-default-class t)
1819 ;; (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
1820 ;; (:latex-header-extra "LATEX_HEADER" nil nil newline))
1821 ;; "Alist between HTML export properties and ways to set them.
1822 ;; See `org-export-option-alist' for more information on the
1823 ;; structure of the value.")
1825 (defconst org-e-html-option-alist
1826 '((:agenda-style nil nil org-agenda-export-html-style
)
1827 (:convert-org-links nil nil org-export-e-html-link-org-files-as-html
)
1828 ;; (:expand-quoted-html nil "@" org-export-e-html-expand) FIXME
1829 (:inline-images nil nil org-export-e-html-inline-images
)
1830 ;; (:link-home nil nil org-export-e-html-link-home) FIXME
1831 ;; (:link-up nil nil org-export-e-html-link-up) FIXME
1832 (:style nil nil org-export-e-html-style
)
1833 (:style-extra nil nil org-export-e-html-style-extra
)
1834 (:style-include-default nil nil org-export-e-html-style-include-default
)
1835 (:style-include-scripts nil nil org-export-e-html-style-include-scripts
)
1836 (:timestamp nil nil org-export-e-html-with-timestamp
)
1837 (:html-extension nil nil org-export-e-html-extension
)
1838 (:html-postamble nil nil org-export-e-html-postamble
)
1839 (:html-preamble nil nil org-export-e-html-preamble
)
1840 (:html-table-tag nil nil org-export-e-html-table-tag
)
1841 (:xml-declaration nil nil org-export-e-html-xml-declaration
)
1842 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
))
1843 "Alist between export properties and ways to set them.
1845 The car of the alist is the property name, and the cdr is a list
1846 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
1848 KEYWORD is a string representing a buffer keyword, or nil.
1849 OPTION is a string that could be found in an #+OPTIONS: line.
1850 DEFAULT is the default value for the property.
1851 BEHAVIOUR determine how Org should handle multiple keywords for
1852 the same property. It is a symbol among:
1853 nil Keep old value and discard the new one.
1854 t Replace old value with the new one.
1855 `space' Concatenate the values, separating them with a space.
1856 `newline' Concatenate the values, separating them with
1858 `split' Split values at white spaces, and cons them to the
1861 KEYWORD and OPTION have precedence over DEFAULT.
1863 All these properties should be back-end agnostic. For back-end
1864 specific properties, define a similar variable named
1865 `org-BACKEND-option-alist', replacing BACKEND with the name of
1866 the appropriate back-end. You can also redefine properties
1867 there, as they have precedence over these.")
1871 ;;; User Configurable Variables
1873 (defgroup org-export-e-html nil
1874 "Options for exporting Org mode files to HTML."
1875 :tag
"Org Export HTML"
1881 (defcustom org-e-html-default-class
"article"
1882 "The default HTML class."
1883 :group
'org-export-e-html
1884 :type
'(string :tag
"HTML class"))
1886 (defcustom org-e-html-classes
1888 "\\documentclass[11pt]{article}"
1889 ("\\section{%s}" .
"\\section*{%s}")
1890 ("\\subsection{%s}" .
"\\subsection*{%s}")
1891 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")
1892 ("\\paragraph{%s}" .
"\\paragraph*{%s}")
1893 ("\\subparagraph{%s}" .
"\\subparagraph*{%s}"))
1895 "\\documentclass[11pt]{report}"
1896 ("\\part{%s}" .
"\\part*{%s}")
1897 ("\\chapter{%s}" .
"\\chapter*{%s}")
1898 ("\\section{%s}" .
"\\section*{%s}")
1899 ("\\subsection{%s}" .
"\\subsection*{%s}")
1900 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}"))
1902 "\\documentclass[11pt]{book}"
1903 ("\\part{%s}" .
"\\part*{%s}")
1904 ("\\chapter{%s}" .
"\\chapter*{%s}")
1905 ("\\section{%s}" .
"\\section*{%s}")
1906 ("\\subsection{%s}" .
"\\subsection*{%s}")
1907 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")))
1908 "Alist of HTML classes and associated header and structure.
1909 If #+HTML_CLASS is set in the buffer, use its value and the
1910 associated information. Here is the structure of each cell:
1914 \(numbered-section . unnumbered-section\)
1920 The HEADER-STRING is the header that will be inserted into the
1921 HTML file. It should contain the \\documentclass macro, and
1922 anything else that is needed for this setup. To this header, the
1923 following commands will be added:
1925 - Calls to \\usepackage for all packages mentioned in the
1926 variables `org-export-latex-default-packages-alist' and
1927 `org-export-latex-packages-alist'. Thus, your header
1928 definitions should avoid to also request these packages.
1930 - Lines specified via \"#+HTML_HEADER:\"
1932 If you need more control about the sequence in which the header
1933 is built up, or if you want to exclude one of these building
1934 blocks for a particular class, you can use the following
1935 macro-like placeholders.
1937 [DEFAULT-PACKAGES] \\usepackage statements for default packages
1938 [NO-DEFAULT-PACKAGES] do not include any of the default packages
1939 [PACKAGES] \\usepackage statements for packages
1940 [NO-PACKAGES] do not include the packages
1941 [EXTRA] the stuff from #+HTML_HEADER
1942 [NO-EXTRA] do not include #+HTML_HEADER stuff
1943 [BEAMER-HEADER-EXTRA] the beamer extra headers
1947 \\documentclass{article}
1948 [NO-DEFAULT-PACKAGES]
1950 \\providecommand{\\alert}[1]{\\textbf{#1}}
1953 will omit the default packages, and will include the
1954 #+HTML_HEADER lines, then have a call to \\providecommand, and
1955 then place \\usepackage commands based on the content of
1956 `org-export-latex-packages-alist'.
1958 If your header, `org-export-latex-default-packages-alist' or
1959 `org-export-latex-packages-alist' inserts
1960 \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be
1961 replaced with a coding system derived from
1962 `buffer-file-coding-system'. See also the variable
1963 `org-e-html-inputenc-alist' for a way to influence this
1966 The sectioning structure
1967 ------------------------
1969 The sectioning structure of the class is given by the elements
1970 following the header string. For each sectioning level, a number
1971 of strings is specified. A %s formatter is mandatory in each
1972 section string and will be replaced by the title of the section.
1974 Instead of a cons cell \(numbered . unnumbered\), you can also
1975 provide a list of 2 or 4 elements,
1977 \(numbered-open numbered-close\)
1981 \(numbered-open numbered-close unnumbered-open unnumbered-close\)
1983 providing opening and closing strings for a HTML environment
1984 that should represent the document section. The opening clause
1985 should have a %s to represent the section title.
1987 Instead of a list of sectioning commands, you can also specify
1988 a function name. That function will be called with two
1989 parameters, the \(reduced) level of the headline, and a predicate
1990 non-nil when the headline should be numbered. It must return
1991 a format string in which the section title will be added."
1992 :group
'org-export-e-html
1994 (list (string :tag
"HTML class")
1995 (string :tag
"HTML header")
1996 (repeat :tag
"Levels" :inline t
1998 (cons :tag
"Heading"
1999 (string :tag
" numbered")
2000 (string :tag
"unnumbered"))
2001 (list :tag
"Environment"
2002 (string :tag
"Opening (numbered)")
2003 (string :tag
"Closing (numbered)")
2004 (string :tag
"Opening (unnumbered)")
2005 (string :tag
"Closing (unnumbered)"))
2006 (function :tag
"Hook computing sectioning"))))))
2008 (defcustom org-e-html-inputenc-alist nil
2009 "Alist of inputenc coding system names, and what should really be used.
2010 For example, adding an entry
2012 (\"utf8\" . \"utf8x\")
2014 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
2015 are written as utf8 files."
2016 :group
'org-export-e-html
2019 (string :tag
"Derived from buffer")
2020 (string :tag
"Use this instead"))))
2022 (defcustom org-e-html-date-format
2024 "Format string for \\date{...}."
2025 :group
'org-export-e-html
2028 (defcustom org-e-html-title-command
"\\maketitle"
2029 "The command used to insert the title just after \\begin{document}.
2030 If this string contains the formatting specification \"%s\" then
2031 it will be used as a formatting string, passing the title as an
2033 :group
'org-export-e-html
2039 (defcustom org-e-html-format-headline-function nil
2040 "Function to format headline text.
2042 This function will be called with 5 arguments:
2043 TODO the todo keyword \(string or nil\).
2044 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
2045 PRIORITY the priority of the headline \(integer or nil\)
2046 TEXT the main headline text \(string\).
2047 TAGS the tags string, separated with colons \(string or nil\).
2049 The function result will be used in the section format string.
2051 As an example, one could set the variable to the following, in
2052 order to reproduce the default set-up:
2054 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
2055 \"Default format function for an headline.\"
2056 \(concat \(when todo
2057 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
2059 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2061 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
2062 :group
'org-export-e-html
2068 (defcustom org-e-html-emphasis-alist
2069 '(("*" .
"\\textbf{%s}")
2070 ("/" .
"\\emph{%s}")
2071 ("_" .
"\\underline{%s}")
2073 ("=" . protectedtexttt
)
2075 "Alist of HTML expressions to convert emphasis fontifiers.
2077 The key is the character used as a marker for fontification. The
2078 value is a formatting string to wrap fontified text with.
2080 Value can also be set to the following symbols: `verb' and
2081 `protectedtexttt'. For the former, Org will use \"\\verb\" to
2082 create a format string and select a delimiter character that
2083 isn't in the string. For the latter, Org will use \"\\texttt\"
2084 to typeset and try to protect special characters."
2085 :group
'org-export-e-html
2091 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
2092 "Text used to separate footnotes."
2093 :group
'org-export-e-html
2099 (defcustom org-e-html-active-timestamp-format
"\\textit{%s}"
2100 "A printf format string to be applied to active time-stamps."
2101 :group
'org-export-e-html
2104 (defcustom org-e-html-inactive-timestamp-format
"\\textit{%s}"
2105 "A printf format string to be applied to inactive time-stamps."
2106 :group
'org-export-e-html
2109 (defcustom org-e-html-diary-timestamp-format
"\\textit{%s}"
2110 "A printf format string to be applied to diary time-stamps."
2111 :group
'org-export-e-html
2117 (defcustom org-e-html-image-default-option
"width=.9\\linewidth"
2118 "Default option for images."
2119 :group
'org-export-e-html
2122 (defcustom org-e-html-default-figure-position
"htb"
2123 "Default position for latex figures."
2124 :group
'org-export-e-html
2127 (defcustom org-e-html-inline-image-rules
2128 '(("file" .
"\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
2129 "Rules characterizing image files that can be inlined into HTML.
2131 A rule consists in an association whose key is the type of link
2132 to consider, and value is a regexp that will be matched against
2135 Note that, by default, the image extension *actually* allowed
2136 depend on the way the HTML file is processed. When used with
2137 pdflatex, pdf, jpg and png images are OK. When processing
2138 through dvi to Postscript, only ps and eps are allowed. The
2139 default we use here encompasses both."
2140 :group
'org-export-e-html
2141 :type
'(alist :key-type
(string :tag
"Type")
2142 :value-type
(regexp :tag
"Path")))
2147 (defcustom org-e-html-default-table-environment
"tabular"
2148 "Default environment used to build tables."
2149 :group
'org-export-e-html
2152 (defcustom org-e-html-tables-centered t
2153 "When non-nil, tables are exported in a center environment."
2154 :group
'org-export-e-html
2157 (defcustom org-e-html-tables-verbatim nil
2158 "When non-nil, tables are exported verbatim."
2159 :group
'org-export-e-html
2162 (defcustom org-e-html-tables-booktabs nil
2163 "When non-nil, display tables in a formal \"booktabs\" style.
2164 This option assumes that the \"booktabs\" package is properly
2165 loaded in the header of the document. This value can be ignored
2166 locally with \"booktabs=yes\" and \"booktabs=no\" HTML
2168 :group
'org-export-e-html
2171 (defcustom org-e-html-table-caption-above t
2172 "When non-nil, place caption string at the beginning of the table.
2173 Otherwise, place it near the end."
2174 :group
'org-export-e-html
2180 (defcustom org-e-html-format-drawer-function nil
2181 "Function called to format a drawer in HTML code.
2183 The function must accept two parameters:
2184 NAME the drawer name, like \"LOGBOOK\"
2185 CONTENTS the contents of the drawer.
2187 The function should return the string to be exported.
2189 For example, the variable could be set to the following function
2190 in order to mimic default behaviour:
2192 \(defun org-e-html-format-drawer-default \(name contents\)
2193 \"Format a drawer element for HTML export.\"
2195 :group
'org-export-e-html
2201 (defcustom org-e-html-format-inlinetask-function nil
2202 "Function called to format an inlinetask in HTML code.
2204 The function must accept six parameters:
2205 TODO the todo keyword, as a string
2206 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
2207 PRIORITY the inlinetask priority, as a string
2208 NAME the inlinetask name, as a string.
2209 TAGS the inlinetask tags, as a string.
2210 CONTENTS the contents of the inlinetask, as a string.
2212 The function should return the string to be exported.
2214 For example, the variable could be set to the following function
2215 in order to mimic default behaviour:
2217 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
2218 \"Format an inline task element for HTML export.\"
2219 \(let \(\(full-title
2222 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
2223 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2225 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
2226 \(format \(concat \"\\\\begin{center}\\n\"
2228 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
2230 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
2232 \"\\\\end{minipage}}\"
2233 \"\\\\end{center}\"\)
2234 full-title contents\)\)"
2235 :group
'org-export-e-html
2241 (defcustom org-e-html-listings nil
2242 "Non-nil means export source code using the listings package.
2243 This package will fontify source code, possibly even with color.
2244 If you want to use this, you also need to make HTML use the
2245 listings package, and if you want to have color, the color
2246 package. Just add these to `org-export-latex-packages-alist',
2247 for example using customize, or with something like:
2249 \(require 'org-e-html)
2250 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"listings\"))
2251 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"color\"))
2255 \(setq org-e-html-listings 'minted)
2257 causes source code to be exported using the minted package as
2258 opposed to listings. If you want to use minted, you need to add
2259 the minted package to `org-export-latex-packages-alist', for
2260 example using customize, or with
2262 \(require 'org-e-html)
2263 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"minted\"))
2265 In addition, it is necessary to install pygments
2266 \(http://pygments.org), and to configure the variable
2267 `org-e-html-pdf-process' so that the -shell-escape option is
2268 passed to pdflatex."
2269 :group
'org-export-e-html
2271 (const :tag
"Use listings" t
)
2272 (const :tag
"Use minted" 'minted
)
2273 (const :tag
"Export verbatim" nil
)))
2275 (defcustom org-e-html-listings-langs
2276 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
2279 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
2280 (html "HTML") (xml "XML")
2281 (tex "TeX") (latex "TeX")
2282 (shell-script "bash")
2284 (ocaml "Caml") (caml "Caml")
2285 (sql "SQL") (sqlite "sql"))
2286 "Alist mapping languages to their listing language counterpart.
2287 The key is a symbol, the major mode symbol without the \"-mode\".
2288 The value is the string that should be inserted as the language
2289 parameter for the listings package. If the mode name and the
2290 listings name are the same, the language does not need an entry
2291 in this list - but it does not hurt if it is present."
2292 :group
'org-export-e-html
2295 (symbol :tag
"Major mode ")
2296 (string :tag
"Listings language"))))
2298 (defcustom org-e-html-listings-options nil
2299 "Association list of options for the latex listings package.
2301 These options are supplied as a comma-separated list to the
2302 \\lstset command. Each element of the association list should be
2303 a list containing two strings: the name of the option, and the
2306 (setq org-e-html-listings-options
2307 '((\"basicstyle\" \"\\small\")
2308 (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
2310 will typeset the code in a small size font with underlined, bold
2313 Note that the same options will be applied to blocks of all
2315 :group
'org-export-e-html
2318 (string :tag
"Listings option name ")
2319 (string :tag
"Listings option value"))))
2321 (defcustom org-e-html-minted-langs
2322 '((emacs-lisp "common-lisp")
2325 (shell-script "bash")
2327 "Alist mapping languages to their minted language counterpart.
2328 The key is a symbol, the major mode symbol without the \"-mode\".
2329 The value is the string that should be inserted as the language
2330 parameter for the minted package. If the mode name and the
2331 listings name are the same, the language does not need an entry
2332 in this list - but it does not hurt if it is present.
2334 Note that minted uses all lower case for language identifiers,
2335 and that the full list of language identifiers can be obtained
2338 pygmentize -L lexers"
2339 :group
'org-export-e-html
2342 (symbol :tag
"Major mode ")
2343 (string :tag
"Minted language"))))
2345 (defcustom org-e-html-minted-options nil
2346 "Association list of options for the latex minted package.
2348 These options are supplied within square brackets in
2349 \\begin{minted} environments. Each element of the alist should
2350 be a list containing two strings: the name of the option, and the
2353 \(setq org-e-html-minted-options
2354 '\((\"bgcolor\" \"bg\") \(\"frame\" \"lines\")))
2356 will result in src blocks being exported with
2358 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
2360 as the start of the minted environment. Note that the same
2361 options will be applied to blocks of all languages."
2362 :group
'org-export-e-html
2365 (string :tag
"Minted option name ")
2366 (string :tag
"Minted option value"))))
2368 (defvar org-e-html-custom-lang-environments nil
2369 "Alist mapping languages to language-specific HTML environments.
2371 It is used during export of src blocks by the listings and minted
2372 latex packages. For example,
2374 \(setq org-e-html-custom-lang-environments
2375 '\(\(python \"pythoncode\"\)\)\)
2377 would have the effect that if org encounters begin_src python
2378 during latex export it will output
2387 (defcustom org-e-html-quotes
2388 '(("fr" ("\\(\\s-\\|[[(]\\)\"" .
"«~") ("\\(\\S-\\)\"" .
"~»") ("\\(\\s-\\|(\\)'" .
"'"))
2389 ("en" ("\\(\\s-\\|[[(]\\)\"" .
"``") ("\\(\\S-\\)\"" .
"''") ("\\(\\s-\\|(\\)'" .
"`")))
2390 "Alist for quotes to use when converting english double-quotes.
2392 The CAR of each item in this alist is the language code.
2393 The CDR of each item in this alist is a list of three CONS:
2394 - the first CONS defines the opening quote;
2395 - the second CONS defines the closing quote;
2396 - the last CONS defines single quotes.
2398 For each item in a CONS, the first string is a regexp
2399 for allowed characters before/after the quote, the second
2400 string defines the replacement string for this quote."
2401 :group
'org-export-e-html
2403 (cons :tag
"Opening quote"
2404 (string :tag
"Regexp for char before")
2405 (string :tag
"Replacement quote "))
2406 (cons :tag
"Closing quote"
2407 (string :tag
"Regexp for char after ")
2408 (string :tag
"Replacement quote "))
2409 (cons :tag
"Single quote"
2410 (string :tag
"Regexp for char before")
2411 (string :tag
"Replacement quote "))))
2416 (defcustom org-e-html-pdf-process
2417 '("pdflatex -interaction nonstopmode -output-directory %o %f"
2418 "pdflatex -interaction nonstopmode -output-directory %o %f"
2419 "pdflatex -interaction nonstopmode -output-directory %o %f")
2420 "Commands to process a HTML file to a PDF file.
2421 This is a list of strings, each of them will be given to the
2422 shell as a command. %f in the command will be replaced by the
2423 full file name, %b by the file base name \(i.e. without
2424 extension) and %o by the base directory of the file.
2426 The reason why this is a list is that it usually takes several
2427 runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
2428 does not have a clever mechanism to detect which of these
2429 commands have to be run to get to a stable result, and it also
2430 does not do any error checking.
2432 By default, Org uses 3 runs of `pdflatex' to do the processing.
2433 If you have texi2dvi on your system and if that does not cause
2434 the infamous egrep/locale bug:
2436 http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
2438 then `texi2dvi' is the superior choice. Org does offer it as one
2439 of the customize options.
2441 Alternatively, this may be a Lisp function that does the
2442 processing, so you could use this to apply the machinery of
2443 AUCTeX or the Emacs HTML mode. This function should accept the
2444 file name as its single argument."
2445 :group
'org-export-pdf
2447 (repeat :tag
"Shell command sequence"
2448 (string :tag
"Shell command"))
2449 (const :tag
"2 runs of pdflatex"
2450 ("pdflatex -interaction nonstopmode -output-directory %o %f"
2451 "pdflatex -interaction nonstopmode -output-directory %o %f"))
2452 (const :tag
"3 runs of pdflatex"
2453 ("pdflatex -interaction nonstopmode -output-directory %o %f"
2454 "pdflatex -interaction nonstopmode -output-directory %o %f"
2455 "pdflatex -interaction nonstopmode -output-directory %o %f"))
2456 (const :tag
"pdflatex,bibtex,pdflatex,pdflatex"
2457 ("pdflatex -interaction nonstopmode -output-directory %o %f"
2459 "pdflatex -interaction nonstopmode -output-directory %o %f"
2460 "pdflatex -interaction nonstopmode -output-directory %o %f"))
2461 (const :tag
"texi2dvi"
2462 ("texi2dvi -p -b -c -V %f"))
2463 (const :tag
"rubber"
2464 ("rubber -d --into %o %f"))
2467 (defcustom org-e-html-logfiles-extensions
2468 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
2469 "The list of file extensions to consider as HTML logfiles."
2470 :group
'org-export-e-html
2471 :type
'(repeat (string :tag
"Extension")))
2473 (defcustom org-e-html-remove-logfiles t
2474 "Non-nil means remove the logfiles produced by PDF production.
2475 These are the .aux, .log, .out, and .toc files."
2476 :group
'org-export-e-html
2481 ;;; Internal Functions
2483 (defun org-e-html--caption/label-string
(caption label info
)
2484 "Return caption and label HTML string for floats.
2486 CAPTION is a cons cell of secondary strings, the car being the
2487 standard caption and the cdr its short form. LABEL is a string
2488 representing the label. INFO is a plist holding contextual
2491 If there's no caption nor label, return the empty string.
2493 For non-floats, see `org-e-html--wrap-label'."
2494 (setq label nil
) ;; FIXME
2496 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
2498 ((and (not caption
) (not label
)) "")
2499 ((not caption
) (format "\\label{%s}\n" label
))
2500 ;; Option caption format with short name.
2502 (format "\\caption[%s]{%s%s}\n"
2503 (org-export-secondary-string (cdr caption
) 'e-html info
)
2505 (org-export-secondary-string (car caption
) 'e-html info
)))
2506 ;; Standard caption format.
2507 ;; (t (format "\\caption{%s%s}\n"
2509 ;; (org-export-secondary-string (car caption) 'e-html info)))
2511 (t (org-export-secondary-string (car caption
) 'e-html info
)))))
2513 (defun org-e-html--guess-inputenc (header)
2514 "Set the coding system in inputenc to what the buffer is.
2516 HEADER is the HTML header string.
2518 Return the new header."
2519 (let* ((cs (or (ignore-errors
2520 (latexenc-coding-system-to-inputenc
2521 buffer-file-coding-system
))
2525 ;; First translate if that is requested.
2526 (setq cs
(or (cdr (assoc cs org-e-html-inputenc-alist
)) cs
))
2527 ;; Then find the \usepackage statement and replace the option.
2528 (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
2529 cs header t nil
1))))
2531 (defun org-e-html--find-verb-separator (s)
2532 "Return a character not used in string S.
2533 This is used to choose a separator for constructs like \\verb."
2534 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
2535 (loop for c across ll
2536 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
2537 return
(char-to-string c
))))
2539 (defun org-e-html--make-option-string (options)
2540 "Return a comma separated string of keywords and values.
2541 OPTIONS is an alist where the key is the options keyword as
2542 a string, and the value a list containing the keyword value, or
2544 (mapconcat (lambda (pair)
2545 (concat (first pair
)
2546 (when (> (length (second pair
)) 0)
2547 (concat "=" (second pair
)))))
2551 (defun org-e-html--quotation-marks (text info
)
2552 "Export quotation marks depending on language conventions.
2553 TEXT is a string containing quotation marks to be replaced. INFO
2554 is a plist used as a communication channel."
2557 (while (setq start
(string-match (car l
) text start
))
2558 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2559 (setq text
(replace-match new-quote t t text
))))))
2560 (cdr (or (assoc (plist-get info
:language
) org-e-html-quotes
)
2561 ;; Falls back on English.
2562 (assoc "en" org-e-html-quotes
))))
2565 (defun org-e-html--wrap-label (element output
)
2566 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
2567 This function shouldn't be used for floats. See
2568 `org-e-html--caption/label-string'."
2569 ;; (let ((label (org-element-get-property :name element)))
2570 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
2572 ;; (concat (format "\\label{%s}\n" label) output)))
2579 ;; (defun org-e-html-template (contents info)
2580 ;; "Return complete document string after HTML conversion.
2581 ;; CONTENTS is the transcoded contents string. INFO is a plist
2582 ;; holding export options."
2583 ;; (let ((title (org-export-secondary-string
2584 ;; (plist-get info :title) 'e-html info)))
2586 ;; ;; 1. Time-stamp.
2587 ;; (and (plist-get info :time-stamp-file)
2588 ;; (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
2589 ;; ;; 2. Document class and packages.
2590 ;; (let ((class (plist-get info :latex-class))
2591 ;; (class-options (plist-get info :latex-class-options)))
2592 ;; (org-element-normalize-string
2593 ;; (let* ((header (nth 1 (assoc class org-e-html-classes)))
2594 ;; (document-class-string
2595 ;; (and (stringp header)
2596 ;; (if class-options
2597 ;; (replace-regexp-in-string
2598 ;; "^[ \t]*\\\\documentclass\\(\\[.*?\\]\\)"
2599 ;; class-options header t nil 1)
2601 ;; (org-e-html--guess-inputenc
2602 ;; (org-splice-latex-header
2603 ;; document-class-string
2604 ;; org-export-latex-default-packages-alist ; defined in org.el
2605 ;; org-export-latex-packages-alist nil ; defined in org.el
2606 ;; (plist-get info :latex-header-extra))))))
2607 ;; ;; 3. Define alert if not yet defined.
2608 ;; "\\providecommand{\\alert}[1]{\\textbf{#1}}\n"
2609 ;; ;; 4. Possibly limit depth for headline numbering.
2610 ;; (let ((sec-num (plist-get info :section-numbers)))
2611 ;; (when (integerp sec-num)
2612 ;; (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
2614 ;; (let ((author (and (plist-get info :with-author)
2615 ;; (let ((auth (plist-get info :author)))
2616 ;; (and auth (org-export-secondary-string
2617 ;; auth 'e-html info)))))
2618 ;; (email (and (plist-get info :with-email)
2619 ;; (org-export-secondary-string
2620 ;; (plist-get info :email) 'e-html info))))
2621 ;; (cond ((and author email (not (string= "" email)))
2622 ;; (format "\\author{%s\\thanks{%s}}\n" author email))
2623 ;; (author (format "\\author{%s}\n" author))
2624 ;; (t "\\author{}\n")))
2626 ;; (let ((date (plist-get info :date)))
2627 ;; (and date (format "\\date{%s}\n" date)))
2629 ;; (format "\\title{%s}\n" title)
2630 ;; ;; 8. Hyperref options.
2631 ;; (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
2632 ;; (or (plist-get info :keywords) "")
2633 ;; (or (plist-get info :description) "")
2634 ;; (if (not (plist-get info :with-creator)) ""
2635 ;; (plist-get info :creator)))
2636 ;; ;; 9. Document start.
2637 ;; "\\begin{document}\n\n"
2638 ;; ;; 10. Title command.
2639 ;; (org-element-normalize-string
2640 ;; (cond ((string= "" title) nil)
2641 ;; ((not (stringp org-e-html-title-command)) nil)
2642 ;; ((string-match "\\(?:[^%]\\|^\\)%s"
2643 ;; org-e-html-title-command)
2644 ;; (format org-e-html-title-command title))
2645 ;; (t org-e-html-title-command)))
2646 ;; ;; 11. Table of contents.
2647 ;; (let ((depth (plist-get info :with-toc)))
2649 ;; (concat (when (wholenump depth)
2650 ;; (format "\\setcounter{tocdepth}{%d}\n" depth))
2651 ;; "\\tableofcontents\n\\vspace*{1cm}\n\n")))
2652 ;; ;; 12. Document's body.
2655 ;; (let ((creator-info (plist-get info :with-creator)))
2657 ;; ((not creator-info) "")
2658 ;; ((eq creator-info 'comment)
2659 ;; (format "%% %s\n" (plist-get info :creator)))
2660 ;; (t (concat (plist-get info :creator) "\n"))))
2661 ;; ;; 14. Document end.
2662 ;; "\\end{document}")))
2664 (defun org-e-html-meta-info (info)
2667 <title>%s</title>" (plist-get info
:title
))
2669 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
2670 (and coding-system-for-write
2671 (fboundp 'coding-system-get
)
2672 (coding-system-get coding-system-for-write
2675 <meta name=\"title\" content=\"%s\"/>" (plist-get info
:title
))
2677 <meta name=\"generator\" content=\"Org-mode\"/>"
2679 <meta name=\"generated\" content=\"%s\"/>" (org-e-html-format-date info
))
2681 <meta name=\"author\" content=\"%s\"/>" (plist-get info
:author
))
2683 <meta name=\"description\" content=\"%s\"/>" (plist-get info
:description
))
2685 <meta name=\"keywords\" content=\"%s\"/>" (plist-get info
:keywords
))))
2687 (defun org-e-html-style (info)
2689 (when (plist-get info
:style-include-default
)
2690 org-export-e-html-style-default
)
2691 (plist-get info
:style
)
2692 (plist-get info
:style-extra
)
2694 (when (plist-get info
:style-include-scripts
)
2695 org-export-e-html-scripts
)))
2697 (defun org-e-html-mathjax (info)
2698 (when (or (eq (plist-get info
:HTML-fragments
) 'mathjax
)
2699 (and org-export-have-math
2700 (eq (plist-get info
:HTML-fragments
) t
)))
2701 (org-export-e-html-mathjax-config
2702 org-export-e-html-mathjax-template
2703 org-export-e-html-mathjax-options
2704 (or (plist-get info
:mathjax
) ""))))
2706 (defun org-e-html-preamble (info)
2707 (when (plist-get info
:html-preamble
)
2708 (let* ((title (plist-get info
:title
))
2709 (date (org-e-html-format-date info
))
2710 (author (plist-get info
:author
))
2711 (lang-words (or (assoc (plist-get info
:language
)
2712 org-export-language-setup
)
2713 (assoc "en" org-export-language-setup
)))
2714 (email (plist-get info
:email
))
2715 (html-pre-real-contents
2717 ((functionp (plist-get info
:html-preamble
))
2719 (funcall (plist-get info
:html-preamble
))
2721 ((stringp (plist-get info
:html-preamble
))
2722 (format-spec (plist-get info
:html-preamble
)
2723 `((?t .
,title
) (?a .
,author
)
2724 (?d .
,date
) (?e .
,email
))))
2727 (or (cadr (assoc (nth 0 lang-words
)
2728 org-export-e-html-preamble-format
))
2729 (cadr (assoc "en" org-export-e-html-preamble-format
)))
2730 `((?t .
,title
) (?a .
,author
)
2731 (?d .
,date
) (?e .
,email
)))))))
2732 (when (not (equal html-pre-real-contents
""))
2735 <div id=\"%s\"> " (nth 0 org-export-e-html-divs
))
2738 html-pre-real-contents
2742 ;; (defun org-e-html-footnote-section (info)
2743 ;; (when org-e-html-footnotes-alist
2744 ;; (setq org-e-html-footnotes-alist
2745 ;; (sort org-e-html-footnotes-alist
2746 ;; (lambda (n1 n2) (< (or (nth 1 n1) most-positive-fixnum)
2747 ;; (or (nth 1 n2) most-positive-fixnum)))))
2748 ;; (org-e-html-format-footnotes-section
2749 ;; (nth 4 (or (assoc (plist-get info :language)
2750 ;; org-export-language-setup)
2751 ;; (assoc "en" org-export-language-setup)))
2754 ;; (org-e-html-format-footnote-definition (nth 2 x) (nth 1 x)))
2755 ;; org-e-html-footnotes-alist "\n"))))
2757 (defun org-e-html-bibliography ()
2758 (org-export-e-html-get-bibliography))
2760 (defun org-e-html-postamble (info)
2762 (when (and (not body-only
)
2763 (plist-get info
:html-postamble
))
2764 (let* ((html-post (plist-get info
:html-postamble
))
2765 (date (org-e-html-format-date info
))
2766 (author (plist-get info
:author
))
2767 (email (plist-get info
:email
))
2768 (lang-words (or (assoc (plist-get info
:language
)
2769 org-export-language-setup
)
2770 (assoc "en" org-export-language-setup
)))
2772 (mapconcat (lambda(e)
2773 (format "<a href=\"mailto:%s\">%s</a>" e e
))
2774 (split-string email
",+ *")
2776 (html-validation-link (or org-export-e-html-validation-link
""))
2778 (concat "Org version " org-version
" with Emacs version "
2779 (number-to-string emacs-major-version
))))
2783 <div id=\"" (nth 2 org-export-e-html-divs
) "\">"
2786 ((eq (plist-get info
:html-postamble
) 'auto
)
2788 (when (plist-get info
:time-stamp-file
)
2790 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words
) date
))
2791 (when (and (plist-get info
:with-author
) author
)
2793 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words
) author
))
2794 (when (and (plist-get info
:with-email
) email
)
2796 <p class=\"email\"> %s </p>" email
))
2797 (when (plist-get info
:with-creator
)
2799 <p class=\"creator\"> %s </p>" creator-info
))
2800 html-validation-link
"\n"))
2801 ;; postamble from a string
2802 ((stringp (plist-get info
:html-postamble
))
2803 (format-spec (plist-get info
:html-postamble
)
2804 `((?a .
,author
) (?e .
,email
)
2805 (?d .
,date
) (?c .
,creator-info
)
2806 (?v .
,html-validation-link
))))
2808 ;; postamble from a function
2809 ((functionp (plist-get info
:html-postamble
))
2811 (funcall (plist-get info
:html-postamble
))
2813 ;; default postamble
2816 (or (cadr (assoc (nth 0 lang-words
)
2817 org-export-e-html-postamble-format
))
2818 (cadr (assoc "en" org-export-e-html-postamble-format
)))
2819 `((?a .
,author
) (?e .
,email
)
2820 (?d .
,date
) (?c .
,creator-info
)
2821 (?v .
,html-validation-link
)))))
2824 org-export-e-html-html-helper-timestamp
))
2826 (defun org-e-html-template (contents info
)
2827 "Return complete document string after HTML conversion.
2828 CONTENTS is the transcoded contents string. RAW-DATA is the
2829 original parsed data. INFO is a plist holding export options."
2832 (or (and (stringp org-export-e-html-xml-declaration
)
2833 org-export-e-html-xml-declaration
)
2834 (cdr (assoc (plist-get info
:html-extension
)
2835 org-export-e-html-xml-declaration
))
2836 (cdr (assoc "html" org-export-e-html-xml-declaration
))
2839 (or (and coding-system-for-write
2840 (fboundp 'coding-system-get
)
2841 (coding-system-get coding-system-for-write
2845 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2846 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
2848 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
2849 (plist-get info
:language
) (plist-get info
:language
))
2852 (org-e-html-meta-info info
) ; meta
2853 (org-e-html-style info
) ; style
2854 (org-e-html-mathjax info
) ; mathjax
2860 (let ((link-up (and (plist-get info
:link-up
)
2861 (string-match "\\S-" (plist-get info
:link-up
))
2862 (plist-get info
:link-up
)))
2863 (link-home (and (plist-get info
:link-home
)
2864 (string-match "\\S-" (plist-get info
:link-home
))
2865 (plist-get info
:link-home
))))
2866 (when (or link-up link-home
)
2867 (format org-export-e-html-home
/up-format
2868 (or link-up link-home
)
2869 (or link-home link-up
))))
2871 (org-e-html-preamble info
)
2875 <div id=\"%s\">" (or org-export-e-html-content-div
2876 (nth 1 org-export-e-html-divs
)))
2878 <h1 class=\"title\"> %s </h1>\n" (plist-get info
:title
))
2881 (org-e-html-footnote-section info
)
2882 (org-e-html-bibliography)
2889 (org-e-html-postamble info
)
2899 ;;; Transcode Functions
2903 (defun org-e-html-center-block (center-block contents info
)
2904 "Transcode a CENTER-BLOCK element from Org to HTML.
2905 CONTENTS holds the contents of the block. INFO is a plist
2906 holding contextual information."
2907 ;; (org-e-html--wrap-label
2909 ;; (format "\\begin{center}\n%s\\end{center}" contents))
2910 (org-e-html--wrap-label
2912 (format "<div style=\"text-align: center\">\n%s</div>" contents
)))
2917 ;; Comments are ignored.
2922 ;; Comment Blocks are ignored.
2927 (defun org-e-html-drawer (drawer contents info
)
2928 "Transcode a DRAWER element from Org to HTML.
2929 CONTENTS holds the contents of the block. INFO is a plist
2930 holding contextual information."
2931 (let* ((name (org-element-get-property :drawer-name drawer
))
2932 (output (if (functionp org-e-html-format-drawer-function
)
2933 (funcall org-e-html-format-drawer-function
2935 ;; If there's no user defined function: simply
2936 ;; display contents of the drawer.
2938 (org-e-html--wrap-label drawer output
)))
2943 (defun org-e-html-dynamic-block (dynamic-block contents info
)
2944 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2945 CONTENTS holds the contents of the block. INFO is a plist
2946 holding contextual information. See
2948 (org-e-html--wrap-label dynamic-block contents
))
2953 (defun org-e-html-emphasis (emphasis contents info
)
2954 "Transcode EMPHASIS from Org to HTML.
2955 CONTENTS is the contents of the emphasized text. INFO is a plist
2956 holding contextual information.."
2957 ;; (format (cdr (assoc (org-element-get-property :marker emphasis)
2958 ;; org-e-html-emphasis-alist))
2960 (org-e-html-format-fontify
2961 contents
(cadr (assoc
2962 (org-element-get-property :marker emphasis
)
2973 (defun org-e-html-entity (entity contents info
)
2974 "Transcode an ENTITY object from Org to HTML.
2975 CONTENTS are the definition itself. INFO is a plist holding
2976 contextual information."
2977 ;; (let ((ent (org-element-get-property :latex entity)))
2978 ;; (if (org-element-get-property :latex-math-p entity)
2979 ;; (format "$%s$" ent)
2981 (org-element-get-property :html entity
))
2987 ;; (defun org-odt-format-source-code-or-example-colored
2988 ;; (lines lang caption textareap cols rows num cont rpllbl fmt))
2990 (defun org-e-html-format-source-code-or-example-plain
2991 (lines lang caption textareap cols rows num cont rpllbl fmt
)
2994 "<pre class=\"example\">\n"
2998 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
3000 lines
"</textarea>\n</p>\n"))
3004 (goto-char (point-min))
3005 (while (re-search-forward "[<>&]" nil t
)
3006 (replace-match (cdr (assq (char-before)
3007 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
3013 (setq lines
(org-export-number-lines lines
1 1 num cont rpllbl fmt
)))
3015 ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
3016 ;; (setq lines (replace-match "\\1" t nil lines)))
3020 (defun org-e-html-format-source-code-or-example-colored
3021 (lines lang caption textareap cols rows num cont rpllbl fmt
)
3022 (let* ((lang-m (when lang
3023 (or (cdr (assoc lang org-src-lang-modes
))
3025 (mode (and lang-m
(intern
3027 (if (symbolp lang-m
)
3028 (symbol-name lang-m
)
3031 (org-inhibit-startup t
)
3032 (org-startup-folded nil
))
3036 (if (functionp mode
)
3039 (font-lock-fontify-buffer)
3040 ;; markup each line separately
3041 (org-remove-formatting-on-newlines-in-region
3042 (point-min) (point-max))
3044 (set-buffer-modified-p nil
)
3045 (org-export-e-htmlize-region-for-paste
3046 (point-min) (point-max))))
3048 (when (string-match "<pre\\([^>]*\\)>\n*" lines
)
3049 (setq lines
(replace-match
3050 (format "<pre class=\"src src-%s\">\n" lang
) t t lines
)))
3055 "<div class=\"org-src-container\">"
3056 (format "<label class=\"org-src-name\">%s</label>" caption
)
3060 (setq lines
(org-export-number-lines lines
1 1 num cont rpllbl fmt
)))
3062 ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
3063 ;; (setq lines (replace-match "\\1" t nil lines)))
3066 (defun org-e-html-format-source-code-or-example
3067 (lang code
&optional opts indent caption
)
3068 "Format CODE from language LANG and return it formatted for export.
3069 The CODE is marked up in `org-export-current-backend' format.
3071 Check if a function by name
3072 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
3073 use it as the custom formatter. Otherwise, use the default
3074 formatter. Default formatters are provided for docbook, html,
3075 latex and ascii backends. For example, use
3076 `org-e-html-format-source-code-or-example' to provide a custom
3077 formatter for export to \"html\".
3079 If LANG is nil, do not add any fontification.
3080 OPTS contains formatting options, like `-n' for triggering numbering lines,
3081 and `+n' for continuing previous numbering.
3082 Code formatting according to language currently only works for HTML.
3083 Numbering lines works for all three major backends (html, latex, and ascii).
3084 INDENT was the original indentation of the block."
3086 (let* ((backend-formatter 'org-e-html-format-source-code-or-example-plain
)
3087 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
3088 (setq opts
(or opts
"")
3089 num
(string-match "[-+]n\\>" opts
)
3090 cont
(string-match "\\+n\\>" opts
)
3091 rpllbl
(string-match "-r\\>" opts
)
3092 keepp
(string-match "-k\\>" opts
)
3093 textareap
(string-match "-t\\>" opts
)
3094 preserve-indentp
(or org-src-preserve-indentation
3095 (string-match "-i\\>" opts
))
3096 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
3097 (string-to-number (match-string 1 opts
))
3099 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
3100 (string-to-number (match-string 1 opts
))
3101 (org-count-lines code
))
3102 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
3103 (match-string 1 opts
)))
3104 (when (and textareap
3105 ;; (eq org-export-current-backend 'html)
3107 ;; we cannot use numbering or highlighting.
3108 (setq num nil cont nil lang nil
))
3109 (if keepp
(setq rpllbl
'keep
))
3110 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
3111 (when (string-match "^," rtn
)
3112 (setq rtn
(with-temp-buffer
3114 ;; Free up the protected lines
3115 (goto-char (point-min))
3116 (while (re-search-forward "^," nil t
)
3117 (if (or (equal lang
"org")
3119 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
3124 (if (featurep 'xemacs
)
3126 (require 'htmlize nil t
)))
3128 (setq backend-formatter
3130 ((fboundp 'htmlize-region-for-paste
)
3131 'org-e-html-format-source-code-or-example-colored
)
3134 "htmlize.el 1.34 or later is needed for source code formatting")
3135 'org-e-html-format-source-code-or-example-plain
)))
3136 (funcall backend-formatter rtn lang caption textareap cols rows
3137 num cont rpllbl fmt
))))
3139 (defun org-e-html-example-block (example-block contents info
)
3140 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
3141 CONTENTS is nil. INFO is a plist holding contextual information."
3142 (let* ((options (or (org-element-get-property :options example-block
) ""))
3143 (value (org-export-handle-code example-block info
)))
3144 ;; (org-e-html--wrap-label
3145 ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
3146 (org-e-html--wrap-label
3147 example-block
(org-e-html-format-source-code-or-example nil value
))))
3152 (defun org-e-html-export-snippet (export-snippet contents info
)
3153 "Transcode a EXPORT-SNIPPET object from Org to HTML.
3154 CONTENTS is nil. INFO is a plist holding contextual information."
3155 (org-element-get-property :value export-snippet
))
3160 (defun org-e-html-export-block (export-block contents info
)
3161 "Transcode a EXPORT-BLOCK element from Org to HTML.
3162 CONTENTS is nil. INFO is a plist holding contextual information."
3163 (when (string= (org-element-get-property :type export-block
) "latex")
3164 (org-remove-indentation (org-element-get-property :value export-block
))))
3169 (defun org-e-html-fixed-width (fixed-width contents info
)
3170 "Transcode a FIXED-WIDTH element from Org to HTML.
3171 CONTENTS is nil. INFO is a plist holding contextual information."
3172 (let* ((value (org-element-normalize-string
3173 (replace-regexp-in-string
3175 (org-element-get-property :value fixed-width
)))))
3176 ;; (org-e-html--wrap-label
3177 ;; fixed-width (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
3178 (org-e-html--wrap-label
3179 fixed-width
(org-e-html-format-source-code-or-example nil value
)) ;; FIXME
3183 ;;;; Footnote Definition
3185 ;; Footnote Definitions are ignored.
3188 ;;;; Footnote Reference
3190 (defun org-e-html-footnote-reference (footnote-reference contents info
)
3191 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
3192 CONTENTS is nil. INFO is a plist holding contextual information."
3194 ;; Insert separator between two footnotes in a row.
3195 (let ((prev (org-export-get-previous-element footnote-reference info
)))
3196 (when (and (listp prev
) (eq (car prev
) 'footnote-reference
))
3197 org-e-html-footnote-separator
))
3198 ;; Use \footnotemark if the footnote has already been defined.
3199 ;; Otherwise, define it with \footnote command.
3201 ((not (org-export-footnote-first-reference-p footnote-reference info
))
3202 ;; (format "\\footnotemark[%s]"
3203 ;; (org-export-get-footnote-number footnote-reference info))
3205 (org-e-html-format-footnote-reference
3206 (org-export-get-footnote-number footnote-reference info
)
3207 "FIXME" 100) ;; FIXME
3210 ;; Inline definitions are secondary strings.
3211 ((eq (org-element-get-property :type footnote-reference
) 'inline
)
3212 ;; (format "\\footnote{%s}"
3214 ;; (org-export-secondary-string
3215 ;; (org-export-get-footnote-definition footnote-reference info)
3219 (let ((n (org-export-get-footnote-number footnote-reference info
))
3223 (org-export-secondary-string
3224 (org-export-get-footnote-definition footnote-reference info
)
3228 (push (cons n def
) org-e-html-footnotes-alist
)
3230 (org-e-html-format-footnote-reference n def
1)))
3231 ;; Non-inline footnotes definitions are full Org data.
3233 ;; (format "\\footnote{%s}"
3236 ;; (org-export-get-footnote-definition footnote-reference info)
3239 (let ((n (org-export-get-footnote-number footnote-reference info
))
3242 (org-export-get-footnote-definition footnote-reference info
)
3245 (push (cons n def
) org-e-html-footnotes-alist
)
3246 (org-e-html-format-footnote-reference n def
1))
3253 (defun org-e-html-todo (todo)
3255 (org-e-html-format-fontify
3257 ;; (ignore-errors (org-lparse-get 'TODO-KWD-CLASS-PREFIX))
3258 org-export-e-html-todo-kwd-class-prefix
3259 (org-e-html-fix-class-name todo
))
3260 (list (if (member todo org-done-keywords
) "done" "todo")
3263 (defun org-e-html-headline (headline contents info
)
3264 "Transcode an HEADLINE element from Org to HTML.
3265 CONTENTS holds the contents of the headline. INFO is a plist
3266 holding contextual information."
3267 (let* ((class (plist-get info
:latex-class
))
3268 (numberedp (plist-get info
:section-numbers
))
3269 ;; Get level relative to current parsed data.
3270 (level (org-export-get-relative-level headline info
))
3271 (class-sectionning (assoc class org-e-html-classes
))
3272 ;; Section formatting will set two placeholders: one for the
3273 ;; title and the other for the contents.
3275 (let ((sec (if (and (symbolp (nth 2 class-sectionning
))
3276 (fboundp (nth 2 class-sectionning
)))
3277 (funcall (nth 2 class-sectionning
) level numberedp
)
3278 (nth (1+ level
) class-sectionning
))))
3280 ;; No section available for that LEVEL.
3282 ;; Section format directly returned by a function.
3284 ;; (numbered-section . unnumbered-section)
3285 ((not (consp (cdr sec
)))
3286 (concat (funcall (if numberedp
#'car
#'cdr
) sec
) "\n%s"))
3287 ;; (numbered-open numbered-close)
3289 (when numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))))
3290 ;; (num-in num-out no-num-in no-num-out)
3293 (concat (car sec
) "\n%s" (nth 1 sec
))
3294 (concat (nth 2 sec
) "\n%s" (nth 3 sec
)))))))
3295 (text (org-export-secondary-string
3296 (org-element-get-property :title headline
) 'e-html info
))
3297 (todo (and (plist-get info
:with-todo-keywords
)
3298 (let ((todo (org-element-get-property
3299 :todo-keyword headline
)))
3301 (org-export-secondary-string todo
'e-html info
)))))
3302 (todo-type (and todo
(org-element-get-property :todo-type headline
)))
3303 (tags (and (plist-get info
:with-tags
)
3304 (org-element-get-property :tags headline
)))
3305 (priority (and (plist-get info
:with-priority
)
3306 (org-element-get-property :priority headline
)))
3307 ;; Create the headline text.
3308 (full-text (if (functionp org-e-html-format-headline-function
)
3309 ;; User-defined formatting function.
3310 (funcall org-e-html-format-headline-function
3311 todo todo-type priority text tags
)
3312 ;; Default formatting.
3315 ;; (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
3316 (org-e-html-todo todo
) " "
3317 (when priority
(format "\\framebox{\\#%c} " priority
))
3319 ;; (when tags (format "\\hfill{}\\textsc{%s}" tags))
3321 ;; Associate some \label to the headline for internal links.
3323 ;; (format "\\label{sec-%s}\n"
3324 ;; (mapconcat 'number-to-string
3325 ;; (org-export-get-headline-number headline info)
3329 (headline-no (org-export-get-headline-number headline info
))
3331 (format "sec-%s" (mapconcat 'number-to-string headline-no
"-")))
3332 (headline-labels (list headline-label
))
3333 (headline-no (org-export-get-headline-number headline info
))
3334 (section-no (mapconcat 'number-to-string headline-no
"."))
3337 (pre-blanks (make-string
3338 (org-element-get-property :pre-blank headline
) 10)))
3340 ;; Case 1: This is a footnote section: ignore it.
3341 ((org-element-get-property :footnote-section-p headline
) nil
)
3342 ;; Case 2. This is a deep sub-tree: export it as a list item.
3343 ;; Also export as items headlines for which no section
3344 ;; format has been found.
3345 ;; ((or (not section-fmt) (org-export-low-level-p headline info)) FIXME
3346 ;; ;; Build the real contents of the sub-tree.
3347 ;; (let ((low-level-body
3349 ;; ;; If the headline is the first sibling, start a list.
3350 ;; (when (org-export-first-sibling-p headline info)
3351 ;; (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
3352 ;; ;; Itemize headline
3353 ;; "\\item " full-text "\n" headline-label pre-blanks contents)))
3354 ;; ;; If headline in the last sibling, close the list, before any
3355 ;; ;; blank line. Otherwise, simply return LOW-LEVEL-BODY.
3356 ;; (if (org-export-last-sibling-p headline info)
3357 ;; (replace-regexp-in-string
3359 ;; (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
3361 ;; low-level-body)))
3362 ;; Case 3. Standard headline. Export it as a section.
3364 ;; (format section-fmt full-text
3365 ;; (concat headline-label pre-blanks contents))
3367 (org-e-html-format-outline contents level section-no full-text tags
3368 (car (last headline-labels
))
3369 (butlast headline-labels
) nil
)))))
3372 ;;;; Horizontal Rule
3374 (defun org-e-html-horizontal-rule (horizontal-rule contents info
)
3375 "Transcode an HORIZONTAL-RULE object from Org to HTML.
3376 CONTENTS is nil. INFO is a plist holding contextual information."
3377 (let ((attr (mapconcat #'identity
3378 (org-element-get-property :attr_html horizontal-rule
)
3380 (org-e-html--wrap-label horizontal-rule
3381 (org-e-html-format-horizontal-line))))
3384 ;;;; Inline Babel Call
3386 ;; Inline Babel Calls are ignored.
3389 ;;;; Inline Src Block
3391 (defun org-e-html-inline-src-block (inline-src-block contents info
)
3392 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
3393 CONTENTS holds the contents of the item. INFO is a plist holding
3394 contextual information."
3395 (let* ((code (org-element-get-property :value inline-src-block
))
3396 (separator (org-e-html--find-verb-separator code
)))
3398 ;; Do not use a special package: transcode it verbatim.
3399 ((not org-e-html-listings
)
3400 (concat "\\verb" separator code separator
))
3401 ;; Use minted package.
3402 ((eq org-e-html-listings
'minted
)
3403 (let* ((org-lang (org-element-get-property :language inline-src-block
))
3404 (mint-lang (or (cadr (assq (intern org-lang
)
3405 org-e-html-minted-langs
))
3407 (options (org-e-html--make-option-string
3408 org-e-html-minted-options
)))
3409 (concat (format "\\mint%s{%s}"
3410 (if (string= options
"") "" (format "[%s]" options
))
3412 separator code separator
)))
3413 ;; Use listings package.
3415 ;; Maybe translate language's name.
3416 (let* ((org-lang (org-element-get-property :language inline-src-block
))
3417 (lst-lang (or (cadr (assq (intern org-lang
)
3418 org-e-html-listings-langs
))
3420 (options (org-e-html--make-option-string
3421 (append org-e-html-listings-options
3422 `(("language" ,lst-lang
))))))
3423 (concat (format "\\lstinline[%s]" options
)
3424 separator code separator
))))))
3429 (defun org-e-html-format-section (text class
&optional id
)
3430 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
3431 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
3433 (defun org-e-html-inlinetask (inlinetask contents info
)
3434 "Transcode an INLINETASK element from Org to HTML.
3435 CONTENTS holds the contents of the block. INFO is a plist
3436 holding contextual information."
3437 (let ((title (org-export-secondary-string
3438 (org-element-get-property :title inlinetask
) 'e-html info
))
3439 (todo (and (plist-get info
:with-todo-keywords
)
3440 (let ((todo (org-element-get-property
3441 :todo-keyword inlinetask
)))
3443 (org-export-secondary-string todo
'e-html info
)))))
3444 (todo-type (org-element-get-property :todo-type inlinetask
))
3445 (tags (and (plist-get info
:with-tags
)
3446 (org-element-get-property :tags inlinetask
)))
3447 (priority (and (plist-get info
:with-priority
)
3448 (org-element-get-property :priority inlinetask
))))
3449 ;; If `org-e-html-format-inlinetask-function' is provided, call it
3450 ;; with appropriate arguments.
3451 (if (functionp org-e-html-format-inlinetask-function
)
3452 (funcall org-e-html-format-inlinetask-function
3453 todo todo-type priority title tags contents
)
3454 ;; Otherwise, use a default template.
3455 (org-e-html--wrap-label
3459 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
3460 (when priority
(format "\\framebox{\\#%c} " priority
))
3462 (when tags
(format "\\hfill{}\\textsc{%s}" tags
)))))
3463 (format (concat "\\begin{center}\n"
3465 "\\begin{minipage}[c]{.6\\textwidth}\n"
3467 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
3472 full-title contents
))))))
3477 (defun org-e-html-format-list-item (contents type
&optional arg headline
)
3478 (setq headline nil
) ; FIXME
3482 (let* ((counter arg
)
3483 (extra (if counter
(format " value=\"%s\"" counter
) "")))
3484 (format "<li%s>" extra
)))
3487 (extra (if id
(format " id=\"%s\"" id
) "")))
3489 (format "<li%s>" extra
)
3490 (when headline
(concat headline
"<br/>")))))
3492 (let* ((desc-tag (or arg
"(no term)")))
3493 (concat (format "<dt> %s </dt>" desc-tag
) "<dd>"))))
3498 (descriptive "</dd>"))))
3500 (defun org-e-html-item (item contents info
)
3501 "Transcode an ITEM element from Org to HTML.
3502 CONTENTS holds the contents of the item. INFO is a plist holding
3503 contextual information."
3504 ;; Grab `:level' from plain-list properties, which is always the
3505 ;; first element above current item.
3506 (let* ((plain-list (car (org-export-get-genealogy item info
)))
3507 (type (org-element-get-property :type plain-list
))
3508 (level (org-element-get-property
3509 :level
(car (plist-get info
:genealogy
))))
3510 (counter (let ((count (org-element-get-property :counter item
)))
3513 (format "\\setcounter{enum%s}{%s}\n"
3514 (nth level
'("i" "ii" "iii" "iv"))
3516 (checkbox (let ((checkbox (org-element-get-property :checkbox item
)))
3517 (cond ((eq checkbox
'on
) "$\\boxtimes$ ")
3518 ((eq checkbox
'off
) "$\\Box$ ")
3519 ((eq checkbox
'trans
) "$\\boxminus$ "))))
3520 (tag (let ((tag (org-element-get-property :tag item
)))
3522 (format "[%s]" (org-export-secondary-string
3523 tag
'e-html info
))))))
3524 ;; (concat counter "\\item" tag " " checkbox contents)
3526 (org-e-html-format-list-item contents type nil
)
3533 (defun org-e-html-keyword (keyword contents info
)
3534 "Transcode a KEYWORD element from Org to HTML.
3535 CONTENTS is nil. INFO is a plist holding contextual information."
3536 (let ((key (downcase (org-element-get-property :key keyword
)))
3537 (value (org-element-get-property :value keyword
)))
3539 ((string= key
"latex") value
)
3540 ((string= key
"index") (format "\\index{%s}" value
))
3541 ((string= key
"target")
3542 (format "\\label{%s}" (org-export-solidify-link-text value
)))
3543 ((string= key
"toc")
3544 (let ((value (downcase value
)))
3546 ((string-match "\\<headlines\\>" value
)
3547 (let ((depth (or (and (string-match "[0-9]+" value
)
3548 (string-to-number (match-string 0 value
)))
3549 (plist-get info
:with-toc
))))
3551 (when (wholenump depth
)
3552 (format "\\setcounter{tocdepth}{%s}\n" depth
))
3553 "\\tableofcontents")))
3554 ((string= "tables" value
) "\\listoftables")
3555 ((string= "figures" value
) "\\listoffigures")
3556 ((string= "listings" value
)
3558 ((eq org-e-html-listings
'minted
) "\\listoflistings")
3559 (org-e-html-listings "\\lstlistoflistings")
3560 ;; At the moment, src blocks with a caption are wrapped
3561 ;; into a figure environment.
3562 (t "\\listoffigures")))))))))
3565 ;;;; Latex Environment
3567 (defun org-e-html-format-latex (latex-frag processing-type
)
3568 (let* ((cache-relpath
3569 (concat "ltxpng/" (file-name-sans-extension
3570 (file-name-nondirectory (buffer-file-name)))))
3571 (cache-dir (file-name-directory (buffer-file-name )))
3572 (display-msg "Creating LaTeX Image..."))
3576 (org-format-latex cache-relpath cache-dir nil display-msg
3577 nil nil processing-type
)
3580 (defun org-e-html-latex-environment (latex-environment contents info
)
3581 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
3582 CONTENTS is nil. INFO is a plist holding contextual information."
3583 ;; (org-e-html--wrap-label
3584 ;; latex-environment
3585 ;; (org-remove-indentation (org-element-get-property :value latex-environment)))
3587 (org-e-html--wrap-label
3590 (org-remove-indentation
3591 (org-element-get-property :value latex-environment
)))
3592 (processing-type (plist-get info
:LaTeX-fragments
)))
3594 ((member processing-type
'(t mathjax
))
3595 (org-e-html-format-latex latex-frag
'mathjax
))
3596 ((equal processing-type
'dvipng
)
3597 (let* ((formula-link (org-e-html-format-latex
3598 latex-frag processing-type
)))
3599 (when (and formula-link
3600 (string-match "file:\\([^]]*\\)" formula-link
))
3601 (setq formula-file
(match-string 1 formula-link
))
3602 (org-e-html-format-inline-image formula-file
))))
3609 (defun org-e-html-latex-fragment (latex-fragment contents info
)
3610 "Transcode a LATEX-FRAGMENT object from Org to HTML.
3611 CONTENTS is nil. INFO is a plist holding contextual information."
3612 ;; (org-element-get-property :value latex-fragment)
3613 (let* ((latex-frag (org-element-get-property :value latex-fragment
)))
3615 ((string-match "\\\\ref{\\([^{}\n]+\\)}" latex-frag
)
3616 (let* ((label (match-string 1 latex-frag
))
3617 (href (and label
(org-export-solidify-link-text label
)))
3618 (text (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
3619 (substring label
(match-beginning 1))
3621 (org-e-html-format-internal-link text href
)))
3623 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
3625 ((member processing-type
'(t mathjax
))
3626 (org-e-html-format-latex latex-frag
'mathjax
))
3627 ((equal processing-type
'dvipng
)
3628 (let* ((formula-link (org-e-html-format-latex
3629 latex-frag processing-type
)))
3630 (when (and formula-link
3631 (string-match "file:\\([^]]*\\)" formula-link
))
3632 (setq formula-file
(match-string 1 formula-link
))
3633 (org-e-html-format-inline-image formula-file
))))
3640 (defun org-e-html-line-break (line-break contents info
)
3641 "Transcode a LINE-BREAK object from Org to HTML.
3642 CONTENTS is nil. INFO is a plist holding contextual information."
3648 (defun org-e-html-link--inline-image (link info
)
3649 "Return HTML code for an inline image.
3650 LINK is the link pointing to the inline image. INFO is a plist
3651 used as a communication channel."
3652 (let* ((parent (org-export-get-parent-paragraph link info
))
3653 (path (let ((raw-path (org-element-get-property :path link
)))
3654 (if (not (file-name-absolute-p raw-path
)) raw-path
3655 (expand-file-name raw-path
))))
3656 (caption (org-e-html--caption/label-string
3657 (org-element-get-property :caption parent
)
3658 (org-element-get-property :name parent
)
3660 (label (org-element-get-property :name parent
))
3661 ;; Retrieve latex attributes from the element around.
3662 (attr (let ((raw-attr
3663 (mapconcat #'identity
3664 (org-element-get-property :attr_html parent
)
3666 (unless (string= raw-attr
"") raw-attr
)))
3669 ((and attr
(string-match "\\<wrap\\>" attr
)) 'wrap
)
3670 ((and attr
(string-match "\\<multicolumn\\>" attr
)) 'multicolumn
)
3671 ((or (and attr
(string-match "\\<float\\>" attr
))
3672 (not (string= caption
"")))
3676 ((and attr
(string-match "\\<placement=\\(\\S-+\\)" attr
))
3677 (org-match-string-no-properties 1 attr
))
3678 ((eq disposition
'wrap
) "{l}{0.5\\textwidth}")
3679 ((eq disposition
'float
)
3680 (concat "[" org-e-html-default-figure-position
"]"))
3682 ;; Now clear ATTR from any special keyword and set a default
3683 ;; value if nothing is left.
3687 (replace-regexp-in-string
3688 "\\(wrap\\|multicolumn\\|float\\|placement=\\S-+\\)" "" attr
))))
3689 (setq attr
(cond ((not (string= attr
"")) attr
)
3690 ((eq disposition
'float
) "width=0.7\\textwidth")
3691 ((eq disposition
'wrap
) "width=0.48\\textwidth")
3692 (t (or org-e-html-image-default-option
""))))
3693 ;; Return proper string, depending on DISPOSITION.
3695 (wrap (format "\\begin{wrapfigure}%s
3697 \\includegraphics[%s]{%s}
3698 %s\\end{wrapfigure}" placement attr path caption
))
3699 (mulicolumn (format "\\begin{figure*}%s
3701 \\includegraphics[%s]{%s}
3702 %s\\end{figure*}" placement attr path caption
))
3703 (float (format "\\begin{figure}%s
3705 \\includegraphics[%s]{%s}
3706 %s\\end{figure}" placement attr path caption
))
3707 (t (format "\\includegraphics[%s]{%s}" attr path
)))
3709 (let ((href (and label
(org-export-solidify-link-text label
))))
3710 (org-e-html-format-inline-image path caption href attr
))))
3712 (defun org-e-html-link (link desc info
)
3713 "Transcode a LINK object from Org to HTML.
3715 DESC is the description part of the link, or the empty string.
3716 INFO is a plist holding contextual information. See
3718 (let* ((type (org-element-get-property :type link
))
3719 (raw-path (org-element-get-property :path link
))
3720 ;; Ensure DESC really exists, or set it to nil.
3721 (desc (and (not (string= desc
"")) desc
))
3722 (imagep (org-export-inline-image-p
3723 link org-e-html-inline-image-rules
))
3725 ((member type
'("http" "https" "ftp" "mailto"))
3726 (concat type
":" raw-path
))
3727 ((string= type
"file")
3728 (when (string-match "\\(.+\\)::.+" raw-path
)
3729 (setq raw-path
(match-string 1 raw-path
)))
3730 (if (file-name-absolute-p raw-path
)
3731 (concat "file://" (expand-file-name raw-path
))
3732 ;; TODO: Not implemented yet. Concat also:
3733 ;; (org-export-directory :HTML info)
3734 (concat "file://" raw-path
)))
3739 (imagep (org-e-html-link--inline-image link info
))
3740 ;; Target or radioed target: replace link with the normalized
3741 ;; custom-id/target name.
3742 ((member type
'("target" "radio"))
3743 ;; (format "\\hyperref[%s]{%s}"
3744 ;; (org-export-solidify-link-text path)
3745 ;; (or desc (org-export-secondary-string path 'e-html info)))
3747 (org-e-html-format-internal-link
3748 (or desc
(org-export-secondary-string path
'e-html info
))
3749 (org-export-solidify-link-text path
)))
3750 ;; Links pointing to an headline: Find destination and build
3751 ;; appropriate referencing commanding.
3752 ((member type
'("custom-id" "fuzzy" "id"))
3753 (let ((destination (if (string= type
"fuzzy")
3754 (org-export-resolve-fuzzy-link link info
)
3755 (org-export-resolve-id-link link info
))))
3756 ;; Fuzzy link points to a target. Do as above.
3757 (case (car destination
)
3759 ;; (format "\\hyperref[%s]{%s}"
3760 ;; (org-export-solidify-link-text
3761 ;; (org-element-get-property :raw-value destination))
3763 ;; (org-export-secondary-string
3764 ;; (org-element-get-property :raw-link link)
3767 (org-e-html-format-internal-link
3769 (org-export-secondary-string
3770 (org-element-get-property :raw-link link
)
3772 (org-export-solidify-link-text
3773 (org-element-get-property :raw-value destination
))))
3774 ;; Fuzzy link points to an headline. If headlines are
3775 ;; numbered and the link has no description, display
3776 ;; headline's number. Otherwise, display description or
3777 ;; headline's title.
3783 (org-export-get-headline-number destination info
)
3785 (if (and (plist-get info
:section-numbers
) (not desc
))
3786 (format "\\ref{%s}" label
)
3787 ;; (format "\\hyperref[%s]{%s}" label
3789 ;; (org-export-secondary-string
3790 ;; (org-element-get-property :title destination)
3793 (org-e-html-format-internal-link
3795 (org-export-secondary-string
3796 (org-element-get-property :title destination
)
3797 'e-html info
)) label
))))
3798 ;; Fuzzy link points nowhere.
3800 ;; (format "\\texttt{%s}"
3802 ;; (org-export-secondary-string
3803 ;; (org-element-get-property :raw-link link)
3806 (org-e-html-format-fontify
3808 (org-export-secondary-string
3809 (org-element-get-property :raw-link link
)
3810 'e-html info
)) 'emphasis
)))))
3811 ;; Coderef: replace link with the reference name or the
3812 ;; equivalent line number.
3813 ((string= type
"coderef")
3814 (format (org-export-get-coderef-format path
(or desc
""))
3815 (org-export-resolve-coderef path info
)))
3816 ;; Link type is handled by a special function.
3817 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
3818 (funcall protocol
(org-link-unescape path
) desc
'html
))
3819 ;; External link with a description part.
3821 ;; (format "\\href{%s}{%s}" path desc)
3822 (org-e-html-format-link desc path
))
3823 ;; External link without a description part.
3825 ;; (format "\\url{%s}" path)
3826 (org-e-html-format-link path path
))
3827 ;; No path, only description. Try to do something useful.
3829 ;; (format "\\texttt{%s}" desc)
3830 (org-e-html-format-fontify desc
'emphasis
)))))
3835 ;; Babel Calls are ignored.
3840 (defun org-e-html-macro (macro contents info
)
3841 "Transcode a MACRO element from Org to HTML.
3842 CONTENTS is nil. INFO is a plist holding contextual information."
3843 ;; Use available tools.
3844 (org-export-expand-macro macro info
))
3849 (defun org-e-html-paragraph (paragraph contents info
)
3850 "Transcode a PARAGRAPH element from Org to HTML.
3851 CONTENTS is the contents of the paragraph, as a string. INFO is
3852 the plist used as a communication channel."
3853 (let* ((style nil
) ; FIXME
3854 (class (cdr (assoc style
'((footnote .
"footnote")
3856 (extra (if class
(format " class=\"%s\"" class
) ""))
3857 (parent (car (org-export-get-genealogy paragraph info
))))
3859 ;; is this the first paragraph in a list item
3862 ;; (plain-list (car (org-export-get-genealogy item info)))
3863 ;; (type (org-element-get-property :type plain-list))
3865 ((and (equal parent
'item
)
3866 (= (org-element-get-property :begin paragraph
)
3867 (plist-get (plist-get info
:parent-properties
)
3871 (concat (format "<p%s> " extra
) contents
"</p>")))))
3876 (defun org-e-html-plain-list (plain-list contents info
)
3877 "Transcode a PLAIN-LIST element from Org to HTML.
3878 CONTENTS is the contents of the list. INFO is a plist holding
3879 contextual information."
3880 (let* ((type (org-element-get-property :type plain-list
))
3881 (paralist-types '("inparaenum" "asparaenum" "inparaitem" "asparaitem"
3882 "inparadesc" "asparadesc"))
3883 (paralist-regexp (concat
3885 (mapconcat 'identity paralist-types
"\\|")
3887 (attr (mapconcat #'identity
3888 (org-element-get-property :attr_html plain-list
)
3893 (format "\\<%s\\>" paralist-regexp
) attr
))
3894 (match-string 1 attr
))
3895 ((eq type
'ordered
) "enumerate")
3896 ((eq type
'unordered
) "itemize")
3897 ((eq type
'descriptive
) "description")))
3900 (org-e-html--wrap-label
3902 ;; (format "\\begin{%s}%s\n%s\\end{%s}"
3904 ;; ;; Once special environment, if any, has been removed, the
3905 ;; ;; rest of the attributes will be optional arguments.
3906 ;; ;; They will be put inside square brackets if necessary.
3907 ;; (let ((opt (replace-regexp-in-string
3908 ;; (format " *%s *" paralist-regexp) "" attr)))
3909 ;; (cond ((string= opt "") "")
3910 ;; ((string-match "\\`\\[[^][]+\\]\\'" opt) opt)
3911 ;; (t (format "[%s]" opt))))
3918 (format "<ol%s>" (if arg1
3919 (format " start=\"%d\"" arg1
)
3922 (descriptive "<dl>"))
3927 (descriptive "</dl>")))
3935 (defun org-e-html-convert-special-strings (string)
3936 "Convert special characters in STRING to HTML."
3937 (let ((all org-export-e-html-special-string-regexps
)
3939 (while (setq a
(pop all
))
3940 (setq re
(car a
) rpl
(cdr a
) start
0)
3941 (while (string-match re string start
)
3942 (setq string
(replace-match rpl t nil string
))))
3945 (defun org-e-html-encode-plain-text (s)
3946 "Convert plain text characters to HTML equivalent.
3947 Possible conversions are set in `org-export-html-protect-char-alist'."
3948 (let ((cl org-export-e-html-protect-char-alist
) c
)
3949 (while (setq c
(pop cl
))
3951 (while (string-match (car c
) s start
)
3952 (setq s
(replace-match (cdr c
) t t s
)
3953 start
(1+ (match-beginning 0))))))
3956 (defun org-e-html-plain-text (text info
)
3957 "Transcode a TEXT string from Org to HTML.
3958 TEXT is the string to transcode. INFO is a plist holding
3959 contextual information."
3960 (setq text
(org-e-html-encode-plain-text text
))
3961 ;; Protect %, #, &, $, ~, ^, _, { and }.
3962 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
3964 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
3966 ;; (setq text (replace-regexp-in-string
3967 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
3968 ;; "$\\backslash$" text nil t 1))
3969 ;; HTML into \HTML{} and TeX into \TeX{}.
3970 ;; (let ((case-fold-search nil)
3972 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
3973 ;; (setq text (replace-match
3974 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
3975 ;; start (match-end 0))))
3976 ;; Handle quotation marks
3977 ;; (setq text (org-e-html--quotation-marks text info))
3978 ;; Convert special strings.
3979 ;; (when (plist-get info :with-special-strings)
3980 ;; (while (string-match (regexp-quote "...") text)
3981 ;; (setq text (replace-match "\\ldots{}" nil t text))))
3982 (when (plist-get info
:with-special-strings
)
3983 (setq text
(org-e-html-convert-special-strings text
)))
3984 ;; Handle break preservation if required.
3985 (when (plist-get info
:preserve-breaks
)
3986 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
3992 ;;;; Property Drawer
3994 (defun org-e-html-property-drawer (property-drawer contents info
)
3995 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3996 CONTENTS is nil. INFO is a plist holding contextual
3998 ;; The property drawer isn't exported but we want separating blank
3999 ;; lines nonetheless.
4005 (defun org-e-html-quote-block (quote-block contents info
)
4006 "Transcode a QUOTE-BLOCK element from Org to HTML.
4007 CONTENTS holds the contents of the block. INFO is a plist
4008 holding contextual information."
4009 ;; (org-e-html--wrap-label
4011 ;; (format "\\begin{quote}\n%s\\end{quote}" contents))
4012 (org-e-html--wrap-label
4013 quote-block
(format "<blockquote>\n%s</blockquote>" contents
)))
4018 (defun org-e-html-quote-section (quote-section contents info
)
4019 "Transcode a QUOTE-SECTION element from Org to HTML.
4020 CONTENTS is nil. INFO is a plist holding contextual information."
4021 (let ((value (org-remove-indentation
4022 (org-element-get-property :value quote-section
))))
4024 ;; (format "\\begin{verbatim}\n%s\\end{verbatim}" value)
4025 (format "<pre>\n%s</pre>" value
))))
4030 (defun org-e-html-section (section contents info
)
4031 "Transcode a SECTION element from Org to HTML.
4032 CONTENTS holds the contents of the section. INFO is a plist
4033 holding contextual information."
4039 (defun org-e-html-radio-target (radio-target text info
)
4040 "Transcode a RADIO-TARGET object from Org to HTML.
4041 TEXT is the text of the target. INFO is a plist holding
4042 contextual information."
4043 ;; (format "\\label{%s}%s"
4044 ;; (org-export-solidify-link-text
4045 ;; (org-element-get-property :raw-value radio-target))
4047 (org-e-html-format-anchor
4049 (org-export-solidify-link-text
4050 (org-element-get-property :raw-value radio-target
))))
4055 (defun org-e-html-special-block (special-block contents info
)
4056 "Transcode a SPECIAL-BLOCK element from Org to HTML.
4057 CONTENTS holds the contents of the block. INFO is a plist
4058 holding contextual information."
4059 (let ((type (downcase (org-element-get-property :type special-block
))))
4060 (org-e-html--wrap-label
4062 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
4067 (defun org-e-html-src-block (src-block contents info
)
4068 "Transcode a SRC-BLOCK element from Org to HTML.
4069 CONTENTS holds the contents of the item. INFO is a plist holding
4070 contextual information."
4071 (let* ((lang (org-element-get-property :language src-block
))
4072 (code (org-export-handle-code src-block info
))
4073 (caption (org-element-get-property :caption src-block
))
4074 (label (org-element-get-property :name src-block
))
4075 (custom-env (and lang
4076 (cadr (assq (intern lang
)
4077 org-e-html-custom-lang-environments
)))))
4078 ;; FIXME: Handle caption
4079 (org-e-html-format-source-code-or-example lang code
)
4082 ;; ;; No source fontification.
4083 ;; ((not org-e-html-listings)
4084 ;; (let ((caption-str (org-e-html--caption/label-string
4085 ;; caption label info))
4086 ;; (float-env (when caption "\\begin{figure}[H]\n%s\n\\end{figure}")))
4087 ;; (format (or float-env "%s")
4090 ;; (format "\\begin{verbatim}\n%s\\end{verbatim}" code)))))
4091 ;; ;; Custom environment.
4093 ;; (format "\\begin{%s}\n%s\\end{%s}\n" custom-env code custom-env))
4094 ;; ;; Use minted package.
4095 ;; ((eq org-e-html-listings 'minted)
4096 ;; (let* ((mint-lang (or (cadr (assq (intern lang) org-e-html-minted-langs))
4098 ;; (float-env (when (or label caption)
4099 ;; (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
4100 ;; (org-e-html--caption/label-string
4101 ;; caption label info))))
4102 ;; (body (format "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
4103 ;; (org-e-html--make-option-string
4104 ;; org-e-html-minted-options)
4105 ;; mint-lang code)))
4106 ;; (if float-env (format float-env body) body)))
4107 ;; ;; Use listings package.
4110 ;; (or (cadr (assq (intern lang) org-e-html-listings-langs)) lang))
4113 ;; (let ((main (org-export-secondary-string
4114 ;; (car caption) 'e-html info)))
4115 ;; (if (not (cdr caption)) (format "{%s}" main)
4118 ;; (org-export-secondary-string (cdr caption) 'e-html info)
4120 ;; (concat (format "\\lstset{%s}\n"
4121 ;; (org-e-html--make-option-string
4122 ;; (append org-e-html-listings-options
4123 ;; `(("language" ,lst-lang))
4124 ;; (when label `(("label" ,label)))
4125 ;; (when caption-str
4126 ;; `(("caption" ,caption-str))))))
4127 ;; (format "\\begin{lstlisting}\n%s\\end{lstlisting}" code)))))
4131 ;;;; Statistics Cookie
4133 (defun org-e-html-statistics-cookie (statistics-cookie contents info
)
4134 "Transcode a STATISTICS-COOKIE object from Org to HTML.
4135 CONTENTS is nil. INFO is a plist holding contextual information."
4136 (org-element-get-property :value statistics-cookie
))
4141 (defun org-e-html-subscript (subscript contents info
)
4142 "Transcode a SUBSCRIPT object from Org to HTML.
4143 CONTENTS is the contents of the object. INFO is a plist holding
4144 contextual information."
4145 ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
4146 (org-e-html-format-fontify contents
'subscript
))
4151 (defun org-e-html-superscript (superscript contents info
)
4152 "Transcode a SUPERSCRIPT object from Org to HTML.
4153 CONTENTS is the contents of the object. INFO is a plist holding
4154 contextual information."
4155 ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
4156 (org-e-html-format-fontify contents
'superscript
))
4161 (defun org-e-html-table--format-string (table table-info info
)
4162 "Return an appropriate format string for TABLE.
4164 TABLE-INFO is the plist containing format info about the table,
4165 as returned by `org-export-table-format-info'. INFO is a plist
4166 used as a communication channel.
4168 The format string leaves one placeholder for the body of the
4170 (let* ((label (org-element-get-property :name table
))
4171 (caption (org-e-html--caption/label-string
4172 (org-element-get-property :caption table
) label info
))
4173 (attr (mapconcat 'identity
4174 (org-element-get-property :attr_html table
)
4176 ;; Determine alignment string.
4177 (alignment (org-e-html-table--align-string attr table-info
))
4178 ;; Determine environment for the table: longtable, tabular...
4180 ((not attr
) org-e-html-default-table-environment
)
4181 ((string-match "\\<longtable\\>" attr
) "longtable")
4182 ((string-match "\\<tabular.?\\>" attr
)
4183 (org-match-string-no-properties 0 attr
))
4184 (t org-e-html-default-table-environment
)))
4185 ;; If table is a float, determine environment: table or table*.
4187 ((string= "longtable" table-env
) nil
)
4189 (or (string-match (regexp-quote "table*") attr
)
4190 (string-match "\\<multicolumn\\>" attr
)))
4192 ((or (not (string= caption
"")) label
) "table")))
4193 ;; Extract others display options.
4194 (width (and attr
(string-match "\\<width=\\(\\S-+\\)" attr
)
4195 (org-match-string-no-properties 1 attr
)))
4197 (if (and attr
(string-match "\\<placement=\\(\\S-+\\)" attr
))
4198 (org-match-string-no-properties 1 attr
)
4199 (format "[%s]" org-e-html-default-figure-position
))))
4200 ;; Prepare the final format string for the table.
4203 ((string= "longtable" table-env
)
4205 "\\begin{longtable}{%s}\n%s\n%%s\n%s\\end{longtable}"
4207 (if (or (not org-e-html-table-caption-above
) (string= "" caption
)) ""
4208 (concat (org-trim caption
) "\\\\"))
4209 (if (or org-e-html-table-caption-above
(string= "" caption
)) ""
4210 (concat (org-trim caption
) "\\\\\n"))))
4212 (t (concat (when float-env
4214 (format "\\begin{%s}%s\n" float-env placement
)
4215 (if org-e-html-table-caption-above caption
"")))
4216 (when org-e-html-tables-centered
"\\begin{center}\n")
4217 (format "\\begin{%s}%s{%s}\n%%s\n\\end{%s}"
4219 (if width
(format "{%s}" width
) "") alignment table-env
)
4220 (when org-e-html-tables-centered
"\n\\end{center}")
4222 (concat (if org-e-html-table-caption-above
"" caption
)
4223 (format "\n\\end{%s}" float-env
))))))))
4225 (defun org-e-html-table--align-string (attr table-info
)
4226 "Return an appropriate HTML alignment string.
4227 ATTR is a string containing table's HTML specific attributes.
4228 TABLE-INFO is the plist containing format info about the table,
4229 as returned by `org-export-table-format-info'."
4231 (string-match "\\<align=\\(\\S-+\\)" attr
)
4232 (match-string 1 attr
))
4233 (let* ((align (copy-sequence (plist-get table-info
:alignment
)))
4234 (colgroups (copy-sequence (plist-get table-info
:column-groups
)))
4235 (cols (length align
))
4236 (separators (make-vector (1+ cols
) "")))
4237 ;; Ignore the first column if it's special.
4238 (when (plist-get table-info
:special-column-p
)
4239 (aset align
0 "") (aset colgroups
0 nil
))
4242 (let ((gr (aref colgroups col
)))
4243 (when (memq gr
'(start start-end
))
4244 (aset separators col
"|"))
4245 (when (memq gr
'(end start-end
))
4246 (aset separators
(1+ col
) "|")))
4249 ;; Build the HTML specific alignment string.
4250 (loop for al across align
4251 for sep across separators
4252 concat
(concat sep al
) into output
4253 finally return
(concat output
(aref separators cols
))))))
4258 (defun org-e-html-begin-table (caption label attributes
)
4259 (let* ((html-table-tag (or (plist-get info
:html-table-tag
) ; FIXME
4260 org-export-e-html-table-tag
))
4262 (org-export-splice-attributes html-table-tag attributes
)))
4264 (setq html-table-tag
4265 (org-export-splice-attributes
4267 (format "id=\"%s\"" (org-solidify-link-text label
)))))
4268 (concat "\n" html-table-tag
4269 (format "\n<caption>%s</caption>" (or caption
"")))))
4271 (defun org-e-html-end-table ()
4272 (when org-lparse-table-is-styled
4274 ;; (unless (car org-table-colgroup-info)
4275 ;; (setq org-table-colgroup-info
4276 ;; (cons :start (cdr org-table-colgroup-info))))
4283 ;; (setf (aref org-lparse-table-colalign-vector c)
4284 ;; (or (aref org-lparse-table-colalign-vector c)
4285 ;; (if (> (/ (float x) (1+ org-lparse-table-rownum))
4286 ;; org-table-number-fraction)
4287 ;; "right" "left"))))
4288 ;; org-lparse-table-num-numeric-items-per-column)
4291 ;; html specific stuff starts here
4292 ;; (org-e-html-end-table)
4296 (defun org-e-html-format-table-cell (text r c horiz-span
)
4297 (let ((cell-style-cookie
4298 (if org-export-e-html-table-align-individual-fields
4299 (format (if (and (boundp 'org-e-html-format-table-no-css
)
4300 org-e-html-format-table-no-css
)
4301 " align=\"%s\"" " class=\"%s\"")
4302 (or (aref (plist-get table-info
:alignment
) c
) "left")) ""))) ;; FIXME
4304 (org-lparse-table-cur-rowgrp-is-hdr
4306 (format (car org-export-table-header-tags
) "col" cell-style-cookie
)
4307 text
(cdr org-export-table-header-tags
)))
4308 ((and (= c
0) org-export-e-html-table-use-header-tags-for-first-column
)
4310 (format (car org-export-table-header-tags
) "row" cell-style-cookie
)
4311 text
(cdr org-export-table-header-tags
)))
4314 (format (car org-export-table-data-tags
) cell-style-cookie
)
4315 text
(cdr org-export-table-data-tags
))))))
4317 (defun org-e-html-format-table-row (row)
4318 (concat (eval (car org-export-table-row-tags
)) row
4319 (eval (cdr org-export-table-row-tags
))))
4321 (defun org-e-html-table-row (fields &optional text-for-empty-fields
)
4322 (if org-lparse-table-ncols
4323 ;; second and subsequent rows of the table
4324 ;; (when (and org-lparse-list-table-p
4325 ;; (> (length fields) org-lparse-table-ncols))
4326 ;; (error "Table row has %d columns but header row claims %d columns"
4327 ;; (length fields) org-lparse-table-ncols))
4328 ;; first row of the table
4329 (setq org-lparse-table-ncols
(length fields
))
4330 ;; (when org-lparse-table-is-styled
4331 ;; (setq org-lparse-table-num-numeric-items-per-column
4332 ;; (make-vector org-lparse-table-ncols 0)))
4334 (incf org-lparse-table-rownum
)
4336 (org-e-html-format-table-row
4339 (when (and (string= x
"") text-for-empty-fields
)
4340 (setq x text-for-empty-fields
))
4342 (let (col-cookie horiz-span
)
4343 (when org-lparse-table-is-styled
4344 ;; (when (and (< i org-lparse-table-ncols)
4345 ;; (string-match org-table-number-regexp x))
4346 ;; (incf (aref org-lparse-table-num-numeric-items-per-column i)))
4347 (setq col-cookie
(cdr (assoc (1+ i
) org-lparse-table-colalign-info
))
4348 horiz-span
(nth 1 col-cookie
)))
4349 (org-e-html-format-table-cell
4350 x org-lparse-table-rownum i
(or horiz-span
0))))
4353 (defun org-e-html-end-table-rowgroup ()
4354 (when org-lparse-table-rowgrp-open
4355 (setq org-lparse-table-rowgrp-open nil
)
4356 (if org-lparse-table-cur-rowgrp-is-hdr
"</thead>" "</tbody>")))
4358 (defun org-e-html-begin-table-rowgroup (&optional is-header-row
)
4360 (when org-lparse-table-rowgrp-open
4361 (org-e-html-end-table-rowgroup))
4363 (setq org-lparse-table-rowgrp-open t
)
4364 (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row
)
4365 (if is-header-row
"<thead>" "<tbody>"))))
4367 (defun org-e-html-table-preamble ()
4368 (let ((colgroup-vector (plist-get table-info
:column-groups
)) ;; FIXME
4369 c gr colgropen preamble
)
4370 (unless (aref colgroup-vector
0)
4371 (setf (aref colgroup-vector
0) 'start
))
4372 (dotimes (c columns-number preamble
)
4373 (setq gr
(aref colgroup-vector c
))
4377 (when (memq gr
'(start start-end
))
4378 (prog1 (if colgropen
"</colgroup>\n<colgroup>" "\n<colgroup>")
4379 (setq colgropen t
)))
4380 (let* ((colalign-vector (plist-get table-info
:alignment
)) ;; FIXME
4381 (align (cdr (assoc (aref colalign-vector c
)
4384 ("c" .
"center")))))
4385 (alignspec (if (and (boundp 'org-e-html-format-table-no-css
)
4386 org-e-html-format-table-no-css
)
4387 " align=\"%s\"" " class=\"%s\""))
4388 (extra (format alignspec align
)))
4389 (format "<col%s />" extra
))
4390 (when (memq gr
'(end start-end
))
4391 (setq colgropen nil
)
4393 (concat preamble
(if colgropen
"</colgroup>"))))
4395 (defun org-e-html-list-table (lines &optional splice
4396 caption label attributes head
4397 org-lparse-table-colalign-info
)
4398 (or (featurep 'org-table
) ; required for
4399 (require 'org-table
)) ; `org-table-number-regexp'
4400 (let* ((org-lparse-table-rownum -
1)
4401 (org-lparse-table-ncols (length (plist-get info
:alignment
)))
4404 org-lparse-table-cur-rowgrp-is-hdr
4405 org-lparse-table-rowgrp-open
4406 ;; org-lparse-table-num-numeric-items-per-column
4407 org-lparse-table-colalign-vector n
4408 org-lparse-table-rowgrp-info
4409 (org-lparse-table-style 'org-table
)
4410 org-lparse-table-is-styled
)
4413 (setq org-lparse-table-is-styled nil
)
4414 (mapconcat 'org-e-html-table-row lines
"\n"))
4416 (setq org-lparse-table-is-styled t
)
4419 (org-e-html-begin-table caption label attributes
)
4420 (org-e-html-table-preamble)
4421 (progn (push (cons (1+ org-lparse-table-rownum
) :start
)
4422 org-lparse-table-rowgrp-info
)
4423 (org-e-html-begin-table-rowgroup head
))
4428 ((equal line
:hrule
)
4429 (push (cons (1+ org-lparse-table-rownum
) :start
)
4430 org-lparse-table-rowgrp-info
)
4431 (org-e-html-begin-table-rowgroup))
4433 (org-e-html-table-row line
))))
4436 (org-e-html-end-table-rowgroup)
4437 (org-e-html-end-table))))))
4439 (defun org-e-html-org-table-to-list-table (lines &optional splice
)
4440 "Convert org-table to list-table.
4441 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
4442 element is a `string' representing a single row of org-table.
4443 Thus each ROW has vertical separators \"|\" separating the table
4444 fields. A ROW could also be a row-group separator of the form
4445 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
4446 ...). ROW could either be symbol `:hrule' or a list of the
4447 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
4451 (while (setq line
(pop lines
))
4452 (unless (string-match "^[ \t]*|-" line
)
4453 (push (org-split-string line
"[ \t]*|[ \t]*") lines-1
))))
4455 (while (setq line
(pop lines
))
4457 ((string-match "^[ \t]*|-" line
)
4459 (push :hrule lines-1
)))
4461 (push (org-split-string line
"[ \t]*|[ \t]*") lines-1
))))))
4462 (nreverse lines-1
)))
4464 (defun org-e-html-table (table contents info
)
4465 "Transcode a TABLE element from Org to HTML.
4466 CONTENTS is nil. INFO is a plist holding contextual information."
4469 ;; see `org-e-html-table--format-string'
4470 (label (org-element-get-property :name table
))
4471 (caption (org-e-html--caption/label-string
4472 (org-element-get-property :caption table
) label info
))
4475 (attr (mapconcat #'identity
4476 (org-element-get-property :attr_html table
)
4478 (raw-table (org-element-get-property :raw-table table
)))
4480 ;; Case 1: verbatim table.
4481 ((or org-e-html-tables-verbatim
4482 (and attr
(string-match "\\<verbatim\\>" attr
)))
4483 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
4484 (org-export-clean-table
4486 (plist-get (org-export-table-format-info raw-table
)
4487 :special-column-p
))))
4488 ;; Case 2: table.el table. Convert it using appropriate tools.
4489 ((eq (org-element-get-property :type table
) 'table.el
)
4491 ;; Ensure "*org-export-table*" buffer is empty.
4492 (with-current-buffer (get-buffer-create "*org-export-table*")
4494 (let ((output (with-temp-buffer
4497 (re-search-forward "^[ \t]*|[^|]" nil t
)
4498 (table-generate-source 'html
"*org-export-table*")
4499 (with-current-buffer "*org-export-table*"
4500 (org-trim (buffer-string))))))
4501 (kill-buffer (get-buffer "*org-export-table*"))
4502 ;; Remove left out comments.
4503 (while (string-match "^%.*\n" output
)
4504 (setq output
(replace-match "" t t output
)))
4505 ;; When the "rmlines" attribute is provided, remove all hlines
4506 ;; but the the one separating heading from the table body.
4507 (when (and attr
(string-match "\\<rmlines\\>" attr
))
4508 (let ((n 0) (pos 0))
4509 (while (and (< (length output
) pos
)
4510 (setq pos
(string-match "^\\\\hline\n?" output pos
)))
4513 (setq output
(replace-match "" nil nil output
))))))
4514 ;; (if (not org-e-html-tables-centered) output
4515 ;; (format "\\begin{center}\n%s\n\\end{center}" output))
4517 ;; Case 3: Standard table.
4519 (let* ((table-info (org-export-table-format-info raw-table
))
4520 (columns-number (length (plist-get table-info
:alignment
)))
4521 (longtablep (and attr
(string-match "\\<longtable\\>" attr
)))
4523 (or (and attr
(string-match "\\<booktabs=\\(yes\\|t\\)\\>" attr
))
4524 org-e-html-tables-booktabs
))
4525 ;; CLEAN-TABLE is a table turned into a list, much like
4526 ;; `org-table-to-lisp', with special column and
4527 ;; formatting cookies removed, and cells already
4529 (lines (org-split-string
4530 (org-export-clean-table
4531 raw-table
(plist-get table-info
:special-column-p
)) "\n"))
4536 ;; (if (string-match org-table-hline-regexp row) 'hline
4539 ;; (org-export-secondary-string
4540 ;; (org-element-parse-secondary-string
4542 ;; (cdr (assq 'table org-element-string-restrictions)))
4544 ;; (org-split-string row "[ \t]*|[ \t]*"))))
4552 (let ((splice nil
) head
)
4553 (setq lines
(org-e-html-org-table-to-list-table lines splice
))
4554 (org-e-html-list-table lines splice caption label attr head nil
))
4555 ;; If BOOKTABSP is non-nil, remove any rule at the beginning
4556 ;; and the end of the table, since booktabs' special rules
4557 ;; will be inserted instead.
4559 ;; (when (eq (car clean-table) 'hline)
4560 ;; (setq clean-table (cdr clean-table)))
4561 ;; (when (eq (car (last clean-table)) 'hline)
4562 ;; (setq clean-table (butlast clean-table))))
4563 ;; Convert ROWS to send them to `orgtbl-to-latex'. In
4564 ;; particular, send each cell to
4565 ;; `org-element-parse-secondary-string' to expand any Org
4566 ;; object within. Eventually, flesh the format string out
4569 ;; (org-e-html-table--format-string table table-info info)
4572 ;; ;; Parameters passed to `orgtbl-to-latex'.
4573 ;; `(:tstart ,(and booktabsp "\\toprule")
4574 ;; :tend ,(and booktabsp "\\bottomrule")
4575 ;; :hline ,(if booktabsp "\\midrule" "\\hline")
4576 ;; ;; Longtable environment requires specific header
4577 ;; ;; lines end string.
4578 ;; :hlend ,(and longtablep
4582 ;; %s\\multicolumn{%d}{r}{Continued on next page}\\\\
4585 ;; (if booktabsp "\\midrule" "\\hline")
4586 ;; (if booktabsp "\\midrule" "\\hline")
4587 ;; columns-number)))))
4593 (defun org-e-html-target (target text info
)
4594 "Transcode a TARGET object from Org to HTML.
4595 TEXT is the text of the target. INFO is a plist holding
4596 contextual information."
4597 ;; (format "\\label{%s}%s"
4598 ;; (org-export-solidify-link-text
4599 ;; (org-element-get-property :raw-value target))
4602 (org-e-html-format-anchor
4603 text
(org-export-solidify-link-text
4604 (org-element-get-property :raw-value target
))))
4609 (defun org-e-html-time-stamp (time-stamp contents info
)
4610 "Transcode a TIME-STAMP object from Org to HTML.
4611 CONTENTS is nil. INFO is a plist holding contextual
4613 ;; (let ((value (org-element-get-property :value time-stamp))
4614 ;; (type (org-element-get-property :type time-stamp))
4615 ;; (appt-type (org-element-get-property :appt-type time-stamp)))
4616 ;; (concat (cond ((eq appt-type 'scheduled)
4617 ;; (format "\\textbf{\\textsc{%s}} " org-scheduled-string))
4618 ;; ((eq appt-type 'deadline)
4619 ;; (format "\\textbf{\\textsc{%s}} " org-deadline-string))
4620 ;; ((eq appt-type 'closed)
4621 ;; (format "\\textbf{\\textsc{%s}} " org-closed-string)))
4622 ;; (cond ((memq type '(active active-range))
4623 ;; (format org-e-html-active-timestamp-format value))
4624 ;; ((memq type '(inactive inactive-range))
4625 ;; (format org-e-html-inactive-timestamp-format value))
4627 ;; (format org-e-html-diary-timestamp-format value)))))
4628 (let ((value (org-element-get-property :value time-stamp
))
4629 (type (org-element-get-property :type time-stamp
))
4630 (appt-type (org-element-get-property :appt-type time-stamp
)))
4631 (org-e-html-format-fontify
4633 (org-e-html-format-fontify
4634 (cond ((eq appt-type
'scheduled
) org-scheduled-string
)
4635 ((eq appt-type
'deadline
) org-deadline-string
)
4636 ((eq appt-type
'closed
) org-closed-string
)) "timestamp-kwd")
4637 ;; FIXME: (org-translate-time value)
4638 (org-e-html-format-fontify value
"timestamp"))
4639 "timestamp-wrapper")))
4644 (defun org-e-html-verbatim (verbatim contents info
)
4645 "Transcode a VERBATIM object from Org to HTML.
4646 CONTENTS is nil. INFO is a plist used as a communication
4648 (org-e-html-emphasis
4649 verbatim
(org-element-get-property :value verbatim
) info
)
4651 ;; (let ((fmt (cdr (assoc (org-element-get-property :marker verbatim)
4652 ;; org-e-html-emphasis-alist)))
4653 ;; (value (org-element-get-property :value verbatim)))
4655 ;; ;; Handle the `verb' special case.
4657 ;; (let ((separator (org-e-html--find-verb-separator value)))
4658 ;; (concat "\\verb" separator value separator)))
4659 ;; ;; Handle the `protectedtexttt' special case.
4660 ;; ((eq 'protectedtexttt fmt)
4662 ;; (trans '(("\\" . "\\textbackslash{}")
4663 ;; ("~" . "\\textasciitilde{}")
4664 ;; ("^" . "\\textasciicircum{}")))
4667 ;; (while (string-match "[\\{}$%&_#~^]" value)
4668 ;; (setq char (match-string 0 value))
4669 ;; (if (> (match-beginning 0) 0)
4670 ;; (setq rtn (concat rtn (substring value 0 (match-beginning 0)))))
4671 ;; (setq value (substring value (1+ (match-beginning 0))))
4672 ;; (setq char (or (cdr (assoc char trans)) (concat "\\" char))
4673 ;; rtn (concat rtn char)))
4674 ;; (setq value (concat rtn value)
4675 ;; fmt "\\texttt{%s}")
4676 ;; (while (string-match "--" value)
4677 ;; (setq value (replace-match "-{}-" t t value)))
4678 ;; (format fmt value)))
4679 ;; ;; Else use format string.
4680 ;; (t (format fmt value))))
4687 (defun org-e-html-verse-block (verse-block contents info
)
4688 "Transcode a VERSE-BLOCK element from Org to HTML.
4689 CONTENTS is nil. INFO is a plist holding contextual information."
4690 (org-e-html--wrap-label
4692 ;; In a verse environment, add a line break to each newline
4693 ;; character and change each white space at beginning of a line
4694 ;; into a space of 1 em. Also change each blank line with
4695 ;; a vertical space of 1 em.
4697 (setq contents
(replace-regexp-in-string
4698 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
4699 (replace-regexp-in-string
4700 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
4701 (org-remove-indentation
4702 (org-export-secondary-string
4703 (org-element-get-property :value verse-block
)
4705 (while (string-match "^[ \t]+" contents
)
4706 (let ((new-str (format "\\hspace*{%dem}"
4707 (length (match-string 0 contents
)))))
4708 (setq contents
(replace-match new-str nil t contents
))))
4709 (format "\\begin{verse}\n%s\\end{verse}" contents
)))
4712 (org-e-html--wrap-label
4714 ;; In a verse environment, add a line break to each newline
4715 ;; character and change each white space at beginning of a line
4716 ;; into a space of 1 em. Also change each blank line with
4717 ;; a vertical space of 1 em.
4719 (setq contents
(replace-regexp-in-string
4720 "^ *\\\\\\\\$" "<br/>\n"
4721 (replace-regexp-in-string
4722 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
4723 (org-remove-indentation
4724 (org-export-secondary-string
4725 (org-element-get-property :value verse-block
)
4727 (while (string-match "^[ \t]+" contents
)
4728 (let ((new-str (format " "
4729 (length (match-string 0 contents
)))))
4730 (setq contents
(replace-match new-str nil t contents
))))
4731 (format "<p class=\"verse\">\n%s</p>" contents
)))
4737 ;;; Interactive functions
4739 (setq org-e-html-pp t
)
4741 (defun org-e-html-export-to-html
4742 (&optional subtreep visible-only body-only ext-plist pub-dir
)
4743 "Export current buffer to a HTML file.
4745 If narrowing is active in the current buffer, only export its
4748 If a region is active, export that region.
4750 When optional argument SUBTREEP is non-nil, export the sub-tree
4751 at point, extracting information from the headline properties
4754 When optional argument VISIBLE-ONLY is non-nil, don't export
4755 contents of hidden elements.
4757 When optional argument BODY-ONLY is non-nil, only write code
4758 between \"\\begin{document}\" and \"\\end{document}\".
4760 EXT-PLIST, when provided, is a property list with external
4761 parameters overriding Org default settings, but still inferior to
4762 file-local settings.
4764 When optional argument PUB-DIR is set, use it as the publishing
4767 Return output file's name."
4770 (setq org-e-html-footnotes-alist nil
)
4773 (with-current-buffer (get-buffer-create "*debug*")
4776 (let ((outfile (org-export-output-file-name ".html" subtreep pub-dir
)))
4778 'e-html outfile subtreep visible-only body-only ext-plist
)))
4780 (defun org-e-html-export-to-pdf
4781 (&optional subtreep visible-only body-only ext-plist pub-dir
)
4782 "Export current buffer to HTML then process through to PDF.
4784 If narrowing is active in the current buffer, only export its
4787 If a region is active, export that region.
4789 When optional argument SUBTREEP is non-nil, export the sub-tree
4790 at point, extracting information from the headline properties
4793 When optional argument VISIBLE-ONLY is non-nil, don't export
4794 contents of hidden elements.
4796 When optional argument BODY-ONLY is non-nil, only write code
4797 between \"\\begin{document}\" and \"\\end{document}\".
4799 EXT-PLIST, when provided, is a property list with external
4800 parameters overriding Org default settings, but still inferior to
4801 file-local settings.
4803 When optional argument PUB-DIR is set, use it as the publishing
4806 Return PDF file's name."
4809 (org-e-html-export-to-html
4810 subtreep visible-only body-only ext-plist pub-dir
)))
4812 (defun org-e-html-compile (texfile)
4813 "Compile a TeX file.
4815 TEXFILE is the name of the file being compiled. Processing is
4816 done through the command specified in `org-e-html-pdf-process'.
4818 Return PDF file name or an error if it couldn't be produced."
4819 (let* ((wconfig (current-window-configuration))
4820 (texfile (file-truename texfile
))
4821 (base (file-name-sans-extension texfile
))
4823 (message (format "Processing HTML file %s ..." texfile
))
4827 ;; A function is provided: Apply it.
4828 ((functionp org-latex-to-pdf-process
)
4829 (funcall org-latex-to-pdf-process
(shell-quote-argument texfile
)))
4830 ;; A list is provided: Replace %b, %f and %o with appropriate
4831 ;; values in each command before applying it. Output is
4832 ;; redirected to "*Org PDF HTML Output*" buffer.
4833 ((consp org-e-html-pdf-process
)
4834 (let* ((out-dir (or (file-name-directory texfile
) "./"))
4835 (outbuf (get-buffer-create "*Org PDF HTML Output*")))
4839 (replace-regexp-in-string
4840 "%b" (shell-quote-argument base
)
4841 (replace-regexp-in-string
4842 "%f" (shell-quote-argument texfile
)
4843 (replace-regexp-in-string
4844 "%o" (shell-quote-argument out-dir
) command
)))
4846 org-e-html-pdf-process
)
4847 ;; Collect standard errors from output buffer.
4848 (setq errors
(org-e-html-collect-errors outbuf
))))
4849 (t (error "No valid command to process to PDF")))
4850 (let ((pdffile (concat base
".pdf")))
4851 ;; Check for process failure. Provide collected errors if
4853 (if (not (file-exists-p pdffile
))
4854 (error (concat (format "PDF file %s wasn't produced" pdffile
)
4855 (when errors
(concat ": " errors
))))
4856 ;; Else remove log files, when specified, and signal end of
4857 ;; process to user, along with any error encountered.
4858 (when org-e-html-remove-logfiles
4859 (dolist (ext org-e-html-logfiles-extensions
)
4860 (let ((file (concat base
"." ext
)))
4861 (when (file-exists-p file
) (delete-file file
)))))
4862 (message (concat "Process completed"
4863 (if (not errors
) "."
4864 (concat " with errors: " errors
)))))
4865 ;; Return output file name.
4867 (set-window-configuration wconfig
))))
4869 (defun org-e-html-collect-errors (buffer)
4870 "Collect some kind of errors from \"pdflatex\" command output.
4872 BUFFER is the buffer containing output.
4874 Return collected error types as a string, or nil if there was
4876 (with-current-buffer buffer
4878 (goto-char (point-max))
4879 ;; Find final "pdflatex" run.
4880 (when (re-search-backward "^[ \t]*This is pdf.*?TeX.*?Version" nil t
)
4881 (let ((case-fold-search t
)
4883 (when (save-excursion
4884 (re-search-forward "Reference.*?undefined" nil t
))
4885 (setq errors
(concat errors
" [undefined reference]")))
4886 (when (save-excursion
4887 (re-search-forward "Citation.*?undefined" nil t
))
4888 (setq errors
(concat errors
" [undefined citation]")))
4889 (when (save-excursion
4890 (re-search-forward "Undefined control sequence" nil t
))
4891 (setq errors
(concat errors
" [undefined control sequence]")))
4892 (when (save-excursion
4893 (re-search-forward "^! HTML.*?Error" nil t
))
4894 (setq errors
(concat errors
" [HTML error]")))
4895 (when (save-excursion
4896 (re-search-forward "^! Package.*?Error" nil t
))
4897 (setq errors
(concat errors
" [package error]")))
4898 (and (org-string-nw-p errors
) (org-trim errors
)))))))
4901 (provide 'org-e-html
)
4902 ;;; org-e-html.el ends here