1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31 (declare-function org-id-find-id-file
"org-id" (id))
32 (declare-function htmlize-region
"ext:htmlize" (beg end
))
34 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
35 <h2 class=\"footnotes\">%s: </h2>
36 <div id=\"text-footnotes\">
40 "Format for the footnotes section.
41 Should contain a two instances of %s. The first will be replaced with the
42 language-specific word for \"Footnotes\", the second one will be replaced
43 by the footnotes themselves."
44 :group
'org-export-html
47 (defgroup org-export-html nil
48 "Options specific for HTML export of Org-mode files."
49 :tag
"Org Export HTML"
52 (defcustom org-export-html-coding-system nil
53 "Coding system for HTML export, defaults to buffer-file-coding-system."
54 :group
'org-export-html
57 (defcustom org-export-html-extension
"html"
58 "The extension for exported HTML files."
59 :group
'org-export-html
62 (defcustom org-export-html-xml-declaration
63 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
64 ("php" .
"<?php echo '<?xml version=\"1.0\" encoding=\"%s\" ?>'; ?>"))
65 "The extension for exported HTML files.
66 %s will be replaced with the charset of the exported file.
67 This may be a string, or an alist with export extensions
68 and corresponding declarations."
69 :group
'org-export-html
71 (string :tag
"Single declaration")
72 (repeat :tag
"Dependent on extension"
73 (cons (string :tag
"Extension")
74 (string :tag
"Declaration")))))
76 (defcustom org-export-html-style-include-scripts t
77 "Non-nil means, include the javascript snippets in exported HTML files.
78 The actual script is defined in `org-export-html-scripts' and should
80 :group
'org-export-html
83 (defconst org-export-html-scripts
84 "<script type=\"text/javascript\">
85 <!--/*--><![CDATA[/*><!--*/
86 function CodeHighlightOn(elem, id)
88 var target = document.getElementById(id);
90 elem.cacheClassElem = elem.className;
91 elem.cacheClassTarget = target.className;
92 target.className = \"code-highlighted\";
93 elem.className = \"code-highlighted\";
96 function CodeHighlightOff(elem, id)
98 var target = document.getElementById(id);
99 if(elem.cacheClassElem)
100 elem.className = elem.cacheClassElem;
101 if(elem.cacheClassTarget)
102 target.className = elem.cacheClassTarget;
106 "Basic javascript that is needed by HTML files produced by Org-mode.")
108 (defconst org-export-html-style-default
109 "<style type=\"text/css\">
110 <!--/*--><![CDATA[/*><!--*/
111 html { font-family: Times, serif; font-size: 12pt; }
112 .title { text-align: center; }
113 .todo { color: red; }
114 .done { color: green; }
115 .tag { background-color: #add8e6; font-weight:normal }
117 .timestamp { color: #bebebe; }
118 .timestamp-kwd { color: #5f9ea0; }
119 p.verse { margin-left: 3% }
121 border: 1pt solid #AEBDCC;
122 background-color: #F3F5F7;
124 font-family: courier, monospace;
128 table { border-collapse: collapse; }
129 td, th { vertical-align: top; }
130 dt { font-weight: bold; }
131 div.figure { padding: 0.5em; }
132 div.figure p { text-align: center; }
133 .linenr { font-size:smaller }
134 .code-highlighted {background-color:#ffff00;}
135 .org-info-js_info-navigation { border-style:none; }
136 #org-info-js_console-label { font-size:10px; font-weight:bold;
137 white-space:nowrap; }
138 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
142 "The default style specification for exported HTML files.
143 Please use the variables `org-export-html-style' and
144 `org-export-html-style-extra' to add to this style. If you wish to not
145 have the default style included, customize the variable
146 `org-export-html-style-include-default'.")
148 (defcustom org-export-html-style-include-default t
149 "Non-nil means, include the default style in exported HTML files.
150 The actual style is defined in `org-export-html-style-default' and should
151 not be modified. Use the variables `org-export-html-style' to add
152 your own style information."
153 :group
'org-export-html
156 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
158 (defcustom org-export-html-style
""
159 "Org-wide style definitions for exported HTML files.
161 This variable needs to contain the full HTML structure to provide a style,
162 including the surrounding HTML tags. If you set the value of this variable,
163 you should consider to include definitions for the following classes:
164 title, todo, done, timestamp, timestamp-kwd, tag, target.
166 For example, a valid value would be:
168 <style type=\"text/css\">
170 p { font-weight: normal; color: gray; }
172 .title { text-align: center; }
173 .todo, .timestamp-kwd { color: red; }
174 .done { color: green; }
178 If you'd like to refer to en external style file, use something like
180 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
182 As the value of this option simply gets inserted into the HTML <head> header,
183 you can \"misuse\" it to add arbitrary text to the header.
184 See also the variable `org-export-html-style-extra'."
185 :group
'org-export-html
188 (put 'org-export-html-style
'safe-local-variable
'stringp
)
190 (defcustom org-export-html-style-extra
""
191 "Additional style information for HTML export.
192 The value of this variable is inserted into the HTML buffer right after
193 the value of `org-export-html-style'. Use this variable for per-file
194 settings of style information, and do not forget to surround the style
195 settings with <style>...</style> tags."
196 :group
'org-export-html
199 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
201 (defcustom org-export-html-tag-class-prefix
""
202 "Prefix to clas names for TODO keywords.
203 Each tag gets a class given by the tag itself, with this prefix.
204 The default prefix is empty because it is nice to just use the keyword
205 as a class name. But if you get into conflicts with other, existing
206 CSS classes, then this prefic can be very useful."
207 :group
'org-export-html
210 (defcustom org-export-html-todo-kwd-class-prefix
""
211 "Prefix to clas names for TODO keywords.
212 Each TODO keyword gets a class given by the keyword itself, with this prefix.
213 The default prefix is empty because it is nice to just use the keyword
214 as a class name. But if you get into conflicts with other, existing
215 CSS classes, then this prefic can be very useful."
216 :group
'org-export-html
219 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
220 "Format for typesetting the document title in HTML export."
221 :group
'org-export-html
224 (defcustom org-export-html-toplevel-hlevel
2
225 "The <H> level for level 1 headings in HTML export.
226 This is also important for the classes that will be wrapped around headlines
227 and outline structure. If this variable is 1, the top-level headlines will
228 be <h1>, and the corresponding classes will be outline-1, section-number-1,
229 and outline-text-1. If this is 2, all of these will get a 2 instead.
230 The default for this variable is 2, because we use <h1> for formatting the
232 :group
'org-export-html
235 (defcustom org-export-html-link-org-files-as-html t
236 "Non-nil means, make file links to `file.org' point to `file.html'.
237 When org-mode is exporting an org-mode file to HTML, links to
238 non-html files are directly put into a href tag in HTML.
239 However, links to other Org-mode files (recognized by the
240 extension `.org.) should become links to the corresponding html
241 file, assuming that the linked org-mode file will also be
243 When nil, the links still point to the plain `.org' file."
244 :group
'org-export-html
247 (defcustom org-export-html-inline-images
'maybe
248 "Non-nil means, inline images into exported HTML pages.
249 This is done using an <img> tag. When nil, an anchor with href is used to
250 link to the image. If this option is `maybe', then images in links with
251 an empty description will be inlined, while images with a description will
253 :group
'org-export-html
254 :type
'(choice (const :tag
"Never" nil
)
255 (const :tag
"Always" t
)
256 (const :tag
"When there is no description" maybe
)))
258 (defcustom org-export-html-inline-image-extensions
259 '("png" "jpeg" "jpg" "gif")
260 "Extensions of image files that can be inlined into HTML."
261 :group
'org-export-html
262 :type
'(repeat (string :tag
"Extension")))
264 (defcustom org-export-html-table-tag
265 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
266 "The HTML tag that is used to start a table.
267 This must be a <table> tag, but you may change the options like
268 borders and spacing."
269 :group
'org-export-html
272 (defcustom org-export-table-header-tags
'("<th scope=\"%s\">" .
"</th>")
273 "The opening tag for table header fields.
274 This is customizable so that alignment options can be specified.
275 %s will be filled with the scope of the field, either row or col.
276 See also the variable `org-export-html-table-use-header-tags-for-first-column'."
277 :group
'org-export-tables
278 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
280 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
281 "The opening tag for table data fields.
282 This is customizable so that alignment options can be specified."
283 :group
'org-export-tables
284 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
286 (defcustom org-export-html-table-use-header-tags-for-first-column nil
287 "Non-nil means, format column one in tables with header tags.
288 When nil, also column one will use data tags."
289 :group
'org-export-tables
292 (defcustom org-export-html-validation-link nil
293 "Non-nil means, add validationlink to postamble of HTML exported files."
294 :group
'org-export-html
296 (const :tag
"Nothing" nil
)
297 (const :tag
"XHTML 1.0" "<p class=\"xhtml-validation\"><a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a></p>")
298 (string :tag
"Specify full HTML")))
301 (defcustom org-export-html-with-timestamp nil
302 "If non-nil, write `org-export-html-html-helper-timestamp'
303 into the exported HTML text. Otherwise, the buffer will just be saved
305 :group
'org-export-html
308 (defcustom org-export-html-html-helper-timestamp
309 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
310 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
311 :group
'org-export-html
314 (defgroup org-export-htmlize nil
315 "Options for processing examples with htmlize.el."
316 :tag
"Org Export Htmlize"
317 :group
'org-export-html
)
319 (defcustom org-export-htmlize-output-type
'inline-css
320 "Output type to be used by htmlize when formatting code snippets.
321 We use as default `inline-css', in order to make the resulting
322 HTML self-containing.
323 However, this will fail when using Emacs in batch mode for export, because
324 then no rich font definitions are in place. It will also not be good if
325 people with different Emacs setup contribute HTML files to a website,
326 because the fonts will represent the individual setups. In these cases,
327 it is much better to let Org/Htmlize assign classes only, and to use
328 a style file to define the look of these classes.
329 To get a start for your css file, start Emacs session nnd make sure that
330 all the faces you are interested in are defined, for example by loading files
331 in all modes you want. Then, use the command
332 \\[org-export-htmlize-generate-css] to extract class definitions."
333 :group
'org-export-htmlize
334 :type
'(choice (const css
) (const inline-css
)))
336 (defcustom org-export-htmlize-css-font-prefix
"org-"
337 "The prefix for CSS class names for htmlize font specifications."
338 :group
'org-export-htmlize
341 (defcustom org-export-htmlized-org-css-url nil
342 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
343 Normally when creating an htmlized version of an Org buffer, htmlize will
344 create CSS to define the font colors. However, this does not work when
345 converting in batch mode, and it also can look bad if different people
346 with different fontification setup work on the same website.
347 When this variable is non-nil, creating an htmlized version of an Org buffer
348 using `org-export-as-org' will remove the internal CSS section and replace it
349 with a link to this URL."
350 :group
'org-export-htmlize
352 (const :tag
"Keep internal css" nil
)
353 (string :tag
"URL or local href")))
355 ;;; Variables, constants, and parameter plists
357 (defvar org-export-html-preamble nil
358 "Preamble, to be inserted just before <body>. Set by publishing functions.")
359 (defvar org-export-html-postamble nil
360 "Preamble, to be inserted just after </body>. Set by publishing functions.")
361 (defvar org-export-html-auto-preamble t
362 "Should default preamble be inserted? Set by publishing functions.")
363 (defvar org-export-html-auto-postamble t
364 "Should default postamble be inserted? Set by publishing functions.")
368 (defvar org-export-html-after-blockquotes-hook nil
369 "Hook run during HTML export, after blockquote, verse, center are done.")
373 (defun org-export-html-preprocess (parameters)
374 ;; Convert LaTeX fragments to images
375 (when (and org-current-export-file
376 (plist-get parameters
:LaTeX-fragments
))
378 (concat "ltxpng/" (file-name-sans-extension
379 (file-name-nondirectory
380 org-current-export-file
)))
381 org-current-export-dir nil
"Creating LaTeX image %s"))
382 (message "Exporting..."))
385 (defun org-export-as-html-and-open (arg)
386 "Export the outline as HTML and immediately open it with a browser.
387 If there is an active region, export only the region.
388 The prefix ARG specifies how many levels of the outline should become
389 headlines. The default is 3. Lower levels will become bulleted lists."
391 (org-export-as-html arg
'hidden
)
392 (org-open-file buffer-file-name
))
395 (defun org-export-as-html-batch ()
396 "Call `org-export-as-html', may be used in batch processing as
398 --load=$HOME/lib/emacs/org.el
399 --eval \"(setq org-export-headline-levels 2)\"
400 --visit=MyFile --funcall org-export-as-html-batch"
401 (org-export-as-html org-export-headline-levels
'hidden
))
404 (defun org-export-as-html-to-buffer (arg)
405 "Call `org-export-as-html` with output to a temporary buffer.
406 No file is created. The prefix ARG is passed through to `org-export-as-html'."
408 (org-export-as-html arg nil nil
"*Org HTML Export*")
409 (when org-export-show-temporary-export-buffer
410 (switch-to-buffer-other-window "*Org HTML Export*")))
413 (defun org-replace-region-by-html (beg end
)
414 "Assume the current region has org-mode syntax, and convert it to HTML.
415 This can be used in any buffer. For example, you could write an
416 itemized list in org-mode syntax in an HTML buffer and then use this
417 command to convert it."
419 (let (reg html buf pop-up-frames
)
420 (save-window-excursion
422 (setq html
(org-export-region-as-html
424 (setq reg
(buffer-substring beg end
)
425 buf
(get-buffer-create "*Org tmp*"))
426 (with-current-buffer buf
430 (setq html
(org-export-region-as-html
431 (point-min) (point-max) t
'string
)))
433 (delete-region beg end
)
437 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
438 "Convert region from BEG to END in org-mode buffer to HTML.
439 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
440 contents, and only produce the region of converted text, useful for
441 cut-and-paste operations.
442 If BUFFER is a buffer or a string, use/create that buffer as a target
443 of the converted HTML. If BUFFER is the symbol `string', return the
444 produced HTML as a string and leave not buffer behind. For example,
445 a Lisp program could call this function in the following way:
447 (setq html (org-export-region-as-html beg end t 'string))
449 When called interactively, the output buffer is selected, and shown
450 in a window. A non-interactive call will only return the buffer."
452 (when (interactive-p)
453 (setq buffer
"*Org HTML Export*"))
454 (let ((transient-mark-mode t
) (zmacs-regions t
)
456 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
458 (set-mark (point)) ;; to activate the region
460 (setq rtn
(org-export-as-html
463 (if (fboundp 'deactivate-mark
) (deactivate-mark))
464 (if (and (interactive-p) (bufferp rtn
))
465 (switch-to-buffer-other-window rtn
)
468 (defvar html-table-tag nil
) ; dynamically scoped into this.
469 (defvar org-par-open nil
)
471 (defun org-export-as-html (arg &optional hidden ext-plist
472 to-buffer body-only pub-dir
)
473 "Export the outline as a pretty HTML file.
474 If there is an active region, export only the region. The prefix
475 ARG specifies how many levels of the outline should become
476 headlines. The default is 3. Lower levels will become bulleted
477 lists. HIDDEN is obsolete and does nothing.
478 EXT-PLIST is a property list with external parameters overriding
479 org-mode's default settings, but still inferior to file-local
480 settings. When TO-BUFFER is non-nil, create a buffer with that
481 name and export to that buffer. If TO-BUFFER is the symbol
482 `string', don't leave any buffer behind but just return the
483 resulting HTML as a string. When BODY-ONLY is set, don't produce
484 the file header and footer, simply return the content of
485 <body>...</body>, without even the body tags themselves. When
486 PUB-DIR is set, use this as the publishing directory."
489 ;; Make sure we have a file name when we need it.
490 (when (and (not (or to-buffer body-only
))
491 (not buffer-file-name
))
492 (if (buffer-base-buffer)
493 (org-set-local 'buffer-file-name
494 (with-current-buffer (buffer-base-buffer)
496 (error "Need a file name to be able to export.")))
498 (message "Exporting...")
499 (setq-default org-todo-line-regexp org-todo-line-regexp
)
500 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
501 (setq-default org-done-keywords org-done-keywords
)
502 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
504 (org-export-process-option-filters
505 (org-combine-plists (org-default-export-plist)
507 (org-infile-export-plist))))
508 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
509 (style (concat (if (plist-get opt-plist
:style-include-default
)
510 org-export-html-style-default
)
511 (plist-get opt-plist
:style
)
512 (plist-get opt-plist
:style-extra
)
514 (if (plist-get opt-plist
:style-include-scripts
)
515 org-export-html-scripts
)))
516 (html-extension (plist-get opt-plist
:html-extension
))
517 (link-validate (plist-get opt-plist
:link-validation-function
))
518 valid thetoc have-headings first-heading-pos
519 (odd org-odd-levels-only
)
520 (region-p (org-region-active-p))
521 (rbeg (and region-p
(region-beginning)))
522 (rend (and region-p
(region-end)))
524 (if (plist-get opt-plist
:ignore-subree-p
)
529 (and (org-at-heading-p)
530 (>= (org-end-of-subtree t t
) rend
))))))
531 (level-offset (if subtree-p
534 (+ (funcall outline-level
)
535 (if org-odd-levels-only
1 0)))
537 (opt-plist (setq org-export-opt-plist
539 (org-export-add-subtree-options opt-plist rbeg
)
541 ;; The following two are dynamically scoped into other
543 (org-current-export-dir
544 (or pub-dir
(org-export-directory :html opt-plist
)))
545 (org-current-export-file buffer-file-name
)
546 (level 0) (line "") (origline "") txt todo
549 (filename (if to-buffer nil
552 (file-name-sans-extension
554 (org-entry-get (region-beginning)
555 "EXPORT_FILE_NAME" t
))
556 (file-name-nondirectory buffer-file-name
)))
558 (file-name-as-directory
559 (or pub-dir
(org-export-directory :html opt-plist
))))))
560 (current-dir (if buffer-file-name
561 (file-name-directory buffer-file-name
)
563 (buffer (if to-buffer
565 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
566 (t (get-buffer-create to-buffer
)))
567 (find-file-noselect filename
)))
568 (org-levels-open (make-vector org-level-max nil
))
569 (date (plist-get opt-plist
:date
))
570 (author (plist-get opt-plist
:author
))
571 (title (or (and subtree-p
(org-export-get-title-from-subtree))
572 (plist-get opt-plist
:title
)
574 (plist-get opt-plist
:skip-before-1st-heading
))
575 (org-export-grab-title-from-buffer))
576 (and buffer-file-name
577 (file-name-sans-extension
578 (file-name-nondirectory buffer-file-name
)))
580 (html-table-tag (plist-get opt-plist
:html-table-tag
))
581 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
582 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
587 (local-list-type nil
)
588 (local-list-indent nil
)
589 (llt org-plain-list-ordered-item-terminator
)
590 (email (plist-get opt-plist
:email
))
591 (language (plist-get opt-plist
:language
))
592 (keywords (plist-get opt-plist
:keywords
))
593 (description (plist-get opt-plist
:description
))
597 (coding-system (and (boundp 'buffer-file-coding-system
)
598 buffer-file-coding-system
))
599 (coding-system-for-write (or org-export-html-coding-system
601 (save-buffer-coding-system (or org-export-html-coding-system
603 (charset (and coding-system-for-write
604 (fboundp 'coding-system-get
)
605 (coding-system-get coding-system-for-write
609 (if region-p
(region-beginning) (point-min))
610 (if region-p
(region-end) (point-max))))
613 (org-export-preprocess-string
617 :skip-before-1st-heading
618 (plist-get opt-plist
:skip-before-1st-heading
)
619 :drawers
(plist-get opt-plist
:drawers
)
620 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
621 :tags
(plist-get opt-plist
:tags
)
622 :priority
(plist-get opt-plist
:priority
)
623 :footnotes
(plist-get opt-plist
:footnotes
)
624 :timestamps
(plist-get opt-plist
:timestamps
)
626 (plist-get opt-plist
:archived-trees
)
627 :select-tags
(plist-get opt-plist
:select-tags
)
628 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
630 (plist-get opt-plist
:text
)
632 (plist-get opt-plist
:LaTeX-fragments
))
635 table-buffer table-orig-buffer
636 ind item-type starter didclose
637 rpl path attr desc descp desc1 desc2 link
639 footnotes footref-seen
643 (let ((inhibit-read-only t
))
645 (remove-text-properties (point-min) (point-max)
646 '(:org-license-to-kill t
))))
648 (message "Exporting...")
650 (setq org-min-level
(org-get-min-level lines level-offset
))
651 (setq org-last-level org-min-level
)
652 (org-init-section-numbers)
655 ((and date
(string-match "%" date
))
656 (setq date
(format-time-string date
)))
658 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
660 ;; Get the language-dependent settings
661 (setq lang-words
(or (assoc language org-export-language-setup
)
662 (assoc "en" org-export-language-setup
)))
664 ;; Switch to the output buffer
666 (let ((inhibit-read-only t
)) (erase-buffer))
669 (and (fboundp 'set-buffer-file-coding-system
)
670 (set-buffer-file-coding-system coding-system-for-write
))
672 (let ((case-fold-search nil
)
673 (org-odd-levels-only odd
))
674 ;; create local variables for all options, to make sure all called
675 ;; functions get the correct information
677 (set (make-local-variable (nth 2 x
))
678 (plist-get opt-plist
(car x
))))
679 org-export-plist-vars
)
680 (setq umax
(if arg
(prefix-numeric-value arg
)
681 org-export-headline-levels
))
682 (setq umax-toc
(if (integerp org-export-with-toc
)
683 (min org-export-with-toc umax
)
689 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
690 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
691 <html xmlns=\"http://www.w3.org/1999/xhtml\"
692 lang=\"%s\" xml:lang=\"%s\">
695 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
696 <meta name=\"generator\" content=\"Org-mode\"/>
697 <meta name=\"generated\" content=\"%s\"/>
698 <meta name=\"author\" content=\"%s\"/>
699 <meta name=\"description\" content=\"%s\"/>
700 <meta name=\"keywords\" content=\"%s\"/>
707 (or (and (stringp org-export-html-xml-declaration
)
708 org-export-html-xml-declaration
)
709 (cdr (assoc html-extension org-export-html-xml-declaration
))
710 (cdr (assoc "html" org-export-html-xml-declaration
))
713 (or charset
"iso-8859-1"))
714 language language
(org-html-expand title
)
715 (or charset
"iso-8859-1")
716 date author description keywords
719 (insert (or (plist-get opt-plist
:preamble
) ""))
721 (when (plist-get opt-plist
:auto-preamble
)
722 (if title
(insert (format org-export-html-title-format
723 (org-html-expand title
))))))
725 (if (and org-export-with-toc
(not body-only
))
727 (push (format "<h%d>%s</h%d>\n"
728 org-export-html-toplevel-hlevel
730 org-export-html-toplevel-hlevel
)
732 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
733 (push "<ul>\n<li>" thetoc
)
735 (mapcar '(lambda (line)
736 (if (string-match org-todo-line-regexp line
)
737 ;; This is a headline
739 (setq have-headings t
)
740 (setq level
(- (match-end 1) (match-beginning 1)
742 level
(org-tr-level level
)
745 (org-export-cleanup-toc-line
746 (match-string 3 line
))))
748 (or (and org-export-mark-todo-in-toc
750 (not (member (match-string 2 line
)
753 (and org-export-mark-todo-in-toc
755 (org-search-todo-below
758 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
759 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
760 (if (string-match quote-re0 txt
)
761 (setq txt
(replace-match "" t t txt
)))
762 (setq snumber
(org-section-number level
))
763 (if org-export-with-section-numbers
764 (setq txt
(concat snumber
" " txt
)))
765 (if (<= level
(max umax umax-toc
))
766 (setq head-count
(+ head-count
1)))
767 (if (<= level umax-toc
)
769 (if (> level org-last-level
)
771 (setq cnt
(- level org-last-level
))
772 (while (>= (setq cnt
(1- cnt
)) 0)
773 (push "\n<ul>\n<li>" thetoc
))
775 (if (< level org-last-level
)
777 (setq cnt
(- org-last-level level
))
778 (while (>= (setq cnt
(1- cnt
)) 0)
779 (push "</li>\n</ul>" thetoc
))
782 (while (string-match org-any-target-regexp line
)
783 (setq line
(replace-match
784 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
786 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
787 (setq txt
(replace-match "" t t txt
)))
788 (setq href
(format "sec-%s" snumber
))
789 (setq href
(or (cdr (assoc href org-export-preferred-target-alist
)) href
))
793 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
794 "</li>\n<li><a href=\"#%s\">%s</a>")
797 (setq org-last-level level
))
801 (while (> org-last-level
(1- org-min-level
))
802 (setq org-last-level
(1- org-last-level
))
803 (push "</li>\n</ul>\n" thetoc
))
804 (push "</div>\n" thetoc
)
805 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
808 (org-init-section-numbers)
812 (while (setq line
(pop lines
) origline line
)
815 ;; end of quote section?
816 (when (and inquote
(string-match "^\\*+ " line
))
820 ;; inside a quote section?
822 (insert (org-html-protect line
) "\n")
823 (throw 'nextline nil
))
825 ;; Fixed-width, verbatim lines (examples)
826 (when (and org-export-with-fixed-width
827 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
830 (org-close-par-maybe)
832 (insert "<pre class=\"example\">\n"))
833 (insert (org-html-protect (match-string 3 line
)) "\n")
834 (when (or (not lines
)
835 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
840 (throw 'nextline nil
))
842 (org-export-html-close-lists-maybe line
)
845 (when (get-text-property 0 'org-protected line
)
847 (when (re-search-backward
848 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
849 (setq par
(match-string 1))
850 (replace-match "\\2\n"))
853 (or (= (length (car lines
)) 0)
854 (get-text-property 0 'org-protected
(car lines
))))
855 (insert (pop lines
) "\n"))
856 (and par
(insert "<p>\n")))
857 (throw 'nextline nil
))
860 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
862 (insert "\n</p>\n<hr/>\n<p>\n")
863 (insert "\n<hr/>\n"))
864 (throw 'nextline nil
))
866 ;; Blockquotes, verse, and center
867 (when (equal "ORG-BLOCKQUOTE-START" line
)
868 (org-close-par-maybe)
869 (insert "<blockquote>\n")
871 (throw 'nextline nil
))
872 (when (equal "ORG-BLOCKQUOTE-END" line
)
873 (org-close-par-maybe)
874 (insert "\n</blockquote>\n")
876 (throw 'nextline nil
))
877 (when (equal "ORG-VERSE-START" line
)
878 (org-close-par-maybe)
879 (insert "\n<p class=\"verse\">\n")
881 (throw 'nextline nil
))
882 (when (equal "ORG-VERSE-END" line
)
886 (throw 'nextline nil
))
887 (when (equal "ORG-CENTER-START" line
)
888 (org-close-par-maybe)
889 (insert "\n<div style=\"text-align: center\">")
891 (throw 'nextline nil
))
892 (when (equal "ORG-CENTER-END" line
)
893 (org-close-par-maybe)
896 (throw 'nextline nil
))
897 (run-hooks 'org-export-html-after-blockquotes-hook
)
899 (let ((i (org-get-string-indentation line
)))
901 (setq line
(concat (mapconcat 'identity
902 (make-list (* 2 i
) "\\nbsp") "")
903 " " (org-trim line
))))
904 (unless (string-match "\\\\\\\\[ \t]*$" line
)
905 (setq line
(concat line
"\\\\")))))
907 ;; make targets to anchors
909 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
912 (setq line
(replace-match
914 "@<a name=\"%s\" id=\"%s\">@</a>"
915 (org-solidify-link-text (match-string 1 line
))
916 (org-solidify-link-text (match-string 1 line
)))
918 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
919 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
920 (setq line
(replace-match
921 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
922 ; (concat "@<i>" (match-string 1 line) "@</i> ")
925 (setq line
(replace-match
926 (concat "@<a name=\""
927 (org-solidify-link-text (match-string 1 line
))
928 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
931 (setq line
(org-html-handle-time-stamps line
))
933 ;; replace "&" by "&", "<" and ">" by "<" and ">"
934 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
935 ;; Also handle sub_superscripts and checkboxes
936 (or (string-match org-table-hline-regexp line
)
937 (setq line
(org-html-expand line
)))
941 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
942 (setq start
(match-beginning 0))
943 (setq path
(save-match-data (org-link-unescape
944 (match-string 3 line
))))
946 ((match-end 2) (match-string 2 line
))
948 (or (file-name-absolute-p path
)
949 (string-match "^\\.\\.?/" path
)))
952 (setq path
(org-extract-attributes (org-link-unescape path
)))
953 (setq attr
(get-text-property 0 'org-attributes path
))
954 (setq desc1
(if (match-end 5) (match-string 5 line
))
955 desc2
(if (match-end 2) (concat type
":" path
) path
)
956 descp
(and desc1
(not (equal desc1 desc2
)))
957 desc
(or desc1 desc2
))
958 ;; Make an image out of the description if that is so wanted
959 (when (and descp
(org-file-image-p
960 desc org-export-html-inline-image-extensions
))
962 (if (string-match "^file:" desc
)
963 (setq desc
(substring desc
(match-end 0)))))
964 (setq desc
(org-add-props
965 (concat "<img src=\"" desc
"\"/>")
966 '(org-protected t
))))
967 ;; FIXME: do we need to unescape here somewhere?
969 ((equal type
"internal")
973 (if (= (string-to-char path
) ?
#) "" "#")
974 (org-solidify-link-text
975 (save-match-data (org-link-unescape path
)) nil
)
977 (org-export-html-format-desc desc
)
979 ((and (equal type
"id")
980 (setq id-file
(org-id-find-id-file path
)))
981 ;; This is an id: link to another file (if it was the same file,
982 ;; it would have become an internal link...)
983 (setq id-file
(file-relative-name
984 id-file
(file-name-directory org-current-export-file
)))
985 (setq id-file
(concat (file-name-sans-extension id-file
)
987 (setq rpl
(concat "<a href=\"" id-file
"#"
988 (if (org-uuidgen-p path
) "ID-")
991 (org-export-html-format-desc desc
)
993 ((member type
'("http" "https"))
994 ;; standard URL, just check if we need to inline an image
995 (if (and (or (eq t org-export-html-inline-images
)
996 (and org-export-html-inline-images
(not descp
)))
998 path org-export-html-inline-image-extensions
))
999 (setq rpl
(org-export-html-format-image
1000 (concat type
":" path
) org-par-open
))
1001 (setq link
(concat type
":" path
))
1002 (setq rpl
(concat "<a href=\""
1003 (org-export-html-format-href link
)
1005 (org-export-html-format-desc desc
)
1007 ((member type
'("ftp" "mailto" "news"))
1009 (setq link
(concat type
":" path
))
1010 (setq rpl
(concat "<a href=\""
1011 (org-export-html-format-href link
)
1013 (org-export-html-format-desc desc
)
1016 ((string= type
"coderef")
1017 (setq rpl
(format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
1019 (format (org-export-get-coderef-format path
(and descp desc
))
1020 (cdr (assoc path org-export-code-refs
))))))
1022 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
1023 ;; The link protocol has a function for format the link
1026 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
1028 ((string= type
"file")
1030 (let* ((filename path
)
1031 (abs-p (file-name-absolute-p filename
))
1032 thefile file-is-image-p search
)
1034 (if (string-match "::\\(.*\\)" filename
)
1035 (setq search
(match-string 1 filename
)
1036 filename
(replace-match "" t nil filename
)))
1038 (if (functionp link-validate
)
1039 (funcall link-validate filename current-dir
)
1041 (setq file-is-image-p
1043 filename org-export-html-inline-image-extensions
))
1044 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
1045 (when (and org-export-html-link-org-files-as-html
1046 (string-match "\\.org$" thefile
))
1047 (setq thefile
(concat (substring thefile
0
1048 (match-beginning 0))
1049 "." html-extension
))
1051 ;; make sure this is can be used as target search
1052 (not (string-match "^[0-9]*$" search
))
1053 (not (string-match "^\\*" search
))
1054 (not (string-match "^/.*/$" search
)))
1055 (setq thefile
(concat thefile
"#"
1056 (org-solidify-link-text
1057 (org-link-unescape search
)))))
1058 (when (string-match "^file:" desc
)
1059 (setq desc
(replace-match "" t t desc
))
1060 (if (string-match "\\.org$" desc
)
1061 (setq desc
(replace-match "" t t desc
))))))
1062 (setq rpl
(if (and file-is-image-p
1063 (or (eq t org-export-html-inline-images
)
1064 (and org-export-html-inline-images
1067 (message "image %s %s" thefile org-par-open
)
1068 (org-export-html-format-image thefile org-par-open
))
1069 (concat "<a href=\"" thefile
"\"" attr
">"
1070 (org-export-html-format-desc desc
)
1072 (if (not valid
) (setq rpl desc
))))
1075 ;; just publish the path, as default
1076 (setq rpl
(concat "<i><" type
":"
1077 (save-match-data (org-link-unescape path
))
1079 (setq line
(replace-match rpl t t line
)
1080 start
(+ start
(length rpl
))))
1083 (if (and (string-match org-todo-line-regexp line
)
1084 (match-beginning 2))
1087 (concat (substring line
0 (match-beginning 2))
1089 (if (member (match-string 2 line
)
1092 " " (match-string 2 line
)
1093 "\"> " (org-export-html-get-todo-kwd-class-name
1094 (match-string 2 line
))
1095 "</span>" (substring line
(match-end 2)))))
1097 ;; Does this contain a reference to a footnote?
1098 (when org-export-with-footnotes
1100 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
1101 (if (get-text-property (match-beginning 2) 'org-protected line
)
1102 (setq start
(match-end 2))
1103 (let ((n (match-string 2 line
)) extra a
)
1104 (if (setq a
(assoc n footref-seen
))
1106 (setcdr a
(1+ (cdr a
)))
1107 (setq extra
(format ".%d" (cdr a
))))
1109 (push (cons n
1) footref-seen
))
1113 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
1114 (match-string 1 line
) n extra n n
)
1118 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1119 ;; This is a headline
1120 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1122 txt
(match-string 2 line
))
1123 (if (string-match quote-re0 txt
)
1124 (setq txt
(replace-match "" t t txt
)))
1125 (if (<= level
(max umax umax-toc
))
1126 (setq head-count
(+ head-count
1)))
1128 ;; Close any local lists before inserting a new header line
1129 (while local-list-type
1130 (org-close-li (car local-list-type
))
1131 (insert (format "</%sl>\n" (car local-list-type
)))
1132 (pop local-list-type
))
1133 (setq local-list-indent nil
1135 (setq first-heading-pos
(or first-heading-pos
(point)))
1136 (org-html-level-start level txt umax
1137 (and org-export-with-toc
(<= level umax
))
1141 (when (string-match quote-re line
)
1142 (org-close-par-maybe)
1146 ((string-match "^[ \t]*- __+[ \t]*$" line
)
1147 ;; Explicit list closure
1148 (when local-list-type
1149 (let ((ind (org-get-indentation line
)))
1150 (while (and local-list-indent
1151 (<= ind
(car local-list-indent
)))
1152 (org-close-li (car local-list-type
))
1153 (insert (format "</%sl>\n" (car local-list-type
)))
1154 (pop local-list-type
)
1155 (pop local-list-indent
))
1156 (or local-list-indent
(setq in-local-list nil
))))
1157 (throw 'nextline nil
))
1159 ((and org-export-with-tables
1160 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1161 (when (not table-open
)
1163 (setq table-open t table-buffer nil table-orig-buffer nil
))
1166 (setq table-buffer
(cons line table-buffer
)
1167 table-orig-buffer
(cons origline table-orig-buffer
))
1168 (when (or (not lines
)
1169 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1171 (setq table-open nil
1172 table-buffer
(nreverse table-buffer
)
1173 table-orig-buffer
(nreverse table-orig-buffer
))
1174 (org-close-par-maybe)
1175 (insert (org-format-table-html table-buffer table-orig-buffer
))))
1180 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1181 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1182 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1183 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
1185 (setq ind
(or (get-text-property 0 'original-indentation line
)
1186 (org-get-string-indentation line
))
1187 item-type
(if (match-beginning 4) "o" "u")
1188 starter
(if (match-beginning 2)
1189 (substring (match-string 2 line
) 0 -
1))
1190 line
(substring line
(match-beginning 5))
1192 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
1194 item-tag
(match-string 1 line
)
1195 line
(substring line
(match-end 0))))
1196 (when (and (not (equal item-type
"d"))
1197 (not (string-match "[^ \t]" line
)))
1198 ;; empty line. Pretend indentation is large.
1199 (setq ind
(if org-empty-line-terminates-plain-lists
1201 (1+ (or (car local-list-indent
) 1)))))
1203 (while (and in-local-list
1204 (or (and (= ind
(car local-list-indent
))
1206 (< ind
(car local-list-indent
))))
1208 (org-close-li (car local-list-type
))
1209 (insert (format "</%sl>\n" (car local-list-type
)))
1210 (pop local-list-type
) (pop local-list-indent
)
1211 (setq in-local-list local-list-indent
))
1214 (or (not in-local-list
)
1215 (> ind
(car local-list-indent
))))
1216 ;; Start new (level of) list
1217 (org-close-par-maybe)
1219 ((equal item-type
"u") "<ul>\n<li>\n")
1220 ((equal item-type
"o") "<ol>\n<li>\n")
1221 ((equal item-type
"d")
1222 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
1223 (push item-type local-list-type
)
1224 (push ind local-list-indent
)
1225 (setq in-local-list t
))
1227 ;; continue current list
1228 (org-close-li (car local-list-type
))
1230 ((equal (car local-list-type
) "d")
1231 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
1234 ;; we did close a list, normal text follows: need <p>
1236 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
1239 (if (equal (match-string 1 line
) "X")
1241 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
1244 ;; Empty lines start a new paragraph. If hand-formatted lists
1245 ;; are not fully interpreted, lines starting with "-", "+", "*"
1246 ;; also start a new paragraph.
1247 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
1249 ;; Is this the start of a footnote?
1250 (when org-export-with-footnotes
1251 (when (and (boundp 'footnote-section-tag-regexp
)
1252 (string-match (concat "^" footnote-section-tag-regexp
)
1255 (throw 'nextline nil
))
1256 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1257 (org-close-par-maybe)
1258 (let ((n (match-string 1 line
)))
1259 (setq org-par-open t
1261 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
1263 ;; Check if the line break needs to be conserved
1265 ((string-match "\\\\\\\\[ \t]*$" line
)
1266 (setq line
(replace-match "<br/>" t t line
)))
1267 (org-export-preserve-breaks
1268 (setq line
(concat line
"<br/>"))))
1270 ;; Check if a paragraph should be started
1272 (while (and org-par-open
1273 (string-match "\\\\par\\>" line start
))
1274 ;; Leave a space in the </p> so that the footnote matcher
1275 ;; does not see this.
1276 (if (not (get-text-property (match-beginning 0)
1277 'org-protected line
))
1278 (setq line
(replace-match "</p ><p >" t t line
)))
1279 (setq start
(match-end 0))))
1281 (insert line
"\n")))))
1283 ;; Properly close all local lists and other lists
1288 ;; Close any local lists before inserting a new header line
1289 (while local-list-type
1290 (org-close-li (car local-list-type
))
1291 (insert (format "</%sl>\n" (car local-list-type
)))
1292 (pop local-list-type
))
1293 (setq local-list-indent nil
1295 (org-html-level-start 1 nil umax
1296 (and org-export-with-toc
(<= level umax
))
1298 ;; the </div> to close the last text-... div.
1299 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
1302 (goto-char (point-min))
1303 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
1304 (push (match-string 0) footnotes
)
1305 (replace-match "" t t
)))
1307 (insert (format org-export-html-footnotes-section
1308 (or (nth 4 lang-words
) "Footnotes")
1309 (mapconcat 'identity
(nreverse footnotes
) "\n"))
1311 (let ((bib (org-export-html-get-bibliography)))
1313 (insert "\n" bib
"\n")))
1315 (when (plist-get opt-plist
:auto-postamble
)
1316 (insert "<div id=\"postamble\">\n")
1317 (when (and org-export-author-info author
)
1318 (insert "<p class=\"author\"> "
1319 (nth 1 lang-words
) ": " author
"\n")
1321 (if (listp (split-string email
",+ *"))
1323 (insert "<a href=\"mailto:" e
"\"><"
1325 (split-string email
",+ *"))
1326 (insert "<a href=\"mailto:" email
"\"><"
1327 email
"></a>\n")))
1329 (when (and date org-export-time-stamp-file
)
1330 (insert "<p class=\"date\"> "
1331 (nth 2 lang-words
) ": "
1333 (when org-export-creator-info
1334 (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
1335 org-version emacs-major-version
)))
1336 (when org-export-html-validation-link
1337 (insert org-export-html-validation-link
"\n"))
1340 (if org-export-html-with-timestamp
1341 (insert org-export-html-html-helper-timestamp
))
1342 (insert (or (plist-get opt-plist
:postamble
) ""))
1343 (insert "\n</div>\n</body>\n</html>\n"))
1345 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1347 (if (eq major-mode default-major-mode
) (html-mode)))
1349 ;; insert the table of contents
1350 (goto-char (point-min))
1352 (if (or (re-search-forward
1353 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1355 "\\[TABLE-OF-CONTENTS\\]" nil t
))
1357 (goto-char (match-beginning 0))
1359 (goto-char first-heading-pos
)
1360 (when (looking-at "\\s-*</p>")
1361 (goto-char (match-end 0))
1363 (insert "<div id=\"table-of-contents\">\n")
1364 (mapc 'insert thetoc
)
1365 (insert "</div>\n"))
1366 ;; remove empty paragraphs and lists
1367 (goto-char (point-min))
1368 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
1370 (goto-char (point-min))
1371 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
1373 (goto-char (point-min))
1374 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
1376 ;; Convert whitespace place holders
1377 (goto-char (point-min))
1379 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1380 (setq n
(get-text-property beg
'org-whitespace
)
1381 end
(next-single-property-change beg
'org-whitespace
))
1383 (delete-region beg end
)
1384 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1385 (make-string n ?x
)))))
1386 (or to-buffer
(save-buffer))
1387 (goto-char (point-min))
1388 (or (org-export-push-to-kill-ring "HTML")
1389 (message "Exporting... done"))
1390 (if (eq to-buffer
'string
)
1391 (prog1 (buffer-substring (point-min) (point-max))
1392 (kill-buffer (current-buffer)))
1393 (current-buffer)))))
1395 (defun org-export-html-format-href (s)
1396 "Make sure the S is valid as a href reference in an XHTML document."
1399 (while (string-match "&" s start
)
1400 (setq start
(+ (match-beginning 0) 3)
1401 s
(replace-match "&" t t s
)))))
1404 (defun org-export-html-format-desc (s)
1405 "Make sure the S is valid as a description in a link."
1406 (if (and s
(not (get-text-property 1 'org-protected s
)))
1408 (org-html-do-expand s
))
1411 (defun org-export-html-format-image (src par-open
)
1412 "Create image tag with source and attributes."
1414 (if (string-match "^ltxpng/" src
)
1415 (format "<img src=\"%s\"/>" src
)
1416 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1417 (attr (org-find-text-property-in-string 'org-attributes src
))
1418 (label (org-find-text-property-in-string 'org-label src
)))
1419 (format "%s<div %sclass=\"figure\">
1420 <p><img src=\"%s\"%s /></p>%s
1422 (if org-par-open
"</p>\n" "")
1423 (if label
(format "id=\"%s\" " label
) "")
1425 (if (string-match "\\<alt=" (or attr
""))
1427 (concat " " attr
" alt=\"" src
"\""))
1428 (if caption
(concat "\n<p>" caption
"</p>") "")
1429 (if org-par-open
"\n<p>" ""))))))
1431 (defun org-export-html-get-bibliography ()
1432 "Find bibliography, cut it out and return it."
1434 (let (beg end
(cnt 1) bib
)
1436 (goto-char (point-min))
1437 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1438 (setq beg
(match-beginning 0))
1439 (while (re-search-forward "</?div\\>" nil t
)
1440 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1442 (and (looking-at ">") (forward-char 1))
1443 (setq bib
(buffer-substring beg
(point)))
1444 (delete-region beg
(point))
1445 (throw 'exit bib
))))
1448 (defvar org-table-number-regexp
) ; defined in org-table.el
1449 (defun org-format-table-html (lines olines
)
1450 "Find out which HTML converter to use and return the HTML code."
1452 (setq lines
(org-split-string lines
"\n")))
1453 (if (string-match "^[ \t]*|" (car lines
))
1454 ;; A normal org table
1455 (org-format-org-table-html lines
)
1456 ;; Table made by table.el - test for spanning
1457 (let* ((hlines (delq nil
(mapcar
1459 (if (string-match "^[ \t]*\\+-" x
) x
1462 (first (car hlines
))
1463 (ll (and (string-match "\\S-+" first
)
1464 (match-string 0 first
)))
1465 (re (concat "^[ \t]*" (regexp-quote ll
)))
1466 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
1468 (if (and (not spanning
)
1469 (not org-export-prefer-native-exporter-for-tables
))
1470 ;; We can use my own converter with HTML conversions
1471 (org-format-table-table-html lines
)
1472 ;; Need to use the code generator in table.el, with the original text.
1473 (org-format-table-table-html-using-table-generate-source olines
)))))
1475 (defvar org-table-number-fraction
) ; defined in org-table.el
1476 (defun org-format-org-table-html (lines &optional splice
)
1477 "Format a table into HTML."
1478 (require 'org-table
)
1479 ;; Get rid of hlines at beginning and end
1480 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1481 (setq lines
(nreverse lines
))
1482 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1483 (setq lines
(nreverse lines
))
1484 (when org-export-table-remove-special-lines
1485 ;; Check if the table has a marking column. If yes remove the
1486 ;; column and the special lines
1487 (setq lines
(org-table-clean-before-export lines
)))
1489 (let* ((caption (or (get-text-property 0 'org-caption
(car lines
))
1490 (get-text-property (or (next-single-property-change
1491 0 'org-caption
(car lines
))
1493 'org-caption
(car lines
))))
1494 (attributes (or (get-text-property 0 'org-attributes
(car lines
))
1495 (get-text-property (or (next-single-property-change
1496 0 'org-attributes
(car lines
))
1498 'org-attributes
(car lines
))))
1499 (html-table-tag (org-export-splice-attributes
1500 html-table-tag attributes
))
1501 (head (and org-export-highlight-first-table-line
1503 (lambda (x) (string-match "^[ \t]*|-" x
))
1507 tbopen line fields html gr colgropen
)
1508 (if splice
(setq head nil
))
1509 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
1511 (while (setq line
(pop lines
))
1513 (if (string-match "^[ \t]*|-" line
)
1516 (push (if head
"</thead>" "</tbody>") html
)
1517 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
1518 (setq head nil
) ;; head ends here, first time around
1520 (throw 'next-line t
)))
1521 ;; Break the line into fields
1522 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
1523 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
1524 (setq nlines
(1+ nlines
) i -
1)
1525 (push (concat "<tr>"
1529 (if (and (< i nlines
)
1530 (string-match org-table-number-regexp x
))
1531 (incf (aref fnum i
)))
1535 (format (car org-export-table-header-tags
) "col")
1537 (cdr org-export-table-header-tags
)))
1538 ((and (= i
0) org-export-html-table-use-header-tags-for-first-column
)
1540 (format (car org-export-table-header-tags
) "row")
1542 (cdr org-export-table-header-tags
)))
1544 (concat (car org-export-table-data-tags
) x
1545 (cdr org-export-table-data-tags
)))))
1549 (unless splice
(if tbopen
(push "</tbody>" html
)))
1550 (unless splice
(push "</table>\n" html
))
1551 (setq html
(nreverse html
))
1553 ;; Put in col tags with the alignment (unfortunately often ignored...)
1558 (setq gr
(pop org-table-colgroup-info
))
1559 (format "<col align=\"%s\" />"
1560 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
1566 ;; Since the output of HTML table formatter can also be used in
1567 ;; DocBook document, we want to always include the caption to make
1568 ;; DocBook XML file valid.
1569 (push (format "<caption>%s</caption>" (or caption
"")) html
)
1570 (push html-table-tag html
))
1571 (concat (mapconcat 'identity html
"\n") "\n")))
1573 (defun org-export-splice-attributes (tag attributes
)
1574 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1575 (if (not attributes
)
1577 (let (oldatt newatt
)
1578 (setq oldatt
(org-extract-attributes-from-string tag
)
1580 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1582 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1583 (if (string-match ">" tag
)
1585 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1589 (defun org-format-table-table-html (lines)
1590 "Format a table generated by table.el into HTML.
1591 This conversion does *not* use `table-generate-source' from table.el.
1592 This has the advantage that Org-mode's HTML conversions can be used.
1593 But it has the disadvantage, that no cell- or row-spanning is allowed."
1594 (let (line field-buffer
1595 (head org-export-highlight-first-table-line
)
1596 fields html empty i
)
1597 (setq html
(concat html-table-tag
"\n"))
1598 (while (setq line
(pop lines
))
1599 (setq empty
" ")
1601 (if (string-match "^[ \t]*\\+-" line
)
1612 (if (equal x
"") (setq x empty
))
1615 (format (car org-export-table-header-tags
) "col")
1617 (cdr org-export-table-header-tags
))
1618 (concat (car org-export-table-data-tags
) x
1619 (cdr org-export-table-data-tags
))))
1623 (setq field-buffer nil
)))
1625 (throw 'next-line t
)))
1626 ;; Break the line into fields and store the fields
1627 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
1629 (setq field-buffer
(mapcar
1631 (concat x
"<br/>" (pop fields
)))
1633 (setq field-buffer fields
))))
1634 (setq html
(concat html
"</table>\n"))
1637 (defun org-format-table-table-html-using-table-generate-source (lines)
1638 "Format a table into html, using `table-generate-source' from table.el.
1639 This has the advantage that cell- or row-spanning is allowed.
1640 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
1642 (with-current-buffer (get-buffer-create " org-tmp1 ")
1644 (insert (mapconcat 'identity lines
"\n"))
1645 (goto-char (point-min))
1646 (if (not (re-search-forward "|[^+]" nil t
))
1647 (error "Error processing table"))
1648 (table-recognize-table)
1649 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
1650 (table-generate-source 'html
" org-tmp2 ")
1651 (set-buffer " org-tmp2 ")
1652 (buffer-substring (point-min) (point-max))))
1654 (defun org-export-splice-style (style extra
)
1655 "Splice EXTRA into STYLE, just before \"</style>\"."
1656 (if (and (stringp extra
)
1657 (string-match "\\S-" extra
)
1658 (string-match "</style>" style
))
1659 (concat (substring style
0 (match-beginning 0))
1661 (substring style
(match-beginning 0)))
1664 (defun org-html-handle-time-stamps (s)
1665 "Format time stamps in string S, or remove them."
1668 (while (string-match org-maybe-keyword-time-regexp s
)
1669 (or b
(setq b
(substring s
0 (match-beginning 0))))
1671 r
(substring s
0 (match-beginning 0))
1672 " @<span class=\"timestamp-wrapper\">"
1674 (format "@<span class=\"timestamp-kwd\">%s @</span>"
1675 (match-string 1 s
)))
1676 (format " @<span class=\"timestamp\">%s@</span>"
1678 (org-translate-time (match-string 3 s
)) 1 -
1))
1680 s
(substring s
(match-end 0))))
1681 ;; Line break if line started and ended with time stamp stuff
1684 (setq r
(concat r s
))
1685 (unless (string-match "\\S-" (concat b s
))
1686 (setq r
(concat r
"@<br/>")))
1689 (defvar htmlize-buffer-places
) ; from htmlize.el
1690 (defun org-export-htmlize-region-for-paste (beg end
)
1691 "Convert the region to HTML, using htmlize.el.
1692 This is much like `htmlize-region-for-paste', only that it uses
1693 the settings define in the org-... variables."
1694 (let* ((htmlize-output-type org-export-htmlize-output-type
)
1695 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
1696 (htmlbuf (htmlize-region beg end
)))
1698 (with-current-buffer htmlbuf
1699 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1700 (plist-get htmlize-buffer-places
'content-end
)))
1701 (kill-buffer htmlbuf
))))
1704 (defun org-export-htmlize-generate-css ()
1705 "Create the CSS for all font definitions in the current Emacs session.
1706 Use this to create face definitions in your CSS style file that can then
1707 be used by code snippets transformed by htmlize.
1708 This command just produces a buffer that contains class definitions for all
1709 faces used in the current Emacs session. You can copy and paste the ones you
1710 need into your CSS file.
1712 If you then set `org-export-htmlize-output-type' to `css', calls to
1713 the function `org-export-htmlize-region-for-paste' will produce code
1714 that uses these same face definitions."
1717 (and (get-buffer "*html*") (kill-buffer "*html*"))
1719 (let ((fl (face-list))
1720 (htmlize-css-name-prefix "org-")
1721 (htmlize-output-type 'css
)
1723 (while (setq f
(pop fl
)
1724 i
(and f
(face-attribute f
:inherit
)))
1725 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1726 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1727 (htmlize-region (point-min) (point-max))))
1728 (switch-to-buffer "*html*")
1729 (goto-char (point-min))
1730 (if (re-search-forward "<style" nil t
)
1731 (delete-region (point-min) (match-beginning 0)))
1732 (if (re-search-forward "</style>" nil t
)
1733 (delete-region (1+ (match-end 0)) (point-max)))
1734 (beginning-of-line 1)
1735 (if (looking-at " +") (replace-match ""))
1736 (goto-char (point-min)))
1738 (defun org-html-protect (s)
1739 ;; convert & to &, < to < and > to >
1741 (while (string-match "&" s start
)
1742 (setq s
(replace-match "&" t t s
)
1743 start
(1+ (match-beginning 0))))
1744 (while (string-match "<" s
)
1745 (setq s
(replace-match "<" t t s
)))
1746 (while (string-match ">" s
)
1747 (setq s
(replace-match ">" t t s
)))
1748 ; (while (string-match "\"" s)
1749 ; (setq s (replace-match """ t t s)))
1753 (defun org-html-expand (string)
1754 "Prepare STRING for HTML export. Applies all active conversions.
1755 If there are links in the string, don't modify these."
1756 (let* ((re (concat org-bracket-link-regexp
"\\|"
1757 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
1759 (while (setq m
(string-match re string
))
1760 (setq s
(substring string
0 m
)
1761 l
(match-string 0 string
)
1762 string
(substring string
(match-end 0)))
1763 (push (org-html-do-expand s
) res
)
1765 (push (org-html-do-expand string
) res
)
1766 (apply 'concat
(nreverse res
))))
1768 (defun org-html-do-expand (s)
1769 "Apply all active conversions to translate special ASCII to HTML."
1770 (setq s
(org-html-protect s
))
1771 (if org-export-html-expand
1772 (while (string-match "@<\\([^&]*\\)>" s
)
1773 (setq s
(replace-match "<\\1>" t nil s
))))
1774 (if org-export-with-emphasize
1775 (setq s
(org-export-html-convert-emphasize s
)))
1776 (if org-export-with-special-strings
1777 (setq s
(org-export-html-convert-special-strings s
)))
1778 (if org-export-with-sub-superscripts
1779 (setq s
(org-export-html-convert-sub-super s
)))
1780 (if org-export-with-TeX-macros
1781 (let ((start 0) wd ass
)
1782 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
1784 (if (get-text-property (match-beginning 0) 'org-protected s
)
1785 (setq start
(match-end 0))
1786 (setq wd
(match-string 1 s
))
1787 (if (setq ass
(assoc wd org-html-entities
))
1788 (setq s
(replace-match (or (cdr ass
)
1789 (concat "&" (car ass
) ";"))
1791 (setq start
(+ start
(length wd
))))))))
1794 (defconst org-export-html-special-string-regexps
1795 '(("\\\\-" .
"­")
1796 ("---\\([^-]\\)" .
"—\\1")
1797 ("--\\([^-]\\)" .
"–\\1")
1798 ("\\.\\.\\." .
"…"))
1799 "Regular expressions for special string conversion.")
1801 (defun org-export-html-convert-special-strings (string)
1802 "Convert special characters in STRING to HTML."
1803 (let ((all org-export-html-special-string-regexps
)
1805 (while (setq a
(pop all
))
1806 (setq re
(car a
) rpl
(cdr a
) start
0)
1807 (while (string-match re string start
)
1808 (if (get-text-property (match-beginning 0) 'org-protected string
)
1809 (setq start
(match-end 0))
1810 (setq string
(replace-match rpl t nil string
)))))
1813 (defun org-export-html-convert-sub-super (string)
1814 "Convert sub- and superscripts in STRING to HTML."
1815 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
1816 (while (string-match org-match-substring-regexp string s
)
1818 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
1819 ((get-text-property (match-beginning 2) 'org-protected string
)
1820 (setq s
(match-end 2)))
1822 (setq s
(match-end 1)
1823 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
1824 c
(or (match-string 8 string
)
1825 (match-string 6 string
)
1826 (match-string 5 string
))
1827 string
(replace-match
1828 (concat (match-string 1 string
)
1829 "<" key
">" c
"</" key
">")
1831 (while (string-match "\\\\\\([_^]\\)" string
)
1832 (setq string
(replace-match (match-string 1 string
) t t string
)))
1835 (defun org-export-html-convert-emphasize (string)
1838 (while (string-match org-emph-re string s
)
1840 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
1841 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
1842 (setq s
(match-beginning 0)
1845 (match-string 1 string
)
1846 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
1847 (match-string 4 string
)
1848 (nth 3 (assoc (match-string 3 string
)
1849 org-emphasis-alist
))
1850 (match-string 5 string
))
1851 string
(replace-match rpl t t string
)
1852 s
(+ s
(- (length rpl
) 2)))
1856 (defun org-open-par ()
1857 "Insert <p>, but first close previous paragraph if any."
1858 (org-close-par-maybe)
1860 (setq org-par-open t
))
1861 (defun org-close-par-maybe ()
1862 "Close paragraph if there is one open."
1865 (setq org-par-open nil
)))
1866 (defun org-close-li (&optional type
)
1867 "Close <li> if necessary."
1868 (org-close-par-maybe)
1869 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
1871 (defvar in-local-list
)
1872 (defvar local-list-indent
)
1873 (defvar local-list-type
)
1874 (defun org-export-html-close-lists-maybe (line)
1875 (let ((ind (or (get-text-property 0 'original-indentation line
)
1876 (org-get-indentation line
)))
1879 (while (and in-local-list
1880 (<= ind
(car local-list-indent
)))
1882 (org-close-li (car local-list-type
))
1883 (insert (format "</%sl>\n" (car local-list-type
)))
1884 (pop local-list-type
) (pop local-list-indent
)
1885 (setq in-local-list local-list-indent
))
1886 (and didclose
(org-open-par)))))
1888 (defvar body-only
) ; dynamically scoped into this.
1889 (defun org-html-level-start (level title umax with-toc head-count
)
1890 "Insert a new level in HTML export.
1891 When TITLE is nil, just close all open levels."
1892 (org-close-par-maybe)
1893 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
1894 (extra-targets (assoc target org-export-target-aliases
))
1895 (preferred (cdr (assoc target org-export-preferred-target-alist
)))
1896 (remove (or preferred target
))
1898 snumber href suffix
)
1899 (setq extra-targets
(remove remove extra-targets
))
1901 (mapconcat (lambda (x)
1902 (if (org-uuidgen-p x
) (setq x
(concat "ID-" x
)))
1903 (format "<a name=\"%s\" id=\"%s\"></a>"
1908 (if (aref org-levels-open
(1- l
))
1910 (org-html-level-close l umax
)
1911 (aset org-levels-open
(1- l
) nil
)))
1914 ;; If title is nil, this means this function is called to close
1915 ;; all levels, so the rest is done only if title is given
1916 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
1917 (setq title
(replace-match
1918 (if org-export-with-tags
1921 " <span class=\"tag\">"
1924 (format "<span class=\"%s\">%s</span>"
1925 (org-export-html-get-tag-class-name x
)
1927 (org-split-string (match-string 1 title
) ":")
1934 (if (aref org-levels-open
(1- level
))
1938 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
1939 (insert "<li>" title
"<br/>\n")))
1940 (aset org-levels-open
(1- level
) t
)
1941 (org-close-par-maybe)
1943 (insert (format "<ul>\n<li id=\"%s\">" target
)
1944 extra-targets title
"<br/>\n")
1945 (insert "<ul>\n<li>" title
"<br/>\n"))))
1946 (aset org-levels-open
(1- level
) t
)
1947 (setq snumber
(org-section-number level
))
1948 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
1949 (if (and org-export-with-section-numbers
(not body-only
))
1951 (format "<span class=\"section-number-%d\">%s</span>"
1954 (unless (= head-count
1) (insert "\n</div>\n"))
1955 (setq href
(cdr (assoc (concat "sec-" snumber
) org-export-preferred-target-alist
)))
1956 (setq suffix
(or href snumber
))
1957 (setq href
(or href
(concat "sec-" snumber
)))
1958 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
1959 suffix level level href
1961 title level level suffix
))
1964 (defun org-export-html-get-tag-class-name (tag)
1965 "Turn tag into a valid class name.
1966 Replaces invalid characters with \"_\" and then prepends a prefix."
1968 (while (string-match "[^a-zA-Z0-9_]" tag
)
1969 (setq tag
(replace-match "_" t t tag
))))
1970 (concat org-export-html-tag-class-prefix tag
))
1972 (defun org-export-html-get-todo-kwd-class-name (kwd)
1973 "Turn todo keyword into a valid class name.
1974 Replaces invalid characters with \"_\" and then prepends a prefix."
1976 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1977 (setq kwd
(replace-match "_" t t kwd
))))
1978 (concat org-export-html-todo-kwd-class-prefix kwd
))
1980 (defun org-html-level-close (level max-outline-level
)
1981 "Terminate one level in HTML export."
1982 (if (<= level max-outline-level
)
1985 (insert "</ul>\n")))
1989 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
1991 ;;; org-html.el ends here