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" "svg")
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 "Postamble, 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 (concat "file://" (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 (concat type
":" str
)
765 ;;Can't inline a URL with a fragment.
768 (message "image %s %s" thefile org-par-open
)
769 (org-export-html-format-image thefile org-par-open
))
771 "<a href=\"" thefile
"\"" attr
">"
772 (org-export-html-format-desc desc
)
775 ;;; org-export-as-html
777 (defun org-export-as-html (arg &optional hidden ext-plist
778 to-buffer body-only pub-dir
)
779 "Export the outline as a pretty HTML file.
780 If there is an active region, export only the region. The prefix
781 ARG specifies how many levels of the outline should become
782 headlines. The default is 3. Lower levels will become bulleted
783 lists. HIDDEN is obsolete and does nothing.
784 EXT-PLIST is a property list with external parameters overriding
785 org-mode's default settings, but still inferior to file-local
786 settings. When TO-BUFFER is non-nil, create a buffer with that
787 name and export to that buffer. If TO-BUFFER is the symbol
788 `string', don't leave any buffer behind but just return the
789 resulting HTML as a string. When BODY-ONLY is set, don't produce
790 the file header and footer, simply return the content of
791 <body>...</body>, without even the body tags themselves. When
792 PUB-DIR is set, use this as the publishing directory."
794 (run-hooks 'org-export-first-hook
)
796 ;; Make sure we have a file name when we need it.
797 (when (and (not (or to-buffer body-only
))
798 (not buffer-file-name
))
799 (if (buffer-base-buffer)
800 (org-set-local 'buffer-file-name
801 (with-current-buffer (buffer-base-buffer)
803 (error "Need a file name to be able to export")))
805 (message "Exporting...")
806 (setq-default org-todo-line-regexp org-todo-line-regexp
)
807 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
808 (setq-default org-done-keywords org-done-keywords
)
809 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
811 (org-export-process-option-filters
812 (org-combine-plists (org-default-export-plist)
814 (org-infile-export-plist))))
815 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
816 (style (concat (if (plist-get opt-plist
:style-include-default
)
817 org-export-html-style-default
)
818 (plist-get opt-plist
:style
)
819 (plist-get opt-plist
:style-extra
)
821 (if (plist-get opt-plist
:style-include-scripts
)
822 org-export-html-scripts
)))
823 (html-extension (plist-get opt-plist
:html-extension
))
824 (link-validate (plist-get opt-plist
:link-validation-function
))
825 valid thetoc have-headings first-heading-pos
826 (odd org-odd-levels-only
)
827 (region-p (org-region-active-p))
828 (rbeg (and region-p
(region-beginning)))
829 (rend (and region-p
(region-end)))
831 (if (plist-get opt-plist
:ignore-subtree-p
)
836 (and (org-at-heading-p)
837 (>= (org-end-of-subtree t t
) rend
))))))
838 (level-offset (if subtree-p
841 (+ (funcall outline-level
)
842 (if org-odd-levels-only
1 0)))
844 (opt-plist (setq org-export-opt-plist
846 (org-export-add-subtree-options opt-plist rbeg
)
848 ;; The following two are dynamically scoped into other
850 (org-current-export-dir
851 (or pub-dir
(org-export-directory :html opt-plist
)))
852 (org-current-export-file buffer-file-name
)
853 (level 0) (line "") (origline "") txt todo
856 (filename (if to-buffer nil
859 (file-name-sans-extension
861 (org-entry-get (region-beginning)
862 "EXPORT_FILE_NAME" t
))
863 (file-name-nondirectory buffer-file-name
)))
865 (file-name-as-directory
866 (or pub-dir
(org-export-directory :html opt-plist
))))))
867 (current-dir (if buffer-file-name
868 (file-name-directory buffer-file-name
)
870 (buffer (if to-buffer
872 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
873 (t (get-buffer-create to-buffer
)))
874 (find-file-noselect filename
)))
875 (org-levels-open (make-vector org-level-max nil
))
876 (date (plist-get opt-plist
:date
))
877 (author (plist-get opt-plist
:author
))
878 (title (or (and subtree-p
(org-export-get-title-from-subtree))
879 (plist-get opt-plist
:title
)
882 (plist-get opt-plist
:skip-before-1st-heading
))
883 (org-export-grab-title-from-buffer))
884 (and buffer-file-name
885 (file-name-sans-extension
886 (file-name-nondirectory buffer-file-name
)))
888 (link-up (and (plist-get opt-plist
:link-up
)
889 (string-match "\\S-" (plist-get opt-plist
:link-up
))
890 (plist-get opt-plist
:link-up
)))
891 (link-home (and (plist-get opt-plist
:link-home
)
892 (string-match "\\S-" (plist-get opt-plist
:link-home
))
893 (plist-get opt-plist
:link-home
)))
894 (dummy (setq opt-plist
(plist-put opt-plist
:title title
)))
895 (html-table-tag (plist-get opt-plist
:html-table-tag
))
896 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
897 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
902 (local-list-type nil
)
903 (local-list-indent nil
)
904 (llt org-plain-list-ordered-item-terminator
)
905 (email (plist-get opt-plist
:email
))
906 (language (plist-get opt-plist
:language
))
907 (keywords (plist-get opt-plist
:keywords
))
908 (description (plist-get opt-plist
:description
))
912 (coding-system (and (boundp 'buffer-file-coding-system
)
913 buffer-file-coding-system
))
914 (coding-system-for-write (or org-export-html-coding-system
916 (save-buffer-coding-system (or org-export-html-coding-system
918 (charset (and coding-system-for-write
919 (fboundp 'coding-system-get
)
920 (coding-system-get coding-system-for-write
924 (if region-p
(region-beginning) (point-min))
925 (if region-p
(region-end) (point-max))))
926 (org-export-have-math nil
)
929 (org-export-preprocess-string
933 :skip-before-1st-heading
934 (plist-get opt-plist
:skip-before-1st-heading
)
935 :drawers
(plist-get opt-plist
:drawers
)
936 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
937 :tags
(plist-get opt-plist
:tags
)
938 :priority
(plist-get opt-plist
:priority
)
939 :footnotes
(plist-get opt-plist
:footnotes
)
940 :timestamps
(plist-get opt-plist
:timestamps
)
942 (plist-get opt-plist
:archived-trees
)
943 :select-tags
(plist-get opt-plist
:select-tags
)
944 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
946 (plist-get opt-plist
:text
)
948 (plist-get opt-plist
:LaTeX-fragments
))
951 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
952 (and org-export-have-math
953 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
955 (org-export-html-mathjax-config
956 org-export-html-mathjax-template
957 org-export-html-mathjax-options
958 (or (plist-get opt-plist
:mathjax
) ""))
961 table-buffer table-orig-buffer
962 ind item-type starter
963 rpl path attr desc descp desc1 desc2 link
964 snumber fnc item-tag item-number
965 footnotes footref-seen
969 (let ((inhibit-read-only t
))
971 (remove-text-properties (point-min) (point-max)
972 '(:org-license-to-kill t
))))
974 (message "Exporting...")
976 (setq org-min-level
(org-get-min-level lines level-offset
))
977 (setq org-last-level org-min-level
)
978 (org-init-section-numbers)
981 ((and date
(string-match "%" date
))
982 (setq date
(format-time-string date
)))
984 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
986 ;; Get the language-dependent settings
987 (setq lang-words
(or (assoc language org-export-language-setup
)
988 (assoc "en" org-export-language-setup
)))
990 ;; Switch to the output buffer
992 (let ((inhibit-read-only t
)) (erase-buffer))
994 (org-install-letbind)
996 (and (fboundp 'set-buffer-file-coding-system
)
997 (set-buffer-file-coding-system coding-system-for-write
))
999 (let ((case-fold-search nil
)
1000 (org-odd-levels-only odd
))
1001 ;; create local variables for all options, to make sure all called
1002 ;; functions get the correct information
1004 (set (make-local-variable (nth 2 x
))
1005 (plist-get opt-plist
(car x
))))
1006 org-export-plist-vars
)
1007 (setq umax
(if arg
(prefix-numeric-value arg
)
1008 org-export-headline-levels
))
1009 (setq umax-toc
(if (integerp org-export-with-toc
)
1010 (min org-export-with-toc umax
)
1016 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1017 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1018 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1019 lang=\"%s\" xml:lang=\"%s\">
1022 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1023 <meta name=\"generator\" content=\"Org-mode\"/>
1024 <meta name=\"generated\" content=\"%s\"/>
1025 <meta name=\"author\" content=\"%s\"/>
1026 <meta name=\"description\" content=\"%s\"/>
1027 <meta name=\"keywords\" content=\"%s\"/>
1032 <div id=\"content\">
1036 (or (and (stringp org-export-html-xml-declaration
)
1037 org-export-html-xml-declaration
)
1038 (cdr (assoc html-extension org-export-html-xml-declaration
))
1039 (cdr (assoc "html" org-export-html-xml-declaration
))
1042 (or charset
"iso-8859-1"))
1045 (or charset
"iso-8859-1")
1046 date author description keywords
1049 (if (or link-up link-home
)
1051 (format org-export-html-home
/up-format
1052 (or link-up link-home
)
1053 (or link-home link-up
))
1057 (org-export-html-insert-plist-item opt-plist
:preamble opt-plist
)
1059 (when (plist-get opt-plist
:auto-preamble
)
1060 (if title
(insert (format org-export-html-title-format
1061 (org-html-expand title
))))))
1063 (if (and org-export-with-toc
(not body-only
))
1065 (push (format "<h%d>%s</h%d>\n"
1066 org-export-html-toplevel-hlevel
1068 org-export-html-toplevel-hlevel
)
1070 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
1071 (push "<ul>\n<li>" thetoc
)
1073 (mapcar '(lambda (line)
1074 (if (and (string-match org-todo-line-regexp line
)
1075 (not (get-text-property 0 'org-protected line
)))
1076 ;; This is a headline
1078 (setq have-headings t
)
1079 (setq level
(- (match-end 1) (match-beginning 1)
1081 level
(org-tr-level level
)
1082 txt
(save-match-data
1084 (org-export-cleanup-toc-line
1085 (match-string 3 line
))))
1087 (or (and org-export-mark-todo-in-toc
1089 (not (member (match-string 2 line
)
1090 org-done-keywords
)))
1092 (and org-export-mark-todo-in-toc
1094 (org-search-todo-below
1095 line lines level
))))
1097 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
1098 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
1099 (if (string-match quote-re0 txt
)
1100 (setq txt
(replace-match "" t t txt
)))
1101 (setq snumber
(org-section-number level
))
1102 (if org-export-with-section-numbers
1103 (setq txt
(concat snumber
" " txt
)))
1104 (if (<= level
(max umax umax-toc
))
1105 (setq head-count
(+ head-count
1)))
1106 (if (<= level umax-toc
)
1108 (if (> level org-last-level
)
1110 (setq cnt
(- level org-last-level
))
1111 (while (>= (setq cnt
(1- cnt
)) 0)
1112 (push "\n<ul>\n<li>" thetoc
))
1113 (push "\n" thetoc
)))
1114 (if (< level org-last-level
)
1116 (setq cnt
(- org-last-level level
))
1117 (while (>= (setq cnt
(1- cnt
)) 0)
1118 (push "</li>\n</ul>" thetoc
))
1119 (push "\n" thetoc
)))
1120 ;; Check for targets
1121 (while (string-match org-any-target-regexp line
)
1122 (setq line
(replace-match
1123 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
1125 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
1126 (setq txt
(replace-match "" t t txt
)))
1128 (replace-regexp-in-string
1129 "\\." "_" (format "sec-%s" snumber
)))
1130 (setq href
(or (cdr (assoc href org-export-preferred-target-alist
)) href
))
1134 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1135 "</li>\n<li><a href=\"#%s\">%s</a>")
1138 (setq org-last-level level
))
1142 (while (> org-last-level
(1- org-min-level
))
1143 (setq org-last-level
(1- org-last-level
))
1144 (push "</li>\n</ul>\n" thetoc
))
1145 (push "</div>\n" thetoc
)
1146 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1149 (org-init-section-numbers)
1153 (while (setq line
(pop lines
) origline line
)
1156 ;; end of quote section?
1157 (when (and inquote
(string-match "^\\*+ " line
))
1161 ;; inside a quote section?
1163 (insert (org-html-protect line
) "\n")
1164 (throw 'nextline nil
))
1166 ;; Fixed-width, verbatim lines (examples)
1167 (when (and org-export-with-fixed-width
1168 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
1171 (org-close-par-maybe)
1173 (insert "<pre class=\"example\">\n"))
1174 (insert (org-html-protect (match-string 3 line
)) "\n")
1175 (when (or (not lines
)
1176 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1181 (throw 'nextline nil
))
1183 ;; Explicit list closure
1184 (when (equal "ORG-LIST-END" line
)
1185 (while local-list-indent
1186 (org-close-li (car local-list-type
))
1187 (insert (format "</%sl>\n" (car local-list-type
)))
1188 (pop local-list-type
)
1189 (pop local-list-indent
))
1190 (setq in-local-list nil
)
1192 (throw 'nextline nil
))
1195 (when (get-text-property 0 'org-protected line
)
1196 (let (par (ind (get-text-property 0 'original-indentation line
)))
1197 (when (re-search-backward
1198 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
1199 (setq par
(match-string 1))
1200 (replace-match "\\2\n"))
1203 (or (= (length (car lines
)) 0)
1205 (equal ind
(get-text-property 0 'original-indentation
(car lines
))))
1206 (or (= (length (car lines
)) 0)
1207 (get-text-property 0 'org-protected
(car lines
))))
1208 (insert (pop lines
) "\n"))
1209 (and par
(insert "<p>\n")))
1210 (throw 'nextline nil
))
1212 ;; Blockquotes, verse, and center
1213 (when (equal "ORG-BLOCKQUOTE-START" line
)
1214 (org-close-par-maybe)
1215 (insert "<blockquote>\n")
1217 (throw 'nextline nil
))
1218 (when (equal "ORG-BLOCKQUOTE-END" line
)
1219 (org-close-par-maybe)
1220 (insert "\n</blockquote>\n")
1222 (throw 'nextline nil
))
1223 (when (equal "ORG-VERSE-START" line
)
1224 (org-close-par-maybe)
1225 (insert "\n<p class=\"verse\">\n")
1226 (setq org-par-open t
)
1228 (throw 'nextline nil
))
1229 (when (equal "ORG-VERSE-END" line
)
1231 (setq org-par-open nil
)
1234 (throw 'nextline nil
))
1235 (when (equal "ORG-CENTER-START" line
)
1236 (org-close-par-maybe)
1237 (insert "\n<div style=\"text-align: center\">")
1239 (throw 'nextline nil
))
1240 (when (equal "ORG-CENTER-END" line
)
1241 (org-close-par-maybe)
1244 (throw 'nextline nil
))
1245 (run-hooks 'org-export-html-after-blockquotes-hook
)
1247 (let ((i (org-get-string-indentation line
)))
1249 (setq line
(concat (mapconcat 'identity
1250 (make-list (* 2 i
) "\\nbsp") "")
1251 " " (org-trim line
))))
1252 (unless (string-match "\\\\\\\\[ \t]*$" line
)
1253 (setq line
(concat line
"\\\\")))))
1255 ;; make targets to anchors
1257 (while (string-match
1258 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start
)
1260 ((get-text-property (match-beginning 1) 'org-protected line
)
1261 (setq start
(match-end 1)))
1263 (setq line
(replace-match
1265 "@<a name=\"%s\" id=\"%s\">@</a>"
1266 (org-solidify-link-text (match-string 1 line
))
1267 (org-solidify-link-text (match-string 1 line
)))
1269 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
1270 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1271 (setq line
(replace-match
1272 (concat "@<span class=\"target\">"
1273 (match-string 1 line
) "@</span> ")
1274 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1277 (setq line
(replace-match
1278 (concat "@<a name=\""
1279 (org-solidify-link-text (match-string 1 line
))
1280 "\" class=\"target\">" (match-string 1 line
)
1284 (setq line
(org-html-handle-time-stamps line
))
1286 ;; replace "&" by "&", "<" and ">" by "<" and ">"
1287 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
1288 ;; Also handle sub_superscripts and checkboxes
1289 (or (string-match org-table-hline-regexp line
)
1290 (setq line
(org-html-expand line
)))
1294 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
1295 (setq start
(match-beginning 0))
1296 (setq path
(save-match-data (org-link-unescape
1297 (match-string 3 line
))))
1299 ((match-end 2) (match-string 2 line
))
1301 (or (file-name-absolute-p path
)
1302 (string-match "^\\.\\.?/" path
)))
1305 (setq path
(org-extract-attributes (org-link-unescape path
)))
1306 (setq attr
(get-text-property 0 'org-attributes path
))
1307 (setq desc1
(if (match-end 5) (match-string 5 line
))
1308 desc2
(if (match-end 2) (concat type
":" path
) path
)
1309 descp
(and desc1
(not (equal desc1 desc2
)))
1310 desc
(or desc1 desc2
))
1311 ;; Make an image out of the description if that is so wanted
1312 (when (and descp
(org-file-image-p
1313 desc org-export-html-inline-image-extensions
))
1315 (if (string-match "^file:" desc
)
1316 (setq desc
(substring desc
(match-end 0)))))
1317 (setq desc
(org-add-props
1318 (concat "<img src=\"" desc
"\"/>")
1319 '(org-protected t
))))
1321 ((equal type
"internal")
1324 (if (= (string-to-char path
) ?
#)
1332 (org-solidify-link-text
1333 (save-match-data (org-link-unescape frag-0
))
1336 ((and (equal type
"id")
1337 (setq id-file
(org-id-find-id-file path
)))
1338 ;; This is an id: link to another file (if it was the same file,
1339 ;; it would have become an internal link...)
1341 (setq id-file
(file-relative-name
1343 (file-name-directory org-current-export-file
)))
1345 (org-html-make-link opt-plist
1347 (concat (if (org-uuidgen-p path
) "ID-") path
)
1351 ((member type
'("http" "https"))
1352 ;; standard URL, can inline as image
1354 (org-html-make-link opt-plist
1358 (org-html-should-inline-p path descp
))))
1359 ((member type
'("ftp" "mailto" "news"))
1360 ;; standard URL, can't inline as image
1362 (org-html-make-link opt-plist
1368 ((string= type
"coderef")
1370 ((coderef-str (format "coderef-%s" path
))
1372 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1373 coderef-str coderef-str
)))
1375 (org-html-make-link opt-plist
1378 (org-export-get-coderef-format
1381 (cdr (assoc path org-export-code-refs
)))
1385 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
1386 ;; The link protocol has a function for format the link
1389 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
1391 ((string= type
"file")
1397 (string-match "::\\(.*\\)" path
)
1399 (replace-match "" t nil path
)
1400 (match-string 1 path
))
1403 ;;The proper path, without a fragment
1409 (second components
))
1411 ;;Check the fragment. If it can't be used as
1412 ;;target fragment we'll pass nil instead.
1416 (not (string-match "^[0-9]*$" fragment-0
))
1417 (not (string-match "^\\*" fragment-0
))
1418 (not (string-match "^/.*/$" fragment-0
)))
1419 (org-solidify-link-text
1420 (org-link-unescape fragment-0
))
1423 ;;Description minus "file:" and ".org"
1424 (if (string-match "^file:" desc
)
1426 ((desc-1 (replace-match "" t t desc
)))
1427 (if (string-match "\\.org$" desc-1
)
1428 (replace-match "" t t desc-1
)
1435 (functionp link-validate
)
1436 (not (funcall link-validate path-1 current-dir
)))
1438 (org-html-make-link opt-plist
1439 "file" path-1 fragment-1 desc-2 attr
1440 (org-html-should-inline-p path-1 descp
)))))))
1443 ;; just publish the path, as default
1444 (setq rpl
(concat "<i><" type
":"
1445 (save-match-data (org-link-unescape path
))
1447 (setq line
(replace-match rpl t t line
)
1448 start
(+ start
(length rpl
))))
1451 (if (and (string-match org-todo-line-regexp line
)
1452 (match-beginning 2))
1455 (concat (substring line
0 (match-beginning 2))
1457 (if (member (match-string 2 line
)
1460 " " (match-string 2 line
)
1461 "\"> " (org-export-html-get-todo-kwd-class-name
1462 (match-string 2 line
))
1463 "</span>" (substring line
(match-end 2)))))
1465 ;; Does this contain a reference to a footnote?
1466 (when org-export-with-footnotes
1468 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
1469 (if (get-text-property (match-beginning 2) 'org-protected line
)
1470 (setq start
(match-end 2))
1471 (let ((n (match-string 2 line
)) extra a
)
1472 (if (setq a
(assoc n footref-seen
))
1474 (setcdr a
(1+ (cdr a
)))
1475 (setq extra
(format ".%d" (cdr a
))))
1477 (push (cons n
1) footref-seen
))
1482 (format org-export-html-footnote-format
1483 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"))
1484 (or (match-string 1 line
) "") n extra n n
)
1488 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1489 ;; This is a headline
1490 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1492 txt
(match-string 2 line
))
1493 (if (string-match quote-re0 txt
)
1494 (setq txt
(replace-match "" t t txt
)))
1495 (if (<= level
(max umax umax-toc
))
1496 (setq head-count
(+ head-count
1)))
1497 (setq first-heading-pos
(or first-heading-pos
(point)))
1498 (org-html-level-start level txt umax
1499 (and org-export-with-toc
(<= level umax
))
1503 (when (string-match quote-re line
)
1504 (org-close-par-maybe)
1508 ((and org-export-with-tables
1509 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1510 (when (not table-open
)
1512 (setq table-open t table-buffer nil table-orig-buffer nil
))
1515 (setq table-buffer
(cons line table-buffer
)
1516 table-orig-buffer
(cons origline table-orig-buffer
))
1517 (when (or (not lines
)
1518 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1520 (setq table-open nil
1521 table-buffer
(nreverse table-buffer
)
1522 table-orig-buffer
(nreverse table-orig-buffer
))
1523 (org-close-par-maybe)
1524 (insert (org-format-table-html table-buffer table-orig-buffer
))))
1529 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1530 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1531 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
1532 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
1534 (setq ind
(or (get-text-property 0 'original-indentation line
)
1535 (org-get-string-indentation line
))
1536 item-type
(if (match-beginning 4) "o" "u")
1537 starter
(if (match-beginning 2)
1538 (substring (match-string 2 line
) 0 -
1))
1539 line
(substring line
(match-beginning 5))
1542 (if (string-match "\\[@\\(?:start:\\)?\\([0-9]+\\)\\][ \t]?" line
)
1543 (setq item-number
(match-string 1 line
)
1544 line
(replace-match "" t t line
)))
1545 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
1547 item-tag
(match-string 1 line
)
1548 line
(substring line
(match-end 0))))
1551 (or (not in-local-list
)
1552 (> ind
(car local-list-indent
))))
1553 ;; Start new (level of) list
1554 (org-close-par-maybe)
1556 ((equal item-type
"u") "<ul>\n<li>\n")
1557 ((and (equal item-type
"o") item-number
)
1558 (format "<ol>\n<li value=\"%s\">\n" item-number
))
1559 ((equal item-type
"o") "<ol>\n<li>\n")
1560 ((equal item-type
"d")
1561 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
1562 (push item-type local-list-type
)
1563 (push ind local-list-indent
)
1564 (setq in-local-list t
))
1567 ;; terminate any previous sublist but first ensure
1568 ;; list is not ill-formed.
1569 (let ((min-ind (apply 'min local-list-indent
)))
1570 (when (< ind min-ind
) (setq ind min-ind
)))
1571 (while (< ind
(car local-list-indent
))
1572 (org-close-li (car local-list-type
))
1573 (insert (format "</%sl>\n" (car local-list-type
)))
1574 (pop local-list-type
) (pop local-list-indent
)
1575 (setq in-local-list local-list-indent
))
1577 (org-close-li (car local-list-type
))
1579 ((equal (car local-list-type
) "d")
1580 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
1581 ((and (equal item-type
"o") item-number
)
1582 (format "<li value=\"%s\">\n" item-number
))
1584 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
1587 (if (equal (match-string 1 line
) "X")
1589 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
1593 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
1595 (insert "\n</p>\n<hr/>\n<p>\n")
1596 (insert "\n<hr/>\n"))
1597 (throw 'nextline nil
))
1599 ;; Empty lines start a new paragraph. If hand-formatted lists
1600 ;; are not fully interpreted, lines starting with "-", "+", "*"
1601 ;; also start a new paragraph.
1602 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
1604 ;; Is this the start of a footnote?
1605 (when org-export-with-footnotes
1606 (when (and (boundp 'footnote-section-tag-regexp
)
1607 (string-match (concat "^" footnote-section-tag-regexp
)
1610 (throw 'nextline nil
))
1611 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1612 (org-close-par-maybe)
1613 (let ((n (match-string 1 line
)))
1614 (setq org-par-open t
1617 (concat "<p class=\"footnote\">"
1618 (format org-export-html-footnote-format
1619 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1620 n n n
) t t line
)))))
1621 ;; Check if the line break needs to be conserved
1623 ((string-match "\\\\\\\\[ \t]*$" line
)
1624 (setq line
(replace-match "<br/>" t t line
)))
1625 (org-export-preserve-breaks
1626 (setq line
(concat line
"<br/>"))))
1628 ;; Check if a paragraph should be started
1630 (while (and org-par-open
1631 (string-match "\\\\par\\>" line start
))
1632 ;; Leave a space in the </p> so that the footnote matcher
1633 ;; does not see this.
1634 (if (not (get-text-property (match-beginning 0)
1635 'org-protected line
))
1636 (setq line
(replace-match "</p ><p >" t t line
)))
1637 (setq start
(match-end 0))))
1639 (insert line
"\n")))))
1641 ;; Properly close all local lists and other lists
1646 (org-html-level-start 1 nil umax
1647 (and org-export-with-toc
(<= level umax
))
1649 ;; the </div> to close the last text-... div.
1650 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
1653 (goto-char (point-min))
1654 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
1655 (push (match-string 0) footnotes
)
1656 (replace-match "" t t
)))
1658 (insert (format org-export-html-footnotes-section
1660 (mapconcat 'identity
(nreverse footnotes
) "\n"))
1662 (let ((bib (org-export-html-get-bibliography)))
1664 (insert "\n" bib
"\n")))
1666 (when (plist-get opt-plist
:auto-postamble
)
1667 (insert "<div id=\"postamble\">\n")
1668 (when (and org-export-author-info author
)
1669 (insert "<p class=\"author\"> "
1670 (nth 1 lang-words
) ": " author
"\n")
1671 (when (and org-export-email-info email
(string-match "\\S-" email
))
1672 (if (listp (split-string email
",+ *"))
1674 (insert "<a href=\"mailto:" e
"\"><"
1676 (split-string email
",+ *"))
1677 (insert "<a href=\"mailto:" email
"\"><"
1678 email
"></a>\n")))
1680 (when (and date org-export-time-stamp-file
)
1681 (insert "<p class=\"date\"> "
1682 (nth 2 lang-words
) ": "
1684 (when org-export-creator-info
1685 (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
1686 org-version emacs-major-version
)))
1687 (when org-export-html-validation-link
1688 (insert org-export-html-validation-link
"\n"))
1691 (if org-export-html-with-timestamp
1692 (insert org-export-html-html-helper-timestamp
))
1693 (org-export-html-insert-plist-item opt-plist
:postamble opt-plist
)
1694 (insert "\n</div>\n</body>\n</html>\n"))
1696 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1698 (if (eq major-mode
(default-value 'major-mode
))
1701 ;; insert the table of contents
1702 (goto-char (point-min))
1704 (if (or (re-search-forward
1705 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1707 "\\[TABLE-OF-CONTENTS\\]" nil t
))
1709 (goto-char (match-beginning 0))
1711 (goto-char first-heading-pos
)
1712 (when (looking-at "\\s-*</p>")
1713 (goto-char (match-end 0))
1715 (insert "<div id=\"table-of-contents\">\n")
1716 (mapc 'insert thetoc
)
1717 (insert "</div>\n"))
1718 ;; remove empty paragraphs and lists
1719 (goto-char (point-min))
1720 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
1722 (goto-char (point-min))
1723 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
1725 (goto-char (point-min))
1726 ;; Convert whitespace place holders
1727 (goto-char (point-min))
1729 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1730 (setq n
(get-text-property beg
'org-whitespace
)
1731 end
(next-single-property-change beg
'org-whitespace
))
1733 (delete-region beg end
)
1734 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1735 (make-string n ?x
)))))
1736 ;; Remove empty lines at the beginning of the file.
1737 (goto-char (point-min))
1738 (when (looking-at "\\s-+\n") (replace-match ""))
1739 ;; Remove display properties
1740 (remove-text-properties (point-min) (point-max) '(display t
))
1742 (run-hooks 'org-export-html-final-hook
)
1743 (or to-buffer
(save-buffer))
1744 (goto-char (point-min))
1745 (or (org-export-push-to-kill-ring "HTML")
1746 (message "Exporting... done"))
1747 (if (eq to-buffer
'string
)
1748 (prog1 (buffer-substring (point-min) (point-max))
1749 (kill-buffer (current-buffer)))
1750 (current-buffer)))))
1752 (defun org-export-html-insert-plist-item (plist key
&rest args
)
1753 (let ((item (plist-get plist key
)))
1754 (cond ((functionp item
)
1759 (defun org-export-html-format-href (s)
1760 "Make sure the S is valid as a href reference in an XHTML document."
1763 (while (string-match "&" s start
)
1764 (setq start
(+ (match-beginning 0) 3)
1765 s
(replace-match "&" t t s
)))))
1768 (defun org-export-html-format-desc (s)
1769 "Make sure the S is valid as a description in a link."
1770 (if (and s
(not (get-text-property 1 'org-protected s
)))
1772 (org-html-do-expand s
))
1775 (defun org-export-html-format-image (src par-open
)
1776 "Create image tag with source and attributes."
1778 (if (string-match "^ltxpng/" src
)
1779 (format "<img src=\"%s\" alt=\"%s\"/>"
1780 src
(org-find-text-property-in-string 'org-latex-src src
))
1781 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1782 (attr (org-find-text-property-in-string 'org-attributes src
))
1783 (label (org-find-text-property-in-string 'org-label src
)))
1784 (setq caption
(and caption
(org-html-do-expand caption
)))
1787 (format "%s<div %sclass=\"figure\">
1789 (if org-par-open
"</p>\n" "")
1790 (if label
(format "id=\"%s\" " label
) "")))
1791 (format "<img src=\"%s\"%s />"
1793 (if (string-match "\\<alt=" (or attr
""))
1795 (concat " " attr
" alt=\"" src
"\"")))
1799 (concat "\n<p>" caption
"</p>")
1800 (if org-par-open
"\n<p>" ""))))))))
1802 (defun org-export-html-get-bibliography ()
1803 "Find bibliography, cut it out and return it."
1805 (let (beg end
(cnt 1) bib
)
1807 (goto-char (point-min))
1808 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1809 (setq beg
(match-beginning 0))
1810 (while (re-search-forward "</?div\\>" nil t
)
1811 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1813 (and (looking-at ">") (forward-char 1))
1814 (setq bib
(buffer-substring beg
(point)))
1815 (delete-region beg
(point))
1816 (throw 'exit bib
))))
1819 (defvar org-table-number-regexp
) ; defined in org-table.el
1820 (defun org-format-table-html (lines olines
)
1821 "Find out which HTML converter to use and return the HTML code."
1823 (setq lines
(org-split-string lines
"\n")))
1824 (if (string-match "^[ \t]*|" (car lines
))
1825 ;; A normal org table
1826 (org-format-org-table-html lines
)
1827 ;; Table made by table.el - test for spanning
1828 (let* ((hlines (delq nil
(mapcar
1830 (if (string-match "^[ \t]*\\+-" x
) x
1833 (first (car hlines
))
1834 (ll (and (string-match "\\S-+" first
)
1835 (match-string 0 first
)))
1836 (re (concat "^[ \t]*" (regexp-quote ll
)))
1837 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
1839 (if (and (not spanning
)
1840 (not org-export-prefer-native-exporter-for-tables
))
1841 ;; We can use my own converter with HTML conversions
1842 (org-format-table-table-html lines
)
1843 ;; Need to use the code generator in table.el, with the original text.
1844 (org-format-table-table-html-using-table-generate-source olines
)))))
1846 (defvar org-table-number-fraction
) ; defined in org-table.el
1847 (defun org-format-org-table-html (lines &optional splice
)
1848 "Format a table into HTML."
1849 (require 'org-table
)
1850 ;; Get rid of hlines at beginning and end
1851 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1852 (setq lines
(nreverse lines
))
1853 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1854 (setq lines
(nreverse lines
))
1855 (when org-export-table-remove-special-lines
1856 ;; Check if the table has a marking column. If yes remove the
1857 ;; column and the special lines
1858 (setq lines
(org-table-clean-before-export lines
)))
1860 (let* ((caption (org-find-text-property-in-string 'org-caption
(car lines
)))
1861 (label (org-find-text-property-in-string 'org-label
(car lines
)))
1862 (attributes (org-find-text-property-in-string 'org-attributes
1864 (html-table-tag (org-export-splice-attributes
1865 html-table-tag attributes
))
1866 (head (and org-export-highlight-first-table-line
1868 (lambda (x) (string-match "^[ \t]*|-" x
))
1871 (nline 0) fnum nfields i
1872 tbopen line fields html gr colgropen rowstart rowend
)
1873 (setq caption
(and caption
(org-html-do-expand caption
)))
1874 (if splice
(setq head nil
))
1875 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
1877 (while (setq line
(pop lines
))
1879 (if (string-match "^[ \t]*|-" line
)
1882 (push (if head
"</thead>" "</tbody>") html
)
1883 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
1884 (setq head nil
) ;; head ends here, first time around
1886 (throw 'next-line t
)))
1887 ;; Break the line into fields
1888 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
1889 (unless fnum
(setq fnum
(make-vector (length fields
) 0)
1890 nfields
(length fnum
)))
1891 (setq nline
(1+ nline
) i -
1
1892 rowstart
(eval (car org-export-table-row-tags
))
1893 rowend
(eval (cdr org-export-table-row-tags
)))
1894 (push (concat rowstart
1898 (if (and (< i nfields
) ; make sure no rogue line causes an error here
1899 (string-match org-table-number-regexp x
))
1900 (incf (aref fnum i
)))
1904 (format (car org-export-table-header-tags
) "col")
1906 (cdr org-export-table-header-tags
)))
1907 ((and (= i
0) org-export-html-table-use-header-tags-for-first-column
)
1909 (format (car org-export-table-header-tags
) "row")
1911 (cdr org-export-table-header-tags
)))
1913 (concat (car org-export-table-data-tags
) x
1914 (cdr org-export-table-data-tags
)))))
1918 (unless splice
(if tbopen
(push "</tbody>" html
)))
1919 (unless splice
(push "</table>\n" html
))
1920 (setq html
(nreverse html
))
1922 ;; Put in col tags with the alignment (unfortunately often ignored...)
1923 (unless (car org-table-colgroup-info
)
1924 (setq org-table-colgroup-info
1925 (cons :start
(cdr org-table-colgroup-info
))))
1928 (setq gr
(pop org-table-colgroup-info
))
1929 (format "%s<col align=\"%s\" />%s"
1930 (if (memq gr
'(:start
:startend
))
1932 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
1935 (if (> (/ (float x
) nline
) org-table-number-fraction
)
1937 (if (memq gr
'(:end
:startend
))
1938 (progn (setq colgropen nil
) "</colgroup>")
1942 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
1943 ;; Since the output of HTML table formatter can also be used in
1944 ;; DocBook document, we want to always include the caption to make
1945 ;; DocBook XML file valid.
1946 (push (format "<caption>%s</caption>" (or caption
"")) html
)
1947 (when label
(push (format "<a name=\"%s\" id=\"%s\"></a>" label label
)
1949 (push html-table-tag html
))
1950 (concat (mapconcat 'identity html
"\n") "\n")))
1952 (defun org-export-splice-attributes (tag attributes
)
1953 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1954 (if (not attributes
)
1956 (let (oldatt newatt
)
1957 (setq oldatt
(org-extract-attributes-from-string tag
)
1959 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1961 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1962 (if (string-match ">" tag
)
1964 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1968 (defun org-format-table-table-html (lines)
1969 "Format a table generated by table.el into HTML.
1970 This conversion does *not* use `table-generate-source' from table.el.
1971 This has the advantage that Org-mode's HTML conversions can be used.
1972 But it has the disadvantage, that no cell- or row-spanning is allowed."
1973 (let (line field-buffer
1974 (head org-export-highlight-first-table-line
)
1975 fields html empty i
)
1976 (setq html
(concat html-table-tag
"\n"))
1977 (while (setq line
(pop lines
))
1978 (setq empty
" ")
1980 (if (string-match "^[ \t]*\\+-" line
)
1991 (if (equal x
"") (setq x empty
))
1994 (format (car org-export-table-header-tags
) "col")
1996 (cdr org-export-table-header-tags
))
1997 (concat (car org-export-table-data-tags
) x
1998 (cdr org-export-table-data-tags
))))
2002 (setq field-buffer nil
)))
2004 (throw 'next-line t
)))
2005 ;; Break the line into fields and store the fields
2006 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
2008 (setq field-buffer
(mapcar
2010 (concat x
"<br/>" (pop fields
)))
2012 (setq field-buffer fields
))))
2013 (setq html
(concat html
"</table>\n"))
2016 (defun org-format-table-table-html-using-table-generate-source (lines)
2017 "Format a table into html, using `table-generate-source' from table.el.
2018 This has the advantage that cell- or row-spanning is allowed.
2019 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
2021 (with-current-buffer (get-buffer-create " org-tmp1 ")
2023 (insert (mapconcat 'identity lines
"\n"))
2024 (goto-char (point-min))
2025 (if (not (re-search-forward "|[^+]" nil t
))
2026 (error "Error processing table"))
2027 (table-recognize-table)
2028 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2029 (table-generate-source 'html
" org-tmp2 ")
2030 (set-buffer " org-tmp2 ")
2031 (buffer-substring (point-min) (point-max))))
2033 (defun org-export-splice-style (style extra
)
2034 "Splice EXTRA into STYLE, just before \"</style>\"."
2035 (if (and (stringp extra
)
2036 (string-match "\\S-" extra
)
2037 (string-match "</style>" style
))
2038 (concat (substring style
0 (match-beginning 0))
2040 (substring style
(match-beginning 0)))
2043 (defun org-html-handle-time-stamps (s)
2044 "Format time stamps in string S, or remove them."
2047 (while (string-match org-maybe-keyword-time-regexp s
)
2048 (or b
(setq b
(substring s
0 (match-beginning 0))))
2050 r
(substring s
0 (match-beginning 0))
2051 " @<span class=\"timestamp-wrapper\">"
2053 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2054 (match-string 1 s
)))
2055 (format " @<span class=\"timestamp\">%s@</span>"
2057 (org-translate-time (match-string 3 s
)) 1 -
1))
2059 s
(substring s
(match-end 0))))
2060 ;; Line break if line started and ended with time stamp stuff
2063 (setq r
(concat r s
))
2064 (unless (string-match "\\S-" (concat b s
))
2065 (setq r
(concat r
"@<br/>")))
2068 (defvar htmlize-buffer-places
) ; from htmlize.el
2069 (defun org-export-htmlize-region-for-paste (beg end
)
2070 "Convert the region to HTML, using htmlize.el.
2071 This is much like `htmlize-region-for-paste', only that it uses
2072 the settings define in the org-... variables."
2073 (let* ((htmlize-output-type org-export-htmlize-output-type
)
2074 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
2075 (htmlbuf (htmlize-region beg end
)))
2077 (with-current-buffer htmlbuf
2078 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
2079 (plist-get htmlize-buffer-places
'content-end
)))
2080 (kill-buffer htmlbuf
))))
2083 (defun org-export-htmlize-generate-css ()
2084 "Create the CSS for all font definitions in the current Emacs session.
2085 Use this to create face definitions in your CSS style file that can then
2086 be used by code snippets transformed by htmlize.
2087 This command just produces a buffer that contains class definitions for all
2088 faces used in the current Emacs session. You can copy and paste the ones you
2089 need into your CSS file.
2091 If you then set `org-export-htmlize-output-type' to `css', calls to
2092 the function `org-export-htmlize-region-for-paste' will produce code
2093 that uses these same face definitions."
2096 (and (get-buffer "*html*") (kill-buffer "*html*"))
2098 (let ((fl (face-list))
2099 (htmlize-css-name-prefix "org-")
2100 (htmlize-output-type 'css
)
2102 (while (setq f
(pop fl
)
2103 i
(and f
(face-attribute f
:inherit
)))
2104 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
2105 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
2106 (htmlize-region (point-min) (point-max))))
2107 (switch-to-buffer "*html*")
2108 (goto-char (point-min))
2109 (if (re-search-forward "<style" nil t
)
2110 (delete-region (point-min) (match-beginning 0)))
2111 (if (re-search-forward "</style>" nil t
)
2112 (delete-region (1+ (match-end 0)) (point-max)))
2113 (beginning-of-line 1)
2114 (if (looking-at " +") (replace-match ""))
2115 (goto-char (point-min)))
2117 (defun org-html-protect (s)
2118 "convert & to &, < to < and > to >"
2120 (while (string-match "&" s start
)
2121 (setq s
(replace-match "&" t t s
)
2122 start
(1+ (match-beginning 0))))
2123 (while (string-match "<" s
)
2124 (setq s
(replace-match "<" t t s
)))
2125 (while (string-match ">" s
)
2126 (setq s
(replace-match ">" t t s
)))
2127 ; (while (string-match "\"" s)
2128 ; (setq s (replace-match """ t t s)))
2132 (defun org-html-expand (string)
2133 "Prepare STRING for HTML export. Apply all active conversions.
2134 If there are links in the string, don't modify these."
2135 (let* ((re (concat org-bracket-link-regexp
"\\|"
2136 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2138 (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string
)
2140 (while (setq m
(string-match re string
))
2141 (setq s
(substring string
0 m
)
2142 l
(match-string 0 string
)
2143 string
(substring string
(match-end 0)))
2144 (push (org-html-do-expand s
) res
)
2146 (push (org-html-do-expand string
) res
)
2147 (apply 'concat
(nreverse res
)))))
2149 (defun org-html-do-expand (s)
2150 "Apply all active conversions to translate special ASCII to HTML."
2151 (setq s
(org-html-protect s
))
2152 (if org-export-html-expand
2153 (while (string-match "@<\\([^&]*\\)>" s
)
2154 (setq s
(replace-match "<\\1>" t nil s
))))
2155 (if org-export-with-emphasize
2156 (setq s
(org-export-html-convert-emphasize s
)))
2157 (if org-export-with-special-strings
2158 (setq s
(org-export-html-convert-special-strings s
)))
2159 (if org-export-with-sub-superscripts
2160 (setq s
(org-export-html-convert-sub-super s
)))
2161 (if org-export-with-TeX-macros
2162 (let ((start 0) wd rep
)
2163 (while (setq start
(string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2165 (if (get-text-property (match-beginning 0) 'org-protected s
)
2166 (setq start
(match-end 0))
2167 (setq wd
(match-string 1 s
))
2168 (if (setq rep
(org-entity-get-representation wd
'html
))
2169 (setq s
(replace-match rep t t s
))
2170 (setq start
(+ start
(length wd
))))))))
2173 (defun org-export-html-convert-special-strings (string)
2174 "Convert special characters in STRING to HTML."
2175 (let ((all org-export-html-special-string-regexps
)
2177 (while (setq a
(pop all
))
2178 (setq re
(car a
) rpl
(cdr a
) start
0)
2179 (while (string-match re string start
)
2180 (if (get-text-property (match-beginning 0) 'org-protected string
)
2181 (setq start
(match-end 0))
2182 (setq string
(replace-match rpl t nil string
)))))
2185 (defun org-export-html-convert-sub-super (string)
2186 "Convert sub- and superscripts in STRING to HTML."
2187 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
2188 (while (string-match org-match-substring-regexp string s
)
2190 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
2191 ((get-text-property (match-beginning 2) 'org-protected string
)
2192 (setq s
(match-end 2)))
2194 (setq s
(match-end 1)
2195 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
2196 c
(or (match-string 8 string
)
2197 (match-string 6 string
)
2198 (match-string 5 string
))
2199 string
(replace-match
2200 (concat (match-string 1 string
)
2201 "<" key
">" c
"</" key
">")
2203 (while (string-match "\\\\\\([_^]\\)" string
)
2204 (setq string
(replace-match (match-string 1 string
) t t string
)))
2207 (defun org-export-html-convert-emphasize (string)
2210 (while (string-match org-emph-re string s
)
2212 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
2213 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
2214 (setq s
(match-beginning 0)
2217 (match-string 1 string
)
2218 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
2219 (match-string 4 string
)
2220 (nth 3 (assoc (match-string 3 string
)
2221 org-emphasis-alist
))
2222 (match-string 5 string
))
2223 string
(replace-match rpl t t string
)
2224 s
(+ s
(- (length rpl
) 2)))
2228 (defun org-open-par ()
2229 "Insert <p>, but first close previous paragraph if any."
2230 (org-close-par-maybe)
2232 (setq org-par-open t
))
2233 (defun org-close-par-maybe ()
2234 "Close paragraph if there is one open."
2237 (setq org-par-open nil
)))
2238 (defun org-close-li (&optional type
)
2239 "Close <li> if necessary."
2240 (org-close-par-maybe)
2241 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
2243 (defvar in-local-list
)
2244 (defvar local-list-indent
)
2245 (defvar local-list-type
)
2247 (defvar body-only
) ; dynamically scoped into this.
2248 (defun org-html-level-start (level title umax with-toc head-count
)
2249 "Insert a new level in HTML export.
2250 When TITLE is nil, just close all open levels."
2251 (org-close-par-maybe)
2252 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
2253 (extra-targets (and target
2254 (assoc target org-export-target-aliases
)))
2255 (extra-class (and title
(org-get-text-property-any 0 'html-container-class title
)))
2256 (preferred (and target
2257 (cdr (assoc target org-export-preferred-target-alist
))))
2258 (remove (or preferred target
))
2260 snumber snu href suffix
)
2261 (setq extra-targets
(remove remove extra-targets
))
2263 (mapconcat (lambda (x)
2264 (if (org-uuidgen-p x
) (setq x
(concat "ID-" x
)))
2265 (format "<a name=\"%s\" id=\"%s\"></a>"
2270 (if (aref org-levels-open
(1- l
))
2272 (org-html-level-close l umax
)
2273 (aset org-levels-open
(1- l
) nil
)))
2276 ;; If title is nil, this means this function is called to close
2277 ;; all levels, so the rest is done only if title is given
2278 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
2279 (setq title
(replace-match
2280 (if org-export-with-tags
2283 " <span class=\"tag\">"
2286 (format "<span class=\"%s\">%s</span>"
2287 (org-export-html-get-tag-class-name x
)
2289 (org-split-string (match-string 1 title
) ":")
2296 (if (aref org-levels-open
(1- level
))
2300 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
2301 (insert "<li>" title
"<br/>\n")))
2302 (aset org-levels-open
(1- level
) t
)
2303 (org-close-par-maybe)
2305 (insert (format "<ul>\n<li id=\"%s\">" target
)
2306 extra-targets title
"<br/>\n")
2307 (insert "<ul>\n<li>" title
"<br/>\n"))))
2308 (aset org-levels-open
(1- level
) t
)
2309 (setq snumber
(org-section-number level
)
2310 snu
(replace-regexp-in-string "\\." "_" snumber
))
2311 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
2312 (if (and org-export-with-section-numbers
(not body-only
))
2314 (format "<span class=\"section-number-%d\">%s</span>"
2317 (unless (= head-count
1) (insert "\n</div>\n"))
2318 (setq href
(cdr (assoc (concat "sec-" snu
) org-export-preferred-target-alist
)))
2319 (setq suffix
(or href snu
))
2320 (setq href
(or href
(concat "sec-" snu
)))
2321 (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"
2322 suffix level
(if extra-class
(concat " " extra-class
) "")
2325 title level level suffix
))
2328 (defun org-export-html-get-tag-class-name (tag)
2329 "Turn tag into a valid class name.
2330 Replaces invalid characters with \"_\" and then prepends a prefix."
2332 (while (string-match "[^a-zA-Z0-9_]" tag
)
2333 (setq tag
(replace-match "_" t t tag
))))
2334 (concat org-export-html-tag-class-prefix tag
))
2336 (defun org-export-html-get-todo-kwd-class-name (kwd)
2337 "Turn todo keyword into a valid class name.
2338 Replaces invalid characters with \"_\" and then prepends a prefix."
2340 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2341 (setq kwd
(replace-match "_" t t kwd
))))
2342 (concat org-export-html-todo-kwd-class-prefix kwd
))
2344 (defun org-html-level-close (level max-outline-level
)
2345 "Terminate one level in HTML export."
2346 (if (<= level max-outline-level
)
2349 (insert "</ul>\n")))
2353 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
2354 ;;; org-html.el ends here