1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (declare-function org-export-latex-preprocess
"org-export-latex" (parameters))
35 (declare-function org-export-docbook-preprocess
"org-export-docbook" (parameters))
36 (declare-function org-agenda-skip
"org-agenda" ())
37 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
38 (declare-function htmlize-region
"ext:htmlize" (beg end
))
39 (declare-function org-id-find-id-file
"org-id" (id))
40 (defvar htmlize-buffer-places
) ; from htmlize.el
42 (defgroup org-export nil
43 "Options for exporting org-listings."
47 (defgroup org-export-general nil
48 "General options for exporting Org-mode files."
49 :tag
"Org Export General"
53 (defvar org-export-publishing-directory nil
)
55 (defcustom org-export-run-in-background nil
56 "Non-nil means export and publishing commands will run in background.
57 This works by starting up a separate Emacs process visiting the same file
58 and doing the export from there.
59 Not all export commands are affected by this - only the ones which
60 actually write to a file, and that do not depend on the buffer state.
62 If this option is nil, you can still get background export by calling
63 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
65 If this option is t, the double prefix can be used to exceptionally
66 force an export command into the current process."
67 :group
'org-export-general
71 (defcustom org-export-select-tags
'("export")
72 "Tags that select a tree for export.
73 If any such tag is found in a buffer, all trees that do not carry one
74 of these tags will be deleted before export.
75 Inside trees that are selected like this, you can still deselect a
76 subtree by tagging it with one of the `org-export-exclude-tags'."
77 :group
'org-export-general
78 :type
'(repeat (string :tag
"Tag")))
80 (defcustom org-export-exclude-tags
'("noexport")
81 "Tags that exclude a tree from export.
82 All trees carrying any of these tags will be excluded from export.
83 This is without condition, so even subtrees inside that carry one of the
84 `org-export-select-tags' will be removed."
85 :group
'org-export-general
86 :type
'(repeat (string :tag
"Tag")))
88 (defcustom org-export-with-special-strings t
89 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
90 When this option is turned on, these strings will be exported as:
93 -----+----------+--------
99 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
100 :group
'org-export-translation
103 (defcustom org-export-language-setup
104 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
105 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
106 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
107 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
108 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
109 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
110 ("es" "Autor" "Fecha" "Índice" "Pies de página")
111 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
112 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
113 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
114 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
115 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
116 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
117 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
118 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
119 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
120 ("pl" "Autor" "Data" "Spis treści" "Przypis")
121 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
122 "Terms used in export text, translated to different languages.
123 Use the variable `org-export-default-language' to set the language,
124 or use the +OPTION lines for a per-file setting."
125 :group
'org-export-general
128 (string :tag
"HTML language tag")
129 (string :tag
"Author")
131 (string :tag
"Table of Contents")
132 (string :tag
"Footnotes"))))
134 (defcustom org-export-default-language
"en"
135 "The default language of HTML export, as a string.
136 This should have an association in `org-export-language-setup'."
137 :group
'org-export-general
140 (defvar org-export-page-description
""
141 "The page description, for the XHTML meta tag.
142 This is best set with the #+DESCRIPTION line in a file, it does not make
143 sense to set this globally.")
145 (defvar org-export-page-keywords
""
146 "The page description, for the XHTML meta tag.
147 This is best set with the #+KEYWORDS line in a file, it does not make
148 sense to set this globally.")
150 (defcustom org-export-skip-text-before-1st-heading nil
151 "Non-nil means, skip all text before the first headline when exporting.
152 When nil, that text is exported as well."
153 :group
'org-export-general
156 (defcustom org-export-headline-levels
3
157 "The last level which is still exported as a headline.
158 Inferior levels will produce itemize lists when exported.
159 Note that a numeric prefix argument to an exporter function overrides
162 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
163 :group
'org-export-general
166 (defcustom org-export-with-section-numbers t
167 "Non-nil means, add section numbers to headlines when exporting.
169 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
170 :group
'org-export-general
173 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
174 "Format of section numbers for export.
175 The variable has two components.
176 1. A list of lists, each indicating a counter type and a separator.
177 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
178 It causes causes numeric, alphabetic, or roman counters, respectively.
179 The separator is only used if another counter for a subsection is being
181 If there are more numbered section levels than entries in this lists,
182 then the last entry will be reused.
183 2. A terminator string that will be added after the entire
185 :group
'org-export-general
189 (string :tag
"Counter Type")
190 (string :tag
"Separator ")))
191 (string :tag
"Terminator")))
193 (defcustom org-export-with-toc t
194 "Non-nil means, create a table of contents in exported files.
195 The TOC contains headlines with levels up to`org-export-headline-levels'.
196 When an integer, include levels up to N in the toc, this may then be
197 different from `org-export-headline-levels', but it will not be allowed
198 to be larger than the number of headline levels.
199 When nil, no table of contents is made.
201 Headlines which contain any TODO items will be marked with \"(*)\" in
202 ASCII export, and with red color in HTML output, if the option
203 `org-export-mark-todo-in-toc' is set.
205 In HTML output, the TOC will be clickable.
207 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
209 :group
'org-export-general
211 (const :tag
"No Table of Contents" nil
)
212 (const :tag
"Full Table of Contents" t
)
213 (integer :tag
"TOC to level")))
215 (defcustom org-export-mark-todo-in-toc nil
216 "Non-nil means, mark TOC lines that contain any open TODO items."
217 :group
'org-export-general
220 (defcustom org-export-with-todo-keywords t
221 "Non-nil means, include TODO keywords in export.
222 When nil, remove all these keywords from the export."
223 :group
'org-export-general
226 (defcustom org-export-with-priority nil
227 "Non-nil means, include priority cookies in export.
228 When nil, remove priority cookies for export."
229 :group
'org-export-general
232 (defcustom org-export-preserve-breaks nil
233 "Non-nil means, preserve all line breaks when exporting.
234 Normally, in HTML output paragraphs will be reformatted. In ASCII
235 export, line breaks will always be preserved, regardless of this variable.
237 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
238 :group
'org-export-general
241 (defcustom org-export-with-archived-trees
'headline
242 "Whether subtrees with the ARCHIVE tag should be exported.
243 This can have three different values
244 nil Do not export, pretend this tree is not present
245 t Do export the entire tree
246 headline Only export the headline, but skip the tree below it."
247 :group
'org-export-general
250 (const :tag
"not at all" nil
)
251 (const :tag
"headline only" 'headline
)
252 (const :tag
"entirely" t
)))
254 (defcustom org-export-author-info t
255 "Non-nil means, insert author name and email into the exported file.
257 This option can also be set with the +OPTIONS line,
258 e.g. \"author-info:nil\"."
259 :group
'org-export-general
262 (defcustom org-export-creator-info t
263 "Non-nil means, the postamble should contain a creator sentence.
264 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
265 :group
'org-export-general
268 (defcustom org-export-time-stamp-file t
269 "Non-nil means, insert a time stamp into the exported file.
270 The time stamp shows when the file was created.
272 This option can also be set with the +OPTIONS line,
273 e.g. \"timestamp:nil\"."
274 :group
'org-export-general
277 (defcustom org-export-with-timestamps t
278 "If nil, do not export time stamps and associated keywords."
279 :group
'org-export-general
282 (defcustom org-export-remove-timestamps-from-toc t
283 "If nil, remove timestamps from the table of contents entries."
284 :group
'org-export-general
287 (defcustom org-export-with-tags
'not-in-toc
288 "If nil, do not export tags, just remove them from headlines.
289 If this is the symbol `not-in-toc', tags will be removed from table of
290 contents entries, but still be shown in the headlines of the document.
292 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
293 :group
'org-export-general
295 (const :tag
"Off" nil
)
296 (const :tag
"Not in TOC" not-in-toc
)
297 (const :tag
"On" t
)))
299 (defcustom org-export-with-drawers nil
300 "Non-nil means, export with drawers like the property drawer.
301 When t, all drawers are exported. This may also be a list of
302 drawer names to export."
303 :group
'org-export-general
305 (const :tag
"All drawers" t
)
306 (const :tag
"None" nil
)
307 (repeat :tag
"Selected drawers"
308 (string :tag
"Drawer name"))))
310 (defvar org-export-preprocess-hook nil
311 "Hook for preprocessing an export buffer.
312 Pretty much the first thing when exporting is running this hook.")
314 (defvar org-export-preprocess-after-include-files-hook nil
315 "Hook for preprocessing an export buffer.
316 This is run after the contents of included files have been inserted.")
318 (defvar org-export-preprocess-after-tree-selection-hook nil
319 "Hook for preprocessing an export buffer.
320 This is run after selection of trees to be exported has happened.
321 This selection includes tags-based selection, as well as removal
322 of commented and archived trees.")
324 (defvar org-export-preprocess-before-backend-specifics-hook nil
325 "Hook run before backend-specific functions are called during preprocessing.")
327 (defvar org-export-preprocess-final-hook nil
328 "Hook for preprocessing an export buffer.
329 This is run as the last thing in the preprocessing buffer, just before
330 returning the buffer string to the backend.")
332 (defgroup org-export-translation nil
333 "Options for translating special ascii sequences for the export backends."
334 :tag
"Org Export Translation"
337 (defcustom org-export-with-emphasize t
338 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
339 If the export target supports emphasizing text, the word will be
340 typeset in bold, italic, or underlined, respectively. Works only for
341 single words, but you can say: I *really* *mean* *this*.
342 Not all export backends support this.
344 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
345 :group
'org-export-translation
348 (defcustom org-export-with-footnotes t
349 "If nil, export [1] as a footnote marker.
350 Lines starting with [1] will be formatted as footnotes.
352 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
353 :group
'org-export-translation
356 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
357 <h2 class=\"footnotes\">%s: </h2>
358 <div id=\"text-footnotes\">
362 "Format for the footnotes section.
363 Should contain a two instances of %s. The first will be replaced with the
364 language-specific word for \"Footnotes\", the second one will be replaced
365 by the footnotes themselves."
366 :group
'org-export-html
369 (defcustom org-export-with-sub-superscripts t
370 "Non-nil means, interpret \"_\" and \"^\" for export.
371 When this option is turned on, you can use TeX-like syntax for sub- and
372 superscripts. Several characters after \"_\" or \"^\" will be
373 considered as a single item - so grouping with {} is normally not
374 needed. For example, the following things will be parsed as single
375 sub- or superscripts.
377 10^24 or 10^tau several digits will be considered 1 item.
378 10^-12 or 10^-tau a leading sign with digits or a word
379 x^2-y^3 will be read as x^2 - y^3, because items are
380 terminated by almost any nonword/nondigit char.
381 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
383 Still, ambiguity is possible - so when in doubt use {} to enclose the
384 sub/superscript. If you set this variable to the symbol `{}',
385 the braces are *required* in order to trigger interpretations as
386 sub/superscript. This can be helpful in documents that need \"_\"
387 frequently in plain text.
389 Not all export backends support this, but HTML does.
391 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
392 :group
'org-export-translation
394 (const :tag
"Always interpret" t
)
395 (const :tag
"Only with braces" {})
396 (const :tag
"Never interpret" nil
)))
398 (defcustom org-export-with-TeX-macros t
399 "Non-nil means, interpret simple TeX-like macros when exporting.
400 For example, HTML export converts \\alpha to α and \\AA to Å.
401 Not only real TeX macros will work here, but the standard HTML entities
402 for math can be used as macro names as well. For a list of supported
403 names in HTML export, see the constant `org-html-entities'.
404 Not all export backends support this.
406 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
407 :group
'org-export-translation
408 :group
'org-export-latex
411 (defcustom org-export-with-LaTeX-fragments nil
412 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
413 When set, the exporter will find LaTeX environments if the \\begin line is
414 the first non-white thing on a line. It will also find the math delimiters
415 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
418 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
419 :group
'org-export-translation
420 :group
'org-export-latex
423 (defcustom org-export-with-fixed-width t
424 "Non-nil means, lines starting with \":\" will be in fixed width font.
425 This can be used to have pre-formatted text, fragments of code etc. For
427 : ;; Some Lisp examples
430 will be looking just like this in also HTML. See also the QUOTE keyword.
431 Not all export backends support this.
433 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
434 :group
'org-export-translation
437 (defcustom org-match-sexp-depth
3
438 "Number of stacked braces for sub/superscript matching.
439 This has to be set before loading org.el to be effective."
440 :group
'org-export-translation
443 (defgroup org-export-tables nil
444 "Options for exporting tables in Org-mode."
445 :tag
"Org Export Tables"
448 (defcustom org-export-with-tables t
449 "If non-nil, lines starting with \"|\" define a table.
452 | Name | Address | Birthday |
453 |-------------+----------+-----------|
454 | Arthur Dent | England | 29.2.2100 |
456 Not all export backends support this.
458 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
459 :group
'org-export-tables
462 (defcustom org-export-highlight-first-table-line t
463 "Non-nil means, highlight the first table line.
464 In HTML export, this means use <th> instead of <td>.
465 In tables created with table.el, this applies to the first table line.
466 In Org-mode tables, all lines before the first horizontal separator
467 line will be formatted with <th> tags."
468 :group
'org-export-tables
471 (defcustom org-export-table-remove-special-lines t
472 "Remove special lines and marking characters in calculating tables.
473 This removes the special marking character column from tables that are set
474 up for spreadsheet calculations. It also removes the entire lines
475 marked with `!', `_', or `^'. The lines with `$' are kept, because
476 the values of constants may be useful to have."
477 :group
'org-export-tables
480 (defcustom org-export-prefer-native-exporter-for-tables nil
481 "Non-nil means, always export tables created with table.el natively.
482 Natively means, use the HTML code generator in table.el.
483 When nil, Org-mode's own HTML generator is used when possible (i.e. if
484 the table does not use row- or column-spanning). This has the
485 advantage, that the automatic HTML conversions for math symbols and
486 sub/superscripts can be applied. Org-mode's HTML generator is also
488 :group
'org-export-tables
491 (defgroup org-export-ascii nil
492 "Options specific for ASCII export of Org-mode files."
493 :tag
"Org Export ASCII"
496 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
497 "Characters for underlining headings in ASCII export.
498 In the given sequence, these characters will be used for level 1, 2, ..."
499 :group
'org-export-ascii
500 :type
'(repeat character
))
502 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
503 "Bullet characters for headlines converted to lists in ASCII export.
504 The first character is used for the first lest level generated in this
505 way, and so on. If there are more levels than characters given here,
506 the list will be repeated.
507 Note that plain lists will keep the same bullets as the have in the
509 :group
'org-export-ascii
510 :type
'(repeat character
))
512 (defcustom org-export-ascii-links-to-notes t
513 "Non-nil means, convert links to notes before the next headline.
514 When nil, the link will be exported in place. If the line becomes long
515 in this way, it will be wrapped."
516 :group
'org-export-ascii
519 (defgroup org-export-xml nil
520 "Options specific for XML export of Org-mode files."
521 :tag
"Org Export XML"
524 (defgroup org-export-html nil
525 "Options specific for HTML export of Org-mode files."
526 :tag
"Org Export HTML"
529 (defcustom org-export-html-coding-system nil
530 "Coding system for HTML export, defaults to buffer-file-coding-system."
531 :group
'org-export-html
532 :type
'coding-system
)
534 (defcustom org-export-html-extension
"html"
535 "The extension for exported HTML files."
536 :group
'org-export-html
539 (defcustom org-export-html-link-up
""
540 "Where should the \"UP\" link of exported HTML pages lead?"
541 :group
'org-export-html
542 :type
'(string :tag
"File or URL"))
544 (defcustom org-export-html-link-home
""
545 "Where should the \"HOME\" link of exported HTML pages lead?"
546 :group
'org-export-html
547 :type
'(string :tag
"File or URL"))
549 (defcustom org-export-html-style-include-scripts t
550 "Non-nil means, include the javascript snippets in exported HTML files.
551 The actual script is defined in `org-export-html-scripts' and should
553 :group
'org-export-html
556 (defconst org-export-html-scripts
557 "<script type=\"text/javascript\">
558 <!--/*--><![CDATA[/*><!--*/
559 function CodeHighlightOn(elem, id)
561 var target = document.getElementById(id);
563 elem.cacheClassElem = elem.className;
564 elem.cacheClassTarget = target.className;
565 target.className = \"code-highlighted\";
566 elem.className = \"code-highlighted\";
569 function CodeHighlightOff(elem, id)
571 var target = document.getElementById(id);
572 if(elem.cacheClassElem)
573 elem.className = elem.cacheClassElem;
574 if(elem.cacheClassTarget)
575 target.className = elem.cacheClassTarget;
579 "Basic javascript that is needed by HTML files produced by Org-mode.")
581 (defconst org-export-html-style-default
582 "<style type=\"text/css\">
583 <!--/*--><![CDATA[/*><!--*/
584 html { font-family: Times, serif; font-size: 12pt; }
585 .title { text-align: center; }
586 .todo { color: red; }
587 .done { color: green; }
588 .tag { background-color: #add8e6; font-weight:normal }
590 .timestamp { color: #bebebe; }
591 .timestamp-kwd { color: #5f9ea0; }
592 p.verse { margin-left: 3% }
594 border: 1pt solid #AEBDCC;
595 background-color: #F3F5F7;
597 font-family: courier, monospace;
601 table { border-collapse: collapse; }
602 td, th { vertical-align: top; }
603 dt { font-weight: bold; }
604 div.figure { padding: 0.5em; }
605 div.figure p { text-align: center; }
606 .linenr { font-size:smaller }
607 .code-highlighted {background-color:#ffff00;}
608 .org-info-js_info-navigation { border-style:none; }
609 #org-info-js_console-label { font-size:10px; font-weight:bold;
610 white-space:nowrap; }
611 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
615 "The default style specification for exported HTML files.
616 Please use the variables `org-export-html-style' and
617 `org-export-html-style-extra' to add to this style. If you wish to not
618 have the default style included, customize the variable
619 `org-export-html-style-include-default'.")
621 (defcustom org-export-html-style-include-default t
622 "Non-nil means, include the default style in exported HTML files.
623 The actual style is defined in `org-export-html-style-default' and should
624 not be modified. Use the variables `org-export-html-style' to add
625 your own style information."
626 :group
'org-export-html
629 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
631 (defcustom org-export-html-style
""
632 "Org-wide style definitions for exported HTML files.
634 This variable needs to contain the full HTML structure to provide a style,
635 including the surrounding HTML tags. If you set the value of this variable,
636 you should consider to include definitions for the following classes:
637 title, todo, done, timestamp, timestamp-kwd, tag, target.
639 For example, a valid value would be:
641 <style type=\"text/css\">
643 p { font-weight: normal; color: gray; }
645 .title { text-align: center; }
646 .todo, .timestamp-kwd { color: red; }
647 .done { color: green; }
651 If you'd like to refer to en external style file, use something like
653 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
655 As the value of this option simply gets inserted into the HTML <head> header,
656 you can \"misuse\" it to add arbitrary text to the header.
657 See also the variable `org-export-html-style-extra'."
658 :group
'org-export-html
661 (put 'org-export-html-style
'safe-local-variable
'stringp
)
663 (defcustom org-export-html-style-extra
""
664 "Additional style information for HTML export.
665 The value of this variable is inserted into the HTML buffer right after
666 the value of `org-export-html-style'. Use this variable for per-file
667 settings of style information, and do not forget to surround the style
668 settings with <style>...</style> tags."
669 :group
'org-export-html
672 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
674 (defcustom org-export-html-tag-class-prefix
""
675 "Prefix to clas names for TODO keywords.
676 Each tag gets a class given by the tag itself, with this prefix.
677 The default prefix is empty because it is nice to just use the keyword
678 as a class name. But if you get into conflicts with other, existing
679 CSS classes, then this prefic can be very useful."
680 :group
'org-export-html
683 (defcustom org-export-html-todo-kwd-class-prefix
""
684 "Prefix to clas names for TODO keywords.
685 Each TODO keyword gets a class given by the keyword itself, with this prefix.
686 The default prefix is empty because it is nice to just use the keyword
687 as a class name. But if you get into conflicts with other, existing
688 CSS classes, then this prefic can be very useful."
689 :group
'org-export-html
692 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
693 "Format for typesetting the document title in HTML export."
694 :group
'org-export-html
697 (defcustom org-export-html-toplevel-hlevel
2
698 "The <H> level for level 1 headings in HTML export.
699 This is also important for the classes that will be wrapped around headlines
700 and outline structure. If this variable is 1, the top-level headlines will
701 be <h1>, and the corresponding classes will be outline-1, section-number-1,
702 and outline-text-1. If this is 2, all of these will get a 2 instead.
703 The default for this variable is 2, because we use <h1> for formatting the
705 :group
'org-export-html
708 (defcustom org-export-html-link-org-files-as-html t
709 "Non-nil means, make file links to `file.org' point to `file.html'.
710 When org-mode is exporting an org-mode file to HTML, links to
711 non-html files are directly put into a href tag in HTML.
712 However, links to other Org-mode files (recognized by the
713 extension `.org.) should become links to the corresponding html
714 file, assuming that the linked org-mode file will also be
716 When nil, the links still point to the plain `.org' file."
717 :group
'org-export-html
720 (defcustom org-export-html-inline-images
'maybe
721 "Non-nil means, inline images into exported HTML pages.
722 This is done using an <img> tag. When nil, an anchor with href is used to
723 link to the image. If this option is `maybe', then images in links with
724 an empty description will be inlined, while images with a description will
726 :group
'org-export-html
727 :type
'(choice (const :tag
"Never" nil
)
728 (const :tag
"Always" t
)
729 (const :tag
"When there is no description" maybe
)))
731 (defcustom org-export-html-inline-image-extensions
732 '("png" "jpeg" "jpg" "gif")
733 "Extensions of image files that can be inlined into HTML."
734 :group
'org-export-html
735 :type
'(repeat (string :tag
"Extension")))
738 (defcustom org-export-html-expand t
739 "Non-nil means, for HTML export, treat @<...> as HTML tag.
740 When nil, these tags will be exported as plain text and therefore
741 not be interpreted by a browser.
743 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
744 :group
'org-export-html
747 (defcustom org-export-html-table-tag
748 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
749 "The HTML tag that is used to start a table.
750 This must be a <table> tag, but you may change the options like
751 borders and spacing."
752 :group
'org-export-html
755 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
756 "The opening tag for table header fields.
757 This is customizable so that alignment options can be specified."
758 :group
'org-export-tables
759 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
761 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
762 "The opening tag for table data fields.
763 This is customizable so that alignment options can be specified."
764 :group
'org-export-tables
765 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
767 (defcustom org-export-html-validation-link nil
768 "Non-nil means, add validationlink to postamble of HTML exported files."
769 :group
'org-export-html
771 (const :tag
"Nothing" nil
)
772 (const :tag
"XHTML 1.0" "<p class=\"xhtml-validation\"><a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a></p>")
773 (string :tag
"Specify full HTML")))
776 (defcustom org-export-html-with-timestamp nil
777 "If non-nil, write `org-export-html-html-helper-timestamp'
778 into the exported HTML text. Otherwise, the buffer will just be saved
780 :group
'org-export-html
783 (defcustom org-export-html-html-helper-timestamp
784 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
785 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
786 :group
'org-export-html
789 (defgroup org-export-htmlize nil
790 "Options for processing examples with htmlize.el."
791 :tag
"Org Export Htmlize"
792 :group
'org-export-html
)
794 (defcustom org-export-htmlize-output-type
'inline-css
795 "Output type to be used by htmlize when formatting code snippets.
796 Normally this is `inline-css', but if you have defined to appropriate
797 classes in your css style file, setting this to `css' means that the
798 fontification will use the class names.
799 See also the function `org-export-htmlize-generate-css'."
800 :group
'org-export-htmlize
801 :type
'(choice (const css
) (const inline-css
)))
803 (defcustom org-export-htmlize-css-font-prefix
"org-"
804 "The prefix for CSS class names for htmlize font specifications."
805 :group
'org-export-htmlize
808 (defgroup org-export-icalendar nil
809 "Options specific for iCalendar export of Org-mode files."
810 :tag
"Org Export iCalendar"
813 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
814 "The file name for the iCalendar file covering all agenda files.
815 This file is created with the command \\[org-export-icalendar-all-agenda-files].
816 The file name should be absolute, the file will be overwritten without warning."
817 :group
'org-export-icalendar
820 (defcustom org-icalendar-combined-name
"OrgMode"
821 "Calendar name for the combined iCalendar representing all agenda files."
822 :group
'org-export-icalendar
825 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
826 "Contexts where iCalendar export should use a deadline time stamp.
827 This is a list with several symbols in it. Valid symbol are:
829 event-if-todo Deadlines in TODO entries become calendar events.
830 event-if-not-todo Deadlines in non-TODO entries become calendar events.
831 todo-due Use deadlines in TODO entries as due-dates"
832 :group
'org-export-icalendar
833 :type
'(set :greedy t
834 (const :tag
"Deadlines in non-TODO entries become events"
836 (const :tag
"Deadline in TODO entries become events"
838 (const :tag
"Deadlines in TODO entries become due-dates"
841 (defcustom org-icalendar-use-scheduled
'(todo-start)
842 "Contexts where iCalendar export should use a scheduling time stamp.
843 This is a list with several symbols in it. Valid symbol are:
845 event-if-todo Scheduling time stamps in TODO entries become an event.
846 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
847 todo-start Scheduling time stamps in TODO entries become start date.
848 Some calendar applications show TODO entries only after
850 :group
'org-export-icalendar
851 :type
'(set :greedy t
853 "SCHEDULED timestamps in non-TODO entries become events"
855 (const :tag
"SCHEDULED timestamps in TODO entries become events"
857 (const :tag
"SCHEDULED in TODO entries become start date"
860 (defcustom org-icalendar-categories
'(local-tags category
)
861 "Items that should be entered into the categories field.
862 This is a list of symbols, the following are valid:
864 category The Org-mode category of the current file or tree
865 todo-state The todo state, if any
866 local-tags The tags, defined in the current line
867 all-tags All tags, including inherited ones."
868 :group
'org-export-icalendar
871 (const :tag
"The file or tree category" category
)
872 (const :tag
"The TODO state" todo-state
)
873 (const :tag
"Tags defined in current line" local-tags
)
874 (const :tag
"All tags, including inherited ones" all-tags
))))
876 (defcustom org-icalendar-include-todo nil
877 "Non-nil means, export to iCalendar files should also cover TODO items."
878 :group
'org-export-icalendar
880 (const :tag
"None" nil
)
881 (const :tag
"Unfinished" t
)
882 (const :tag
"All" all
)))
884 (defcustom org-icalendar-include-sexps t
885 "Non-nil means, export to iCalendar files should also cover sexp entries.
886 These are entries like in the diary, but directly in an Org-mode file."
887 :group
'org-export-icalendar
890 (defcustom org-icalendar-include-body
100
891 "Amount of text below headline to be included in iCalendar export.
892 This is a number of characters that should maximally be included.
893 Properties, scheduling and clocking lines will always be removed.
894 The text will be inserted into the DESCRIPTION field."
895 :group
'org-export-icalendar
897 (const :tag
"Nothing" nil
)
898 (const :tag
"Everything" t
)
899 (integer :tag
"Max characters")))
901 (defcustom org-icalendar-store-UID nil
902 "Non-nil means, store any created UIDs in properties.
903 The iCalendar standard requires that all entries have a unique identifier.
904 Org will create these identifiers as needed. When this variable is non-nil,
905 the created UIDs will be stored in the ID property of the entry. Then the
906 next time this entry is exported, it will be exported with the same UID,
907 superceding the previous form of it. This is essential for
908 synchronization services.
909 This variable is not turned on by default because we want to avoid creating
910 a property drawer in every entry if people are only playing with this feature,
911 or if they are only using it locally."
912 :group
'org-export-icalendar
917 ;;; Variables, constants, and parameter plists
919 (defconst org-level-max
20)
921 (defvar org-export-html-preamble nil
922 "Preamble, to be inserted just before <body>. Set by publishing functions.")
923 (defvar org-export-html-postamble nil
924 "Preamble, to be inserted just after </body>. Set by publishing functions.")
925 (defvar org-export-html-auto-preamble t
926 "Should default preamble be inserted? Set by publishing functions.")
927 (defvar org-export-html-auto-postamble t
928 "Should default postamble be inserted? Set by publishing functions.")
929 (defvar org-current-export-file nil
) ; dynamically scoped parameter
930 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
931 (defvar org-export-opt-plist nil
932 "Contains the current option plist.")
934 (defconst org-export-plist-vars
935 '((:link-up nil org-export-html-link-up
)
936 (:link-home nil org-export-html-link-home
)
937 (:language nil org-export-default-language
)
938 (:keywords nil org-export-page-keywords
)
939 (:description nil org-export-page-description
)
940 (:customtime nil org-display-custom-times
)
941 (:headline-levels
"H" org-export-headline-levels
)
942 (:section-numbers
"num" org-export-with-section-numbers
)
943 (:section-number-format nil org-export-section-number-format
)
944 (:table-of-contents
"toc" org-export-with-toc
)
945 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
946 (:archived-trees nil org-export-with-archived-trees
)
947 (:emphasize
"*" org-export-with-emphasize
)
948 (:sub-superscript
"^" org-export-with-sub-superscripts
)
949 (:special-strings
"-" org-export-with-special-strings
)
950 (:footnotes
"f" org-export-with-footnotes
)
951 (:drawers
"d" org-export-with-drawers
)
952 (:tags
"tags" org-export-with-tags
)
953 (:todo-keywords
"todo" org-export-with-todo-keywords
)
954 (:priority
"pri" org-export-with-priority
)
955 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
956 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
957 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
958 (:fixed-width
":" org-export-with-fixed-width
)
959 (:timestamps
"<" org-export-with-timestamps
)
960 (:author-info
"author" org-export-author-info
)
961 (:creator-info
"creator" org-export-creator-info
)
962 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
963 (:tables
"|" org-export-with-tables
)
964 (:table-auto-headline nil org-export-highlight-first-table-line
)
965 (:style-include-default nil org-export-html-style-include-default
)
966 (:style-include-scripts nil org-export-html-style-include-scripts
)
967 (:style nil org-export-html-style
)
968 (:style-extra nil org-export-html-style-extra
)
969 (:agenda-style nil org-agenda-export-html-style
)
970 (:convert-org-links nil org-export-html-link-org-files-as-html
)
971 (:inline-images nil org-export-html-inline-images
)
972 (:html-extension nil org-export-html-extension
)
973 (:html-table-tag nil org-export-html-table-tag
)
974 (:expand-quoted-html
"@" org-export-html-expand
)
975 (:timestamp nil org-export-html-with-timestamp
)
976 (:publishing-directory nil org-export-publishing-directory
)
977 (:preamble nil org-export-html-preamble
)
978 (:postamble nil org-export-html-postamble
)
979 (:auto-preamble nil org-export-html-auto-preamble
)
980 (:auto-postamble nil org-export-html-auto-postamble
)
981 (:author nil user-full-name
)
982 (:email nil user-mail-address
)
983 (:select-tags nil org-export-select-tags
)
984 (:exclude-tags nil org-export-exclude-tags
))
985 "List of properties that represent export/publishing variables.
986 Each element is a list of 3 items:
987 1. The property that is used internally, and also for org-publish-project-alist
988 2. The string that can be used in the OPTION lines to set this option,
989 or nil if this option cannot be changed in this way
990 3. The customization variable that sets the default for this option."
994 (defun org-default-export-plist ()
995 "Return the property list with default settings for the export variables."
996 (let ((l org-export-plist-vars
) rtn e
)
997 (while (setq e
(pop l
))
998 (setq rtn
(cons (car e
) (cons (symbol-value (nth 2 e
)) rtn
))))
1001 (defvar org-export-inbuffer-options-extra nil
1002 "List of additional in-buffer options that should be detected.
1003 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
1004 etc. Extensions can add to this list to get their options detected, and they
1005 can then add a function to `org-export-options-filters' to process these
1007 Each element in this list must be a list, with the in-buffer keyword as car,
1008 and a property (a symbol) as the next element. All occurrences of the
1009 keyword will be found, the values concatenated with a space character
1010 in between, and the result stored in the export options property list.")
1012 (defvar org-export-options-filters nil
1013 "Functions to be called to finalize the export/publishing options.
1014 All these options are stored in a property list, and each of the functions
1015 in this hook gets a chance to modify this property list. Each function
1016 must accept the property list as an argument, and must return the (possibly
1019 ;; FIXME: should we fold case here?
1020 (defun org-infile-export-plist ()
1021 "Return the property list with file-local settings for export."
1025 (goto-char (point-min))
1026 (let ((re (org-make-options-regexp
1028 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
1029 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
1030 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
1031 "KEYWORDS" "DESCRIPTION")
1032 (mapcar 'car org-export-inbuffer-options-extra
))))
1033 p key val text options a pr style
1035 ext-setup-or-nil setup-contents
(start 0))
1036 (while (or (and ext-setup-or-nil
1037 (string-match re ext-setup-or-nil start
)
1038 (setq start
(match-end 0)))
1039 (and (setq ext-setup-or-nil nil start
0)
1040 (re-search-forward re nil t
)))
1041 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
1042 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
1044 ((setq a
(assoc key org-export-inbuffer-options-extra
))
1046 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
1047 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
1048 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
1049 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
1050 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
1051 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
1052 ((string-equal key
"DESCRIPTION")
1053 (setq p
(plist-put p
:description val
)))
1054 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
1055 ((string-equal key
"STYLE")
1056 (setq style
(concat style
"\n" val
)))
1057 ((string-equal key
"LATEX_HEADER")
1058 (setq latex-header
(concat latex-header
"\n" val
)))
1059 ((string-equal key
"TEXT")
1060 (setq text
(if text
(concat text
"\n" val
) val
)))
1061 ((string-equal key
"OPTIONS")
1062 (setq options
(concat val
" " options
)))
1063 ((string-equal key
"LINK_UP")
1064 (setq p
(plist-put p
:link-up val
)))
1065 ((string-equal key
"LINK_HOME")
1066 (setq p
(plist-put p
:link-home val
)))
1067 ((string-equal key
"EXPORT_SELECT_TAGS")
1068 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
1069 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
1070 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
1071 ((equal key
"SETUPFILE")
1072 (setq setup-contents
(org-file-contents
1074 (org-remove-double-quotes
1077 (if (not ext-setup-or-nil
)
1078 (setq ext-setup-or-nil setup-contents start
0)
1079 (setq ext-setup-or-nil
1080 (concat (substring ext-setup-or-nil
0 start
)
1081 "\n" setup-contents
"\n"
1082 (substring ext-setup-or-nil start
)))))))
1083 (setq p
(plist-put p
:text text
))
1084 (when style
(setq p
(plist-put p
:style-extra style
)))
1086 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
1088 (setq p
(org-export-add-options-to-plist p options
)))
1089 ;; Add macro definitions
1090 (goto-char (point-min))
1091 (while (re-search-forward
1092 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
1094 (setq p
(plist-put p
(intern (concat ":macro-"
1095 (downcase (match-string 1))))
1099 (defun org-export-add-options-to-plist (p options
)
1100 "Parse an OPTIONS line and set values in the property list P."
1103 (let ((op org-export-plist-vars
))
1104 (while (setq o
(pop op
))
1106 (string-match (concat (regexp-quote (nth 1 o
))
1107 ":\\([^ \t\n\r;,.]*\\)")
1109 (setq p
(plist-put p
(car o
)
1110 (car (read-from-string
1111 (match-string 1 options
))))))))))
1114 (defun org-export-add-subtree-options (p pos
)
1115 "Add options in subtree at position POS to property list P."
1118 (when (org-at-heading-p)
1120 ;; This is actually read in `org-export-get-title-from-subtree'
1121 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1122 ;; (setq p (plist-put p :title a)))
1123 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1124 (setq p
(plist-put p
:text a
)))
1125 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1126 (setq p
(org-export-add-options-to-plist p a
)))))
1129 (defun org-export-directory (type plist
)
1130 (let* ((val (plist-get plist
:publishing-directory
))
1131 (dir (if (listp val
)
1132 (or (cdr (assoc type val
)) ".")
1136 (defun org-export-process-option-filters (plist)
1137 (let ((functions org-export-options-filters
) f
)
1138 (while (setq f
(pop functions
))
1139 (setq plist
(funcall f plist
))))
1143 (defun org-export (&optional arg
)
1144 "Export dispatcher for Org-mode.
1145 When `org-export-run-in-background' is non-nil, try to run the command
1146 in the background. This will be done only for commands that write
1147 to a file. For details see the docstring of `org-export-run-in-background'.
1149 The prefix argument ARG will be passed to the exporter. However, if
1150 ARG is a double universal prefix `C-u C-u', that means to inverse the
1151 value of `org-export-run-in-background'."
1153 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1154 (help "[t] insert the export option template
1155 \[v] limit export to visible part of outline tree
1157 \[a] export as ASCII
1160 \[H] export as HTML to temporary buffer
1161 \[R] export region as HTML
1162 \[b] export as HTML and browse immediately
1165 \[l] export as LaTeX
1166 \[p] export as LaTeX and process to PDF
1167 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1168 \[L] export as LaTeX to temporary buffer
1170 \[i] export current file as iCalendar file
1171 \[I] export all agenda files as iCalendar files
1172 \[c] export agenda files into combined iCalendar file
1174 \[F] publish current file
1175 \[P] publish current project
1176 \[X] publish... (project will be prompted for)
1177 \[A] publish all projects")
1179 '((?t org-insert-export-options-template nil
)
1180 (?v org-export-visible nil
)
1181 (?a org-export-as-ascii t
)
1182 (?h org-export-as-html t
)
1183 (?b org-export-as-html-and-open t
)
1184 (?H org-export-as-html-to-buffer nil
)
1185 (?R org-export-region-as-html nil
)
1186 (?x org-export-as-xoxo t
)
1187 (?l org-export-as-latex t
)
1188 (?p org-export-as-pdf t
)
1189 (?d org-export-as-pdf-and-open t
)
1190 (?L org-export-as-latex-to-buffer nil
)
1191 (?i org-export-icalendar-this-file t
)
1192 (?I org-export-icalendar-all-agenda-files t
)
1193 (?c org-export-icalendar-combine-agenda-files t
)
1194 (?F org-publish-current-file t
)
1195 (?P org-publish-current-project t
)
1197 (?A org-publish-all t
)))
1200 (save-window-excursion
1201 (delete-other-windows)
1202 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1204 (org-fit-window-to-buffer (get-buffer-window
1205 "*Org Export/Publishing Help*"))
1206 (message "Select command: ")
1207 (setq r1
(read-char-exclusive))))
1208 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1209 (unless (setq ass
(assq r2 cmds
))
1210 (error "No command associated with key %c" r1
))
1211 (if (and bg
(nth 2 ass
)
1212 (not (buffer-base-buffer))
1213 (not (org-region-active-p)))
1214 ;; execute in background
1215 (let ((p (start-process
1216 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1218 (expand-file-name invocation-name invocation-directory
)
1221 "--eval" "(require 'org-exp)"
1222 "--eval" "(setq org-wait .2)"
1224 "-f" (symbol-name (nth 1 ass
)))))
1225 (set-process-sentinel p
'org-export-process-sentinel
)
1226 (message "Background process \"%s\": started" p
))
1227 ;; background processing not requested, or not possible
1228 (call-interactively (nth 1 ass
)))))
1230 (defun org-export-process-sentinel (process status
)
1231 (if (string-match "\n+\\'" status
)
1232 (setq status
(substring status
0 -
1)))
1233 (message "Background process \"%s\": %s" process status
))
1235 (defconst org-html-entities
1276 ("Aring") ("AA".
"Å")
1365 ("varepsilon".
"ε")
1378 ("sigmaf") ("varsigma".
"ς")
1386 ("thetasym") ("vartheta".
"ϑ")
1389 ("bull") ("bullet".
"•")
1390 ("hellip") ("dots".
"…")
1400 ("larr") ("leftarrow".
"←") ("gets".
"←")
1401 ("uarr") ("uparrow".
"↑")
1402 ("rarr") ("to".
"→") ("rightarrow".
"→")
1403 ("darr")("downarrow".
"↓")
1404 ("harr") ("leftrightarrow".
"↔")
1405 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1406 ("lArr") ("Leftarrow".
"⇐")
1407 ("uArr") ("Uparrow".
"⇑")
1408 ("rArr") ("Rightarrow".
"⇒")
1409 ("dArr") ("Downarrow".
"⇓")
1410 ("hArr") ("Leftrightarrow".
"⇔")
1412 ("part") ("partial".
"∂")
1413 ("exist") ("exists".
"∃")
1414 ("empty") ("emptyset".
"∅")
1416 ("isin") ("in".
"∈")
1422 ("lowast") ("ast".
"∗")
1424 ("prop") ("proptp".
"∝")
1425 ("infin") ("infty".
"∞")
1426 ("ang") ("angle".
"∠")
1427 ("and") ("wedge".
"∧")
1428 ("or") ("vee".
"∨")
1434 ("cong") ("simeq".
"≅")
1435 ("asymp")("approx".
"≈")
1436 ("ne") ("neq".
"≠")
1440 ("sub") ("subset".
"⊂")
1441 ("sup") ("supset".
"⊃")
1448 ("sdot") ("cdot".
"⋅")
1455 ("loz") ("Diamond".
"◊")
1456 ("spades") ("spadesuit".
"♠")
1457 ("clubs") ("clubsuit".
"♣")
1458 ("hearts") ("diamondsuit".
"♥")
1459 ("diams") ("diamondsuit".
"♦")
1460 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1527 "Entities for TeX->HTML translation.
1528 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1529 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1530 In that case, \"\\ent\" will be translated to \"&other;\".
1531 The list contains HTML entities for Latin-1, Greek and other symbols.
1532 It is supplemented by a number of commonly used TeX macros with appropriate
1533 translations. There is currently no way for users to extend this.")
1535 ;;; General functions for all backends
1537 (defvar org-export-target-aliases nil
1538 "Alist of targets with invisible aliases.")
1539 (defvar org-export-code-refs nil
1540 "Alist of code references and line numbers")
1542 (defun org-export-preprocess-string (string &rest parameters
)
1543 "Cleanup STRING so that that the true exported has a more consistent source.
1544 This function takes STRING, which should be a buffer-string of an org-file
1545 to export. It then creates a temporary buffer where it does its job.
1546 The result is then again returned as a string, and the exporter works
1547 on this string to produce the exported version."
1549 (let* ((htmlp (plist-get parameters
:for-html
))
1550 (asciip (plist-get parameters
:for-ascii
))
1551 (latexp (plist-get parameters
:for-LaTeX
))
1552 (docbookp (plist-get parameters
:for-docbook
))
1553 (backend (cond (htmlp 'html
)
1556 (docbookp 'docbook
)))
1557 (archived-trees (plist-get parameters
:archived-trees
))
1558 (inhibit-read-only t
)
1559 (drawers org-drawers
)
1560 (outline-regexp "\\*+ ")
1563 (setq org-export-target-aliases nil
)
1564 (setq org-export-code-refs nil
)
1566 (with-current-buffer (get-buffer-create " org-mode-tmp")
1569 (setq case-fold-search t
)
1571 ;; Remove license-to-kill stuff
1572 ;; The caller marks some stuff for killing, stuff that has been
1573 ;; used to create the page title, for example.
1574 (org-export-kill-licensed-text)
1576 (let ((org-inhibit-startup t
)) (org-mode))
1577 (setq case-fold-search t
)
1580 (run-hooks 'org-export-preprocess-hook
)
1582 ;; Process the macros
1583 (org-export-preprocess-apply-macros)
1584 (run-hooks 'org-export-preprocess-after-macros-hook
)
1586 (untabify (point-min) (point-max))
1588 ;; Handle include files, and call a hook
1589 (org-export-handle-include-files)
1590 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1592 ;; Get rid of archived trees
1593 (org-export-remove-archived-trees archived-trees
)
1595 ;; Remove comment environment and comment subtrees
1596 (org-export-remove-comment-blocks-and-subtrees)
1598 ;; Get rid of excluded trees, and call a hook
1599 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1600 (plist-get parameters
:exclude-tags
))
1601 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1603 ;; Handle source code snippets
1604 (org-export-replace-src-segments-and-examples backend
)
1606 ;; Protect short examples marked by a leading colon
1607 (org-export-protect-colon-examples)
1609 ;; Normalize footnotes
1610 (when (plist-get parameters
:footnotes
)
1611 (org-footnote-normalize nil t
))
1613 ;; Find all headings and compute the targets for them
1614 (setq target-alist
(org-export-define-heading-targets target-alist
))
1616 ;; Get rid of drawers
1617 (org-export-remove-or-extract-drawers drawers
1618 (plist-get parameters
:drawers
))
1620 ;; Get the correct stuff before the first headline
1621 (when (plist-get parameters
:skip-before-1st-heading
)
1622 (goto-char (point-min))
1623 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1624 (delete-region (point-min) (match-beginning 0))
1625 (goto-char (point-min))
1627 (when (plist-get parameters
:add-text
)
1628 (goto-char (point-min))
1629 (insert (plist-get parameters
:add-text
) "\n"))
1631 ;; Remove todo-keywords before exporting, if the user has requested so
1632 (org-export-remove-headline-metadata parameters
)
1634 ;; Find targets in comments and move them out of comments,
1635 ;; but mark them as targets that should be invisible
1636 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1638 ;; Select and protect backend specific stuff, throw away stuff
1639 ;; that is specific for other backends
1640 (org-export-select-backend-specific-text backend
)
1642 ;; Protect quoted subtrees
1643 (org-export-protect-quoted-subtrees)
1645 ;; Remove clock lines
1646 (org-export-remove-clock-lines)
1648 ;; Protect verbatim elements
1649 (org-export-protect-verbatim)
1651 ;; Blockquotes and verse
1652 (org-export-mark-blockquote-and-verse)
1654 ;; Remove timestamps, if the user has requested so
1655 (unless (plist-get parameters
:timestamps
)
1656 (org-export-remove-timestamps))
1658 ;; Attach captions to the correct object
1659 (setq target-alist
(org-export-attach-captions-and-attributes
1660 backend target-alist
))
1662 ;; Find matches for radio targets and turn them into internal links
1663 (org-export-mark-radio-links)
1665 ;; Find all links that contain a newline and put them into a single line
1666 (org-export-concatenate-multiline-links)
1668 ;; Normalize links: Convert angle and plain links into bracket links
1669 ;; and expand link abbreviations
1670 (org-export-normalize-links)
1672 ;; Find all internal links. If they have a fuzzy match (i.e. not
1673 ;; a *dedicated* target match, let the link point to the
1674 ;; corresponding section.
1675 (org-export-target-internal-links target-alist
)
1677 ;; Find multiline emphasis and put them into single line
1678 (when (plist-get parameters
:emph-multiline
)
1679 (org-export-concatenate-multiline-emphasis))
1681 ;; Remove special table lines
1682 (when org-export-table-remove-special-lines
1683 (org-export-remove-special-table-lines))
1686 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1688 ;; LaTeX-specific preprocessing
1690 (require 'org-export-latex nil
)
1691 (org-export-latex-preprocess parameters
))
1693 ;; ASCII-specific preprocessing
1695 (org-export-ascii-preprocess))
1697 ;; HTML-specific preprocessing
1699 (org-export-html-preprocess parameters
))
1701 ;; DocBook-specific preprocessing
1703 (require 'org-export-docbook nil
)
1704 (org-export-docbook-preprocess parameters
))
1706 ;; Remove or replace comments
1707 (org-export-handle-comments (plist-get parameters
:comments
))
1709 ;; Run the final hook
1710 (run-hooks 'org-export-preprocess-final-hook
)
1712 (setq rtn
(buffer-string)))
1713 (kill-buffer " org-mode-tmp")
1716 (defun org-export-kill-licensed-text ()
1717 "Remove all text that is marked with a :org-license-to-kill property."
1719 (while (setq p
(text-property-any (point-min) (point-max)
1720 :org-license-to-kill t
))
1722 p
(or (next-single-property-change p
:org-license-to-kill
)
1725 (defun org-export-define-heading-targets (target-alist)
1726 "Find all headings and define the targets for them.
1727 The new targets are added to TARGET-ALIST, which is also returned."
1728 (goto-char (point-min))
1729 (org-init-section-numbers)
1730 (let ((re (concat "^" org-outline-regexp
1731 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1732 level target last-section-target a
)
1733 (while (re-search-forward re nil t
)
1736 (push (cons (org-match-string-no-properties 1)
1737 target
) target-alist
)
1738 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1740 (push (list last-section-target
)
1741 org-export-target-aliases
)
1742 (car org-export-target-aliases
))))
1743 (push (caar target-alist
) (cdr a
)))
1744 (setq level
(org-reduced-level
1745 (save-excursion (goto-char (point-at-bol))
1746 (org-outline-level))))
1747 (setq target
(org-solidify-link-text
1748 (format "sec-%s" (org-section-number level
))))
1749 (setq last-section-target target
)
1750 (push (cons target target
) target-alist
)
1751 (add-text-properties
1752 (point-at-bol) (point-at-eol)
1753 (list 'target target
)))))
1756 (defun org-export-handle-invisible-targets (target-alist)
1757 "Find targets in comments and move them out of comments.
1758 Mark them as invisible targets."
1760 (goto-char (point-min))
1761 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1762 ;; Check if the line before or after is a headline with a target
1763 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1764 (get-text-property (point-at-bol 2) 'target
)))
1766 ;; use the existing target in a neighboring line
1767 (setq tmp
(match-string 2))
1769 (and (looking-at "\n") (delete-char 1))
1770 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1772 (setq a
(or (assoc target org-export-target-aliases
)
1774 (push (list target
) org-export-target-aliases
)
1775 (car org-export-target-aliases
))))
1777 ;; Make an invisible target
1778 (replace-match "\\1(INVISIBLE)"))))
1781 (defun org-export-target-internal-links (target-alist)
1782 "Find all internal links and assign targets to them.
1783 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1784 let the link point to the corresponding section.
1785 This function also handles the id links, if they have a match in
1787 (goto-char (point-min))
1788 (while (re-search-forward org-bracket-link-regexp nil t
)
1790 (let* ((md (match-data))
1791 (desc (match-end 2))
1792 (link (org-link-unescape (match-string 1)))
1793 (slink (org-solidify-link-text link
))
1794 found props pos cref
1797 ((cdr (assoc slink target-alist
)))
1798 ((and (string-match "^id:" link
)
1799 (cdr (assoc (substring link
3) target-alist
))))
1800 ((string-match "^(\\(.*\\))$" link
)
1801 (setq cref
(match-string 1 link
))
1802 (concat "coderef:" cref
))
1803 ((string-match org-link-types-re link
) nil
)
1804 ((or (file-name-absolute-p link
)
1805 (string-match "^\\." link
))
1809 (setq found
(condition-case nil
(org-link-search link
)
1812 (or (org-on-heading-p)
1813 (not (eq found
'dedicated
))))
1814 (or (get-text-property (point) 'target
)
1817 (1- (or (previous-single-property-change
1818 (point) 'target
) 0)))
1822 (goto-char (match-beginning 1))
1823 (setq props
(text-properties-at (point)))
1824 (delete-region (match-beginning 1) (match-end 1))
1827 (unless desc
(insert "][" link
))
1828 (add-text-properties pos
(point) props
))))))
1830 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1831 "Remove drawers, or extract the content.
1832 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1833 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1834 whose content to keep."
1835 (unless (eq t exp-drawers
)
1836 (goto-char (point-min))
1837 (let ((re (concat "^[ \t]*:\\("
1840 (org-delete-all exp-drawers
1841 (copy-sequence all-drawers
))
1843 "\\):[ \t]*\n\\([^\000]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1844 (while (re-search-forward re nil t
)
1846 (replace-match ""))))))
1848 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1849 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1850 Both arguments are lists of tags.
1851 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1853 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1855 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1856 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1859 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1863 (goto-char (point-min))
1864 (when (and select-tags
1866 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1867 ;; At least one tree is marked for export, this means
1868 ;; all the unmarked stuff needs to go.
1869 ;; Dig out the trees that should be exported
1870 (goto-char (point-min))
1871 (outline-next-heading)
1873 (put-text-property beg
(point-max) :org-delete t
)
1874 (while (re-search-forward re-sel nil t
)
1875 (when (org-on-heading-p)
1876 (org-back-to-heading)
1877 (remove-text-properties
1878 (max (1- (point)) (point-min))
1879 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1881 (while (and (org-up-heading-safe)
1882 (get-text-property (point) :org-delete
))
1883 (remove-text-properties (max (1- (point)) (point-min))
1884 (point-at-eol) '(:org-delete t
)))
1886 ;; Remove the trees explicitly marked for noexport
1888 (goto-char (point-min))
1889 (while (re-search-forward re-excl nil t
)
1890 (when (org-at-heading-p)
1891 (org-back-to-heading t
)
1893 (org-end-of-subtree t
)
1894 (delete-region beg
(point)))))
1895 ;; Remove everything that is now still marked for deletion
1896 (goto-char (point-min))
1897 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1898 (setq end
(or (next-single-property-change beg
:org-delete
)
1900 (delete-region beg end
))))
1902 (defun org-export-remove-archived-trees (export-archived-trees)
1903 "Remove archived trees.
1904 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1905 When it is t, the entire archived tree will be exported.
1906 When it is nil the entire tree including the headline will be removed
1908 (let ((re-archive (concat ":" org-archive-tag
":"))
1910 (when (not (eq export-archived-trees t
))
1911 (goto-char (point-min))
1912 (while (re-search-forward re-archive nil t
)
1913 (if (not (org-on-heading-p t
))
1914 (org-end-of-subtree t
)
1915 (beginning-of-line 1)
1916 (setq a
(if export-archived-trees
1917 (1+ (point-at-eol)) (point))
1918 b
(org-end-of-subtree t
))
1919 (if (> b a
) (delete-region a b
)))))))
1921 (defun org-export-remove-headline-metadata (opts)
1922 "Remove meta data from the headline, according to user options."
1923 (let ((re org-complex-heading-regexp
)
1924 (todo (plist-get opts
:todo-keywords
))
1925 (tags (plist-get opts
:tags
))
1926 (pri (plist-get opts
:priority
))
1929 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1930 (when (or (not todo
) (not tags
) (not pri
))
1931 (goto-char (point-min))
1932 (while (re-search-forward re nil t
)
1934 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1936 (replace-match rpl t t
))))))
1938 (defun org-export-remove-timestamps ()
1939 "Remove timestamps and keywords for export."
1940 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1943 (unless (save-match-data (org-at-table-p))
1945 (beginning-of-line 1)
1946 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1947 (replace-match ""))))))
1949 (defun org-export-remove-clock-lines ()
1950 "Remove clock lines for export."
1951 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1952 (while (re-search-forward re nil t
)
1954 (replace-match "")))))
1956 (defun org-export-protect-quoted-subtrees ()
1957 "Mark quoted subtrees with the protection property."
1958 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1959 (goto-char (point-min))
1960 (while (re-search-forward re-quote nil t
)
1961 (goto-char (match-beginning 0))
1963 (add-text-properties (point) (org-end-of-subtree t
)
1964 '(org-protected t
)))))
1966 (defun org-export-protect-verbatim ()
1967 "Mark verbatim snippets with the protection property."
1968 (goto-char (point-min))
1969 (while (re-search-forward org-verbatim-re nil t
)
1970 (add-text-properties (match-beginning 4) (match-end 4)
1972 (goto-char (1+ (match-end 4)))))
1974 (defun org-export-protect-colon-examples ()
1975 "Protect lines starting with a colon."
1976 (goto-char (point-min))
1977 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1978 (while (re-search-forward re nil t
)
1979 (beginning-of-line 1)
1981 (while (looking-at re
)
1983 (or (eobp) (forward-char 1)))
1984 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1985 '(org-protected t
)))))
1987 (defun org-export-select-backend-specific-text (backend)
1989 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1990 (html "HTML" "BEGIN_HTML" "END_HTML")
1991 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1992 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1993 (case-fold-search t
)
1997 (setq fmt
(pop formatters
))
1998 (when (eq (car fmt
) backend
)
1999 ;; This is selected code, put it into the file for real
2000 (goto-char (point-min))
2001 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
2002 ":[ \t]*\\(.*\\)") nil t
)
2003 (replace-match "\\1" t
)
2004 (add-text-properties
2005 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
2006 '(org-protected t
))))
2007 (goto-char (point-min))
2008 (while (re-search-forward
2010 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
2011 (cadddr fmt
) "\\>.*\n?") nil t
)
2012 (if (eq (car fmt
) backend
)
2014 (add-text-properties (match-beginning 1) (1+ (match-end 1))
2016 ;; No, this is for a different backend, kill it
2017 (delete-region (match-beginning 0) (match-end 0)))))))
2019 (defun org-export-mark-blockquote-and-verse ()
2020 "Mark block quote and verse environments with special cookies.
2021 These special cookies will later be interpreted by the backend."
2023 (goto-char (point-min))
2024 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
2026 (replace-match (if (equal (downcase (match-string 1)) "end")
2027 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
2030 (goto-char (point-min))
2031 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
2032 (replace-match (if (equal (downcase (match-string 1)) "end")
2033 "ORG-VERSE-END" "ORG-VERSE-START")
2036 (defun org-export-attach-captions-and-attributes (backend target-alist
)
2037 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
2038 If the next thing following is a table, add the text properties to the first
2039 table line. If it is a link, add it to the line containing the link."
2040 (goto-char (point-min))
2041 (remove-text-properties (point-min) (point-max)
2042 '(org-caption nil org-attributes nil
))
2043 (let ((case-fold-search t
)
2044 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
2046 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
2048 "^#\\+label:[ \t]+\\(.*\\)"
2052 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
2054 (while (re-search-forward re nil t
)
2057 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
2059 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
2061 (setq label
(org-trim (match-string 3))))
2063 (add-text-properties (point-at-bol) (point-at-eol)
2064 (list 'org-caption cap
2065 'org-attributes attr
2067 (if label
(push (cons label label
) target-alist
))
2068 (setq cap nil attr nil label nil
)))))
2071 (defun org-export-remove-comment-blocks-and-subtrees ()
2072 "Remove the comment environment, and also commented subtrees."
2073 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
2074 (case-fold-search nil
))
2075 ;; Remove comment environment
2076 (goto-char (point-min))
2077 (while (re-search-forward
2078 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
2079 (replace-match "" t t
))
2080 ;; Remove subtrees that are commented
2081 (goto-char (point-min))
2082 (while (re-search-forward re-commented nil t
)
2083 (goto-char (match-beginning 0))
2084 (delete-region (point) (org-end-of-subtree t
)))))
2086 (defun org-export-handle-comments (commentsp)
2087 "Remove comments, or convert to backend-specific format.
2088 COMMENTSP can be a format string for publishing comments.
2089 When it is nil, all comments will be removed."
2090 (let ((re "^#\\(.*\n?\\)")
2092 (goto-char (point-min))
2093 (while (or (looking-at re
)
2094 (re-search-forward re nil t
))
2095 (setq pos
(match-beginning 0))
2097 (progn (add-text-properties
2098 (match-beginning 0) (match-end 0) '(org-protected t
))
2099 (replace-match (format commentsp
(match-string 1)) t t
))
2100 (goto-char (1+ pos
))
2103 (goto-char (max (point-min) (1- pos
))))))))
2105 (defun org-export-mark-radio-links ()
2106 "Find all matches for radio targets and turn them into internal links."
2107 (let ((re-radio (and org-target-link-regexp
2108 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2109 (goto-char (point-min))
2111 (while (re-search-forward re-radio nil t
)
2113 (replace-match "\\1[[\\2]]"))))))
2115 (defun org-export-remove-special-table-lines ()
2116 "Remove tables lines that are used for internal purposes."
2117 (goto-char (point-min))
2118 (while (re-search-forward "^[ \t]*|" nil t
)
2119 (beginning-of-line 1)
2120 (if (or (looking-at "[ \t]*| *[!_^] *|")
2121 (and (looking-at ".*?| *<[0-9]+> *|")
2122 (not (looking-at ".*?| *[^ <|]"))))
2123 (delete-region (max (point-min) (1- (point-at-bol)))
2127 (defun org-export-normalize-links ()
2128 "Convert all links to bracket links, and expand link abbreviations."
2129 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2130 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
2131 (goto-char (point-min))
2132 (while (re-search-forward re-plain-link nil t
)
2133 (goto-char (1- (match-end 0)))
2134 (org-if-unprotected-at (1+ (match-beginning 0))
2135 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2136 ":" (match-string 3) "]]")))
2137 ;; added 'org-link face to links
2138 (put-text-property 0 (length s
) 'face
'org-link s
)
2139 (replace-match s t t
))))
2140 (goto-char (point-min))
2141 (while (re-search-forward re-angle-link nil t
)
2142 (goto-char (1- (match-end 0)))
2144 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2145 ":" (match-string 3) "]]")))
2146 (put-text-property 0 (length s
) 'face
'org-link s
)
2147 (replace-match s t t
))))
2148 (goto-char (point-min))
2149 (while (re-search-forward org-bracket-link-regexp nil t
)
2150 (goto-char (1- (match-end 0)))
2152 (let* ((xx (save-match-data
2154 (org-link-expand-abbrev (match-string 1)))))
2156 "[[" (org-add-props (copy-sequence xx
)
2157 nil
'org-protected t
)
2161 (concat "[" (org-add-props
2166 (put-text-property 0 (length s
) 'face
'org-link s
)
2167 (replace-match s t t
))))))
2169 (defun org-export-concatenate-multiline-links ()
2170 "Find multi-line links and put it all into a single line.
2171 This is to make sure that the line-processing export backends
2172 can work correctly."
2173 (goto-char (point-min))
2174 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2176 (replace-match "\\1 \\3")
2177 (goto-char (match-beginning 0)))))
2179 (defun org-export-concatenate-multiline-emphasis ()
2180 "Find multi-line emphasis and put it all into a single line.
2181 This is to make sure that the line-processing export backends
2182 can work correctly."
2183 (goto-char (point-min))
2184 (while (re-search-forward org-emph-re nil t
)
2185 (if (and (not (= (char-after (match-beginning 3))
2186 (char-after (match-beginning 4))))
2187 (save-excursion (goto-char (match-beginning 0))
2188 (save-match-data (not (org-at-table-p)))))
2190 (subst-char-in-region (match-beginning 0) (match-end 0)
2192 (goto-char (1- (match-end 0))))
2193 (goto-char (1+ (match-beginning 0))))))
2195 (defun org-export-grab-title-from-buffer ()
2196 "Get a title for the current document, from looking at the buffer."
2197 (let ((inhibit-read-only t
))
2199 (goto-char (point-min))
2200 (let ((end (if (looking-at org-outline-regexp
)
2202 (save-excursion (outline-next-heading) (point)))))
2203 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2204 ;; Mark the line so that it will not be exported as normal text.
2206 (add-text-properties (match-beginning 0) (match-end 0)
2207 (list :org-license-to-kill t
)))
2208 ;; Return the title string
2209 (org-trim (match-string 0)))))))
2211 (defun org-export-get-title-from-subtree ()
2212 "Return subtree title and exclude it from export."
2213 (let (title (rbeg (region-beginning)) (rend (region-end)))
2216 (when (and (org-at-heading-p)
2217 (>= (org-end-of-subtree t t
) rend
))
2218 ;; This is a subtree, we take the title from the first heading
2220 (looking-at org-todo-line-regexp
)
2221 (setq title
(match-string 3))
2223 (add-text-properties (point) (1+ (point-at-eol))
2224 (list :org-license-to-kill t
)))
2225 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2228 (defun org-solidify-link-text (s &optional alist
)
2229 "Take link text and make a safe target out of it."
2234 (org-split-string s
"[ \t\r\n]+") "=="))
2235 (a (assoc rtn alist
)))
2238 (defun org-get-min-level (lines &optional offset
)
2239 "Get the minimum level in LINES."
2240 (let ((re "^\\(\\*+\\) ") l
)
2242 (while (setq l
(pop lines
))
2243 (if (string-match re l
)
2244 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2248 ;; Variable holding the vector with section numbers
2249 (defvar org-section-numbers
(make-vector org-level-max
0))
2251 (defun org-init-section-numbers ()
2252 "Initialize the vector for the section numbers."
2254 (numbers (nreverse (org-split-string "" "\\.")))
2255 (depth (1- (length org-section-numbers
)))
2256 (i depth
) number-string
)
2259 (aset org-section-numbers i
0)
2260 (setq number-string
(or (car numbers
) "0"))
2261 (if (string-match "\\`[A-Z]\\'" number-string
)
2262 (aset org-section-numbers i
2263 (- (string-to-char number-string
) ?A -
1))
2264 (aset org-section-numbers i
(string-to-number number-string
)))
2268 (defun org-section-number (&optional level
)
2269 "Return a string with the current section number.
2270 When LEVEL is non-nil, increase section numbers on that level."
2271 (let* ((depth (1- (length org-section-numbers
)))
2273 (fmts (car org-export-section-number-format
))
2274 (term (cdr org-export-section-number-format
))
2279 (aset org-section-numbers
2280 level
(1+ (aref org-section-numbers level
))))
2281 (setq idx
(1+ level
))
2282 (while (<= idx depth
)
2284 (aset org-section-numbers idx
0))
2285 (setq idx
(1+ idx
))))
2287 (while (<= idx depth
)
2288 (when (> (aref org-section-numbers idx
) 0)
2289 (setq fmt
(or (pop fmts
) fmt
)
2291 n
(aref org-section-numbers idx
)
2293 (concat string sep
(org-number-to-counter n ctype
))
2294 (concat string
".0"))
2296 (setq idx
(1+ idx
)))
2298 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2299 (setq string
(replace-match "" t nil string
)))
2300 (if (string-match "\\(\\.0\\)+\\'" string
)
2301 (setq string
(replace-match "" t nil string
))))
2302 (concat string term
)))
2304 (defun org-number-to-counter (n type
)
2305 "Concert number N to a string counter, according to TYPE.
2306 TYPE must be a string, any of:
2310 I upper case roman numeral
2311 i lower case roman numeral"
2313 ((equal type
"1") (number-to-string n
))
2314 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2315 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2316 ((equal type
"I") (org-number-to-roman n
))
2317 ((equal type
"i") (downcase (org-number-to-roman n
)))
2318 (t (error "Invalid counter type `%s'" type
))))
2320 (defun org-number-to-roman (n)
2321 "Convert integer N into a roman numeral."
2322 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2323 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2324 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2328 (number-to-string n
)
2330 (if (>= n
(caar roman
))
2331 (setq n
(- n
(caar roman
))
2332 res
(concat res
(cdar roman
)))
2338 (defun org-export-preprocess-apply-macros ()
2339 "Replace macro references."
2340 (goto-char (point-min))
2342 (while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t
)
2343 (setq key
(downcase (match-string 1)))
2344 (when (setq val
(or (plist-get org-export-opt-plist
2345 (intern (concat ":macro-" key
)))
2346 (plist-get org-export-opt-plist
2347 (intern (concat ":" key
)))))
2349 (replace-match val t t
))))))
2353 (defun org-export-handle-include-files ()
2354 "Include the contents of include files, with proper formatting."
2355 (let ((case-fold-search t
)
2356 params file markup lang start end prefix prefix1 switches
)
2357 (goto-char (point-min))
2358 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2359 (setq params
(read (concat "(" (match-string 1) ")"))
2360 prefix
(org-get-and-remove-property 'params
:prefix
)
2361 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2362 file
(org-symname-or-string (pop params
))
2363 markup
(org-symname-or-string (pop params
))
2364 lang
(and (member markup
'("src" "SRC"))
2365 (org-symname-or-string (pop params
)))
2366 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2367 (delete-region (match-beginning 0) (match-end 0))
2369 (not (file-exists-p file
))
2370 (not (file-readable-p file
)))
2371 (insert (format "CANNOT INCLUDE FILE %s" file
))
2373 (if (equal (downcase markup
) "src")
2374 (setq start
(format "#+begin_src %s %s\n"
2375 (or lang
"fundamental")
2378 (setq start
(format "#+begin_%s %s\n" markup switches
)
2379 end
(format "#+end_%s" markup
))))
2380 (insert (or start
""))
2381 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2382 (or (bolp) (newline))
2383 (insert (or end
""))))))
2385 (defun org-get-file-contents (file &optional prefix prefix1
)
2386 "Get the contents of FILE and return them as a string.
2387 If PREFIX is a string, prepend it to each line. If PREFIX1
2388 is a string, prepend it to the first line instead of PREFIX."
2390 (insert-file-contents file
)
2391 (when (or prefix prefix1
)
2392 (goto-char (point-min))
2394 (insert (or prefix1 prefix
))
2396 (beginning-of-line 2)))
2399 (defun org-get-and-remove-property (listvar prop
)
2400 "Check if the value of LISTVAR contains PROP as a property.
2401 If yes, return the value of that property (i.e. the element following
2402 in the list) and remove property and value from the list in LISTVAR."
2403 (let ((list (symbol-value listvar
)) m v
)
2404 (when (setq m
(member prop list
))
2406 (if (equal (car list
) prop
)
2407 (set listvar
(cddr list
))
2408 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2410 (set listvar list
)))
2413 (defun org-symname-or-string (s)
2415 (if s
(symbol-name s
) s
)
2418 ;;; Fontification and line numbers for code examples
2420 (defvar org-export-last-code-line-counter-value
0)
2422 (defun org-export-replace-src-segments-and-examples (backend)
2423 "Replace source code segments with special code for export."
2424 (setq org-export-last-code-line-counter-value
0)
2425 (let ((case-fold-search t
)
2426 lang code trans opts
)
2427 (goto-char (point-min))
2428 (while (re-search-forward
2429 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2433 (setq lang
(match-string 2)
2434 opts
(match-string 3)
2435 code
(match-string 4))
2437 opts
(match-string 6)
2438 code
(match-string 7)))
2440 (setq trans
(org-export-format-source-code-or-example
2441 backend lang code opts
))
2442 (replace-match trans t t
))))
2444 (defvar htmlp
) ;; dynamically scoped
2445 (defvar latexp
) ;; dynamically scoped
2447 (defun org-export-format-source-code-or-example (backend
2448 lang code
&optional opts
)
2449 "Format CODE from language LANG and return it formatted for export.
2450 If LANG is nil, do not add any fontification.
2451 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2452 and `+n' for continuing previous numering.
2453 Code formatting according to language currently only works for HTML.
2454 Numbering lines works for all three major backends (html, latex, and ascii)."
2456 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2457 (setq opts
(or opts
"")
2458 num
(string-match "[-+]n\\>" opts
)
2459 cont
(string-match "\\+n\\>" opts
)
2460 rpllbl
(string-match "-r\\>" opts
)
2461 keepp
(string-match "-k\\>" opts
)
2462 textareap
(string-match "-t\\>" opts
)
2463 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2464 (string-to-number (match-string 1 opts
))
2466 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2467 (string-to-number (match-string 1 opts
))
2468 (org-count-lines code
))
2469 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2470 (match-string 1 opts
)))
2471 (when (or (and textareap
(eq backend
'html
))
2472 (eq backend
'docbook
))
2473 ;; we cannot use numbering or highlighting.
2474 (setq num nil cont nil lang nil
))
2475 (if keepp
(setq rpllbl
'keep
))
2477 (when (equal lang
"org")
2478 (setq rtn
(with-temp-buffer
2480 ;; Free up the protected lines
2481 (goto-char (point-min))
2482 (while (re-search-forward "^," nil t
)
2486 ;; Now backend-specific coding
2488 ((eq backend
'docbook
)
2489 (setq rtn
(concat "<programlisting><![CDATA[\n"
2491 "]]>\n</programlisting>\n"))
2492 (concat "\n#+BEGIN_DOCBOOK\n"
2494 "\n#+END_DOCBOOK\n\n")
2497 ;; We are exporting to HTML
2499 (require 'htmlize nil t
)
2500 (when (not (fboundp 'htmlize-region-for-paste
))
2501 ;; we do not have htmlize.el, or an old version of it
2504 "htmlize.el 1.34 or later is needed for source code formatting")))
2507 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2508 (org-inhibit-startup t
)
2509 (org-startup-folded nil
))
2513 (if (functionp mode
)
2516 (font-lock-fontify-buffer)
2517 (set-buffer-modified-p nil
)
2518 (org-export-htmlize-region-for-paste
2519 (point-min) (point-max))))
2520 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2521 (setq rtn
(replace-match
2522 (format "<pre class=\"src src-%s\">\n" lang
)
2526 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2528 rtn
"</textarea>\n</p>\n"))
2531 (goto-char (point-min))
2532 (while (re-search-forward "[<>&]" nil t
)
2533 (replace-match (cdr (assq (char-before)
2534 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2536 (setq rtn
(buffer-string)))
2537 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2539 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2541 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2542 ((eq backend
'latex
)
2543 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2544 (concat "\n#+BEGIN_LaTeX\n"
2545 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2548 ((eq backend
'ascii
)
2549 ;; This is not HTML or LaTeX, so just make it an example.
2550 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2551 (concat "#+BEGIN_ASCII\n"
2555 (lambda (l) (concat " " l
))
2556 (org-split-string rtn
"\n")
2560 "#+END_ASCII\n"))))))
2562 (defun org-export-number-lines (text backend
2563 &optional skip1 skip2 number cont
2564 replace-labels label-format
)
2565 (if (and (not number
) (not (eq replace-labels
'keep
)))
2566 (setq replace-labels nil
)) ;; must use names if no numbers
2567 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2568 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2571 (goto-char (point-max))
2572 (skip-chars-backward " \t\n\r")
2573 (delete-region (point) (point-max))
2574 (beginning-of-line (- 1 skip2
))
2575 (let* ((last (org-current-line))
2576 (n org-export-last-code-line-counter-value
)
2577 (nmax (+ n
(- last skip1
)))
2578 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2581 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2583 ((eq backend
'ascii
) fmt
)
2584 ((eq backend
'latex
) fmt
)
2586 (label-format (or label-format org-coderef-label-format
))
2587 (label-pre (if (string-match "%s" label-format
)
2588 (substring label-format
0 (match-beginning 0))
2590 (label-post (if (string-match "%s" label-format
)
2591 (substring label-format
(match-end 0))
2595 ".*?\\S-.*?\\([ \t]*\\("
2596 (regexp-quote label-pre
)
2597 "\\([-a-zA-Z0-9_]+\\)"
2598 (regexp-quote label-post
)
2602 (goto-line (1+ skip1
))
2603 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2605 (insert (format fm
(incf n
)))
2607 (when (and (not (eq replace-labels
'keep
))
2608 (looking-at lbl-re
))
2609 (setq ref
(match-string 3))
2612 (delete-region (match-beginning 1) (match-end 1))
2613 (push (cons ref n
) org-export-code-refs
))
2614 (goto-char (match-beginning 2))
2615 (delete-region (match-beginning 2) (match-end 2))
2616 (insert "(" ref
")")
2617 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2618 (when (eq backend
'html
)
2620 (beginning-of-line 1)
2621 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2624 (insert "</span>")))))
2625 (setq org-export-last-code-line-counter-value n
)
2626 (goto-char (point-max))
2632 (defvar org-last-level nil
) ; dynamically scoped variable
2633 (defvar org-min-level nil
) ; dynamically scoped variable
2634 (defvar org-levels-open nil
) ; dynamically scoped parameter
2635 (defvar org-ascii-current-indentation nil
) ; For communication
2638 (defun org-export-as-ascii (arg)
2639 "Export the outline as a pretty ASCII file.
2640 If there is an active region, export only the region.
2641 The prefix ARG specifies how many levels of the outline should become
2642 underlined headlines. The default is 3."
2644 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2645 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2646 (org-infile-export-plist)))
2647 (region-p (org-region-active-p))
2648 (rbeg (and region-p
(region-beginning)))
2649 (rend (and region-p
(region-end)))
2654 (and (org-at-heading-p)
2655 (>= (org-end-of-subtree t t
) rend
)))))
2656 (level-offset (if subtree-p
2659 (+ (funcall outline-level
)
2660 (if org-odd-levels-only
1 0)))
2662 (opt-plist (setq org-export-opt-plist
2664 (org-export-add-subtree-options opt-plist rbeg
)
2666 (custom-times org-display-custom-times
)
2667 (org-ascii-current-indentation '(0 .
0))
2671 (case-fold-search nil
)
2672 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2673 (filename (concat (file-name-as-directory
2674 (org-export-directory :ascii opt-plist
))
2675 (file-name-sans-extension
2677 (org-entry-get (region-beginning)
2678 "EXPORT_FILE_NAME" t
))
2679 (file-name-nondirectory bfname
)))
2681 (filename (if (equal (file-truename filename
)
2682 (file-truename bfname
))
2683 (concat filename
".txt")
2685 (buffer (find-file-noselect filename
))
2686 (org-levels-open (make-vector org-level-max nil
))
2687 (odd org-odd-levels-only
)
2688 (date (plist-get opt-plist
:date
))
2689 (author (plist-get opt-plist
:author
))
2690 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2691 (plist-get opt-plist
:title
)
2693 (plist-get opt-plist
:skip-before-1st-heading
))
2694 (org-export-grab-title-from-buffer))
2695 (file-name-sans-extension
2696 (file-name-nondirectory bfname
))))
2697 (email (plist-get opt-plist
:email
))
2698 (language (plist-get opt-plist
:language
))
2699 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2700 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2705 (if (org-region-active-p) (region-beginning) (point-min))
2706 (if (org-region-active-p) (region-end) (point-max))))
2707 (lines (org-split-string
2708 (org-export-preprocess-string
2711 :skip-before-1st-heading
2712 (plist-get opt-plist
:skip-before-1st-heading
)
2713 :drawers
(plist-get opt-plist
:drawers
)
2714 :tags
(plist-get opt-plist
:tags
)
2715 :priority
(plist-get opt-plist
:priority
)
2716 :footnotes
(plist-get opt-plist
:footnotes
)
2717 :timestamps
(plist-get opt-plist
:timestamps
)
2718 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
2719 :verbatim-multiline t
2720 :select-tags
(plist-get opt-plist
:select-tags
)
2721 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2723 (plist-get opt-plist
:archived-trees
)
2724 :add-text
(plist-get opt-plist
:text
))
2726 thetoc have-headings first-heading-pos
2727 table-open table-buffer link-buffer link desc desc0 rpl wrap
)
2728 (let ((inhibit-read-only t
))
2730 (remove-text-properties (point-min) (point-max)
2731 '(:org-license-to-kill t
))))
2733 (setq org-min-level
(org-get-min-level lines level-offset
))
2734 (setq org-last-level org-min-level
)
2735 (org-init-section-numbers)
2737 (find-file-noselect filename
)
2739 (setq lang-words
(or (assoc language org-export-language-setup
)
2740 (assoc "en" org-export-language-setup
)))
2741 (switch-to-buffer-other-window buffer
)
2744 ;; create local variables for all options, to make sure all called
2745 ;; functions get the correct information
2747 (set (make-local-variable (nth 2 x
))
2748 (plist-get opt-plist
(car x
))))
2749 org-export-plist-vars
)
2750 (org-set-local 'org-odd-levels-only odd
)
2751 (setq umax
(if arg
(prefix-numeric-value arg
)
2752 org-export-headline-levels
))
2753 (setq umax-toc
(if (integerp org-export-with-toc
)
2754 (min org-export-with-toc umax
)
2758 (if title
(org-insert-centered title ?
=))
2760 (if (and (or author email
)
2761 org-export-author-info
)
2762 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2763 (if email
(concat " <" email
">") "")
2767 ((and date
(string-match "%" date
))
2768 (setq date
(format-time-string date
)))
2770 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2772 (if (and date org-export-time-stamp-file
)
2773 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2777 (if org-export-with-toc
2779 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2780 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2782 (mapc '(lambda (line)
2783 (if (string-match org-todo-line-regexp
2785 ;; This is a headline
2787 (setq have-headings t
)
2788 (setq level
(- (match-end 1) (match-beginning 1)
2790 level
(org-tr-level level
)
2791 txt
(match-string 3 line
)
2793 (or (and org-export-mark-todo-in-toc
2795 (not (member (match-string 2 line
)
2796 org-done-keywords
)))
2798 (and org-export-mark-todo-in-toc
2800 (org-search-todo-below
2801 line lines level
))))
2802 (setq txt
(org-html-expand-for-ascii txt
))
2804 (while (string-match org-bracket-link-regexp txt
)
2807 (match-string (if (match-end 2) 3 1) txt
)
2810 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2812 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2814 (setq txt
(replace-match "" t t txt
)))
2815 (if (string-match quote-re0 txt
)
2816 (setq txt
(replace-match "" t t txt
)))
2818 (if org-export-with-section-numbers
2819 (setq txt
(concat (org-section-number level
)
2821 (if (<= level umax-toc
)
2826 (* (max 0 (- level org-min-level
)) 4) ?\
)
2827 (format (if todo
"%s (*)\n" "%s\n") txt
))
2829 (setq org-last-level level
))
2832 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2834 (org-init-section-numbers)
2835 (while (setq line
(pop lines
))
2836 (when (and link-buffer
(string-match "^\\*+ " line
))
2837 (org-export-ascii-push-links (nreverse link-buffer
))
2838 (setq link-buffer nil
))
2840 ;; Remove the quoted HTML tags.
2841 (setq line
(org-html-expand-for-ascii line
))
2842 ;; Replace links with the description when possible
2843 (while (string-match org-bracket-link-regexp line
)
2844 (setq link
(match-string 1 line
)
2845 desc0
(match-string 3 line
)
2846 desc
(or desc0
(match-string 1 line
)))
2847 (if (and (> (length link
) 8)
2848 (equal (substring link
0 8) "coderef:"))
2849 (setq line
(replace-match
2850 (format (org-export-get-coderef-format (substring link
8) desc
)
2853 org-export-code-refs
)))
2855 (setq rpl
(concat "["
2856 (or (match-string 3 line
) (match-string 1 line
))
2858 (when (and desc0
(not (equal desc0 link
)))
2859 (if org-export-ascii-links-to-notes
2860 (push (cons desc0 link
) link-buffer
)
2861 (setq rpl
(concat rpl
" (" link
")")
2862 wrap
(+ (length line
) (- (length (match-string 0)))
2864 (setq line
(replace-match rpl t t line
))))
2866 (setq line
(org-translate-time line
)))
2868 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2870 (setq first-heading-pos
(or first-heading-pos
(point)))
2871 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
2873 txt
(match-string 2 line
))
2874 (org-ascii-level-start level txt umax lines
))
2876 ((and org-export-with-tables
2877 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2878 (if (not table-open
)
2880 (setq table-open t table-buffer nil
))
2882 (setq table-buffer
(cons line table-buffer
))
2883 (when (or (not lines
)
2884 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2886 (setq table-open nil
2887 table-buffer
(nreverse table-buffer
))
2890 (org-fix-indentation x org-ascii-current-indentation
))
2891 (org-format-table-ascii table-buffer
)
2894 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2895 ;; Remove forced line breaks
2896 (if (string-match "\\\\\\\\[ \t]*$" line
)
2897 (setq line
(replace-match "" t t line
)))
2898 (if (and org-export-with-fixed-width
2899 (string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line
))
2900 (setq line
(replace-match "\\1" nil nil line
))
2901 (if wrap
(setq line
(org-export-ascii-wrap line wrap
))))
2902 (insert line
"\n"))))
2904 (org-export-ascii-push-links (nreverse link-buffer
))
2908 ;; insert the table of contents
2910 (goto-char (point-min))
2911 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2913 (goto-char (match-beginning 0))
2915 (goto-char first-heading-pos
))
2916 (mapc 'insert thetoc
)
2917 (or (looking-at "[ \t]*\n[ \t]*\n")
2920 ;; Convert whitespace place holders
2921 (goto-char (point-min))
2923 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2924 (setq end
(next-single-property-change beg
'org-whitespace
))
2926 (delete-region beg end
)
2927 (insert (make-string (- end beg
) ?\
))))
2930 ;; remove display and invisible chars
2932 (goto-char (point-min))
2933 (while (setq beg
(next-single-property-change (point) 'display
))
2934 (setq end
(next-single-property-change beg
'display
))
2935 (delete-region beg end
)
2938 (goto-char (point-min))
2939 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2940 (setq end
(next-single-property-change beg
'org-cwidth
))
2941 (delete-region beg end
)
2943 (goto-char (point-min))))
2945 (defun org-export-ascii-preprocess ()
2946 "Do extra work for ASCII export"
2947 ;; Put quotes around verbatim text
2948 (goto-char (point-min))
2949 (while (re-search-forward org-verbatim-re nil t
)
2950 (goto-char (match-end 2))
2951 (backward-delete-char 1) (insert "'")
2952 (goto-char (match-beginning 2))
2953 (delete-char 1) (insert "`")
2954 (goto-char (match-end 2)))
2955 ;; Remove target markers
2956 (goto-char (point-min))
2957 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t
)
2958 (replace-match "\\1\\2")))
2960 (defun org-search-todo-below (line lines level
)
2961 "Search the subtree below LINE for any TODO entries."
2962 (let ((rest (cdr (memq line lines
)))
2963 (re org-todo-line-regexp
)
2966 (while (setq line
(pop rest
))
2967 (if (string-match re line
)
2969 (setq lv
(- (match-end 1) (match-beginning 1))
2970 todo
(and (match-beginning 2)
2971 (not (member (match-string 2 line
)
2972 org-done-keywords
))))
2974 (if (<= lv level
) (throw 'exit nil
))
2975 (if todo
(throw 'exit t
))))))))
2977 (defun org-html-expand-for-ascii (line)
2978 "Handle quoted HTML for ASCII export."
2979 (if org-export-html-expand
2980 (while (string-match "@<[^<>\n]*>" line
)
2981 ;; We just remove the tags for now.
2982 (setq line
(replace-match "" nil nil line
))))
2986 (defun org-export-ascii-wrap (line where
)
2987 "Wrap LINE at or before WHERE."
2988 (let ((ind (org-get-indentation line
))
2991 (loop for i from where downto
(/ where
2) do
2992 (and (equal (aref line i
) ?\
)
2996 (concat (substring line
0 pos
) "\n"
2997 (make-string ind ?\
)
2998 (substring line
(1+ pos
)))
3001 (defun org-export-ascii-push-links (link-buffer)
3002 "Push out links in the buffer."
3004 ;; We still have links to push out.
3010 "^\\(\\([ \t]*\\)\\|\\(\\*+ \\)\\)[^ \t\n]" nil t
))
3011 (setq ind
(or (match-string 2)
3012 (make-string (length (match-string 3)) ?\
)))))
3013 (mapc (lambda (x) (insert ind
"[" (car x
) "]: " (cdr x
) "\n"))
3017 (defun org-insert-centered (s &optional underline
)
3018 "Insert the string S centered and underline it with character UNDERLINE."
3019 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
3020 (insert (make-string ind ?\
) s
"\n")
3022 (insert (make-string ind ?\
)
3023 (make-string (string-width s
) underline
)
3026 (defun org-ascii-level-start (level title umax
&optional lines
)
3027 "Insert a new level in ASCII export."
3028 (let (char (n (- level umax
1)) (ind 0))
3031 (insert (make-string (* 2 n
) ?\
)
3032 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
3033 org-export-ascii-bullets
))
3035 ;; find the indentation of the next non-empty line
3038 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
3039 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
3040 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
3042 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
3043 (if (or (not (equal (char-before) ?
\n))
3044 (not (equal (char-before (1- (point))) ?
\n)))
3046 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
3047 (unless org-export-with-tags
3048 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3049 (setq title
(replace-match "" t t title
))))
3050 (if org-export-with-section-numbers
3051 (setq title
(concat (org-section-number level
) " " title
)))
3052 (insert title
"\n" (make-string (string-width title
) char
) "\n")
3053 (setq org-ascii-current-indentation
'(0 .
0)))))
3056 (defun org-export-visible (type arg
)
3057 "Create a copy of the visible part of the current buffer, and export it.
3058 The copy is created in a temporary buffer and removed after use.
3059 TYPE is the final key (as a string) that also select the export command in
3060 the `C-c C-e' export dispatcher.
3061 As a special case, if the you type SPC at the prompt, the temporary
3062 org-mode file will not be removed but presented to you so that you can
3063 continue to use it. The prefix arg ARG is passed through to the exporting
3067 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
3068 (read-char-exclusive))
3069 current-prefix-arg
))
3070 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
3071 (error "Invalid export key"))
3072 (let* ((binding (cdr (assoc type
3073 '((?a . org-export-as-ascii
)
3074 (?\C-a . org-export-as-ascii
)
3075 (?b . org-export-as-html-and-open
)
3076 (?\C-b . org-export-as-html-and-open
)
3077 (?h . org-export-as-html
)
3078 (?H . org-export-as-html-to-buffer
)
3079 (?R . org-export-region-as-html
)
3080 (?x . org-export-as-xoxo
)))))
3081 (keepp (equal type ?\
))
3082 (file buffer-file-name
)
3083 (buffer (get-buffer-create "*Org Export Visible*"))
3085 ;; Need to hack the drawers here.
3087 (goto-char (point-min))
3088 (while (re-search-forward org-drawer-regexp nil t
)
3089 (goto-char (match-beginning 1))
3090 (or (org-invisible-p) (org-flag-drawer nil
))))
3091 (with-current-buffer buffer
(erase-buffer))
3093 (setq s
(goto-char (point-min)))
3094 (while (not (= (point) (point-max)))
3095 (goto-char (org-find-invisible))
3096 (append-to-buffer buffer s
(point))
3097 (setq s
(goto-char (org-find-visible))))
3098 (org-cycle-hide-drawers 'all
)
3099 (goto-char (point-min))
3101 ;; Copy all comment lines to the end, to make sure #+ settings are
3102 ;; still available for the second export step. Kind of a hack, but
3103 ;; does do the trick.
3104 (if (looking-at "#[^\r\n]*")
3105 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
3106 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
3107 (append-to-buffer buffer
(1+ (match-beginning 0))
3108 (min (point-max) (1+ (match-end 0))))))
3110 (let ((buffer-file-name file
)
3111 (org-inhibit-startup t
))
3114 (unless keepp
(funcall binding arg
))))
3116 (kill-buffer buffer
)
3117 (switch-to-buffer-other-window buffer
)
3118 (goto-char (point-min)))))
3120 (defun org-find-visible ()
3122 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
3123 (get-char-property s
'invisible
)))
3125 (defun org-find-invisible ()
3127 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
3128 (not (get-char-property s
'invisible
))))
3133 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
3134 (defun org-get-current-options ()
3135 "Return a string with current options as keyword options.
3136 Does include HTML export options as well as TODO and CATEGORY stuff."
3137 (require 'org-archive
)
3146 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
3147 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
3149 #+EXPORT_SELECT_TAGS: %s
3150 #+EXPORT_EXCLUDE_TAGS: %s
3156 #+PRIORITIES: %c %c %c
3158 #+STARTUP: %s %s %s %s %s
3164 (buffer-name) (user-full-name) user-mail-address
3165 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
3166 org-export-default-language
3167 org-export-headline-levels
3168 org-export-with-section-numbers
3170 org-export-preserve-breaks
3171 org-export-html-expand
3172 org-export-with-fixed-width
3173 org-export-with-tables
3174 org-export-with-sub-superscripts
3175 org-export-with-special-strings
3176 org-export-with-footnotes
3177 org-export-with-emphasize
3178 org-export-with-timestamps
3179 org-export-with-TeX-macros
3180 org-export-with-LaTeX-fragments
3181 org-export-skip-text-before-1st-heading
3182 org-export-with-drawers
3183 org-export-with-todo-keywords
3184 org-export-with-priority
3185 org-export-with-tags
3186 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
3187 (mapconcat 'identity org-export-select-tags
" ")
3188 (mapconcat 'identity org-export-exclude-tags
" ")
3189 org-export-html-link-up
3190 org-export-html-link-home
3192 (file-name-sans-extension
3193 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3195 "TODO FEEDBACK VERIFY DONE"
3196 "Me Jason Marie DONE"
3197 org-highest-priority org-lowest-priority org-default-priority
3198 (mapconcat 'identity org-drawers
" ")
3199 (cdr (assoc org-startup-folded
3200 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3201 (if org-odd-levels-only
"odd" "oddeven")
3202 (if org-hide-leading-stars
"hidestars" "showstars")
3203 (if org-startup-align-all-tables
"align" "noalign")
3204 (cond ((eq org-log-done t
) "logdone")
3205 ((equal org-log-done
'note
) "lognotedone")
3206 ((not org-log-done
) "nologdone"))
3207 (or (mapconcat (lambda (x)
3209 ((equal '(:startgroup
) x
) "{")
3210 ((equal '(:endgroup
) x
) "}")
3211 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3213 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3214 (mapconcat 'identity org-file-tags
" ")
3215 org-archive-location
3216 "org file:~/org/%s.org"
3219 (defun org-export-html-preprocess (parameters)
3220 ;; Convert LaTeX fragments to images
3221 (when (plist-get parameters
:LaTeX-fragments
)
3223 (concat "ltxpng/" (file-name-sans-extension
3224 (file-name-nondirectory
3225 org-current-export-file
)))
3226 org-current-export-dir nil
"Creating LaTeX image %s"))
3227 (message "Exporting..."))
3230 (defun org-insert-export-options-template ()
3231 "Insert into the buffer a template with information for exporting."
3233 (if (not (bolp)) (newline))
3234 (let ((s (org-get-current-options)))
3235 (and (string-match "#\\+CATEGORY" s
)
3236 (setq s
(substring s
0 (match-beginning 0))))
3240 (defun org-export-as-html-and-open (arg)
3241 "Export the outline as HTML and immediately open it with a browser.
3242 If there is an active region, export only the region.
3243 The prefix ARG specifies how many levels of the outline should become
3244 headlines. The default is 3. Lower levels will become bulleted lists."
3246 (org-export-as-html arg
'hidden
)
3247 (org-open-file buffer-file-name
))
3250 (defun org-export-as-html-batch ()
3251 "Call `org-export-as-html', may be used in batch processing as
3253 --load=$HOME/lib/emacs/org.el
3254 --eval \"(setq org-export-headline-levels 2)\"
3255 --visit=MyFile --funcall org-export-as-html-batch"
3256 (org-export-as-html org-export-headline-levels
'hidden
))
3259 (defun org-export-as-html-to-buffer (arg)
3260 "Call `org-export-as-html` with output to a temporary buffer.
3261 No file is created. The prefix ARG is passed through to `org-export-as-html'."
3263 (org-export-as-html arg nil nil
"*Org HTML Export*")
3264 (switch-to-buffer-other-window "*Org HTML Export*"))
3267 (defun org-replace-region-by-html (beg end
)
3268 "Assume the current region has org-mode syntax, and convert it to HTML.
3269 This can be used in any buffer. For example, you could write an
3270 itemized list in org-mode syntax in an HTML buffer and then use this
3271 command to convert it."
3273 (let (reg html buf pop-up-frames
)
3274 (save-window-excursion
3276 (setq html
(org-export-region-as-html
3278 (setq reg
(buffer-substring beg end
)
3279 buf
(get-buffer-create "*Org tmp*"))
3280 (with-current-buffer buf
3284 (setq html
(org-export-region-as-html
3285 (point-min) (point-max) t
'string
)))
3287 (delete-region beg end
)
3291 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
3292 "Convert region from BEG to END in org-mode buffer to HTML.
3293 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
3294 contents, and only produce the region of converted text, useful for
3295 cut-and-paste operations.
3296 If BUFFER is a buffer or a string, use/create that buffer as a target
3297 of the converted HTML. If BUFFER is the symbol `string', return the
3298 produced HTML as a string and leave not buffer behind. For example,
3299 a Lisp program could call this function in the following way:
3301 (setq html (org-export-region-as-html beg end t 'string))
3303 When called interactively, the output buffer is selected, and shown
3304 in a window. A non-interactive call will only return the buffer."
3305 (interactive "r\nP")
3306 (when (interactive-p)
3307 (setq buffer
"*Org HTML Export*"))
3308 (let ((transient-mark-mode t
) (zmacs-regions t
)
3310 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
3312 (set-mark (point)) ;; to activate the region
3314 (setq rtn
(org-export-as-html
3317 (if (fboundp 'deactivate-mark
) (deactivate-mark))
3318 (if (and (interactive-p) (bufferp rtn
))
3319 (switch-to-buffer-other-window rtn
)
3322 (defvar html-table-tag nil
) ; dynamically scoped into this.
3323 (defvar org-par-open nil
)
3325 (defun org-export-as-html (arg &optional hidden ext-plist
3326 to-buffer body-only pub-dir
)
3327 "Export the outline as a pretty HTML file.
3328 If there is an active region, export only the region. The prefix
3329 ARG specifies how many levels of the outline should become
3330 headlines. The default is 3. Lower levels will become bulleted
3331 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3332 EXT-PLIST is a property list with external parameters overriding
3333 org-mode's default settings, but still inferior to file-local
3334 settings. When TO-BUFFER is non-nil, create a buffer with that
3335 name and export to that buffer. If TO-BUFFER is the symbol
3336 `string', don't leave any buffer behind but just return the
3337 resulting HTML as a string. When BODY-ONLY is set, don't produce
3338 the file header and footer, simply return the content of
3339 <body>...</body>, without even the body tags themselves. When
3340 PUB-DIR is set, use this as the publishing directory."
3343 ;; Make sure we have a file name when we need it.
3344 (when (and (not (or to-buffer body-only
))
3345 (not buffer-file-name
))
3346 (if (buffer-base-buffer)
3347 (org-set-local 'buffer-file-name
3348 (with-current-buffer (buffer-base-buffer)
3350 (error "Need a file name to be able to export.")))
3352 (message "Exporting...")
3353 (setq-default org-todo-line-regexp org-todo-line-regexp
)
3354 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
3355 (setq-default org-done-keywords org-done-keywords
)
3356 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
3358 (org-export-process-option-filters
3359 (org-combine-plists (org-default-export-plist)
3361 (org-infile-export-plist))))
3362 (style (concat (if (plist-get opt-plist
:style-include-default
)
3363 org-export-html-style-default
)
3364 (plist-get opt-plist
:style
)
3365 (plist-get opt-plist
:style-extra
)
3367 (if (plist-get opt-plist
:style-include-scripts
)
3368 org-export-html-scripts
)))
3369 (html-extension (plist-get opt-plist
:html-extension
))
3370 (link-validate (plist-get opt-plist
:link-validation-function
))
3371 valid thetoc have-headings first-heading-pos
3372 (odd org-odd-levels-only
)
3373 (region-p (org-region-active-p))
3374 (rbeg (and region-p
(region-beginning)))
3375 (rend (and region-p
(region-end)))
3377 (if (plist-get opt-plist
:ignore-subree-p
)
3382 (and (org-at-heading-p)
3383 (>= (org-end-of-subtree t t
) rend
))))))
3384 (level-offset (if subtree-p
3387 (+ (funcall outline-level
)
3388 (if org-odd-levels-only
1 0)))
3390 (opt-plist (setq org-export-opt-plist
3392 (org-export-add-subtree-options opt-plist rbeg
)
3394 ;; The following two are dynamically scoped into other
3396 (org-current-export-dir
3397 (or pub-dir
(org-export-directory :html opt-plist
)))
3398 (org-current-export-file buffer-file-name
)
3399 (level 0) (line "") (origline "") txt todo
3402 (filename (if to-buffer nil
3405 (file-name-sans-extension
3407 (org-entry-get (region-beginning)
3408 "EXPORT_FILE_NAME" t
))
3409 (file-name-nondirectory buffer-file-name
)))
3411 (file-name-as-directory
3412 (or pub-dir
(org-export-directory :html opt-plist
))))))
3413 (current-dir (if buffer-file-name
3414 (file-name-directory buffer-file-name
)
3416 (buffer (if to-buffer
3418 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
3419 (t (get-buffer-create to-buffer
)))
3420 (find-file-noselect filename
)))
3421 (org-levels-open (make-vector org-level-max nil
))
3422 (date (plist-get opt-plist
:date
))
3423 (author (plist-get opt-plist
:author
))
3424 (title (or (and subtree-p
(org-export-get-title-from-subtree))
3425 (plist-get opt-plist
:title
)
3427 (plist-get opt-plist
:skip-before-1st-heading
))
3428 (org-export-grab-title-from-buffer))
3429 (and buffer-file-name
3430 (file-name-sans-extension
3431 (file-name-nondirectory buffer-file-name
)))
3433 (html-table-tag (plist-get opt-plist
:html-table-tag
))
3434 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
3435 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
3440 (local-list-type nil
)
3441 (local-list-indent nil
)
3442 (llt org-plain-list-ordered-item-terminator
)
3443 (email (plist-get opt-plist
:email
))
3444 (language (plist-get opt-plist
:language
))
3445 (keywords (plist-get opt-plist
:keywords
))
3446 (description (plist-get opt-plist
:description
))
3450 (coding-system (and (boundp 'buffer-file-coding-system
)
3451 buffer-file-coding-system
))
3452 (coding-system-for-write (or org-export-html-coding-system
3454 (save-buffer-coding-system (or org-export-html-coding-system
3456 (charset (and coding-system-for-write
3457 (fboundp 'coding-system-get
)
3458 (coding-system-get coding-system-for-write
3462 (if region-p
(region-beginning) (point-min))
3463 (if region-p
(region-end) (point-max))))
3466 (org-export-preprocess-string
3470 :skip-before-1st-heading
3471 (plist-get opt-plist
:skip-before-1st-heading
)
3472 :drawers
(plist-get opt-plist
:drawers
)
3473 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
3474 :tags
(plist-get opt-plist
:tags
)
3475 :priority
(plist-get opt-plist
:priority
)
3476 :footnotes
(plist-get opt-plist
:footnotes
)
3477 :timestamps
(plist-get opt-plist
:timestamps
)
3479 (plist-get opt-plist
:archived-trees
)
3480 :select-tags
(plist-get opt-plist
:select-tags
)
3481 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
3483 (plist-get opt-plist
:text
)
3485 (plist-get opt-plist
:LaTeX-fragments
))
3488 table-buffer table-orig-buffer
3489 ind item-type starter didclose
3490 rpl path attr desc descp desc1 desc2 link
3491 snumber fnc item-tag
3492 footnotes footref-seen
3496 (let ((inhibit-read-only t
))
3498 (remove-text-properties (point-min) (point-max)
3499 '(:org-license-to-kill t
))))
3501 (message "Exporting...")
3503 (setq org-min-level
(org-get-min-level lines level-offset
))
3504 (setq org-last-level org-min-level
)
3505 (org-init-section-numbers)
3508 ((and date
(string-match "%" date
))
3509 (setq date
(format-time-string date
)))
3511 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
3513 ;; Get the language-dependent settings
3514 (setq lang-words
(or (assoc language org-export-language-setup
)
3515 (assoc "en" org-export-language-setup
)))
3517 ;; Switch to the output buffer
3519 (let ((inhibit-read-only t
)) (erase-buffer))
3522 (and (fboundp 'set-buffer-file-coding-system
)
3523 (set-buffer-file-coding-system coding-system-for-write
))
3525 (let ((case-fold-search nil
)
3526 (org-odd-levels-only odd
))
3527 ;; create local variables for all options, to make sure all called
3528 ;; functions get the correct information
3530 (set (make-local-variable (nth 2 x
))
3531 (plist-get opt-plist
(car x
))))
3532 org-export-plist-vars
)
3533 (setq umax
(if arg
(prefix-numeric-value arg
)
3534 org-export-headline-levels
))
3535 (setq umax-toc
(if (integerp org-export-with-toc
)
3536 (min org-export-with-toc umax
)
3541 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3542 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3543 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3544 lang=\"%s\" xml:lang=\"%s\">
3547 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3548 <meta name=\"generator\" content=\"Org-mode\"/>
3549 <meta name=\"generated\" content=\"%s\"/>
3550 <meta name=\"author\" content=\"%s\"/>
3551 <meta name=\"description\" content=\"%s\"/>
3552 <meta name=\"keywords\" content=\"%s\"/>
3556 <div id=\"content\">
3558 language language
(org-html-expand title
)
3559 (or charset
"iso-8859-1")
3560 date author description keywords
3563 (insert (or (plist-get opt-plist
:preamble
) ""))
3565 (when (plist-get opt-plist
:auto-preamble
)
3566 (if title
(insert (format org-export-html-title-format
3567 (org-html-expand title
))))))
3569 (if (and org-export-with-toc
(not body-only
))
3571 (push (format "<h%d>%s</h%d>\n"
3572 org-export-html-toplevel-hlevel
3574 org-export-html-toplevel-hlevel
)
3576 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3577 (push "<ul>\n<li>" thetoc
)
3579 (mapcar '(lambda (line)
3580 (if (string-match org-todo-line-regexp line
)
3581 ;; This is a headline
3583 (setq have-headings t
)
3584 (setq level
(- (match-end 1) (match-beginning 1)
3586 level
(org-tr-level level
)
3587 txt
(save-match-data
3589 (org-export-cleanup-toc-line
3590 (match-string 3 line
))))
3592 (or (and org-export-mark-todo-in-toc
3594 (not (member (match-string 2 line
)
3595 org-done-keywords
)))
3597 (and org-export-mark-todo-in-toc
3599 (org-search-todo-below
3600 line lines level
))))
3602 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3603 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3604 (if (string-match quote-re0 txt
)
3605 (setq txt
(replace-match "" t t txt
)))
3606 (setq snumber
(org-section-number level
))
3607 (if org-export-with-section-numbers
3608 (setq txt
(concat snumber
" " txt
)))
3609 (if (<= level
(max umax umax-toc
))
3610 (setq head-count
(+ head-count
1)))
3611 (if (<= level umax-toc
)
3613 (if (> level org-last-level
)
3615 (setq cnt
(- level org-last-level
))
3616 (while (>= (setq cnt
(1- cnt
)) 0)
3617 (push "\n<ul>\n<li>" thetoc
))
3618 (push "\n" thetoc
)))
3619 (if (< level org-last-level
)
3621 (setq cnt
(- org-last-level level
))
3622 (while (>= (setq cnt
(1- cnt
)) 0)
3623 (push "</li>\n</ul>" thetoc
))
3624 (push "\n" thetoc
)))
3625 ;; Check for targets
3626 (while (string-match org-any-target-regexp line
)
3627 (setq line
(replace-match
3628 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3630 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3631 (setq txt
(replace-match "" t t txt
)))
3635 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3636 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3637 snumber txt
) thetoc
)
3639 (setq org-last-level level
))
3643 (while (> org-last-level
(1- org-min-level
))
3644 (setq org-last-level
(1- org-last-level
))
3645 (push "</li>\n</ul>\n" thetoc
))
3646 (push "</div>\n" thetoc
)
3647 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3650 (org-init-section-numbers)
3654 (while (setq line
(pop lines
) origline line
)
3657 ;; end of quote section?
3658 (when (and inquote
(string-match "^\\*+ " line
))
3661 ;; inside a quote section?
3663 (insert (org-html-protect line
) "\n")
3664 (throw 'nextline nil
))
3666 ;; Fixed-width, verbatim lines (examples)
3667 (when (and org-export-with-fixed-width
3668 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
3671 (org-close-par-maybe)
3672 (insert "<pre class=\"example\">\n"))
3673 (insert (org-html-protect (match-string 3 line
)) "\n")
3674 (when (or (not lines
)
3675 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
3678 (insert "</pre>\n"))
3679 (throw 'nextline nil
))
3682 (when (get-text-property 0 'org-protected line
)
3684 (when (re-search-backward
3685 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3686 (setq par
(match-string 1))
3687 (replace-match "\\2\n"))
3690 (or (= (length (car lines
)) 0)
3691 (get-text-property 0 'org-protected
(car lines
))))
3692 (insert (pop lines
) "\n"))
3693 (and par
(insert "<p>\n")))
3694 (throw 'nextline nil
))
3697 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3699 (insert "\n</p>\n<hr/>\n<p>\n")
3700 (insert "\n<hr/>\n"))
3701 (throw 'nextline nil
))
3703 ;; Blockquotes and verse
3704 (when (equal "ORG-BLOCKQUOTE-START" line
)
3705 (org-close-par-maybe)
3706 (insert "<blockquote>\n<p>\n")
3707 (throw 'nextline nil
))
3708 (when (equal "ORG-BLOCKQUOTE-END" line
)
3709 (insert "</p>\n</blockquote>\n")
3710 (throw 'nextline nil
))
3711 (when (equal "ORG-VERSE-START" line
)
3712 (org-close-par-maybe)
3713 (insert "\n<p class=\"verse\">\n")
3715 (throw 'nextline nil
))
3716 (when (equal "ORG-VERSE-END" line
)
3719 (throw 'nextline nil
))
3721 (let ((i (org-get-string-indentation line
)))
3723 (setq line
(concat (mapconcat 'identity
3724 (make-list (* 2 i
) "\\nbsp") "")
3725 " " (org-trim line
))))
3726 (setq line
(concat line
"\\\\"))))
3728 ;; make targets to anchors
3729 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3732 (setq line
(replace-match
3734 "@<a name=\"%s\" id=\"%s\">@</a>"
3735 (org-solidify-link-text (match-string 1 line
))
3736 (org-solidify-link-text (match-string 1 line
)))
3738 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3739 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3740 (setq line
(replace-match
3741 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3742 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3745 (setq line
(replace-match
3746 (concat "@<a name=\""
3747 (org-solidify-link-text (match-string 1 line
))
3748 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3751 (setq line
(org-html-handle-time-stamps line
))
3753 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3754 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3755 ;; Also handle sub_superscripts and checkboxes
3756 (or (string-match org-table-hline-regexp line
)
3757 (setq line
(org-html-expand line
)))
3761 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
3762 (setq start
(match-beginning 0))
3763 (setq path
(save-match-data (org-link-unescape
3764 (match-string 3 line
))))
3766 ((match-end 2) (match-string 2 line
))
3768 (or (file-name-absolute-p path
)
3769 (string-match "^\\.\\.?/" path
)))
3772 (setq path
(org-extract-attributes (org-link-unescape path
)))
3773 (setq attr
(get-text-property 0 'org-attributes path
))
3774 (setq desc1
(if (match-end 5) (match-string 5 line
))
3775 desc2
(if (match-end 2) (concat type
":" path
) path
)
3776 descp
(and desc1
(not (equal desc1 desc2
)))
3777 desc
(or desc1 desc2
))
3778 ;; Make an image out of the description if that is so wanted
3779 (when (and descp
(org-file-image-p
3780 desc org-export-html-inline-image-extensions
))
3782 (if (string-match "^file:" desc
)
3783 (setq desc
(substring desc
(match-end 0)))))
3784 (setq desc
(org-add-props
3785 (concat "<img src=\"" desc
"\"/>")
3786 '(org-protected t
))))
3787 ;; FIXME: do we need to unescape here somewhere?
3789 ((equal type
"internal")
3793 (org-solidify-link-text
3794 (save-match-data (org-link-unescape path
)) nil
)
3796 (org-export-html-format-desc desc
)
3798 ((and (equal type
"id")
3799 (setq id-file
(org-id-find-id-file path
)))
3800 ;; This is an id: link to another file (if it was the same file,
3801 ;; it would have become an internal link...)
3802 (setq id-file
(file-relative-name
3803 id-file
(file-name-directory org-current-export-file
)))
3804 (setq id-file
(concat (file-name-sans-extension id-file
)
3805 "." html-extension
))
3806 (setq rpl
(concat "<a href=\"" id-file
"#"
3807 (if (org-uuidgen-p path
) "ID-")
3810 (org-export-html-format-desc desc
)
3812 ((member type
'("http" "https"))
3813 ;; standard URL, just check if we need to inline an image
3814 (if (and (or (eq t org-export-html-inline-images
)
3815 (and org-export-html-inline-images
(not descp
)))
3817 path org-export-html-inline-image-extensions
))
3818 (setq rpl
(org-export-html-format-image
3819 (concat type
":" path
) org-par-open
))
3820 (setq link
(concat type
":" path
))
3821 (setq rpl
(concat "<a href=\""
3822 (org-export-html-format-href link
)
3824 (org-export-html-format-desc desc
)
3826 ((member type
'("ftp" "mailto" "news"))
3828 (setq link
(concat type
":" path
))
3829 (setq rpl
(concat "<a href=\""
3830 (org-export-html-format-href link
)
3832 (org-export-html-format-desc desc
)
3835 ((string= type
"coderef")
3837 (setq rpl
(format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3839 (format (org-export-get-coderef-format path
(and descp desc
))
3840 (cdr (assoc path org-export-code-refs
))))))
3842 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3843 ;; The link protocol has a function for format the link
3846 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3848 ((string= type
"file")
3850 (let* ((filename path
)
3851 (abs-p (file-name-absolute-p filename
))
3852 thefile file-is-image-p search
)
3854 (if (string-match "::\\(.*\\)" filename
)
3855 (setq search
(match-string 1 filename
)
3856 filename
(replace-match "" t nil filename
)))
3858 (if (functionp link-validate
)
3859 (funcall link-validate filename current-dir
)
3861 (setq file-is-image-p
3863 filename org-export-html-inline-image-extensions
))
3864 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3865 (when (and org-export-html-link-org-files-as-html
3866 (string-match "\\.org$" thefile
))
3867 (setq thefile
(concat (substring thefile
0
3868 (match-beginning 0))
3869 "." html-extension
))
3871 ;; make sure this is can be used as target search
3872 (not (string-match "^[0-9]*$" search
))
3873 (not (string-match "^\\*" search
))
3874 (not (string-match "^/.*/$" search
)))
3875 (setq thefile
(concat thefile
"#"
3876 (org-solidify-link-text
3877 (org-link-unescape search
)))))
3878 (when (string-match "^file:" desc
)
3879 (setq desc
(replace-match "" t t desc
))
3880 (if (string-match "\\.org$" desc
)
3881 (setq desc
(replace-match "" t t desc
))))))
3882 (setq rpl
(if (and file-is-image-p
3883 (or (eq t org-export-html-inline-images
)
3884 (and org-export-html-inline-images
3887 (message "image %s %s" thefile org-par-open
)
3888 (org-export-html-format-image thefile org-par-open
))
3889 (concat "<a href=\"" thefile
"\"" attr
">"
3890 (org-export-html-format-desc desc
)
3892 (if (not valid
) (setq rpl desc
))))
3895 ;; just publish the path, as default
3896 (setq rpl
(concat "<i><" type
":"
3897 (save-match-data (org-link-unescape path
))
3899 (setq line
(replace-match rpl t t line
)
3900 start
(+ start
(length rpl
))))
3903 (if (and (string-match org-todo-line-regexp line
)
3904 (match-beginning 2))
3907 (concat (substring line
0 (match-beginning 2))
3909 (if (member (match-string 2 line
)
3912 " " (match-string 2 line
)
3913 "\"> " (org-export-html-get-todo-kwd-class-name
3914 (match-string 2 line
))
3915 "</span>" (substring line
(match-end 2)))))
3917 ;; Does this contain a reference to a footnote?
3918 (when org-export-with-footnotes
3920 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3921 (if (get-text-property (match-beginning 2) 'org-protected line
)
3922 (setq start
(match-end 2))
3923 (let ((n (match-string 2 line
)) extra a
)
3924 (if (setq a
(assoc n footref-seen
))
3926 (setcdr a
(1+ (cdr a
)))
3927 (setq extra
(format ".%d" (cdr a
))))
3929 (push (cons n
1) footref-seen
))
3933 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3934 (match-string 1 line
) n extra n n
)
3938 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3939 ;; This is a headline
3940 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
3942 txt
(match-string 2 line
))
3943 (if (string-match quote-re0 txt
)
3944 (setq txt
(replace-match "" t t txt
)))
3945 (if (<= level
(max umax umax-toc
))
3946 (setq head-count
(+ head-count
1)))
3948 ;; Close any local lists before inserting a new header line
3949 (while local-list-type
3950 (org-close-li (car local-list-type
))
3951 (insert (format "</%sl>\n" (car local-list-type
)))
3952 (pop local-list-type
))
3953 (setq local-list-indent nil
3955 (setq first-heading-pos
(or first-heading-pos
(point)))
3956 (org-html-level-start level txt umax
3957 (and org-export-with-toc
(<= level umax
))
3960 (when (string-match quote-re line
)
3961 (org-close-par-maybe)
3965 ((and org-export-with-tables
3966 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3967 (if (not table-open
)
3969 (setq table-open t table-buffer nil table-orig-buffer nil
))
3971 (setq table-buffer
(cons line table-buffer
)
3972 table-orig-buffer
(cons origline table-orig-buffer
))
3973 (when (or (not lines
)
3974 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3976 (setq table-open nil
3977 table-buffer
(nreverse table-buffer
)
3978 table-orig-buffer
(nreverse table-orig-buffer
))
3979 (org-close-par-maybe)
3980 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3985 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3986 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3987 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3988 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3990 (setq ind
(org-get-string-indentation line
)
3991 item-type
(if (match-beginning 4) "o" "u")
3992 starter
(if (match-beginning 2)
3993 (substring (match-string 2 line
) 0 -
1))
3994 line
(substring line
(match-beginning 5))
3996 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3998 item-tag
(match-string 1 line
)
3999 line
(substring line
(match-end 0))))
4000 (when (and (not (equal item-type
"d"))
4001 (not (string-match "[^ \t]" line
)))
4002 ;; empty line. Pretend indentation is large.
4003 (setq ind
(if org-empty-line-terminates-plain-lists
4005 (1+ (or (car local-list-indent
) 1)))))
4007 (while (and in-local-list
4008 (or (and (= ind
(car local-list-indent
))
4010 (< ind
(car local-list-indent
))))
4012 (org-close-li (car local-list-type
))
4013 (insert (format "</%sl>\n" (car local-list-type
)))
4014 (pop local-list-type
) (pop local-list-indent
)
4015 (setq in-local-list local-list-indent
))
4018 (or (not in-local-list
)
4019 (> ind
(car local-list-indent
))))
4020 ;; Start new (level of) list
4021 (org-close-par-maybe)
4023 ((equal item-type
"u") "<ul>\n<li>\n")
4024 ((equal item-type
"o") "<ol>\n<li>\n")
4025 ((equal item-type
"d")
4026 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
4027 (push item-type local-list-type
)
4028 (push ind local-list-indent
)
4029 (setq in-local-list t
))
4031 ;; continue current list
4032 (org-close-li (car local-list-type
))
4034 ((equal (car local-list-type
) "d")
4035 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
4038 ;; we did close a list, normal text follows: need <p>
4040 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
4043 (if (equal (match-string 1 line
) "X")
4045 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
4048 ;; Empty lines start a new paragraph. If hand-formatted lists
4049 ;; are not fully interpreted, lines starting with "-", "+", "*"
4050 ;; also start a new paragraph.
4051 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
4053 ;; Is this the start of a footnote?
4054 (when org-export-with-footnotes
4055 (when (and (boundp 'footnote-section-tag-regexp
)
4056 (string-match (concat "^" footnote-section-tag-regexp
)
4059 (throw 'nextline nil
))
4060 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
4061 (org-close-par-maybe)
4062 (let ((n (match-string 1 line
)))
4063 (setq org-par-open t
4065 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
4067 ;; Check if the line break needs to be conserved
4069 ((string-match "\\\\\\\\[ \t]*$" line
)
4070 (setq line
(replace-match "<br/>" t t line
)))
4071 (org-export-preserve-breaks
4072 (setq line
(concat line
"<br/>"))))
4074 ;; Check if a paragraph should be started
4076 (while (and org-par-open
4077 (string-match "\\\\par\\>" line start
))
4078 ;; Leave a space in the </p> so that the footnote matcher
4079 ;; does not see this.
4080 (if (not (get-text-property (match-beginning 0)
4081 'org-protected line
))
4082 (setq line
(replace-match "</p ><p >" t t line
)))
4083 (setq start
(match-end 0))))
4085 (insert line
"\n")))))
4087 ;; Properly close all local lists and other lists
4092 ;; Close any local lists before inserting a new header line
4093 (while local-list-type
4094 (org-close-li (car local-list-type
))
4095 (insert (format "</%sl>\n" (car local-list-type
)))
4096 (pop local-list-type
))
4097 (setq local-list-indent nil
4099 (org-html-level-start 1 nil umax
4100 (and org-export-with-toc
(<= level umax
))
4102 ;; the </div> to close the last text-... div.
4103 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
4106 (goto-char (point-min))
4107 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
4108 (push (match-string 0) footnotes
)
4109 (replace-match "" t t
)))
4111 (insert (format org-export-html-footnotes-section
4112 (or (nth 4 lang-words
) "Footnotes")
4113 (mapconcat 'identity
(nreverse footnotes
) "\n"))
4115 (let ((bib (org-export-html-get-bibliography)))
4117 (insert "\n" bib
"\n")))
4119 (when (plist-get opt-plist
:auto-postamble
)
4120 (insert "<div id=\"postamble\">\n")
4121 (when (and org-export-author-info author
)
4122 (insert "<p class=\"author\"> "
4123 (nth 1 lang-words
) ": " author
"\n")
4125 (if (listp (split-string email
",+ *"))
4127 (insert "<a href=\"mailto:" e
"\"><"
4129 (split-string email
",+ *"))
4130 (insert "<a href=\"mailto:" email
"\"><"
4131 email
"></a>\n")))
4133 (when (and date org-export-time-stamp-file
)
4134 (insert "<p class=\"date\"> "
4135 (nth 2 lang-words
) ": "
4137 (when org-export-creator-info
4138 (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
4139 org-version emacs-major-version
)))
4140 (when org-export-html-validation-link
4141 (insert org-export-html-validation-link
"\n"))
4144 (if org-export-html-with-timestamp
4145 (insert org-export-html-html-helper-timestamp
))
4146 (insert (or (plist-get opt-plist
:postamble
) ""))
4147 (insert "\n</div>\n</body>\n</html>\n"))
4149 (unless (plist-get opt-plist
:buffer-will-be-killed
)
4151 (if (eq major-mode default-major-mode
) (html-mode)))
4153 ;; insert the table of contents
4154 (goto-char (point-min))
4156 (if (or (re-search-forward
4157 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
4159 "\\[TABLE-OF-CONTENTS\\]" nil t
))
4161 (goto-char (match-beginning 0))
4163 (goto-char first-heading-pos
)
4164 (when (looking-at "\\s-*</p>")
4165 (goto-char (match-end 0))
4167 (insert "<div id=\"table-of-contents\">\n")
4168 (mapc 'insert thetoc
)
4169 (insert "</div>\n"))
4170 ;; remove empty paragraphs and lists
4171 (goto-char (point-min))
4172 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
4174 (goto-char (point-min))
4175 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
4177 (goto-char (point-min))
4178 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
4180 ;; Convert whitespace place holders
4181 (goto-char (point-min))
4183 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
4184 (setq n
(get-text-property beg
'org-whitespace
)
4185 end
(next-single-property-change beg
'org-whitespace
))
4187 (delete-region beg end
)
4188 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
4189 (make-string n ?x
)))))
4190 (or to-buffer
(save-buffer))
4191 (goto-char (point-min))
4192 (message "Exporting... done")
4193 (if (eq to-buffer
'string
)
4194 (prog1 (buffer-substring (point-min) (point-max))
4195 (kill-buffer (current-buffer)))
4196 (current-buffer)))))
4198 (defun org-export-get-coderef-format (path desc
)
4200 (if (and desc
(string-match
4201 (regexp-quote (concat "(" path
")"))
4203 (replace-match "%s" t t desc
)
4207 (defun org-export-html-format-href (s)
4208 "Make sure the S is valid as a href reference in an XHTML document."
4211 (while (string-match "&" s start
)
4212 (setq start
(+ (match-beginning 0) 3)
4213 s
(replace-match "&" t t s
)))))
4216 (defun org-export-html-format-desc (s)
4217 "Make sure the S is valid as a description in a link."
4218 (if (and s
(not (get-text-property 1 'org-protected s
)))
4220 (org-html-do-expand s
))
4223 (defun org-export-html-format-image (src par-open
)
4224 "Create image tag with source and attributes."
4226 (if (string-match "^ltxpng/" src
)
4227 (format "<img src=\"%s\"/>" src
)
4228 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
4229 (attr (org-find-text-property-in-string 'org-attributes src
))
4230 (label (org-find-text-property-in-string 'org-label src
)))
4231 (format "%s<div %sclass=\"figure\">
4232 <p><img src=\"%s\"%s /></p>%s
4234 (if org-par-open
"</p>\n" "")
4235 (if label
(format "id=\"%s\" " label
) "")
4237 (if (string-match "\\<alt=" (or attr
""))
4239 (concat " " attr
" alt=\"" src
"\""))
4240 (if caption
(concat "\n<p>" caption
"</p>") "")
4241 (if org-par-open
"\n<p>" ""))))))
4243 (defun org-export-html-get-bibliography ()
4244 "Find bibliography, cut it out and return it."
4246 (let (beg end
(cnt 1) bib
)
4248 (goto-char (point-min))
4249 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
4250 (setq beg
(match-beginning 0))
4251 (while (re-search-forward "</?div\\>" nil t
)
4252 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
4254 (and (looking-at ">") (forward-char 1))
4255 (setq bib
(buffer-substring beg
(point)))
4256 (delete-region beg
(point))
4257 (throw 'exit bib
))))
4260 (defvar org-table-colgroup-info nil
)
4261 (defun org-format-table-ascii (lines)
4262 "Format a table for ascii export."
4264 (setq lines
(org-split-string lines
"\n")))
4265 (if (not (string-match "^[ \t]*|" (car lines
)))
4266 ;; Table made by table.el - test for spanning
4269 ;; A normal org table
4270 ;; Get rid of hlines at beginning and end
4271 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4272 (setq lines
(nreverse lines
))
4273 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4274 (setq lines
(nreverse lines
))
4275 (when org-export-table-remove-special-lines
4276 ;; Check if the table has a marking column. If yes remove the
4277 ;; column and the special lines
4278 (setq lines
(org-table-clean-before-export lines
)))
4279 ;; Get rid of the vertical lines except for grouping
4280 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
4282 (while (setq line
(pop lines
))
4283 (if (string-match org-table-hline-regexp line
)
4284 (and (string-match "|\\(.*\\)|" line
)
4285 (setq line
(replace-match " \\1" t nil line
)))
4286 (setq start
0 vl1 vl
)
4287 (while (string-match "|" line start
)
4288 (setq start
(match-end 0))
4289 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
4293 (defun org-colgroup-info-to-vline-list (info)
4296 (setq last new new
(pop info
))
4297 (if (or (memq last
'(:end
:startend
))
4298 (memq new
'(:start
:startend
)))
4301 (setq vl
(nreverse vl
))
4302 (and vl
(setcar vl nil
))
4305 (defvar org-table-number-regexp
) ; defined in org-table.el
4306 (defun org-format-table-html (lines olines
)
4307 "Find out which HTML converter to use and return the HTML code."
4309 (setq lines
(org-split-string lines
"\n")))
4310 (if (string-match "^[ \t]*|" (car lines
))
4311 ;; A normal org table
4312 (org-format-org-table-html lines
)
4313 ;; Table made by table.el - test for spanning
4314 (let* ((hlines (delq nil
(mapcar
4316 (if (string-match "^[ \t]*\\+-" x
) x
4319 (first (car hlines
))
4320 (ll (and (string-match "\\S-+" first
)
4321 (match-string 0 first
)))
4322 (re (concat "^[ \t]*" (regexp-quote ll
)))
4323 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
4325 (if (and (not spanning
)
4326 (not org-export-prefer-native-exporter-for-tables
))
4327 ;; We can use my own converter with HTML conversions
4328 (org-format-table-table-html lines
)
4329 ;; Need to use the code generator in table.el, with the original text.
4330 (org-format-table-table-html-using-table-generate-source olines
)))))
4332 (defvar org-table-number-fraction
) ; defined in org-table.el
4333 (defun org-format-org-table-html (lines &optional splice
)
4334 "Format a table into HTML."
4335 (require 'org-table
)
4336 ;; Get rid of hlines at beginning and end
4337 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4338 (setq lines
(nreverse lines
))
4339 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4340 (setq lines
(nreverse lines
))
4341 (when org-export-table-remove-special-lines
4342 ;; Check if the table has a marking column. If yes remove the
4343 ;; column and the special lines
4344 (setq lines
(org-table-clean-before-export lines
)))
4346 (let ((caption (or (get-text-property 0 'org-caption
(car lines
))
4347 (get-text-property (or (next-single-property-change
4348 0 'org-caption
(car lines
))
4350 'org-caption
(car lines
))))
4351 (head (and org-export-highlight-first-table-line
4353 (lambda (x) (string-match "^[ \t]*|-" x
))
4357 tbopen line fields html gr colgropen
)
4358 (if splice
(setq head nil
))
4359 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
4361 (while (setq line
(pop lines
))
4363 (if (string-match "^[ \t]*|-" line
)
4366 (push (if head
"</thead>" "</tbody>") html
)
4367 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
4368 (setq head nil
) ;; head ends here, first time around
4370 (throw 'next-line t
)))
4371 ;; Break the line into fields
4372 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4373 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
4374 (setq nlines
(1+ nlines
) i -
1)
4375 (push (concat "<tr>"
4379 (if (and (< i nlines
)
4380 (string-match org-table-number-regexp x
))
4381 (incf (aref fnum i
)))
4383 (concat (car org-export-table-header-tags
) x
4384 (cdr org-export-table-header-tags
))
4385 (concat (car org-export-table-data-tags
) x
4386 (cdr org-export-table-data-tags
))))
4390 (unless splice
(if tbopen
(push "</tbody>" html
)))
4391 (unless splice
(push "</table>\n" html
))
4392 (setq html
(nreverse html
))
4394 ;; Put in col tags with the alignment (unfortunately often ignored...)
4397 (setq gr
(pop org-table-colgroup-info
))
4398 (format "%s<col align=\"%s\"></col>%s"
4399 (if (memq gr
'(:start
:startend
))
4401 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
4404 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
4406 (if (memq gr
'(:end
:startend
))
4407 (progn (setq colgropen nil
) "</colgroup>")
4411 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
4412 ;; Since the output of HTML table formatter can also be used in
4413 ;; DocBook document, we want to always include the caption to make
4414 ;; DocBook XML file valid.
4415 (push (format "<caption>%s</caption>" (or caption
"")) html
)
4416 (push html-table-tag html
))
4417 (concat (mapconcat 'identity html
"\n") "\n")))
4419 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
4420 "Check if the table has a marking column.
4421 If yes remove the column and the special lines."
4422 (setq org-table-colgroup-info nil
)
4425 (lambda (x) (or (string-match "^[ \t]*|-" x
)
4428 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
4429 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
4433 (setq org-table-clean-did-remove-column nil
)
4438 ((string-match "^[ \t]*| */ *|" x
)
4439 (setq org-table-colgroup-info
4441 (cond ((member x
'("<" "<")) :start
)
4442 ((member x
'(">" ">")) :end
)
4443 ((member x
'("<>" "<>")) :startend
)
4445 (org-split-string x
"[ \t]*|[ \t]*")))
4449 (setq org-table-clean-did-remove-column t
)
4454 ((string-match "^[ \t]*| */ *|" x
)
4455 (setq org-table-colgroup-info
4457 (cond ((member x
'("<" "<")) :start
)
4458 ((member x
'(">" ">")) :end
)
4459 ((member x
'("<>" "<>")) :startend
)
4461 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
4463 ((string-match "^[ \t]*| *[!_^/] *|" x
)
4464 nil
) ; ignore this line
4465 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
4466 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
4467 ;; remove the first column
4468 (replace-match "\\1|" t nil x
))))
4471 (defun org-format-table-table-html (lines)
4472 "Format a table generated by table.el into HTML.
4473 This conversion does *not* use `table-generate-source' from table.el.
4474 This has the advantage that Org-mode's HTML conversions can be used.
4475 But it has the disadvantage, that no cell- or row-spanning is allowed."
4476 (let (line field-buffer
4477 (head org-export-highlight-first-table-line
)
4479 (setq html
(concat html-table-tag
"\n"))
4480 (while (setq line
(pop lines
))
4481 (setq empty
" ")
4483 (if (string-match "^[ \t]*\\+-" line
)
4494 (if (equal x
"") (setq x empty
))
4496 (concat (car org-export-table-header-tags
) x
4497 (cdr org-export-table-header-tags
))
4498 (concat (car org-export-table-data-tags
) x
4499 (cdr org-export-table-data-tags
))))
4503 (setq field-buffer nil
)))
4505 (throw 'next-line t
)))
4506 ;; Break the line into fields and store the fields
4507 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4509 (setq field-buffer
(mapcar
4511 (concat x
"<br/>" (pop fields
)))
4513 (setq field-buffer fields
))))
4514 (setq html
(concat html
"</table>\n"))
4517 (defun org-format-table-table-html-using-table-generate-source (lines)
4518 "Format a table into html, using `table-generate-source' from table.el.
4519 This has the advantage that cell- or row-spanning is allowed.
4520 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4522 (with-current-buffer (get-buffer-create " org-tmp1 ")
4524 (insert (mapconcat 'identity lines
"\n"))
4525 (goto-char (point-min))
4526 (if (not (re-search-forward "|[^+]" nil t
))
4527 (error "Error processing table"))
4528 (table-recognize-table)
4529 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4530 (table-generate-source 'html
" org-tmp2 ")
4531 (set-buffer " org-tmp2 ")
4532 (buffer-substring (point-min) (point-max))))
4534 (defun org-export-splice-style (style extra
)
4535 "Splice EXTRA into STYLE, just before \"</style>\"."
4536 (if (and (stringp extra
)
4537 (string-match "\\S-" extra
)
4538 (string-match "</style>" style
))
4539 (concat (substring style
0 (match-beginning 0))
4541 (substring style
(match-beginning 0)))
4544 (defun org-html-handle-time-stamps (s)
4545 "Format time stamps in string S, or remove them."
4548 (while (string-match org-maybe-keyword-time-regexp s
)
4549 (or b
(setq b
(substring s
0 (match-beginning 0))))
4551 r
(substring s
0 (match-beginning 0))
4553 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4554 (match-string 1 s
)))
4555 (format " @<span class=\"timestamp\">%s@</span>"
4557 (org-translate-time (match-string 3 s
)) 1 -
1)))
4558 s
(substring s
(match-end 0))))
4559 ;; Line break if line started and ended with time stamp stuff
4562 (setq r
(concat r s
))
4563 (unless (string-match "\\S-" (concat b s
))
4564 (setq r
(concat r
"@<br/>")))
4567 (defun org-export-htmlize-region-for-paste (beg end
)
4568 "Convert the region to HTML, using htmlize.el.
4569 This is much like `htmlize-region-for-paste', only that it uses
4570 the settings define in the org-... variables."
4571 (let* ((htmlize-output-type org-export-htmlize-output-type
)
4572 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
4573 (htmlbuf (htmlize-region beg end
)))
4575 (with-current-buffer htmlbuf
4576 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
4577 (plist-get htmlize-buffer-places
'content-end
)))
4578 (kill-buffer htmlbuf
))))
4581 (defun org-export-htmlize-generate-css ()
4582 "Create the CSS for all font definitions in the current Emacs session.
4583 Use this to create face definitions in your CSS style file that can then
4584 be used by code snippets transformed by htmlize.
4585 This command just produces a buffer that contains class definitions for all
4586 faces used in the current Emacs session. You can copy and paste the ones you
4587 need into your CSS file.
4589 If you then set `org-export-htmlize-output-type' to `css', calls to
4590 the function `org-export-htmlize-region-for-paste' will produce code
4591 that uses these same face definitions."
4594 (and (get-buffer "*html*") (kill-buffer "*html*"))
4596 (let ((fl (face-list))
4597 (htmlize-css-name-prefix "org-")
4598 (htmlize-output-type 'css
)
4600 (while (setq f
(pop fl
)
4601 i
(and f
(face-attribute f
:inherit
)))
4602 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
4603 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
4604 (htmlize-region (point-min) (point-max))))
4605 (switch-to-buffer "*html*")
4606 (goto-char (point-min))
4607 (if (re-search-forward "<style" nil t
)
4608 (delete-region (point-min) (match-beginning 0)))
4609 (if (re-search-forward "</style>" nil t
)
4610 (delete-region (1+ (match-end 0)) (point-max)))
4611 (beginning-of-line 1)
4612 (if (looking-at " +") (replace-match ""))
4613 (goto-char (point-min)))
4615 (defun org-html-protect (s)
4616 ;; convert & to &, < to < and > to >
4618 (while (string-match "&" s start
)
4619 (setq s
(replace-match "&" t t s
)
4620 start
(1+ (match-beginning 0))))
4621 (while (string-match "<" s
)
4622 (setq s
(replace-match "<" t t s
)))
4623 (while (string-match ">" s
)
4624 (setq s
(replace-match ">" t t s
)))
4625 ; (while (string-match "\"" s)
4626 ; (setq s (replace-match """ t t s)))
4630 (defun org-export-cleanup-toc-line (s)
4631 "Remove tags and timestamps from lines going into the toc."
4632 (when (memq org-export-with-tags
'(not-in-toc nil
))
4633 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
4634 (setq s
(replace-match "" t t s
))))
4635 (when org-export-remove-timestamps-from-toc
4636 (while (string-match org-maybe-keyword-time-regexp s
)
4637 (setq s
(replace-match "" t t s
))))
4638 (while (string-match org-bracket-link-regexp s
)
4639 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
4643 (defun org-html-expand (string)
4644 "Prepare STRING for HTML export. Applies all active conversions.
4645 If there are links in the string, don't modify these."
4646 (let* ((re (concat org-bracket-link-regexp
"\\|"
4647 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4649 (while (setq m
(string-match re string
))
4650 (setq s
(substring string
0 m
)
4651 l
(match-string 0 string
)
4652 string
(substring string
(match-end 0)))
4653 (push (org-html-do-expand s
) res
)
4655 (push (org-html-do-expand string
) res
)
4656 (apply 'concat
(nreverse res
))))
4658 (defun org-html-do-expand (s)
4659 "Apply all active conversions to translate special ASCII to HTML."
4660 (setq s
(org-html-protect s
))
4661 (if org-export-html-expand
4662 (while (string-match "@<\\([^&]*\\)>" s
)
4663 (setq s
(replace-match "<\\1>" t nil s
))))
4664 (if org-export-with-emphasize
4665 (setq s
(org-export-html-convert-emphasize s
)))
4666 (if org-export-with-special-strings
4667 (setq s
(org-export-html-convert-special-strings s
)))
4668 (if org-export-with-sub-superscripts
4669 (setq s
(org-export-html-convert-sub-super s
)))
4670 (if org-export-with-TeX-macros
4671 (let ((start 0) wd ass
)
4672 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4674 (if (get-text-property (match-beginning 0) 'org-protected s
)
4675 (setq start
(match-end 0))
4676 (setq wd
(match-string 1 s
))
4677 (if (setq ass
(assoc wd org-html-entities
))
4678 (setq s
(replace-match (or (cdr ass
)
4679 (concat "&" (car ass
) ";"))
4681 (setq start
(+ start
(length wd
))))))))
4684 (defun org-create-multibrace-regexp (left right n
)
4685 "Create a regular expression which will match a balanced sexp.
4686 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4687 as single character strings.
4688 The regexp returned will match the entire expression including the
4689 delimiters. It will also define a single group which contains the
4690 match except for the outermost delimiters. The maximum depth of
4691 stacked delimiters is N. Escaping delimiters is not possible."
4692 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4695 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4698 re
(concat re or next
)
4699 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4700 (concat left
"\\(" re
"\\)" right
)))
4702 (defvar org-match-substring-regexp
4704 "\\([^\\]\\)\\([_^]\\)\\("
4705 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4707 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4709 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4710 "The regular expression matching a sub- or superscript.")
4712 (defvar org-match-substring-with-braces-regexp
4714 "\\([^\\]\\)\\([_^]\\)\\("
4715 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4717 "The regular expression matching a sub- or superscript, forcing braces.")
4719 (defconst org-export-html-special-string-regexps
4720 '(("\\\\-" .
"­")
4721 ("---\\([^-]\\)" .
"—\\1")
4722 ("--\\([^-]\\)" .
"–\\1")
4723 ("\\.\\.\\." .
"…"))
4724 "Regular expressions for special string conversion.")
4726 (defun org-export-html-convert-special-strings (string)
4727 "Convert special characters in STRING to HTML."
4728 (let ((all org-export-html-special-string-regexps
)
4730 (while (setq a
(pop all
))
4731 (setq re
(car a
) rpl
(cdr a
) start
0)
4732 (while (string-match re string start
)
4733 (if (get-text-property (match-beginning 0) 'org-protected string
)
4734 (setq start
(match-end 0))
4735 (setq string
(replace-match rpl t nil string
)))))
4738 (defun org-export-html-convert-sub-super (string)
4739 "Convert sub- and superscripts in STRING to HTML."
4740 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4741 (while (string-match org-match-substring-regexp string s
)
4743 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4744 ((get-text-property (match-beginning 2) 'org-protected string
)
4745 (setq s
(match-end 2)))
4747 (setq s
(match-end 1)
4748 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4749 c
(or (match-string 8 string
)
4750 (match-string 6 string
)
4751 (match-string 5 string
))
4752 string
(replace-match
4753 (concat (match-string 1 string
)
4754 "<" key
">" c
"</" key
">")
4756 (while (string-match "\\\\\\([_^]\\)" string
)
4757 (setq string
(replace-match (match-string 1 string
) t t string
)))
4760 (defun org-export-html-convert-emphasize (string)
4763 (while (string-match org-emph-re string s
)
4765 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4766 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4767 (setq s
(match-beginning 0)
4770 (match-string 1 string
)
4771 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4772 (match-string 4 string
)
4773 (nth 3 (assoc (match-string 3 string
)
4774 org-emphasis-alist
))
4775 (match-string 5 string
))
4776 string
(replace-match rpl t t string
)
4777 s
(+ s
(- (length rpl
) 2)))
4781 (defun org-open-par ()
4782 "Insert <p>, but first close previous paragraph if any."
4783 (org-close-par-maybe)
4785 (setq org-par-open t
))
4786 (defun org-close-par-maybe ()
4787 "Close paragraph if there is one open."
4790 (setq org-par-open nil
)))
4791 (defun org-close-li (&optional type
)
4792 "Close <li> if necessary."
4793 (org-close-par-maybe)
4794 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4796 (defvar body-only
) ; dynamically scoped into this.
4797 (defun org-html-level-start (level title umax with-toc head-count
)
4798 "Insert a new level in HTML export.
4799 When TITLE is nil, just close all open levels."
4800 (org-close-par-maybe)
4801 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
4803 (mapconcat (lambda (x)
4804 (if (org-uuidgen-p x
) (setq x
(concat "ID-" x
)))
4805 (format "<a name=\"%s\" id=\"%s\"></a>"
4807 (cdr (assoc target org-export-target-aliases
))
4812 (if (aref org-levels-open
(1- l
))
4814 (org-html-level-close l umax
)
4815 (aset org-levels-open
(1- l
) nil
)))
4818 ;; If title is nil, this means this function is called to close
4819 ;; all levels, so the rest is done only if title is given
4820 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4821 (setq title
(replace-match
4822 (if org-export-with-tags
4825 " <span class=\"tag\">"
4828 (format "<span class=\"%s\">%s</span>"
4829 (org-export-html-get-tag-class-name x
)
4831 (org-split-string (match-string 1 title
) ":")
4838 (if (aref org-levels-open
(1- level
))
4842 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
4843 (insert "<li>" title
"<br/>\n")))
4844 (aset org-levels-open
(1- level
) t
)
4845 (org-close-par-maybe)
4847 (insert (format "<ul>\n<li id=\"%s\">" target
)
4848 extra-targets title
"<br/>\n")
4849 (insert "<ul>\n<li>" title
"<br/>\n"))))
4850 (aset org-levels-open
(1- level
) t
)
4851 (setq snumber
(org-section-number level
))
4852 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4853 (if (and org-export-with-section-numbers
(not body-only
))
4855 (format "<span class=\"section-number-%d\">%s</span>"
4858 (unless (= head-count
1) (insert "\n</div>\n"))
4859 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
4860 snumber level level snumber extra-targets
4861 title level level snumber
))
4864 (defun org-get-text-property-any (pos prop
&optional object
)
4865 (or (get-text-property pos prop object
)
4866 (and (setq pos
(next-single-property-change pos prop object
))
4867 (get-text-property pos prop object
))))
4869 (defun org-export-html-get-tag-class-name (tag)
4870 "Turn tag into a valid class name.
4871 Replaces invalid characters with \"_\" and then prepends a prefix."
4873 (while (string-match "[^a-zA-Z0-9_]" tag
)
4874 (setq tag
(replace-match "_" t t tag
))))
4875 (concat org-export-html-tag-class-prefix tag
))
4877 (defun org-export-html-get-todo-kwd-class-name (kwd)
4878 "Turn todo keyword into a valid class name.
4879 Replaces invalid characters with \"_\" and then prepends a prefix."
4881 (while (string-match "[^a-zA-Z0-9_]" kwd
)
4882 (setq kwd
(replace-match "_" t t kwd
))))
4883 (concat org-export-html-todo-kwd-class-prefix kwd
))
4885 (defun org-html-level-close (level max-outline-level
)
4886 "Terminate one level in HTML export."
4887 (if (<= level max-outline-level
)
4890 (insert "</ul>\n")))
4892 ;;; iCalendar export
4895 (defun org-export-icalendar-this-file ()
4896 "Export current file as an iCalendar file.
4897 The iCalendar file will be located in the same directory as the Org-mode
4898 file, but with extension `.ics'."
4900 (org-export-icalendar nil buffer-file-name
))
4903 (defun org-export-icalendar-all-agenda-files ()
4904 "Export all files in `org-agenda-files' to iCalendar .ics files.
4905 Each iCalendar file will be located in the same directory as the Org-mode
4906 file, but with extension `.ics'."
4908 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4911 (defun org-export-icalendar-combine-agenda-files ()
4912 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4913 The file is stored under the name `org-combined-agenda-icalendar-file'."
4915 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4917 (defun org-export-icalendar (combine &rest files
)
4918 "Create iCalendar files for all elements of FILES.
4919 If COMBINE is non-nil, combine all calendar entries into a single large
4920 file and store it under the name `org-combined-agenda-icalendar-file'."
4922 (org-prepare-agenda-buffers files
)
4923 (let* ((dir (org-export-directory
4924 :ical
(list :publishing-directory
4925 org-export-publishing-directory
)))
4926 file ical-file ical-buffer category started org-agenda-new-buffers
)
4927 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4930 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4931 org-combined-agenda-icalendar-file
4932 (expand-file-name org-combined-agenda-icalendar-file dir
))
4933 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4934 (set-buffer ical-buffer
) (erase-buffer))
4935 (while (setq file
(pop files
))
4937 (org-check-agenda-file file
)
4938 (set-buffer (org-get-agenda-file-buffer file
))
4940 (setq ical-file
(concat (file-name-as-directory dir
)
4941 (file-name-sans-extension
4942 (file-name-nondirectory buffer-file-name
))
4944 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4945 (with-current-buffer ical-buffer
(erase-buffer)))
4946 (setq category
(or org-category
4947 (file-name-sans-extension
4948 (file-name-nondirectory buffer-file-name
))))
4949 (if (symbolp category
) (setq category
(symbol-name category
)))
4950 (let ((standard-output ical-buffer
))
4952 (and (not started
) (setq started t
)
4953 (org-start-icalendar-file org-icalendar-combined-name
))
4954 (org-start-icalendar-file category
))
4955 (org-print-icalendar-entries combine
)
4956 (when (or (and combine
(not files
)) (not combine
))
4957 (org-finish-icalendar-file)
4958 (set-buffer ical-buffer
)
4959 (run-hooks 'org-before-save-iCalendar-file-hook
)
4961 (run-hooks 'org-after-save-iCalendar-file-hook
)
4962 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4964 (org-release-buffers org-agenda-new-buffers
))))
4966 (defvar org-before-save-iCalendar-file-hook nil
4967 "Hook run before an iCalendar file has been saved.
4968 This can be used to modify the result of the export.")
4970 (defvar org-after-save-iCalendar-file-hook nil
4971 "Hook run after an iCalendar file has been saved.
4972 The iCalendar buffer is still current when this hook is run.
4973 A good way to use this is to tell a desktop calendar application to re-read
4974 the iCalendar file.")
4976 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4977 (defun org-print-icalendar-entries (&optional combine
)
4978 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4979 When COMBINE is non nil, add the category to each line."
4980 (require 'org-agenda
)
4981 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4982 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4983 (dts (org-ical-ts-to-string
4984 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4986 hd ts ts2 state status
(inc t
) pos b sexp rrule
4987 scheduledp deadlinep todo prefix due start
4988 tmp pri categories location summary desc uid
4989 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4990 (org-refresh-category-properties)
4992 (goto-char (point-min))
4993 (while (re-search-forward re1 nil t
)
4996 (when (boundp 'org-icalendar-verify-function
)
4997 (unless (funcall org-icalendar-verify-function
)
4998 (outline-next-heading)
5001 (setq pos
(match-beginning 0)
5004 hd
(condition-case nil
5005 (org-icalendar-cleanup-string
5007 (error (throw :skip nil
)))
5008 summary
(org-icalendar-cleanup-string
5009 (org-entry-get nil
"SUMMARY"))
5010 desc
(org-icalendar-cleanup-string
5011 (or (org-entry-get nil
"DESCRIPTION")
5012 (and org-icalendar-include-body
(org-get-entry)))
5013 t org-icalendar-include-body
)
5014 location
(org-icalendar-cleanup-string
5015 (org-entry-get nil
"LOCATION" 'selective
))
5016 uid
(if org-icalendar-store-UID
5018 (or (org-id-get) (org-id-new)))
5019 categories
(org-export-get-categories)
5020 deadlinep nil scheduledp nil
)
5021 (if (looking-at re2
)
5023 (goto-char (match-end 0))
5024 (setq ts2
(match-string 1)
5025 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
5026 (setq tmp
(buffer-substring (max (point-min)
5027 (- pos org-ds-keyword-length
))
5029 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
5032 (replace-match "\\1" t nil ts
))
5034 deadlinep
(string-match org-deadline-regexp tmp
)
5035 scheduledp
(string-match org-scheduled-regexp tmp
)
5036 todo
(org-get-todo-state)
5037 ;; donep (org-entry-is-done-p)
5042 (not (memq 'event-if-todo org-icalendar-use-deadline
))
5043 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
5048 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
5049 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
5051 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
5052 (if (or (string-match org-tr-regexp hd
)
5053 (string-match org-ts-regexp hd
))
5054 (setq hd
(replace-match "" t t hd
)))
5055 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
5057 (concat "\nRRULE:FREQ="
5060 '(("d" .
"DAILY")("w" .
"WEEKLY")
5061 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
5062 ";INTERVAL=" (match-string 1 ts
)))
5064 (setq summary
(or summary hd
))
5065 (if (string-match org-bracket-link-regexp summary
)
5067 (replace-match (if (match-end 3)
5068 (match-string 3 summary
)
5069 (match-string 1 summary
))
5071 (if deadlinep
(setq summary
(concat "DL: " summary
)))
5072 (if scheduledp
(setq summary
(concat "S: " summary
)))
5073 (if (string-match "\\`<%%" ts
)
5074 (with-current-buffer sexp-buffer
5075 (insert (substring ts
1 -
1) " " summary
"\n"))
5076 (princ (format "BEGIN:VEVENT
5084 (org-ical-ts-to-string ts
"DTSTART")
5085 (org-ical-ts-to-string ts2
"DTEND" inc
)
5087 (if (and desc
(string-match "\\S-" desc
))
5088 (concat "\nDESCRIPTION: " desc
) "")
5089 (if (and location
(string-match "\\S-" location
))
5090 (concat "\nLOCATION: " location
) "")
5092 (when (and org-icalendar-include-sexps
5093 (condition-case nil
(require 'icalendar
) (error nil
))
5094 (fboundp 'icalendar-export-region
))
5095 ;; Get all the literal sexps
5096 (goto-char (point-min))
5097 (while (re-search-forward "^&?%%(" nil t
)
5100 (setq b
(match-beginning 0))
5101 (goto-char (1- (match-end 0)))
5104 (setq sexp
(buffer-substring b
(point)))
5105 (with-current-buffer sexp-buffer
5106 (insert sexp
"\n"))))
5107 (princ (org-diary-to-ical-string sexp-buffer
))
5108 (kill-buffer sexp-buffer
))
5110 (when org-icalendar-include-todo
5111 (setq prefix
"TODO-")
5112 (goto-char (point-min))
5113 (while (re-search-forward org-todo-line-regexp nil t
)
5116 (when (boundp 'org-icalendar-verify-function
)
5117 (unless (funcall org-icalendar-verify-function
)
5118 (outline-next-heading)
5121 (setq state
(match-string 2))
5122 (setq status
(if (member state org-done-keywords
)
5123 "COMPLETED" "NEEDS-ACTION"))
5125 (or (not (member state org-done-keywords
))
5126 (eq org-icalendar-include-todo
'all
))
5127 (not (member org-archive-tag
(org-get-tags-at)))
5129 (setq hd
(match-string 3)
5130 summary
(org-icalendar-cleanup-string
5131 (org-entry-get nil
"SUMMARY"))
5132 desc
(org-icalendar-cleanup-string
5133 (or (org-entry-get nil
"DESCRIPTION")
5134 (and org-icalendar-include-body
(org-get-entry)))
5135 t org-icalendar-include-body
)
5136 location
(org-icalendar-cleanup-string
5137 (org-entry-get nil
"LOCATION" 'selective
))
5138 due
(and (member 'todo-due org-icalendar-use-deadline
)
5139 (org-entry-get nil
"DEADLINE"))
5140 start
(and (member 'todo-start org-icalendar-use-scheduled
)
5141 (org-entry-get nil
"SCHEDULED"))
5142 categories
(org-export-get-categories)
5143 uid
(if org-icalendar-store-UID
5145 (or (org-id-get) (org-id-new))))
5146 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
5147 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
5149 (if (string-match org-bracket-link-regexp hd
)
5150 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
5151 (match-string 1 hd
))
5153 (if (string-match org-priority-regexp hd
)
5154 (setq pri
(string-to-char (match-string 2 hd
))
5155 hd
(concat (substring hd
0 (match-beginning 1))
5156 (substring hd
(match-end 1))))
5157 (setq pri org-default-priority
))
5158 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
5159 (- org-lowest-priority org-highest-priority
))))))
5161 (princ (format "BEGIN:VTODO
5173 (if (and location
(string-match "\\S-" location
))
5174 (concat "\nLOCATION: " location
) "")
5175 (if (and desc
(string-match "\\S-" desc
))
5176 (concat "\nDESCRIPTION: " desc
) "")
5177 (if due
(concat "\n" due
) "")
5181 (defun org-export-get-categories ()
5182 "Get categories according to `org-icalendar-categories'."
5183 (let ((cs org-icalendar-categories
) c rtn tmp
)
5184 (while (setq c
(pop cs
))
5186 ((eq c
'category
) (push (org-get-category) rtn
))
5188 (setq tmp
(org-get-todo-state))
5189 (and tmp
(push tmp rtn
)))
5191 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
5193 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
5194 (mapconcat 'identity
(nreverse rtn
) ",")))
5196 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
5197 "Take out stuff and quote what needs to be quoted.
5198 When IS-BODY is non-nil, assume that this is the body of an item, clean up
5199 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
5204 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
5205 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
5206 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
5207 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
5209 (while (string-match "\\([,;]\\)" s start
)
5210 (setq start
(+ (match-beginning 0) 2)
5211 s
(replace-match "\\\\\\1" nil nil s
))))
5212 (setq s
(org-trim s
))
5214 (while (string-match "[ \t]*\n[ \t]*" s
)
5215 (setq s
(replace-match "\\n" t t s
))))
5218 (if (and (numberp maxlength
)
5219 (> (length s
) maxlength
))
5220 (setq s
(substring s
0 maxlength
)))))
5223 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
5224 "Take out stuff and quote what needs to be quoted.
5225 When IS-BODY is non-nil, assume that this is the body of an item, clean up
5226 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
5228 This seems to be more like RFC 2455, but it causes problems, so it is
5229 not used right now."
5233 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
5234 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
5235 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
5236 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
5237 (setq s
(org-trim s
))
5238 (while (string-match "[ \t]*\n[ \t]*" s
)
5239 (setq s
(replace-match "\\n" t t s
)))
5241 (if (and (numberp maxlength
)
5242 (> (length s
) maxlength
))
5243 (setq s
(substring s
0 maxlength
)))))
5244 (setq s
(org-trim s
)))
5245 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
5246 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
5249 (defun org-get-entry ()
5250 "Clean-up description string."
5252 (org-back-to-heading t
)
5253 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
5255 (defun org-start-icalendar-file (name)
5256 "Start an iCalendar file by inserting the header."
5257 (let ((user user-full-name
)
5258 (name (or name
"unknown"))
5259 (timezone (cadr (current-time-zone))))
5261 (format "BEGIN:VCALENDAR
5264 PRODID:-//%s//Emacs with Org-mode//EN
5266 CALSCALE:GREGORIAN\n" name user timezone
))))
5268 (defun org-finish-icalendar-file ()
5269 "Finish an iCalendar file by inserting the END statement."
5270 (princ "END:VCALENDAR\n"))
5272 (defun org-ical-ts-to-string (s keyword
&optional inc
)
5273 "Take a time string S and convert it to iCalendar format.
5274 KEYWORD is added in front, to make a complete line like DTSTART....
5275 When INC is non-nil, increase the hour by two (if time string contains
5276 a time), or the day by one (if it does not contain a time)."
5277 (let ((t1 (org-parse-time-string s
'nodefault
))
5278 t2 fmt have-time time
)
5279 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
5280 (setq t2 t1 have-time t
)
5281 (setq t2
(org-parse-time-string s
)))
5282 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
5283 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
5286 (if org-agenda-default-appointment-duration
5287 (setq mi
(+ org-agenda-default-appointment-duration mi
))
5290 (setq time
(encode-time s mi h d m y
)))
5291 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
5292 (concat keyword
(format-time-string fmt time
))))
5296 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
5297 (with-current-buffer buffer
5298 (apply 'insert output
)))
5299 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
5302 (defun org-export-as-xoxo (&optional buffer
)
5303 "Export the org buffer as XOXO.
5304 The XOXO buffer is named *xoxo-<source buffer name>*"
5305 (interactive (list (current-buffer)))
5306 ;; A quickie abstraction
5308 ;; Output everything as XOXO
5309 (with-current-buffer (get-buffer buffer
)
5310 (let* ((pos (point))
5311 (opt-plist (org-combine-plists (org-default-export-plist)
5312 (org-infile-export-plist)))
5313 (filename (concat (file-name-as-directory
5314 (org-export-directory :xoxo opt-plist
))
5315 (file-name-sans-extension
5316 (file-name-nondirectory buffer-file-name
))
5318 (out (find-file-noselect filename
))
5321 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
5322 ;; Check the output buffer is empty.
5323 (with-current-buffer out
(erase-buffer))
5324 ;; Kick off the output
5325 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
5326 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
5327 (let* ((hd (match-string-no-properties 1))
5330 (match-string-no-properties 2)
5332 (goto-char (match-end 0))
5337 (if (looking-at "^[ \t]\\(.*\\)")
5338 (setq str
(concat str
(match-string-no-properties 1)))
5339 (throw 'loop str
)))))))))
5341 ;; Handle level rendering
5343 ((> level last-level
)
5344 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
5346 ((< level last-level
)
5347 (dotimes (- (- last-level level
) 1)
5349 (org-export-as-xoxo-insert-into out
"</li>\n"))
5350 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5352 (org-export-as-xoxo-insert-into out
"</li>\n")
5353 (setq hanging-li nil
)))
5355 ((equal level last-level
)
5357 (org-export-as-xoxo-insert-into out
"</li>\n")))
5360 (setq last-level level
)
5362 ;; And output the new li
5363 (setq hanging-li
't
)
5364 (if (equal ?
+ (elt text
0))
5365 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
5366 (org-export-as-xoxo-insert-into out
"<li>" text
))))
5368 ;; Finally finish off the ol
5369 (dotimes (- last-level
1)
5371 (org-export-as-xoxo-insert-into out
"</li>\n"))
5372 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5375 ;; Finish the buffer off and clean it up.
5376 (switch-to-buffer-other-window out
)
5377 (indent-region (point-min) (point-max) nil
)
5379 (goto-char (point-min))
5384 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
5386 ;;; org-exp.el ends here