1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (eval-when-compile (require 'cl
))
35 (declare-function org-id-find-id-file
"org-id" (id))
36 (declare-function htmlize-region
"ext:htmlize" (beg end
))
38 (defgroup org-export-html nil
39 "Options specific for HTML export of Org-mode files."
40 :tag
"Org Export HTML"
43 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
44 <h2 class=\"footnotes\">%s: </h2>
45 <div id=\"text-footnotes\">
49 "Format for the footnotes section.
50 Should contain a two instances of %s. The first will be replaced with the
51 language-specific word for \"Footnotes\", the second one will be replaced
52 by the footnotes themselves."
53 :group
'org-export-html
56 (defcustom org-export-html-footnote-format
"<sup>%s</sup>"
57 "The format for the footnote reference.
58 %s will be replaced by the footnote reference itself."
59 :group
'org-export-html
62 (defcustom org-export-html-coding-system nil
63 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
64 :group
'org-export-html
67 (defcustom org-export-html-extension
"html"
68 "The extension for exported HTML files."
69 :group
'org-export-html
72 (defcustom org-export-html-xml-declaration
73 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
74 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
75 "The extension for exported HTML files.
76 %s will be replaced with the charset of the exported file.
77 This may be a string, or an alist with export extensions
78 and corresponding declarations."
79 :group
'org-export-html
81 (string :tag
"Single declaration")
82 (repeat :tag
"Dependent on extension"
83 (cons (string :tag
"Extension")
84 (string :tag
"Declaration")))))
86 (defcustom org-export-html-style-include-scripts t
87 "Non-nil means include the JavaScript snippets in exported HTML files.
88 The actual script is defined in `org-export-html-scripts' and should
90 :group
'org-export-html
93 (defconst org-export-html-scripts
94 "<script type=\"text/javascript\">
95 <!--/*--><![CDATA[/*><!--*/
96 function CodeHighlightOn(elem, id)
98 var target = document.getElementById(id);
100 elem.cacheClassElem = elem.className;
101 elem.cacheClassTarget = target.className;
102 target.className = \"code-highlighted\";
103 elem.className = \"code-highlighted\";
106 function CodeHighlightOff(elem, id)
108 var target = document.getElementById(id);
109 if(elem.cacheClassElem)
110 elem.className = elem.cacheClassElem;
111 if(elem.cacheClassTarget)
112 target.className = elem.cacheClassTarget;
116 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
118 (defconst org-export-html-style-default
119 "<style type=\"text/css\">
120 <!--/*--><![CDATA[/*><!--*/
121 html { font-family: Times, serif; font-size: 12pt; }
122 .title { text-align: center; }
123 .todo { color: red; }
124 .done { color: green; }
125 .tag { background-color: #add8e6; font-weight:normal }
127 .timestamp { color: #bebebe; }
128 .timestamp-kwd { color: #5f9ea0; }
129 p.verse { margin-left: 3% }
131 border: 1pt solid #AEBDCC;
132 background-color: #F3F5F7;
134 font-family: courier, monospace;
138 table { border-collapse: collapse; }
139 td, th { vertical-align: top; }
140 dt { font-weight: bold; }
141 div.figure { padding: 0.5em; }
142 div.figure p { text-align: center; }
143 textarea { overflow-x: auto; }
144 .linenr { font-size:smaller }
145 .code-highlighted {background-color:#ffff00;}
146 .org-info-js_info-navigation { border-style:none; }
147 #org-info-js_console-label { font-size:10px; font-weight:bold;
148 white-space:nowrap; }
149 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
153 "The default style specification for exported HTML files.
154 Please use the variables `org-export-html-style' and
155 `org-export-html-style-extra' to add to this style. If you wish to not
156 have the default style included, customize the variable
157 `org-export-html-style-include-default'.")
159 (defcustom org-export-html-style-include-default t
160 "Non-nil means include the default style in exported HTML files.
161 The actual style is defined in `org-export-html-style-default' and should
162 not be modified. Use the variables `org-export-html-style' to add
163 your own style information."
164 :group
'org-export-html
167 (put 'org-export-html-style-include-default
'safe-local-variable
'booleanp
)
169 (defcustom org-export-html-style
""
170 "Org-wide style definitions for exported HTML files.
172 This variable needs to contain the full HTML structure to provide a style,
173 including the surrounding HTML tags. If you set the value of this variable,
174 you should consider to include definitions for the following classes:
175 title, todo, done, timestamp, timestamp-kwd, tag, target.
177 For example, a valid value would be:
179 <style type=\"text/css\">
181 p { font-weight: normal; color: gray; }
183 .title { text-align: center; }
184 .todo, .timestamp-kwd { color: red; }
185 .done { color: green; }
189 If you'd like to refer to en external style file, use something like
191 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
193 As the value of this option simply gets inserted into the HTML <head> header,
194 you can \"misuse\" it to add arbitrary text to the header.
195 See also the variable `org-export-html-style-extra'."
196 :group
'org-export-html
199 (put 'org-export-html-style
'safe-local-variable
'stringp
)
201 (defcustom org-export-html-style-extra
""
202 "Additional style information for HTML export.
203 The value of this variable is inserted into the HTML buffer right after
204 the value of `org-export-html-style'. Use this variable for per-file
205 settings of style information, and do not forget to surround the style
206 settings with <style>...</style> tags."
207 :group
'org-export-html
210 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
212 (defcustom org-export-html-mathjax-options
213 '((path "http://orgmode.org/mathjax/MathJax.js")
218 "Options for MathJax setup.
220 path The path where to find MathJax
221 scale Scaling for the HTML-CSS backend, usually between 100 and 133
222 align How to align display math: left, center, or right
223 indent If align is not center, how far from the left/right side?
224 mathml Should a MathML player be used if available?
225 This is faster and reduces bandwidth use, but currently
226 sometimes has lower spacing quality. Therefore, the default is
227 nil. When browsers get better, this switch can be flipped.
229 You can also customize this for each buffer, using something like
231 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
232 :group
'org-export-html
233 :type
'(list :greedy t
234 (list :tag
"path (the path from where to load MathJax.js)"
235 (const :format
" " path
) (string))
236 (list :tag
"scale (scaling for the displayed math)"
237 (const :format
" " scale
) (string))
238 (list :tag
"align (alignment of displayed equations)"
239 (const :format
" " align
) (string))
240 (list :tag
"indent (indentation with left or right alignment)"
241 (const :format
" " indent
) (string))
242 (list :tag
"mathml (should MathML display be used is possible)"
243 (const :format
" " mathml
) (boolean))))
245 (defun org-export-html-mathjax-config (template options in-buffer
)
246 "Insert the user setup into the matchjax template."
247 (let (name val
(yes " ") (no "// ") x
)
250 (setq name
(car e
) val
(nth 1 e
))
251 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
252 (setq val
(car (read-from-string
253 (substring in-buffer
(match-end 0))))))
254 (if (not (stringp val
)) (setq val
(format "%s" val
)))
255 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
256 (setq template
(replace-match val t t template
))))
258 (setq val
(nth 1 (assq 'mathml options
)))
259 (if (string-match (concat "\\<mathml:") in-buffer
)
260 (setq val
(car (read-from-string
261 (substring in-buffer
(match-end 0))))))
262 ;; Exchange prefixes depending on mathml setting
263 (if (not val
) (setq x yes yes no no x
))
264 ;; Replace cookies to turn on or off the config/jax lines
265 (if (string-match ":MMLYES:" template
)
266 (setq template
(replace-match yes t t template
)))
267 (if (string-match ":MMLNO:" template
)
268 (setq template
(replace-match no t t template
)))
269 ;; Return the modified template
272 (defcustom org-export-html-mathjax-template
273 "<script type=\"text/javascript\" src=\"%PATH\">
274 <!--/*--><![CDATA[/*><!--*/
276 // Only one of the two following lines, depending on user settings
277 // First allows browser-native MathML display, second forces HTML/CSS
278 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
279 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
280 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
281 \"TeX/noUndefined.js\"],
283 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
284 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ],
285 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
286 ignoreClass: \"tex2jax_ignore\",
287 processEscapes: false,
288 processEnvironments: true,
291 showProcessingMessages: true,
292 displayAlign: \"%ALIGN\",
293 displayIndent: \"%INDENT\",
297 availableFonts: [\"STIX\",\"TeX\"],
298 preferredFont: \"TeX\",
314 "The MathJax setup for XHTML files."
315 :group
'org-export-html
318 (defcustom org-export-html-tag-class-prefix
""
319 "Prefix to class names for TODO keywords.
320 Each tag gets a class given by the tag itself, with this prefix.
321 The default prefix is empty because it is nice to just use the keyword
322 as a class name. But if you get into conflicts with other, existing
323 CSS classes, then this prefix can be very useful."
324 :group
'org-export-html
327 (defcustom org-export-html-todo-kwd-class-prefix
""
328 "Prefix to class names for TODO keywords.
329 Each TODO keyword gets a class given by the keyword itself, with this prefix.
330 The default prefix is empty because it is nice to just use the keyword
331 as a class name. But if you get into conflicts with other, existing
332 CSS classes, then this prefix can be very useful."
333 :group
'org-export-html
336 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
337 "Format for typesetting the document title in HTML export."
338 :group
'org-export-html
341 (defcustom org-export-html-home
/up-format
342 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
343 <a accesskey=\"h\" href=\"%s\"> UP </a>
345 <a accesskey=\"H\" href=\"%s\"> HOME </a>
347 "Snippet used to insert the HOME and UP links.
348 This is a format string, the first %s will receive the UP link,
349 the second the HOME link. If both `org-export-html-link-up' and
350 `org-export-html-link-home' are empty, the entire snippet will be
352 :group
'org-export-html
355 (defcustom org-export-html-toplevel-hlevel
2
356 "The <H> level for level 1 headings in HTML export.
357 This is also important for the classes that will be wrapped around headlines
358 and outline structure. If this variable is 1, the top-level headlines will
359 be <h1>, and the corresponding classes will be outline-1, section-number-1,
360 and outline-text-1. If this is 2, all of these will get a 2 instead.
361 The default for this variable is 2, because we use <h1> for formatting the
363 :group
'org-export-html
366 (defcustom org-export-html-link-org-files-as-html t
367 "Non-nil means make file links to `file.org' point to `file.html'.
368 When org-mode is exporting an org-mode file to HTML, links to
369 non-html files are directly put into a href tag in HTML.
370 However, links to other Org-mode files (recognized by the
371 extension `.org.) should become links to the corresponding html
372 file, assuming that the linked org-mode file will also be
374 When nil, the links still point to the plain `.org' file."
375 :group
'org-export-html
378 (defcustom org-export-html-inline-images
'maybe
379 "Non-nil means inline images into exported HTML pages.
380 This is done using an <img> tag. When nil, an anchor with href is used to
381 link to the image. If this option is `maybe', then images in links with
382 an empty description will be inlined, while images with a description will
384 :group
'org-export-html
385 :type
'(choice (const :tag
"Never" nil
)
386 (const :tag
"Always" t
)
387 (const :tag
"When there is no description" maybe
)))
389 (defcustom org-export-html-inline-image-extensions
390 '("png" "jpeg" "jpg" "gif")
391 "Extensions of image files that can be inlined into HTML."
392 :group
'org-export-html
393 :type
'(repeat (string :tag
"Extension")))
395 (defcustom org-export-html-table-tag
396 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
397 "The HTML tag that is used to start a table.
398 This must be a <table> tag, but you may change the options like
399 borders and spacing."
400 :group
'org-export-html
403 (defcustom org-export-table-header-tags
'("<th scope=\"%s\">" .
"</th>")
404 "The opening tag for table header fields.
405 This is customizable so that alignment options can be specified.
406 %s will be filled with the scope of the field, either row or col.
407 See also the variable `org-export-html-table-use-header-tags-for-first-column'."
408 :group
'org-export-tables
409 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
411 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
412 "The opening tag for table data fields.
413 This is customizable so that alignment options can be specified."
414 :group
'org-export-tables
415 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
417 (defcustom org-export-table-row-tags
'("<tr>" .
"</tr>")
418 "The opening tag for table data fields.
419 This is customizable so that alignment options can be specified.
420 Instead of strings, these can be Lisp forms that will be evaluated
421 for each row in order to construct the table row tags. During evaluation,
422 the variable `head' will be true when this is a header line, nil when this
423 is a body line. And the variable `nline' will contain the line number,
424 starting from 1 in the first header line. For example
426 (setq org-export-table-row-tags
429 (if (= (mod nline 2) 1)
430 \"<tr class=\\\"tr-odd\\\">\"
431 \"<tr class=\\\"tr-even\\\">\"))
434 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
435 :group
'org-export-tables
437 (choice :tag
"Opening tag"
438 (string :tag
"Specify")
440 (choice :tag
"Closing tag"
441 (string :tag
"Specify")
446 (defcustom org-export-html-table-use-header-tags-for-first-column nil
447 "Non-nil means format column one in tables with header tags.
448 When nil, also column one will use data tags."
449 :group
'org-export-tables
452 (defcustom org-export-html-validation-link nil
453 "Non-nil means add validation link to postamble of HTML exported files."
454 :group
'org-export-html
456 (const :tag
"Nothing" nil
)
457 (const :tag
"XHTML 1.0" "<p class=\"xhtml-validation\"><a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a></p>")
458 (string :tag
"Specify full HTML")))
461 (defcustom org-export-html-with-timestamp nil
462 "If non-nil, write timestamp into the exported HTML text.
463 If non-nil Write `org-export-html-html-helper-timestamp' into the
464 exported HTML text. Otherwise, the buffer will just be saved to
466 :group
'org-export-html
469 (defcustom org-export-html-html-helper-timestamp
470 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
471 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
472 :group
'org-export-html
475 (defgroup org-export-htmlize nil
476 "Options for processing examples with htmlize.el."
477 :tag
"Org Export Htmlize"
478 :group
'org-export-html
)
480 (defcustom org-export-htmlize-output-type
'inline-css
481 "Output type to be used by htmlize when formatting code snippets.
482 We use as default `inline-css', in order to make the resulting
483 HTML self-containing.
484 However, this will fail when using Emacs in batch mode for export, because
485 then no rich font definitions are in place. It will also not be good if
486 people with different Emacs setup contribute HTML files to a website,
487 because the fonts will represent the individual setups. In these cases,
488 it is much better to let Org/Htmlize assign classes only, and to use
489 a style file to define the look of these classes.
490 To get a start for your css file, start Emacs session and make sure that
491 all the faces you are interested in are defined, for example by loading files
492 in all modes you want. Then, use the command
493 \\[org-export-htmlize-generate-css] to extract class definitions."
494 :group
'org-export-htmlize
495 :type
'(choice (const css
) (const inline-css
)))
497 (defcustom org-export-htmlize-css-font-prefix
"org-"
498 "The prefix for CSS class names for htmlize font specifications."
499 :group
'org-export-htmlize
502 (defcustom org-export-htmlized-org-css-url nil
503 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
504 Normally when creating an htmlized version of an Org buffer, htmlize will
505 create CSS to define the font colors. However, this does not work when
506 converting in batch mode, and it also can look bad if different people
507 with different fontification setup work on the same website.
508 When this variable is non-nil, creating an htmlized version of an Org buffer
509 using `org-export-as-org' will remove the internal CSS section and replace it
510 with a link to this URL."
511 :group
'org-export-htmlize
513 (const :tag
"Keep internal css" nil
)
514 (string :tag
"URL or local href")))
516 ;;; Variables, constants, and parameter plists
518 (defvar org-export-html-preamble nil
519 "Preamble, to be inserted just after <body>. Set by publishing functions.
520 This may also be a function, building and inserting the preamble.")
521 (defvar org-export-html-postamble nil
522 "Preamble, to be inserted just before </body>. Set by publishing functions.
523 This may also be a function, building and inserting the postamble.")
524 (defvar org-export-html-auto-preamble t
525 "Should default preamble be inserted? Set by publishing functions.")
526 (defvar org-export-html-auto-postamble t
527 "Should default postamble be inserted? Set by publishing functions.")
531 (defvar org-export-html-after-blockquotes-hook nil
532 "Hook run during HTML export, after blockquote, verse, center are done.")
534 (defvar org-export-html-final-hook nil
535 "Hook run at the end of HTML export, in the new buffer.")
539 (defun org-export-html-preprocess (parameters)
540 "Convert LaTeX fragments to images."
541 (when (and org-current-export-file
542 (plist-get parameters
:LaTeX-fragments
))
544 (concat "ltxpng/" (file-name-sans-extension
545 (file-name-nondirectory
546 org-current-export-file
)))
547 org-current-export-dir nil
"Creating LaTeX image %s"
550 ((eq (plist-get parameters
:LaTeX-fragments
) 'verbatim
) 'verbatim
)
551 ((eq (plist-get parameters
:LaTeX-fragments
) 'mathjax
) 'mathjax
)
552 ((eq (plist-get parameters
:LaTeX-fragments
) t
) 'mathjax
)
553 ((eq (plist-get parameters
:LaTeX-fragments
) 'dvipng
) 'dvipng
)
555 (goto-char (point-min))
557 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
558 (org-if-unprotected-at (match-beginning 1)
559 (setq label
(match-string 1))
561 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
562 (setq l1
(substring label
(match-beginning 1)))
564 (replace-match (format "[[#%s][%s]]" label l1
) t t
)))))
567 (defun org-export-as-html-and-open (arg)
568 "Export the outline as HTML and immediately open it with a browser.
569 If there is an active region, export only the region.
570 The prefix ARG specifies how many levels of the outline should become
571 headlines. The default is 3. Lower levels will become bulleted lists."
573 (org-export-as-html arg
'hidden
)
574 (org-open-file buffer-file-name
)
575 (when org-export-kill-product-buffer-when-displayed
576 (kill-buffer (current-buffer))))
579 (defun org-export-as-html-batch ()
580 "Call the function `org-export-as-html'.
581 This function can be used in batch processing as:
583 --load=$HOME/lib/emacs/org.el
584 --eval \"(setq org-export-headline-levels 2)\"
585 --visit=MyFile --funcall org-export-as-html-batch"
586 (org-export-as-html org-export-headline-levels
'hidden
))
589 (defun org-export-as-html-to-buffer (arg)
590 "Call `org-export-as-html` with output to a temporary buffer.
591 No file is created. The prefix ARG is passed through to `org-export-as-html'."
593 (org-export-as-html arg nil nil
"*Org HTML Export*")
594 (when org-export-show-temporary-export-buffer
595 (switch-to-buffer-other-window "*Org HTML Export*")))
598 (defun org-replace-region-by-html (beg end
)
599 "Assume the current region has org-mode syntax, and convert it to HTML.
600 This can be used in any buffer. For example, you could write an
601 itemized list in org-mode syntax in an HTML buffer and then use this
602 command to convert it."
604 (let (reg html buf pop-up-frames
)
605 (save-window-excursion
607 (setq html
(org-export-region-as-html
609 (setq reg
(buffer-substring beg end
)
610 buf
(get-buffer-create "*Org tmp*"))
611 (with-current-buffer buf
615 (setq html
(org-export-region-as-html
616 (point-min) (point-max) t
'string
)))
618 (delete-region beg end
)
622 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
623 "Convert region from BEG to END in org-mode buffer to HTML.
624 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
625 contents, and only produce the region of converted text, useful for
626 cut-and-paste operations.
627 If BUFFER is a buffer or a string, use/create that buffer as a target
628 of the converted HTML. If BUFFER is the symbol `string', return the
629 produced HTML as a string and leave not buffer behind. For example,
630 a Lisp program could call this function in the following way:
632 (setq html (org-export-region-as-html beg end t 'string))
634 When called interactively, the output buffer is selected, and shown
635 in a window. A non-interactive call will only return the buffer."
637 (when (interactive-p)
638 (setq buffer
"*Org HTML Export*"))
639 (let ((transient-mark-mode t
) (zmacs-regions t
)
641 (setq ext-plist
(plist-put ext-plist
:ignore-subtree-p t
))
643 (set-mark (point)) ;; to activate the region
645 (setq rtn
(org-export-as-html
648 (if (fboundp 'deactivate-mark
) (deactivate-mark))
649 (if (and (interactive-p) (bufferp rtn
))
650 (switch-to-buffer-other-window rtn
)
653 (defvar html-table-tag nil
) ; dynamically scoped into this.
654 (defvar org-par-open nil
)
656 ;;; org-html-cvt-link-fn
657 (defconst org-html-cvt-link-fn
659 "Function to convert link URLs to exportable URLs.
660 Takes two arguments, TYPE and PATH.
661 Returns exportable url as (TYPE PATH), or nil to signal that it
662 didn't handle this case.
663 Intended to be locally bound around a call to `org-export-as-html'." )
665 (defun org-html-cvt-org-as-html (opt-plist type path
)
666 "Convert an org filename to an equivalent html filename.
667 If TYPE is not file, just return `nil'.
668 See variable `org-export-html-link-org-files-as-html'"
672 org-export-html-link-org-files-as-html
673 (string= type
"file")
674 (string-match "\\.org$" path
)
679 (substring path
0 (match-beginning 0))
681 (plist-get opt-plist
:html-extension
)))))))
684 ;;; org-html-should-inline-p
685 (defun org-html-should-inline-p (filename descp
)
686 "Return non-nil if link FILENAME should be inlined.
687 The decision to inline the FILENAME link is based on the current
688 settings. DESCP is the boolean of whether there was a link
689 description. See variables `org-export-html-inline-images' and
690 `org-export-html-inline-image-extensions'."
692 org-export-html-inline-images
693 org-export-html-inline-image-extensions
))
694 (and (or (eq t org-export-html-inline-images
)
695 (and org-export-html-inline-images
(not descp
)))
697 filename org-export-html-inline-image-extensions
)))
699 ;;; org-html-make-link
700 (defun org-html-make-link (opt-plist type path fragment desc attr
703 OPT-PLIST is an options list.
704 TYPE is the device-type of the link (THIS://foo.html)
705 PATH is the path of the link (http://THIS#locationx)
706 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
707 DESC is the link description, if any.
708 ATTR is a string of other attributes of the a element.
709 MAY-INLINE-P allows inlining it as an image."
711 (declare (special org-par-open
))
713 (let* ((filename path
)
714 ;;First pass. Just sanity stuff.
717 ((string= type
"file")
720 ;;Substitute just if original path was absolute.
721 ;;(Otherwise path must remain relative)
722 (if (file-name-absolute-p path
)
723 (expand-file-name path
)
727 (t (list type path
))))
729 ;;Second pass. Components converted so they can refer
733 (and org-html-cvt-link-fn
734 (apply org-html-cvt-link-fn
735 opt-plist components-1
))
736 (apply #'org-html-cvt-org-as-html
737 opt-plist components-1
)
739 (type (first components-2
))
740 (thefile (second components-2
)))
743 ;;Third pass. Build final link except for leading type
748 (string= type
"http")
749 (string= type
"https"))
751 (setq thefile
(concat thefile
"#" fragment
))))
755 ;;Final URL-build, for all types.
758 ((str (org-export-html-format-href thefile
)))
759 (if (and type
(not (string= "file" type
))
760 (org-string-match-p "^//" str
))
761 (concat type
":" str
)
766 ;;Can't inline a URL with a fragment.
769 (message "image %s %s" thefile org-par-open
)
770 (org-export-html-format-image thefile org-par-open
))
772 "<a href=\"" thefile
"\"" attr
">"
773 (org-export-html-format-desc desc
)
776 ;;; org-export-as-html
778 (defun org-export-as-html (arg &optional hidden ext-plist
779 to-buffer body-only pub-dir
)
780 "Export the outline as a pretty HTML file.
781 If there is an active region, export only the region. The prefix
782 ARG specifies how many levels of the outline should become
783 headlines. The default is 3. Lower levels will become bulleted
784 lists. HIDDEN is obsolete and does nothing.
785 EXT-PLIST is a property list with external parameters overriding
786 org-mode's default settings, but still inferior to file-local
787 settings. When TO-BUFFER is non-nil, create a buffer with that
788 name and export to that buffer. If TO-BUFFER is the symbol
789 `string', don't leave any buffer behind but just return the
790 resulting HTML as a string. When BODY-ONLY is set, don't produce
791 the file header and footer, simply return the content of
792 <body>...</body>, without even the body tags themselves. When
793 PUB-DIR is set, use this as the publishing directory."
795 (run-hooks 'org-export-first-hook
)
797 ;; Make sure we have a file name when we need it.
798 (when (and (not (or to-buffer body-only
))
799 (not buffer-file-name
))
800 (if (buffer-base-buffer)
801 (org-set-local 'buffer-file-name
802 (with-current-buffer (buffer-base-buffer)
804 (error "Need a file name to be able to export")))
806 (message "Exporting...")
807 (setq-default org-todo-line-regexp org-todo-line-regexp
)
808 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
809 (setq-default org-done-keywords org-done-keywords
)
810 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
812 (org-export-process-option-filters
813 (org-combine-plists (org-default-export-plist)
815 (org-infile-export-plist))))
816 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
817 (style (concat (if (plist-get opt-plist
:style-include-default
)
818 org-export-html-style-default
)
819 (plist-get opt-plist
:style
)
820 (plist-get opt-plist
:style-extra
)
822 (if (plist-get opt-plist
:style-include-scripts
)
823 org-export-html-scripts
)))
824 (html-extension (plist-get opt-plist
:html-extension
))
825 (link-validate (plist-get opt-plist
:link-validation-function
))
826 valid thetoc have-headings first-heading-pos
827 (odd org-odd-levels-only
)
828 (region-p (org-region-active-p))
829 (rbeg (and region-p
(region-beginning)))
830 (rend (and region-p
(region-end)))
832 (if (plist-get opt-plist
:ignore-subtree-p
)
837 (and (org-at-heading-p)
838 (>= (org-end-of-subtree t t
) rend
))))))
839 (level-offset (if subtree-p
842 (+ (funcall outline-level
)
843 (if org-odd-levels-only
1 0)))
845 (opt-plist (setq org-export-opt-plist
847 (org-export-add-subtree-options opt-plist rbeg
)
849 ;; The following two are dynamically scoped into other
851 (org-current-export-dir
852 (or pub-dir
(org-export-directory :html opt-plist
)))
853 (org-current-export-file buffer-file-name
)
854 (level 0) (line "") (origline "") txt todo
857 (filename (if to-buffer nil
860 (file-name-sans-extension
862 (org-entry-get (region-beginning)
863 "EXPORT_FILE_NAME" t
))
864 (file-name-nondirectory buffer-file-name
)))
866 (file-name-as-directory
867 (or pub-dir
(org-export-directory :html opt-plist
))))))
868 (current-dir (if buffer-file-name
869 (file-name-directory buffer-file-name
)
871 (buffer (if to-buffer
873 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
874 (t (get-buffer-create to-buffer
)))
875 (find-file-noselect filename
)))
876 (org-levels-open (make-vector org-level-max nil
))
877 (date (plist-get opt-plist
:date
))
878 (author (plist-get opt-plist
:author
))
879 (title (or (and subtree-p
(org-export-get-title-from-subtree))
880 (plist-get opt-plist
:title
)
883 (plist-get opt-plist
:skip-before-1st-heading
))
884 (org-export-grab-title-from-buffer))
885 (and buffer-file-name
886 (file-name-sans-extension
887 (file-name-nondirectory buffer-file-name
)))
889 (link-up (and (plist-get opt-plist
:link-up
)
890 (string-match "\\S-" (plist-get opt-plist
:link-up
))
891 (plist-get opt-plist
:link-up
)))
892 (link-home (and (plist-get opt-plist
:link-home
)
893 (string-match "\\S-" (plist-get opt-plist
:link-home
))
894 (plist-get opt-plist
:link-home
)))
895 (dummy (setq opt-plist
(plist-put opt-plist
:title title
)))
896 (html-table-tag (plist-get opt-plist
:html-table-tag
))
897 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
898 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
903 (local-list-type nil
)
904 (local-list-indent nil
)
905 (llt org-plain-list-ordered-item-terminator
)
906 (email (plist-get opt-plist
:email
))
907 (language (plist-get opt-plist
:language
))
908 (keywords (plist-get opt-plist
:keywords
))
909 (description (plist-get opt-plist
:description
))
913 (coding-system (and (boundp 'buffer-file-coding-system
)
914 buffer-file-coding-system
))
915 (coding-system-for-write (or org-export-html-coding-system
917 (save-buffer-coding-system (or org-export-html-coding-system
919 (charset (and coding-system-for-write
920 (fboundp 'coding-system-get
)
921 (coding-system-get coding-system-for-write
925 (if region-p
(region-beginning) (point-min))
926 (if region-p
(region-end) (point-max))))
927 (org-export-have-math nil
)
930 (org-export-preprocess-string
934 :skip-before-1st-heading
935 (plist-get opt-plist
:skip-before-1st-heading
)
936 :drawers
(plist-get opt-plist
:drawers
)
937 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
938 :tags
(plist-get opt-plist
:tags
)
939 :priority
(plist-get opt-plist
:priority
)
940 :footnotes
(plist-get opt-plist
:footnotes
)
941 :timestamps
(plist-get opt-plist
:timestamps
)
943 (plist-get opt-plist
:archived-trees
)
944 :select-tags
(plist-get opt-plist
:select-tags
)
945 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
947 (plist-get opt-plist
:text
)
949 (plist-get opt-plist
:LaTeX-fragments
))
952 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
953 (and org-export-have-math
954 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
956 (org-export-html-mathjax-config
957 org-export-html-mathjax-template
958 org-export-html-mathjax-options
959 (or (plist-get opt-plist
:mathjax
) ""))
962 table-buffer table-orig-buffer
963 ind item-type starter
964 rpl path attr desc descp desc1 desc2 link
965 snumber fnc item-tag item-number
966 footnotes footref-seen
970 (let ((inhibit-read-only t
))
972 (remove-text-properties (point-min) (point-max)
973 '(:org-license-to-kill t
))))
975 (message "Exporting...")
977 (setq org-min-level
(org-get-min-level lines level-offset
))
978 (setq org-last-level org-min-level
)
979 (org-init-section-numbers)
982 ((and date
(string-match "%" date
))
983 (setq date
(format-time-string date
)))
985 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
987 ;; Get the language-dependent settings
988 (setq lang-words
(or (assoc language org-export-language-setup
)
989 (assoc "en" org-export-language-setup
)))
991 ;; Switch to the output buffer
993 (let ((inhibit-read-only t
)) (erase-buffer))
995 (org-install-letbind)
997 (and (fboundp 'set-buffer-file-coding-system
)
998 (set-buffer-file-coding-system coding-system-for-write
))
1000 (let ((case-fold-search nil
)
1001 (org-odd-levels-only odd
))
1002 ;; create local variables for all options, to make sure all called
1003 ;; functions get the correct information
1005 (set (make-local-variable (nth 2 x
))
1006 (plist-get opt-plist
(car x
))))
1007 org-export-plist-vars
)
1008 (setq umax
(if arg
(prefix-numeric-value arg
)
1009 org-export-headline-levels
))
1010 (setq umax-toc
(if (integerp org-export-with-toc
)
1011 (min org-export-with-toc umax
)
1017 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1018 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1019 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1020 lang=\"%s\" xml:lang=\"%s\">
1023 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1024 <meta name=\"generator\" content=\"Org-mode\"/>
1025 <meta name=\"generated\" content=\"%s\"/>
1026 <meta name=\"author\" content=\"%s\"/>
1027 <meta name=\"description\" content=\"%s\"/>
1028 <meta name=\"keywords\" content=\"%s\"/>
1033 <div id=\"content\">
1037 (or (and (stringp org-export-html-xml-declaration
)
1038 org-export-html-xml-declaration
)
1039 (cdr (assoc html-extension org-export-html-xml-declaration
))
1040 (cdr (assoc "html" org-export-html-xml-declaration
))
1043 (or charset
"iso-8859-1"))
1046 (or charset
"iso-8859-1")
1047 date author description keywords
1050 (if (or link-up link-home
)
1052 (format org-export-html-home
/up-format
1053 (or link-up link-home
)
1054 (or link-home link-up
))
1058 (org-export-html-insert-plist-item opt-plist
:preamble opt-plist
)
1060 (when (plist-get opt-plist
:auto-preamble
)
1061 (if title
(insert (format org-export-html-title-format
1062 (org-html-expand title
))))))
1064 (if (and org-export-with-toc
(not body-only
))
1066 (push (format "<h%d>%s</h%d>\n"
1067 org-export-html-toplevel-hlevel
1069 org-export-html-toplevel-hlevel
)
1071 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
1072 (push "<ul>\n<li>" thetoc
)
1074 (mapcar '(lambda (line)
1075 (if (and (string-match org-todo-line-regexp line
)
1076 (not (get-text-property 0 'org-protected line
)))
1077 ;; This is a headline
1079 (setq have-headings t
)
1080 (setq level
(- (match-end 1) (match-beginning 1)
1082 level
(org-tr-level level
)
1083 txt
(save-match-data
1085 (org-export-cleanup-toc-line
1086 (match-string 3 line
))))
1088 (or (and org-export-mark-todo-in-toc
1090 (not (member (match-string 2 line
)
1091 org-done-keywords
)))
1093 (and org-export-mark-todo-in-toc
1095 (org-search-todo-below
1096 line lines level
))))
1098 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
1099 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
1100 (if (string-match quote-re0 txt
)
1101 (setq txt
(replace-match "" t t txt
)))
1102 (setq snumber
(org-section-number level
))
1103 (if org-export-with-section-numbers
1104 (setq txt
(concat snumber
" " txt
)))
1105 (if (<= level
(max umax umax-toc
))
1106 (setq head-count
(+ head-count
1)))
1107 (if (<= level umax-toc
)
1109 (if (> level org-last-level
)
1111 (setq cnt
(- level org-last-level
))
1112 (while (>= (setq cnt
(1- cnt
)) 0)
1113 (push "\n<ul>\n<li>" thetoc
))
1114 (push "\n" thetoc
)))
1115 (if (< level org-last-level
)
1117 (setq cnt
(- org-last-level level
))
1118 (while (>= (setq cnt
(1- cnt
)) 0)
1119 (push "</li>\n</ul>" thetoc
))
1120 (push "\n" thetoc
)))
1121 ;; Check for targets
1122 (while (string-match org-any-target-regexp line
)
1123 (setq line
(replace-match
1124 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
1126 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
1127 (setq txt
(replace-match "" t t txt
)))
1129 (replace-regexp-in-string
1130 "\\." "_" (format "sec-%s" snumber
)))
1131 (setq href
(or (cdr (assoc href org-export-preferred-target-alist
)) href
))
1135 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1136 "</li>\n<li><a href=\"#%s\">%s</a>")
1139 (setq org-last-level level
))
1143 (while (> org-last-level
(1- org-min-level
))
1144 (setq org-last-level
(1- org-last-level
))
1145 (push "</li>\n</ul>\n" thetoc
))
1146 (push "</div>\n" thetoc
)
1147 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1150 (org-init-section-numbers)
1154 (while (setq line
(pop lines
) origline line
)
1157 ;; end of quote section?
1158 (when (and inquote
(string-match "^\\*+ " line
))
1162 ;; inside a quote section?
1164 (insert (org-html-protect line
) "\n")
1165 (throw 'nextline nil
))
1167 ;; Fixed-width, verbatim lines (examples)
1168 (when (and org-export-with-fixed-width
1169 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
1172 (org-close-par-maybe)
1174 (insert "<pre class=\"example\">\n"))
1175 (insert (org-html-protect (match-string 3 line
)) "\n")
1176 (when (or (not lines
)
1177 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1182 (throw 'nextline nil
))
1184 ;; Explicit list closure
1185 (when (equal "ORG-LIST-END" line
)
1186 (while local-list-indent
1187 (org-close-li (car local-list-type
))
1188 (insert (format "</%sl>\n" (car local-list-type
)))
1189 (pop local-list-type
)
1190 (pop local-list-indent
))
1191 (setq in-local-list nil
)
1193 (throw 'nextline nil
))
1196 (when (get-text-property 0 'org-protected line
)
1197 (let (par (ind (get-text-property 0 'original-indentation line
)))
1198 (when (re-search-backward
1199 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
1200 (setq par
(match-string 1))
1201 (replace-match "\\2\n"))
1204 (or (= (length (car lines
)) 0)
1206 (equal ind
(get-text-property 0 'original-indentation
(car lines
))))
1207 (or (= (length (car lines
)) 0)
1208 (get-text-property 0 'org-protected
(car lines
))))
1209 (insert (pop lines
) "\n"))
1210 (and par
(insert "<p>\n")))
1211 (throw 'nextline nil
))
1213 ;; Blockquotes, verse, and center
1214 (when (equal "ORG-BLOCKQUOTE-START" line
)
1215 (org-close-par-maybe)
1216 (insert "<blockquote>\n")
1218 (throw 'nextline nil
))
1219 (when (equal "ORG-BLOCKQUOTE-END" line
)
1220 (org-close-par-maybe)
1221 (insert "\n</blockquote>\n")
1223 (throw 'nextline nil
))
1224 (when (equal "ORG-VERSE-START" line
)
1225 (org-close-par-maybe)
1226 (insert "\n<p class=\"verse\">\n")
1227 (setq org-par-open t
)
1229 (throw 'nextline nil
))
1230 (when (equal "ORG-VERSE-END" line
)
1232 (setq org-par-open nil
)
1235 (throw 'nextline nil
))
1236 (when (equal "ORG-CENTER-START" line
)
1237 (org-close-par-maybe)
1238 (insert "\n<div style=\"text-align: center\">")
1240 (throw 'nextline nil
))
1241 (when (equal "ORG-CENTER-END" line
)
1242 (org-close-par-maybe)
1245 (throw 'nextline nil
))
1246 (run-hooks 'org-export-html-after-blockquotes-hook
)
1248 (let ((i (org-get-string-indentation line
)))
1250 (setq line
(concat (mapconcat 'identity
1251 (make-list (* 2 i
) "\\nbsp") "")
1252 " " (org-trim line
))))
1253 (unless (string-match "\\\\\\\\[ \t]*$" line
)
1254 (setq line
(concat line
"\\\\")))))
1256 ;; make targets to anchors
1258 (while (string-match
1259 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start
)
1261 ((get-text-property (match-beginning 1) 'org-protected line
)
1262 (setq start
(match-end 1)))
1264 (setq line
(replace-match
1266 "@<a name=\"%s\" id=\"%s\">@</a>"
1267 (org-solidify-link-text (match-string 1 line
))
1268 (org-solidify-link-text (match-string 1 line
)))
1270 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
1271 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1272 (setq line
(replace-match
1273 (concat "@<span class=\"target\">"
1274 (match-string 1 line
) "@</span> ")
1275 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1278 (setq line
(replace-match
1279 (concat "@<a name=\""
1280 (org-solidify-link-text (match-string 1 line
))
1281 "\" class=\"target\">" (match-string 1 line
)
1285 (setq line
(org-html-handle-time-stamps line
))
1287 ;; replace "&" by "&", "<" and ">" by "<" and ">"
1288 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
1289 ;; Also handle sub_superscripts and checkboxes
1290 (or (string-match org-table-hline-regexp line
)
1291 (setq line
(org-html-expand line
)))
1295 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
1296 (setq start
(match-beginning 0))
1297 (setq path
(save-match-data (org-link-unescape
1298 (match-string 3 line
))))
1300 ((match-end 2) (match-string 2 line
))
1302 (or (file-name-absolute-p path
)
1303 (string-match "^\\.\\.?/" path
)))
1306 (setq path
(org-extract-attributes (org-link-unescape path
)))
1307 (setq attr
(get-text-property 0 'org-attributes path
))
1308 (setq desc1
(if (match-end 5) (match-string 5 line
))
1309 desc2
(if (match-end 2) (concat type
":" path
) path
)
1310 descp
(and desc1
(not (equal desc1 desc2
)))
1311 desc
(or desc1 desc2
))
1312 ;; Make an image out of the description if that is so wanted
1313 (when (and descp
(org-file-image-p
1314 desc org-export-html-inline-image-extensions
))
1316 (if (string-match "^file:" desc
)
1317 (setq desc
(substring desc
(match-end 0)))))
1318 (setq desc
(org-add-props
1319 (concat "<img src=\"" desc
"\"/>")
1320 '(org-protected t
))))
1322 ((equal type
"internal")
1325 (if (= (string-to-char path
) ?
#)
1333 (org-solidify-link-text
1334 (save-match-data (org-link-unescape frag-0
))
1337 ((and (equal type
"id")
1338 (setq id-file
(org-id-find-id-file path
)))
1339 ;; This is an id: link to another file (if it was the same file,
1340 ;; it would have become an internal link...)
1342 (setq id-file
(file-relative-name
1344 (file-name-directory org-current-export-file
)))
1346 (org-html-make-link opt-plist
1348 (concat (if (org-uuidgen-p path
) "ID-") path
)
1352 ((member type
'("http" "https"))
1353 ;; standard URL, can inline as image
1355 (org-html-make-link opt-plist
1359 (org-html-should-inline-p path descp
))))
1360 ((member type
'("ftp" "mailto" "news"))
1361 ;; standard URL, can't inline as image
1363 (org-html-make-link opt-plist
1369 ((string= type
"coderef")
1371 ((coderef-str (format "coderef-%s" path
))
1373 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1374 coderef-str coderef-str
)))
1376 (org-html-make-link opt-plist
1379 (org-export-get-coderef-format
1382 (cdr (assoc path org-export-code-refs
)))
1386 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
1387 ;; The link protocol has a function for format the link
1390 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
1392 ((string= type
"file")
1398 (string-match "::\\(.*\\)" path
)
1400 (replace-match "" t nil path
)
1401 (match-string 1 path
))
1404 ;;The proper path, without a fragment
1410 (second components
))
1412 ;;Check the fragment. If it can't be used as
1413 ;;target fragment we'll pass nil instead.
1417 (not (string-match "^[0-9]*$" fragment-0
))
1418 (not (string-match "^\\*" fragment-0
))
1419 (not (string-match "^/.*/$" fragment-0
)))
1420 (org-solidify-link-text
1421 (org-link-unescape fragment-0
))
1424 ;;Description minus "file:" and ".org"
1425 (if (string-match "^file:" desc
)
1427 ((desc-1 (replace-match "" t t desc
)))
1428 (if (string-match "\\.org$" desc-1
)
1429 (replace-match "" t t desc-1
)
1436 (functionp link-validate
)
1437 (not (funcall link-validate path-1 current-dir
)))
1439 (org-html-make-link opt-plist
1440 "file" path-1 fragment-1 desc-2 attr
1441 (org-html-should-inline-p path-1 descp
)))))))
1444 ;; just publish the path, as default
1445 (setq rpl
(concat "<i><" type
":"
1446 (save-match-data (org-link-unescape path
))
1448 (setq line
(replace-match rpl t t line
)
1449 start
(+ start
(length rpl
))))
1452 (if (and (string-match org-todo-line-regexp line
)
1453 (match-beginning 2))
1456 (concat (substring line
0 (match-beginning 2))
1458 (if (member (match-string 2 line
)
1461 " " (match-string 2 line
)
1462 "\"> " (org-export-html-get-todo-kwd-class-name
1463 (match-string 2 line
))
1464 "</span>" (substring line
(match-end 2)))))
1466 ;; Does this contain a reference to a footnote?
1467 (when org-export-with-footnotes
1469 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
1470 (if (get-text-property (match-beginning 2) 'org-protected line
)
1471 (setq start
(match-end 2))
1472 (let ((n (match-string 2 line
)) extra a
)
1473 (if (setq a
(assoc n footref-seen
))
1475 (setcdr a
(1+ (cdr a
)))
1476 (setq extra
(format ".%d" (cdr a
))))
1478 (push (cons n
1) footref-seen
))
1483 (format org-export-html-footnote-format
1484 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"))
1485 (or (match-string 1 line
) "") n extra n n
)
1489 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1490 ;; This is a headline
1491 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1493 txt
(match-string 2 line
))
1494 (if (string-match quote-re0 txt
)
1495 (setq txt
(replace-match "" t t txt
)))
1496 (if (<= level
(max umax umax-toc
))
1497 (setq head-count
(+ head-count
1)))
1498 (setq first-heading-pos
(or first-heading-pos
(point)))
1499 (org-html-level-start level txt umax
1500 (and org-export-with-toc
(<= level umax
))
1504 (when (string-match quote-re line
)
1505 (org-close-par-maybe)
1509 ((and org-export-with-tables
1510 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1511 (when (not table-open
)
1513 (setq table-open t table-buffer nil table-orig-buffer nil
))
1516 (setq table-buffer
(cons line table-buffer
)
1517 table-orig-buffer
(cons origline table-orig-buffer
))
1518 (when (or (not lines
)
1519 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1521 (setq table-open nil
1522 table-buffer
(nreverse table-buffer
)
1523 table-orig-buffer
(nreverse table-orig-buffer
))
1524 (org-close-par-maybe)
1525 (insert (org-format-table-html table-buffer table-orig-buffer
))))
1530 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1531 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1532 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1533 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
1535 (setq ind
(or (get-text-property 0 'original-indentation line
)
1536 (org-get-string-indentation line
))
1537 item-type
(if (match-beginning 4) "o" "u")
1538 starter
(if (match-beginning 2)
1539 (substring (match-string 2 line
) 0 -
1))
1540 line
(substring line
(match-beginning 5))
1543 (if (string-match "\\[@\\(?:start:\\)?\\([0-9]+\\)\\][ \t]?" line
)
1544 (setq item-number
(match-string 1 line
)
1545 line
(replace-match "" t t line
)))
1546 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
1548 item-tag
(match-string 1 line
)
1549 line
(substring line
(match-end 0))))
1552 (or (not in-local-list
)
1553 (> ind
(car local-list-indent
))))
1554 ;; Start new (level of) list
1555 (org-close-par-maybe)
1557 ((equal item-type
"u") "<ul>\n<li>\n")
1558 ((and (equal item-type
"o") item-number
)
1559 (format "<ol>\n<li value=\"%s\">\n" item-number
))
1560 ((equal item-type
"o") "<ol>\n<li>\n")
1561 ((equal item-type
"d")
1562 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
1563 (push item-type local-list-type
)
1564 (push ind local-list-indent
)
1565 (setq in-local-list t
))
1568 ;; terminate any previous sublist but first ensure
1569 ;; list is not ill-formed.
1570 (let ((min-ind (apply 'min local-list-indent
)))
1571 (when (< ind min-ind
) (setq ind min-ind
)))
1572 (while (< ind
(car local-list-indent
))
1573 (org-close-li (car local-list-type
))
1574 (insert (format "</%sl>\n" (car local-list-type
)))
1575 (pop local-list-type
) (pop local-list-indent
)
1576 (setq in-local-list local-list-indent
))
1578 (org-close-li (car local-list-type
))
1580 ((equal (car local-list-type
) "d")
1581 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
1582 ((and (equal item-type
"o") item-number
)
1583 (format "<li value=\"%s\">\n" item-number
))
1585 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
1588 (if (equal (match-string 1 line
) "X")
1590 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
1594 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
1596 (insert "\n</p>\n<hr/>\n<p>\n")
1597 (insert "\n<hr/>\n"))
1598 (throw 'nextline nil
))
1600 ;; Empty lines start a new paragraph. If hand-formatted lists
1601 ;; are not fully interpreted, lines starting with "-", "+", "*"
1602 ;; also start a new paragraph.
1603 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
1605 ;; Is this the start of a footnote?
1606 (when org-export-with-footnotes
1607 (when (and (boundp 'footnote-section-tag-regexp
)
1608 (string-match (concat "^" footnote-section-tag-regexp
)
1611 (throw 'nextline nil
))
1612 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1613 (org-close-par-maybe)
1614 (let ((n (match-string 1 line
)))
1615 (setq org-par-open t
1618 (concat "<p class=\"footnote\">"
1619 (format org-export-html-footnote-format
1620 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1621 n n n
) t t line
)))))
1622 ;; Check if the line break needs to be conserved
1624 ((string-match "\\\\\\\\[ \t]*$" line
)
1625 (setq line
(replace-match "<br/>" t t line
)))
1626 (org-export-preserve-breaks
1627 (setq line
(concat line
"<br/>"))))
1629 ;; Check if a paragraph should be started
1631 (while (and org-par-open
1632 (string-match "\\\\par\\>" line start
))
1633 ;; Leave a space in the </p> so that the footnote matcher
1634 ;; does not see this.
1635 (if (not (get-text-property (match-beginning 0)
1636 'org-protected line
))
1637 (setq line
(replace-match "</p ><p >" t t line
)))
1638 (setq start
(match-end 0))))
1640 (insert line
"\n")))))
1642 ;; Properly close all local lists and other lists
1647 (org-html-level-start 1 nil umax
1648 (and org-export-with-toc
(<= level umax
))
1650 ;; the </div> to close the last text-... div.
1651 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
1654 (goto-char (point-min))
1655 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
1656 (push (match-string 0) footnotes
)
1657 (replace-match "" t t
)))
1659 (insert (format org-export-html-footnotes-section
1661 (mapconcat 'identity
(nreverse footnotes
) "\n"))
1663 (let ((bib (org-export-html-get-bibliography)))
1665 (insert "\n" bib
"\n")))
1667 (when (plist-get opt-plist
:auto-postamble
)
1668 (insert "<div id=\"postamble\">\n")
1669 (when (and org-export-author-info author
)
1670 (insert "<p class=\"author\"> "
1671 (nth 1 lang-words
) ": " author
"\n")
1672 (when (and org-export-email-info email
(string-match "\\S-" email
))
1673 (if (listp (split-string email
",+ *"))
1675 (insert "<a href=\"mailto:" e
"\"><"
1677 (split-string email
",+ *"))
1678 (insert "<a href=\"mailto:" email
"\"><"
1679 email
"></a>\n")))
1681 (when (and date org-export-time-stamp-file
)
1682 (insert "<p class=\"date\"> "
1683 (nth 2 lang-words
) ": "
1685 (when org-export-creator-info
1686 (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
1687 org-version emacs-major-version
)))
1688 (when org-export-html-validation-link
1689 (insert org-export-html-validation-link
"\n"))
1692 (if org-export-html-with-timestamp
1693 (insert org-export-html-html-helper-timestamp
))
1694 (org-export-html-insert-plist-item opt-plist
:postamble opt-plist
)
1695 (insert "\n</div>\n</body>\n</html>\n"))
1697 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1699 (if (eq major-mode
(default-value 'major-mode
))
1702 ;; insert the table of contents
1703 (goto-char (point-min))
1705 (if (or (re-search-forward
1706 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1708 "\\[TABLE-OF-CONTENTS\\]" nil t
))
1710 (goto-char (match-beginning 0))
1712 (goto-char first-heading-pos
)
1713 (when (looking-at "\\s-*</p>")
1714 (goto-char (match-end 0))
1716 (insert "<div id=\"table-of-contents\">\n")
1717 (mapc 'insert thetoc
)
1718 (insert "</div>\n"))
1719 ;; remove empty paragraphs and lists
1720 (goto-char (point-min))
1721 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
1723 (goto-char (point-min))
1724 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
1726 (goto-char (point-min))
1727 ;; Convert whitespace place holders
1728 (goto-char (point-min))
1730 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1731 (setq n
(get-text-property beg
'org-whitespace
)
1732 end
(next-single-property-change beg
'org-whitespace
))
1734 (delete-region beg end
)
1735 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1736 (make-string n ?x
)))))
1737 ;; Remove empty lines at the beginning of the file.
1738 (goto-char (point-min))
1739 (when (looking-at "\\s-+\n") (replace-match ""))
1740 ;; Remove display properties
1741 (remove-text-properties (point-min) (point-max) '(display t
))
1743 (run-hooks 'org-export-html-final-hook
)
1744 (or to-buffer
(save-buffer))
1745 (goto-char (point-min))
1746 (or (org-export-push-to-kill-ring "HTML")
1747 (message "Exporting... done"))
1748 (if (eq to-buffer
'string
)
1749 (prog1 (buffer-substring (point-min) (point-max))
1750 (kill-buffer (current-buffer)))
1751 (current-buffer)))))
1753 (defun org-export-html-insert-plist-item (plist key
&rest args
)
1754 (let ((item (plist-get plist key
)))
1755 (cond ((functionp item
)
1760 (defun org-export-html-format-href (s)
1761 "Make sure the S is valid as a href reference in an XHTML document."
1764 (while (string-match "&" s start
)
1765 (setq start
(+ (match-beginning 0) 3)
1766 s
(replace-match "&" t t s
)))))
1769 (defun org-export-html-format-desc (s)
1770 "Make sure the S is valid as a description in a link."
1771 (if (and s
(not (get-text-property 1 'org-protected s
)))
1773 (org-html-do-expand s
))
1776 (defun org-export-html-format-image (src par-open
)
1777 "Create image tag with source and attributes."
1779 (if (string-match "^ltxpng/" src
)
1780 (format "<img src=\"%s\" alt=\"%s\"/>"
1781 src
(org-find-text-property-in-string 'org-latex-src src
))
1782 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1783 (attr (org-find-text-property-in-string 'org-attributes src
))
1784 (label (org-find-text-property-in-string 'org-label src
)))
1785 (setq caption
(and caption
(org-html-do-expand caption
)))
1788 (format "%s<div %sclass=\"figure\">
1790 (if org-par-open
"</p>\n" "")
1791 (if label
(format "id=\"%s\" " label
) "")))
1792 (format "<img src=\"%s\"%s />"
1794 (if (string-match "\\<alt=" (or attr
""))
1796 (concat " " attr
" alt=\"" src
"\"")))
1800 (concat "\n<p>" caption
"</p>")
1801 (if org-par-open
"\n<p>" ""))))))))
1803 (defun org-export-html-get-bibliography ()
1804 "Find bibliography, cut it out and return it."
1806 (let (beg end
(cnt 1) bib
)
1808 (goto-char (point-min))
1809 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1810 (setq beg
(match-beginning 0))
1811 (while (re-search-forward "</?div\\>" nil t
)
1812 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1814 (and (looking-at ">") (forward-char 1))
1815 (setq bib
(buffer-substring beg
(point)))
1816 (delete-region beg
(point))
1817 (throw 'exit bib
))))
1820 (defvar org-table-number-regexp
) ; defined in org-table.el
1821 (defun org-format-table-html (lines olines
)
1822 "Find out which HTML converter to use and return the HTML code."
1824 (setq lines
(org-split-string lines
"\n")))
1825 (if (string-match "^[ \t]*|" (car lines
))
1826 ;; A normal org table
1827 (org-format-org-table-html lines
)
1828 ;; Table made by table.el - test for spanning
1829 (let* ((hlines (delq nil
(mapcar
1831 (if (string-match "^[ \t]*\\+-" x
) x
1834 (first (car hlines
))
1835 (ll (and (string-match "\\S-+" first
)
1836 (match-string 0 first
)))
1837 (re (concat "^[ \t]*" (regexp-quote ll
)))
1838 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
1840 (if (and (not spanning
)
1841 (not org-export-prefer-native-exporter-for-tables
))
1842 ;; We can use my own converter with HTML conversions
1843 (org-format-table-table-html lines
)
1844 ;; Need to use the code generator in table.el, with the original text.
1845 (org-format-table-table-html-using-table-generate-source olines
)))))
1847 (defvar org-table-number-fraction
) ; defined in org-table.el
1848 (defun org-format-org-table-html (lines &optional splice
)
1849 "Format a table into HTML."
1850 (require 'org-table
)
1851 ;; Get rid of hlines at beginning and end
1852 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1853 (setq lines
(nreverse lines
))
1854 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1855 (setq lines
(nreverse lines
))
1856 (when org-export-table-remove-special-lines
1857 ;; Check if the table has a marking column. If yes remove the
1858 ;; column and the special lines
1859 (setq lines
(org-table-clean-before-export lines
)))
1861 (let* ((caption (org-find-text-property-in-string 'org-caption
(car lines
)))
1862 (label (org-find-text-property-in-string 'org-label
(car lines
)))
1863 (attributes (org-find-text-property-in-string 'org-attributes
1865 (html-table-tag (org-export-splice-attributes
1866 html-table-tag attributes
))
1867 (head (and org-export-highlight-first-table-line
1869 (lambda (x) (string-match "^[ \t]*|-" x
))
1872 (nline 0) fnum nfields i
1873 tbopen line fields html gr colgropen rowstart rowend
)
1874 (setq caption
(and caption
(org-html-do-expand caption
)))
1875 (if splice
(setq head nil
))
1876 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
1878 (while (setq line
(pop lines
))
1880 (if (string-match "^[ \t]*|-" line
)
1883 (push (if head
"</thead>" "</tbody>") html
)
1884 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
1885 (setq head nil
) ;; head ends here, first time around
1887 (throw 'next-line t
)))
1888 ;; Break the line into fields
1889 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
1890 (unless fnum
(setq fnum
(make-vector (length fields
) 0)
1891 nfields
(length fnum
)))
1892 (setq nline
(1+ nline
) i -
1
1893 rowstart
(eval (car org-export-table-row-tags
))
1894 rowend
(eval (cdr org-export-table-row-tags
)))
1895 (push (concat rowstart
1899 (if (and (< i nfields
) ; make sure no rogue line causes an error here
1900 (string-match org-table-number-regexp x
))
1901 (incf (aref fnum i
)))
1905 (format (car org-export-table-header-tags
) "col")
1907 (cdr org-export-table-header-tags
)))
1908 ((and (= i
0) org-export-html-table-use-header-tags-for-first-column
)
1910 (format (car org-export-table-header-tags
) "row")
1912 (cdr org-export-table-header-tags
)))
1914 (concat (car org-export-table-data-tags
) x
1915 (cdr org-export-table-data-tags
)))))
1919 (unless splice
(if tbopen
(push "</tbody>" html
)))
1920 (unless splice
(push "</table>\n" html
))
1921 (setq html
(nreverse html
))
1923 ;; Put in col tags with the alignment (unfortunately often ignored...)
1924 (unless (car org-table-colgroup-info
)
1925 (setq org-table-colgroup-info
1926 (cons :start
(cdr org-table-colgroup-info
))))
1929 (setq gr
(pop org-table-colgroup-info
))
1930 (format "%s<col align=\"%s\" />%s"
1931 (if (memq gr
'(:start
:startend
))
1933 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
1936 (if (> (/ (float x
) nline
) org-table-number-fraction
)
1938 (if (memq gr
'(:end
:startend
))
1939 (progn (setq colgropen nil
) "</colgroup>")
1943 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
1944 ;; Since the output of HTML table formatter can also be used in
1945 ;; DocBook document, we want to always include the caption to make
1946 ;; DocBook XML file valid.
1947 (push (format "<caption>%s</caption>" (or caption
"")) html
)
1948 (when label
(push (format "<a name=\"%s\" id=\"%s\"></a>" label label
)
1950 (push html-table-tag html
))
1951 (concat (mapconcat 'identity html
"\n") "\n")))
1953 (defun org-export-splice-attributes (tag attributes
)
1954 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1955 (if (not attributes
)
1957 (let (oldatt newatt
)
1958 (setq oldatt
(org-extract-attributes-from-string tag
)
1960 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1962 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1963 (if (string-match ">" tag
)
1965 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1969 (defun org-format-table-table-html (lines)
1970 "Format a table generated by table.el into HTML.
1971 This conversion does *not* use `table-generate-source' from table.el.
1972 This has the advantage that Org-mode's HTML conversions can be used.
1973 But it has the disadvantage, that no cell- or row-spanning is allowed."
1974 (let (line field-buffer
1975 (head org-export-highlight-first-table-line
)
1976 fields html empty i
)
1977 (setq html
(concat html-table-tag
"\n"))
1978 (while (setq line
(pop lines
))
1979 (setq empty
" ")
1981 (if (string-match "^[ \t]*\\+-" line
)
1992 (if (equal x
"") (setq x empty
))
1995 (format (car org-export-table-header-tags
) "col")
1997 (cdr org-export-table-header-tags
))
1998 (concat (car org-export-table-data-tags
) x
1999 (cdr org-export-table-data-tags
))))
2003 (setq field-buffer nil
)))
2005 (throw 'next-line t
)))
2006 ;; Break the line into fields and store the fields
2007 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
2009 (setq field-buffer
(mapcar
2011 (concat x
"<br/>" (pop fields
)))
2013 (setq field-buffer fields
))))
2014 (setq html
(concat html
"</table>\n"))
2017 (defun org-format-table-table-html-using-table-generate-source (lines)
2018 "Format a table into html, using `table-generate-source' from table.el.
2019 This has the advantage that cell- or row-spanning is allowed.
2020 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
2022 (with-current-buffer (get-buffer-create " org-tmp1 ")
2024 (insert (mapconcat 'identity lines
"\n"))
2025 (goto-char (point-min))
2026 (if (not (re-search-forward "|[^+]" nil t
))
2027 (error "Error processing table"))
2028 (table-recognize-table)
2029 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2030 (table-generate-source 'html
" org-tmp2 ")
2031 (set-buffer " org-tmp2 ")
2032 (buffer-substring (point-min) (point-max))))
2034 (defun org-export-splice-style (style extra
)
2035 "Splice EXTRA into STYLE, just before \"</style>\"."
2036 (if (and (stringp extra
)
2037 (string-match "\\S-" extra
)
2038 (string-match "</style>" style
))
2039 (concat (substring style
0 (match-beginning 0))
2041 (substring style
(match-beginning 0)))
2044 (defun org-html-handle-time-stamps (s)
2045 "Format time stamps in string S, or remove them."
2048 (while (string-match org-maybe-keyword-time-regexp s
)
2049 (or b
(setq b
(substring s
0 (match-beginning 0))))
2051 r
(substring s
0 (match-beginning 0))
2052 " @<span class=\"timestamp-wrapper\">"
2054 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2055 (match-string 1 s
)))
2056 (format " @<span class=\"timestamp\">%s@</span>"
2058 (org-translate-time (match-string 3 s
)) 1 -
1))
2060 s
(substring s
(match-end 0))))
2061 ;; Line break if line started and ended with time stamp stuff
2064 (setq r
(concat r s
))
2065 (unless (string-match "\\S-" (concat b s
))
2066 (setq r
(concat r
"@<br/>")))
2069 (defvar htmlize-buffer-places
) ; from htmlize.el
2070 (defun org-export-htmlize-region-for-paste (beg end
)
2071 "Convert the region to HTML, using htmlize.el.
2072 This is much like `htmlize-region-for-paste', only that it uses
2073 the settings define in the org-... variables."
2074 (let* ((htmlize-output-type org-export-htmlize-output-type
)
2075 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
2076 (htmlbuf (htmlize-region beg end
)))
2078 (with-current-buffer htmlbuf
2079 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
2080 (plist-get htmlize-buffer-places
'content-end
)))
2081 (kill-buffer htmlbuf
))))
2084 (defun org-export-htmlize-generate-css ()
2085 "Create the CSS for all font definitions in the current Emacs session.
2086 Use this to create face definitions in your CSS style file that can then
2087 be used by code snippets transformed by htmlize.
2088 This command just produces a buffer that contains class definitions for all
2089 faces used in the current Emacs session. You can copy and paste the ones you
2090 need into your CSS file.
2092 If you then set `org-export-htmlize-output-type' to `css', calls to
2093 the function `org-export-htmlize-region-for-paste' will produce code
2094 that uses these same face definitions."
2097 (and (get-buffer "*html*") (kill-buffer "*html*"))
2099 (let ((fl (face-list))
2100 (htmlize-css-name-prefix "org-")
2101 (htmlize-output-type 'css
)
2103 (while (setq f
(pop fl
)
2104 i
(and f
(face-attribute f
:inherit
)))
2105 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
2106 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
2107 (htmlize-region (point-min) (point-max))))
2108 (switch-to-buffer "*html*")
2109 (goto-char (point-min))
2110 (if (re-search-forward "<style" nil t
)
2111 (delete-region (point-min) (match-beginning 0)))
2112 (if (re-search-forward "</style>" nil t
)
2113 (delete-region (1+ (match-end 0)) (point-max)))
2114 (beginning-of-line 1)
2115 (if (looking-at " +") (replace-match ""))
2116 (goto-char (point-min)))
2118 (defun org-html-protect (s)
2119 "convert & to &, < to < and > to >"
2121 (while (string-match "&" s start
)
2122 (setq s
(replace-match "&" t t s
)
2123 start
(1+ (match-beginning 0))))
2124 (while (string-match "<" s
)
2125 (setq s
(replace-match "<" t t s
)))
2126 (while (string-match ">" s
)
2127 (setq s
(replace-match ">" t t s
)))
2128 ; (while (string-match "\"" s)
2129 ; (setq s (replace-match """ t t s)))
2133 (defun org-html-expand (string)
2134 "Prepare STRING for HTML export. Apply all active conversions.
2135 If there are links in the string, don't modify these."
2136 (let* ((re (concat org-bracket-link-regexp
"\\|"
2137 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2139 (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string
)
2141 (while (setq m
(string-match re string
))
2142 (setq s
(substring string
0 m
)
2143 l
(match-string 0 string
)
2144 string
(substring string
(match-end 0)))
2145 (push (org-html-do-expand s
) res
)
2147 (push (org-html-do-expand string
) res
)
2148 (apply 'concat
(nreverse res
)))))
2150 (defun org-html-do-expand (s)
2151 "Apply all active conversions to translate special ASCII to HTML."
2152 (setq s
(org-html-protect s
))
2153 (if org-export-html-expand
2154 (while (string-match "@<\\([^&]*\\)>" s
)
2155 (setq s
(replace-match "<\\1>" t nil s
))))
2156 (if org-export-with-emphasize
2157 (setq s
(org-export-html-convert-emphasize s
)))
2158 (if org-export-with-special-strings
2159 (setq s
(org-export-html-convert-special-strings s
)))
2160 (if org-export-with-sub-superscripts
2161 (setq s
(org-export-html-convert-sub-super s
)))
2162 (if org-export-with-TeX-macros
2163 (let ((start 0) wd rep
)
2164 (while (setq start
(string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2166 (if (get-text-property (match-beginning 0) 'org-protected s
)
2167 (setq start
(match-end 0))
2168 (setq wd
(match-string 1 s
))
2169 (if (setq rep
(org-entity-get-representation wd
'html
))
2170 (setq s
(replace-match rep t t s
))
2171 (setq start
(+ start
(length wd
))))))))
2174 (defun org-export-html-convert-special-strings (string)
2175 "Convert special characters in STRING to HTML."
2176 (let ((all org-export-html-special-string-regexps
)
2178 (while (setq a
(pop all
))
2179 (setq re
(car a
) rpl
(cdr a
) start
0)
2180 (while (string-match re string start
)
2181 (if (get-text-property (match-beginning 0) 'org-protected string
)
2182 (setq start
(match-end 0))
2183 (setq string
(replace-match rpl t nil string
)))))
2186 (defun org-export-html-convert-sub-super (string)
2187 "Convert sub- and superscripts in STRING to HTML."
2188 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
2189 (while (string-match org-match-substring-regexp string s
)
2191 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
2192 ((get-text-property (match-beginning 2) 'org-protected string
)
2193 (setq s
(match-end 2)))
2195 (setq s
(match-end 1)
2196 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
2197 c
(or (match-string 8 string
)
2198 (match-string 6 string
)
2199 (match-string 5 string
))
2200 string
(replace-match
2201 (concat (match-string 1 string
)
2202 "<" key
">" c
"</" key
">")
2204 (while (string-match "\\\\\\([_^]\\)" string
)
2205 (setq string
(replace-match (match-string 1 string
) t t string
)))
2208 (defun org-export-html-convert-emphasize (string)
2211 (while (string-match org-emph-re string s
)
2213 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
2214 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
2215 (setq s
(match-beginning 0)
2218 (match-string 1 string
)
2219 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
2220 (match-string 4 string
)
2221 (nth 3 (assoc (match-string 3 string
)
2222 org-emphasis-alist
))
2223 (match-string 5 string
))
2224 string
(replace-match rpl t t string
)
2225 s
(+ s
(- (length rpl
) 2)))
2229 (defun org-open-par ()
2230 "Insert <p>, but first close previous paragraph if any."
2231 (org-close-par-maybe)
2233 (setq org-par-open t
))
2234 (defun org-close-par-maybe ()
2235 "Close paragraph if there is one open."
2238 (setq org-par-open nil
)))
2239 (defun org-close-li (&optional type
)
2240 "Close <li> if necessary."
2241 (org-close-par-maybe)
2242 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
2244 (defvar in-local-list
)
2245 (defvar local-list-indent
)
2246 (defvar local-list-type
)
2248 (defvar body-only
) ; dynamically scoped into this.
2249 (defun org-html-level-start (level title umax with-toc head-count
)
2250 "Insert a new level in HTML export.
2251 When TITLE is nil, just close all open levels."
2252 (org-close-par-maybe)
2253 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
2254 (extra-targets (and target
2255 (assoc target org-export-target-aliases
)))
2256 (extra-class (and title
(org-get-text-property-any 0 'html-container-class title
)))
2257 (preferred (and target
2258 (cdr (assoc target org-export-preferred-target-alist
))))
2259 (remove (or preferred target
))
2261 snumber snu href suffix
)
2262 (setq extra-targets
(remove remove extra-targets
))
2264 (mapconcat (lambda (x)
2265 (if (org-uuidgen-p x
) (setq x
(concat "ID-" x
)))
2266 (format "<a name=\"%s\" id=\"%s\"></a>"
2271 (if (aref org-levels-open
(1- l
))
2273 (org-html-level-close l umax
)
2274 (aset org-levels-open
(1- l
) nil
)))
2277 ;; If title is nil, this means this function is called to close
2278 ;; all levels, so the rest is done only if title is given
2279 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
2280 (setq title
(replace-match
2281 (if org-export-with-tags
2284 " <span class=\"tag\">"
2287 (format "<span class=\"%s\">%s</span>"
2288 (org-export-html-get-tag-class-name x
)
2290 (org-split-string (match-string 1 title
) ":")
2297 (if (aref org-levels-open
(1- level
))
2301 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
2302 (insert "<li>" title
"<br/>\n")))
2303 (aset org-levels-open
(1- level
) t
)
2304 (org-close-par-maybe)
2306 (insert (format "<ul>\n<li id=\"%s\">" target
)
2307 extra-targets title
"<br/>\n")
2308 (insert "<ul>\n<li>" title
"<br/>\n"))))
2309 (aset org-levels-open
(1- level
) t
)
2310 (setq snumber
(org-section-number level
)
2311 snu
(replace-regexp-in-string "\\." "_" snumber
))
2312 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
2313 (if (and org-export-with-section-numbers
(not body-only
))
2315 (format "<span class=\"section-number-%d\">%s</span>"
2318 (unless (= head-count
1) (insert "\n</div>\n"))
2319 (setq href
(cdr (assoc (concat "sec-" snu
) org-export-preferred-target-alist
)))
2320 (setq suffix
(or href snu
))
2321 (setq href
(or href
(concat "sec-" snu
)))
2322 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d%s\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
2323 suffix level
(if extra-class
(concat " " extra-class
) "")
2326 title level level suffix
))
2329 (defun org-export-html-get-tag-class-name (tag)
2330 "Turn tag into a valid class name.
2331 Replaces invalid characters with \"_\" and then prepends a prefix."
2333 (while (string-match "[^a-zA-Z0-9_]" tag
)
2334 (setq tag
(replace-match "_" t t tag
))))
2335 (concat org-export-html-tag-class-prefix tag
))
2337 (defun org-export-html-get-todo-kwd-class-name (kwd)
2338 "Turn todo keyword into a valid class name.
2339 Replaces invalid characters with \"_\" and then prepends a prefix."
2341 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2342 (setq kwd
(replace-match "_" t t kwd
))))
2343 (concat org-export-html-todo-kwd-class-prefix kwd
))
2345 (defun org-html-level-close (level max-outline-level
)
2346 "Terminate one level in HTML export."
2347 (if (<= level max-outline-level
)
2350 (insert "</ul>\n")))
2354 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
2355 ;;; org-html.el ends here