1 ;;; org-exp.el --- Export internals for Org-mode
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 (declare-function org-export-latex-preprocess
"org-latex" (parameters))
39 (declare-function org-export-ascii-preprocess
"org-ascii" (parameters))
40 (declare-function org-export-html-preprocess
"org-html" (parameters))
41 (declare-function org-export-docbook-preprocess
"org-docbook" (parameters))
42 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
43 (declare-function org-export-htmlize-region-for-paste
"org-html" (beg end
))
44 (declare-function htmlize-buffer
"ext:htmlize" (&optional buffer
))
45 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
46 (declare-function org-table-cookie-line-p
"org-table" (line))
47 (declare-function org-table-colgroup-line-p
"org-table" (line))
48 (declare-function org-pop-to-buffer-same-window
"org-compat"
49 (&optional buffer-or-name norecord label
))
51 (autoload 'org-export-generic
"org-export-generic" "Export using the generic exporter" t
)
53 (autoload 'org-export-as-odt
"org-odt"
54 "Export the outline to a OpenDocument Text file." t
)
55 (autoload 'org-export-as-odt-and-open
"org-odt"
56 "Export the outline to a OpenDocument Text file and open it." t
)
58 (defgroup org-export nil
59 "Options for exporting org-listings."
63 (defgroup org-export-general nil
64 "General options for exporting Org-mode files."
65 :tag
"Org Export General"
68 (defcustom org-export-allow-BIND
'confirm
69 "Non-nil means allow #+BIND to define local variable values for export.
70 This is a potential security risk, which is why the user must confirm the
72 :group
'org-export-general
74 (const :tag
"Never" nil
)
75 (const :tag
"Always" t
)
76 (const :tag
"Make the user confirm for each file" confirm
)))
79 (defvar org-export-publishing-directory nil
)
81 (defcustom org-export-show-temporary-export-buffer t
82 "Non-nil means show buffer after exporting to temp buffer.
83 When Org exports to a file, the buffer visiting that file is ever
84 shown, but remains buried. However, when exporting to a temporary
85 buffer, that buffer is popped up in a second window. When this variable
86 is nil, the buffer remains buried also in these cases."
87 :group
'org-export-general
90 (defcustom org-export-copy-to-kill-ring t
91 "Non-nil means exported stuff will also be pushed onto the kill ring."
92 :group
'org-export-general
95 (defcustom org-export-kill-product-buffer-when-displayed nil
96 "Non-nil means kill the product buffer if it is displayed immediately.
97 This applied to the commands `org-export-as-html-and-open' and
98 `org-export-as-pdf-and-open'."
99 :group
'org-export-general
103 (defcustom org-export-run-in-background nil
104 "Non-nil means export and publishing commands will run in background.
105 This works by starting up a separate Emacs process visiting the same file
106 and doing the export from there.
107 Not all export commands are affected by this - only the ones which
108 actually write to a file, and that do not depend on the buffer state.
110 If this option is nil, you can still get background export by calling
111 `org-export' with a double prefix arg: \
112 \\[universal-argument] \\[universal-argument] \\[org-export].
114 If this option is t, the double prefix can be used to exceptionally
115 force an export command into the current process."
116 :group
'org-export-general
119 (defcustom org-export-initial-scope
'buffer
120 "The initial scope when exporting with `org-export'.
121 This variable can be either set to 'buffer or 'subtree."
122 :group
'org-export-general
125 (const :tag
"Export current buffer" 'buffer
)
126 (const :tag
"Export current subtree" 'subtree
)))
128 (defcustom org-export-select-tags
'("export")
129 "Tags that select a tree for export.
130 If any such tag is found in a buffer, all trees that do not carry one
131 of these tags will be deleted before export.
132 Inside trees that are selected like this, you can still deselect a
133 subtree by tagging it with one of the `org-export-exclude-tags'."
134 :group
'org-export-general
135 :type
'(repeat (string :tag
"Tag")))
137 (defcustom org-export-exclude-tags
'("noexport")
138 "Tags that exclude a tree from export.
139 All trees carrying any of these tags will be excluded from export.
140 This is without condition, so even subtrees inside that carry one of the
141 `org-export-select-tags' will be removed."
142 :group
'org-export-general
143 :type
'(repeat (string :tag
"Tag")))
145 ;; FIXME: rename, this is a general variable
146 (defcustom org-export-html-expand t
147 "Non-nil means for HTML export, treat @<...> as HTML tag.
148 When nil, these tags will be exported as plain text and therefore
149 not be interpreted by a browser.
151 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
152 :group
'org-export-html
153 :group
'org-export-general
156 (defcustom org-export-with-special-strings t
157 "Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
158 When this option is turned on, these strings will be exported as:
161 -----+----------+--------
167 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
168 :group
'org-export-translation
171 (defcustom org-export-html-link-up
""
172 "Where should the \"UP\" link of exported HTML pages lead?"
173 :group
'org-export-html
174 :group
'org-export-general
175 :type
'(string :tag
"File or URL"))
177 (defcustom org-export-html-link-home
""
178 "Where should the \"HOME\" link of exported HTML pages lead?"
179 :group
'org-export-html
180 :group
'org-export-general
181 :type
'(string :tag
"File or URL"))
183 (defcustom org-export-language-setup
184 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
185 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
186 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
187 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
188 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
189 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
190 ("es" "Autor" "Fecha" "Índice" "Pies de página")
191 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
192 ("fr" "Auteur" "Date" "Sommaire" "Notes de bas de page")
193 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
194 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
195 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
196 ;; Use numeric character entities for proper rendering of non-UTF8 documents
197 ;; ("ja" "著者" "日付" "目次" "脚注")
198 ("ja" "著者" "日付" "目次" "脚注")
199 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
200 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
201 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
202 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
203 ("pl" "Autor" "Data" "Spis treści" "Przypis")
204 ;; Use numeric character entities for proper rendering of non-UTF8 documents
205 ;; ("ru" "Автор" "Дата" "Содержание" "Сноски")
206 ("ru" "Автор" "Дата" "Содержание" "Сноски")
207 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter")
208 ;; Use numeric character entities for proper rendering of non-UTF8 documents
209 ;; ("uk" "Автор" "Дата" "Зміст" "Примітки")
210 ("uk" "Автор" "Дата" "Зміст" "Примітки")
211 ;; Use numeric character entities for proper rendering of non-UTF8 documents
212 ;; ("zh-CN" "作者" "日期" "目录" "脚注")
213 ("zh-CN" "作者" "日期" "目录" "脚注")
214 ;; Use numeric character entities for proper rendering of non-UTF8 documents
215 ;; ("zh-TW" "作者" "日期" "目錄" "腳註")
216 ("zh-TW" "作者" "日期" "目錄" "腳註"))
217 "Terms used in export text, translated to different languages.
218 Use the variable `org-export-default-language' to set the language,
219 or use the +OPTION lines for a per-file setting."
220 :group
'org-export-general
223 (string :tag
"HTML language tag")
224 (string :tag
"Author")
226 (string :tag
"Table of Contents")
227 (string :tag
"Footnotes"))))
229 (defcustom org-export-default-language
"en"
230 "The default language for export and clocktable translations, as a string.
231 This should have an association in `org-export-language-setup'
232 and in `org-clock-clocktable-language-setup'."
233 :group
'org-export-general
236 (defcustom org-export-date-timestamp-format
"%Y-%m-%d"
237 "Time string format for Org timestamps in the #+DATE option."
238 :group
'org-export-general
242 (defvar org-export-page-description
""
243 "The page description, for the XHTML meta tag.
244 This is best set with the #+DESCRIPTION line in a file, it does not make
245 sense to set this globally.")
247 (defvar org-export-page-keywords
""
248 "The page description, for the XHTML meta tag.
249 This is best set with the #+KEYWORDS line in a file, it does not make
250 sense to set this globally.")
252 (defcustom org-export-skip-text-before-1st-heading nil
253 "Non-nil means skip all text before the first headline when exporting.
254 When nil, that text is exported as well."
255 :group
'org-export-general
258 (defcustom org-export-headline-levels
3
259 "The last level which is still exported as a headline.
260 Inferior levels will produce itemize lists when exported.
261 Note that a numeric prefix argument to an exporter function overrides
264 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
265 :group
'org-export-general
268 (defcustom org-export-with-section-numbers t
269 "Non-nil means add section numbers to headlines when exporting.
271 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
272 :group
'org-export-general
275 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
276 "Format of section numbers for export.
277 The variable has two components.
278 1. A list of lists, each indicating a counter type and a separator.
279 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"i\".
280 It causes causes numeric, alphabetic, or roman counters, respectively.
281 The separator is only used if another counter for a subsection is being
283 If there are more numbered section levels than entries in this lists,
284 then the last entry will be reused.
285 2. A terminator string that will be added after the entire
287 :group
'org-export-general
291 (string :tag
"Counter Type")
292 (string :tag
"Separator ")))
293 (string :tag
"Terminator")))
295 (defcustom org-export-with-toc t
296 "Non-nil means create a table of contents in exported files.
297 The TOC contains headlines with levels up to`org-export-headline-levels'.
298 When an integer, include levels up to N in the toc, this may then be
299 different from `org-export-headline-levels', but it will not be allowed
300 to be larger than the number of headline levels.
301 When nil, no table of contents is made.
303 Headlines which contain any TODO items will be marked with \"(*)\" in
304 ASCII export, and with red color in HTML output, if the option
305 `org-export-mark-todo-in-toc' is set.
307 In HTML output, the TOC will be clickable.
309 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
311 :group
'org-export-general
313 (const :tag
"No Table of Contents" nil
)
314 (const :tag
"Full Table of Contents" t
)
315 (integer :tag
"TOC to level")))
317 (defcustom org-export-mark-todo-in-toc nil
318 "Non-nil means mark TOC lines that contain any open TODO items."
319 :group
'org-export-general
322 (defcustom org-export-with-todo-keywords t
323 "Non-nil means include TODO keywords in export.
324 When nil, remove all these keywords from the export."
325 :group
'org-export-general
328 (defcustom org-export-with-tasks t
329 "Non-nil means include TODO items for export.
330 This may have the following values:
331 t include tasks independent of state.
332 todo include only tasks that are not yet done.
333 done include only tasks that are already done.
334 nil remove all tasks before export
335 list of TODO kwds keep only tasks with these keywords"
336 :group
'org-export-general
339 (const :tag
"All tasks" t
)
340 (const :tag
"No tasks" nil
)
341 (const :tag
"Not-done tasks" todo
)
342 (const :tag
"Only done tasks" done
)
343 (repeat :tag
"Specific TODO keywords"
344 (string :tag
"Keyword"))))
346 (defcustom org-export-with-priority nil
347 "Non-nil means include priority cookies in export.
348 When nil, remove priority cookies for export."
349 :group
'org-export-general
352 (defcustom org-export-preserve-breaks nil
353 "Non-nil means preserve all line breaks when exporting.
354 Normally, in HTML output paragraphs will be reformatted. In ASCII
355 export, line breaks will always be preserved, regardless of this variable.
357 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
358 :group
'org-export-general
361 (defcustom org-export-with-archived-trees
'headline
362 "Whether subtrees with the ARCHIVE tag should be exported.
363 This can have three different values
364 nil Do not export, pretend this tree is not present
365 t Do export the entire tree
366 headline Only export the headline, but skip the tree below it."
367 :group
'org-export-general
370 (const :tag
"not at all" nil
)
371 (const :tag
"headline only" 'headline
)
372 (const :tag
"entirely" t
)))
374 (defcustom org-export-author-info t
375 "Non-nil means insert author name and email into the exported file.
377 This option can also be set with the +OPTIONS line,
378 e.g. \"author:nil\"."
379 :group
'org-export-general
382 (defcustom org-export-email-info nil
383 "Non-nil means insert author name and email into the exported file.
385 This option can also be set with the +OPTIONS line,
387 :group
'org-export-general
391 (defcustom org-export-creator-info t
392 "Non-nil means the postamble should contain a creator sentence.
393 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
394 :group
'org-export-general
397 (defcustom org-export-time-stamp-file t
398 "Non-nil means insert a time stamp into the exported file.
399 The time stamp shows when the file was created.
401 This option can also be set with the +OPTIONS line,
402 e.g. \"timestamp:nil\"."
403 :group
'org-export-general
406 (defcustom org-export-with-timestamps t
407 "If nil, do not export time stamps and associated keywords."
408 :group
'org-export-general
411 (defcustom org-export-remove-timestamps-from-toc t
412 "If t, remove timestamps from the table of contents entries."
413 :group
'org-export-general
416 (defcustom org-export-with-tags
'not-in-toc
417 "If nil, do not export tags, just remove them from headlines.
418 If this is the symbol `not-in-toc', tags will be removed from table of
419 contents entries, but still be shown in the headlines of the document.
421 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
422 :group
'org-export-general
424 (const :tag
"Off" nil
)
425 (const :tag
"Not in TOC" not-in-toc
)
426 (const :tag
"On" t
)))
428 (defcustom org-export-with-drawers nil
429 "Non-nil means export with drawers like the property drawer.
430 When t, all drawers are exported. This may also be a list of
431 drawer names to export."
432 :group
'org-export-general
434 (const :tag
"All drawers" t
)
435 (const :tag
"None" nil
)
436 (repeat :tag
"Selected drawers"
437 (string :tag
"Drawer name"))))
439 (defvar org-export-first-hook nil
440 "Hook called as the first thing in each exporter.
441 Point will be still in the original buffer.
442 Good for general initialization")
444 (defvar org-export-preprocess-hook nil
445 "Hook for preprocessing an export buffer.
446 Pretty much the first thing when exporting is running this hook.
447 Point will be in a temporary buffer that contains a copy of
448 the original buffer, or of the section that is being exported.
449 All the other hooks in the org-export-preprocess... category
450 also work in that temporary buffer, already modified by various
451 stages of the processing.")
453 (defvar org-export-preprocess-after-include-files-hook nil
454 "Hook for preprocessing an export buffer.
455 This is run after the contents of included files have been inserted.")
457 (defvar org-export-preprocess-after-tree-selection-hook nil
458 "Hook for preprocessing an export buffer.
459 This is run after selection of trees to be exported has happened.
460 This selection includes tags-based selection, as well as removal
461 of commented and archived trees.")
463 (defvar org-export-preprocess-after-headline-targets-hook nil
464 "Hook for preprocessing export buffer.
465 This is run just after the headline targets have been defined and
466 the target-alist has been set up.")
468 (defvar org-export-preprocess-before-selecting-backend-code-hook nil
469 "Hook for preprocessing an export buffer.
470 This is run just before backend-specific blocks get selected.")
472 (defvar org-export-preprocess-after-blockquote-hook nil
473 "Hook for preprocessing an export buffer.
474 This is run after blockquote/quote/verse/center have been marked
477 (defvar org-export-preprocess-after-radio-targets-hook nil
478 "Hook for preprocessing an export buffer.
479 This is run after radio target processing.")
481 (defvar org-export-preprocess-before-normalizing-links-hook nil
482 "Hook for preprocessing an export buffer.
483 This hook is run before links are normalized.")
485 (defvar org-export-preprocess-before-backend-specifics-hook nil
486 "Hook run before backend-specific functions are called during preprocessing.")
488 (defvar org-export-preprocess-final-hook nil
489 "Hook for preprocessing an export buffer.
490 This is run as the last thing in the preprocessing buffer, just before
491 returning the buffer string to the backend.")
493 (defgroup org-export-translation nil
494 "Options for translating special ascii sequences for the export backends."
495 :tag
"Org Export Translation"
498 (defcustom org-export-with-emphasize t
499 "Non-nil means interpret *word*, /word/, and _word_ as emphasized text.
500 If the export target supports emphasizing text, the word will be
501 typeset in bold, italic, or underlined, respectively. Works only for
502 single words, but you can say: I *really* *mean* *this*.
503 Not all export backends support this.
505 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
506 :group
'org-export-translation
509 (defcustom org-export-with-footnotes t
510 "If nil, export [1] as a footnote marker.
511 Lines starting with [1] will be formatted as footnotes.
513 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
514 :group
'org-export-translation
517 (defcustom org-export-with-TeX-macros t
518 "Non-nil means interpret simple TeX-like macros when exporting.
519 For example, HTML export converts \\alpha to α and \\AA to Å.
520 Not only real TeX macros will work here, but the standard HTML entities
521 for math can be used as macro names as well. For a list of supported
522 names in HTML export, see the constant `org-entities' and the user option
524 Not all export backends support this.
526 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
527 :group
'org-export-translation
528 :group
'org-export-latex
531 (defcustom org-export-with-LaTeX-fragments t
532 "Non-nil means process LaTeX math fragments for HTML display.
533 When set, the exporter will find and process LaTeX environments if the
534 \\begin line is the first non-white thing on a line. It will also find
535 and process the math delimiters like $a=b$ and \\( a=b \\) for inline math,
536 $$a=b$$ and \\=\\[ a=b \\] for display math.
538 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:mathjax\".
542 nil Don't do anything.
543 verbatim Keep everything in verbatim
544 dvipng Process the LaTeX fragments to images.
545 This will also include processing of non-math environments.
546 imagemagick Convert the LaTeX fragments to pdf files and use imagemagick
547 to convert pdf files to png files.
548 t Do MathJax preprocessing if there is at least on math snippet,
549 and arrange for MathJax.js to be loaded.
551 The default is nil, because this option needs the `dvipng' program which
552 is not available on all systems."
553 :group
'org-export-translation
554 :group
'org-export-latex
556 (const :tag
"Do not process math in any way" nil
)
557 (const :tag
"Obsolete, use dvipng setting" t
)
558 (const :tag
"Use dvipng to make images" dvipng
)
559 (const :tag
"Use imagemagick to make images" imagemagick
)
560 (const :tag
"Use MathJax to display math" mathjax
)
561 (const :tag
"Leave math verbatim" verbatim
)))
563 (defcustom org-export-with-fixed-width t
564 "Non-nil means lines starting with \":\" will be in fixed width font.
565 This can be used to have pre-formatted text, fragments of code etc. For
567 : ;; Some Lisp examples
570 will be looking just like this in also HTML. See also the QUOTE keyword.
571 Not all export backends support this.
573 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
574 :group
'org-export-translation
577 (defgroup org-export-tables nil
578 "Options for exporting tables in Org-mode."
579 :tag
"Org Export Tables"
582 (defcustom org-export-with-tables t
583 "If non-nil, lines starting with \"|\" define a table.
586 | Name | Address | Birthday |
587 |-------------+----------+-----------|
588 | Arthur Dent | England | 29.2.2100 |
590 Not all export backends support this.
592 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
593 :group
'org-export-tables
596 (defcustom org-export-highlight-first-table-line t
597 "Non-nil means highlight the first table line.
598 In HTML export, this means use <th> instead of <td>.
599 In tables created with table.el, this applies to the first table line.
600 In Org-mode tables, all lines before the first horizontal separator
601 line will be formatted with <th> tags."
602 :group
'org-export-tables
605 (defcustom org-export-table-remove-special-lines t
606 "Remove special lines and marking characters in calculating tables.
607 This removes the special marking character column from tables that are set
608 up for spreadsheet calculations. It also removes the entire lines
609 marked with `!', `_', or `^'. The lines with `$' are kept, because
610 the values of constants may be useful to have."
611 :group
'org-export-tables
614 (defcustom org-export-table-remove-empty-lines t
615 "Remove empty lines when exporting tables.
616 This is the global equivalent of the :remove-nil-lines option
617 when locally sending a table with #+ORGTBL."
618 :group
'org-export-tables
622 (defcustom org-export-prefer-native-exporter-for-tables nil
623 "Non-nil means always export tables created with table.el natively.
624 Natively means use the HTML code generator in table.el.
625 When nil, Org-mode's own HTML generator is used when possible (i.e. if
626 the table does not use row- or column-spanning). This has the
627 advantage, that the automatic HTML conversions for math symbols and
628 sub/superscripts can be applied. Org-mode's HTML generator is also
629 much faster. The LaTeX exporter always use the native exporter for
631 :group
'org-export-tables
636 ;;; Variables, constants, and parameter plists
638 (defconst org-level-max
20)
640 (defvar org-export-current-backend nil
641 "During export, this will be bound to a symbol such as 'html,
642 'latex, 'docbook, 'ascii, etc, indicating which of the export
643 backends is in use. Otherwise it has the value nil. Users
644 should not attempt to change the value of this variable
645 directly, but it can be used in code to test whether export is
646 in progress, and if so, what the backend is.")
648 (defvar org-current-export-file nil
) ; dynamically scoped parameter
649 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
650 (defvar org-export-opt-plist nil
651 "Contains the current option plist.")
652 (defvar org-last-level nil
) ; dynamically scoped variable
653 (defvar org-min-level nil
) ; dynamically scoped variable
654 (defvar org-levels-open nil
) ; dynamically scoped parameter
655 (defvar org-export-footnotes-data nil
656 "Alist of labels used in buffers, along with their definition.")
657 (defvar org-export-footnotes-seen nil
658 "Alist of labels encountered so far by the exporter, along with their definition.")
661 (defconst org-export-plist-vars
662 '((:link-up nil org-export-html-link-up
)
663 (:link-home nil org-export-html-link-home
)
664 (:language nil org-export-default-language
)
665 (:keywords nil org-export-page-keywords
)
666 (:description nil org-export-page-description
)
667 (:customtime nil org-display-custom-times
)
668 (:headline-levels
"H" org-export-headline-levels
)
669 (:section-numbers
"num" org-export-with-section-numbers
)
670 (:section-number-format nil org-export-section-number-format
)
671 (:table-of-contents
"toc" org-export-with-toc
)
672 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
673 (:archived-trees nil org-export-with-archived-trees
)
674 (:emphasize
"*" org-export-with-emphasize
)
675 (:sub-superscript
"^" org-export-with-sub-superscripts
)
676 (:special-strings
"-" org-export-with-special-strings
)
677 (:footnotes
"f" org-export-with-footnotes
)
678 (:drawers
"d" org-export-with-drawers
)
679 (:tags
"tags" org-export-with-tags
)
680 (:todo-keywords
"todo" org-export-with-todo-keywords
)
681 (:tasks
"tasks" org-export-with-tasks
)
682 (:priority
"pri" org-export-with-priority
)
683 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
684 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
685 (:latex-listings nil org-export-latex-listings
)
686 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
687 (:fixed-width
":" org-export-with-fixed-width
)
688 (:timestamps
"<" org-export-with-timestamps
)
689 (:author nil user-full-name
)
690 (:email nil user-mail-address
)
691 (:author-info
"author" org-export-author-info
)
692 (:email-info
"email" org-export-email-info
)
693 (:creator-info
"creator" org-export-creator-info
)
694 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
695 (:tables
"|" org-export-with-tables
)
696 (:table-auto-headline nil org-export-highlight-first-table-line
)
697 (:style-include-default nil org-export-html-style-include-default
)
698 (:style-include-scripts nil org-export-html-style-include-scripts
)
699 (:style nil org-export-html-style
)
700 (:style-extra nil org-export-html-style-extra
)
701 (:agenda-style nil org-agenda-export-html-style
)
702 (:convert-org-links nil org-export-html-link-org-files-as-html
)
703 (:inline-images nil org-export-html-inline-images
)
704 (:html-extension nil org-export-html-extension
)
705 (:html-preamble nil org-export-html-preamble
)
706 (:html-postamble nil org-export-html-postamble
)
707 (:xml-declaration nil org-export-html-xml-declaration
)
708 (:html-table-tag nil org-export-html-table-tag
)
709 (:expand-quoted-html
"@" org-export-html-expand
)
710 (:timestamp nil org-export-html-with-timestamp
)
711 (:publishing-directory nil org-export-publishing-directory
)
712 (:select-tags nil org-export-select-tags
)
713 (:exclude-tags nil org-export-exclude-tags
)
715 (:latex-image-options nil org-export-latex-image-default-option
))
716 "List of properties that represent export/publishing variables.
717 Each element is a list of 3 items:
718 1. The property that is used internally, and also for org-publish-project-alist
719 2. The string that can be used in the OPTION lines to set this option,
720 or nil if this option cannot be changed in this way
721 3. The customization variable that sets the default for this option."
724 (defun org-default-export-plist ()
725 "Return the property list with default settings for the export variables."
726 (let* ((infile (org-infile-export-plist))
727 (letbind (plist-get infile
:let-bind
))
728 (l org-export-plist-vars
) rtn e s v
)
729 (while (setq e
(pop l
))
732 ((assq s letbind
) (nth 1 (assq s letbind
)))
733 ((boundp s
) (symbol-value s
)))
734 rtn
(cons (car e
) (cons v rtn
))))
737 (defvar org-export-inbuffer-options-extra nil
738 "List of additional in-buffer options that should be detected.
739 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
740 etc. Extensions can add to this list to get their options detected, and they
741 can then add a function to `org-export-options-filters' to process these
743 Each element in this list must be a list, with the in-buffer keyword as car,
744 and a property (a symbol) as the next element. All occurrences of the
745 keyword will be found, the values concatenated with a space character
746 in between, and the result stored in the export options property list.")
748 (defvar org-export-options-filters nil
749 "Functions to be called to finalize the export/publishing options.
750 All these options are stored in a property list, and each of the functions
751 in this hook gets a chance to modify this property list. Each function
752 must accept the property list as an argument, and must return the (possibly
755 ;; FIXME: should we fold case here?
757 (defun org-infile-export-plist ()
758 "Return the property list with file-local settings for export."
762 (goto-char (point-min))
763 (let ((re (org-make-options-regexp
765 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
767 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE"
768 "LATEX_HEADER" "LATEX_CLASS" "LATEX_CLASS_OPTIONS"
769 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
770 "KEYWORDS" "DESCRIPTION" "MACRO" "BIND" "XSLT")
771 (mapcar 'car org-export-inbuffer-options-extra
))))
773 p key val text options mathjax a pr style
774 latex-header latex-class latex-class-options macros letbind
775 ext-setup-or-nil setup-file setup-dir setup-contents
(start 0))
776 (while (or (and ext-setup-or-nil
777 (string-match re ext-setup-or-nil start
)
778 (setq start
(match-end 0)))
779 (and (setq ext-setup-or-nil nil start
0)
780 (re-search-forward re nil t
)))
781 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
782 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
784 ((setq a
(assoc key org-export-inbuffer-options-extra
))
786 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
787 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
788 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
789 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
790 ((string-equal key
"DATE")
791 ;; If date is an Org timestamp, convert it to a time
792 ;; string using `org-export-date-timestamp-format'
793 (when (string-match org-ts-regexp3 val
)
794 (setq val
(format-time-string
795 org-export-date-timestamp-format
796 (apply 'encode-time
(org-parse-time-string
797 (match-string 0 val
))))))
798 (setq p
(plist-put p
:date val
)))
799 ((string-equal key
"KEYWORDS") (setq p
(plist-put p
:keywords val
)))
800 ((string-equal key
"DESCRIPTION")
801 (setq p
(plist-put p
:description val
)))
802 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
803 ((string-equal key
"STYLE")
804 (setq style
(concat style
"\n" val
)))
805 ((string-equal key
"LATEX_HEADER")
806 (setq latex-header
(concat latex-header
"\n" val
)))
807 ((string-equal key
"LATEX_CLASS")
808 (setq latex-class val
))
809 ((string-equal key
"LATEX_CLASS_OPTIONS")
810 (setq latex-class-options val
))
811 ((string-equal key
"TEXT")
812 (setq text
(if text
(concat text
"\n" val
) val
)))
813 ((string-equal key
"OPTIONS")
814 (setq options
(concat val
" " options
)))
815 ((string-equal key
"MATHJAX")
816 (setq mathjax
(concat val
" " mathjax
)))
817 ((string-equal key
"BIND")
818 (push (read (concat "(" val
")")) letbind
))
819 ((string-equal key
"XSLT")
820 (setq p
(plist-put p
:xslt val
)))
821 ((string-equal key
"LINK_UP")
822 (setq p
(plist-put p
:link-up val
)))
823 ((string-equal key
"LINK_HOME")
824 (setq p
(plist-put p
:link-home val
)))
825 ((string-equal key
"EXPORT_SELECT_TAGS")
826 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
827 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
828 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
829 ((string-equal key
"MACRO")
831 ((equal key
"SETUPFILE")
832 (setq setup-file
(org-remove-double-quotes (org-trim val
))
833 ;; take care of recursive inclusion of setupfiles
834 setup-file
(if (or (file-name-absolute-p val
) (not setup-dir
))
835 (expand-file-name setup-file
)
836 (let ((default-directory setup-dir
))
837 (expand-file-name setup-file
))))
838 (setq setup-dir
(file-name-directory setup-file
))
839 (setq setup-contents
(org-file-contents setup-file
'noerror
))
840 (if (not ext-setup-or-nil
)
841 (setq ext-setup-or-nil setup-contents start
0)
842 (setq ext-setup-or-nil
843 (concat (substring ext-setup-or-nil
0 start
)
844 "\n" setup-contents
"\n"
845 (substring ext-setup-or-nil start
)))))))
846 (setq p
(plist-put p
:text text
))
847 (when (and letbind
(org-export-confirm-letbind))
848 (setq p
(plist-put p
:let-bind letbind
)))
849 (when style
(setq p
(plist-put p
:style-extra style
)))
851 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
853 (setq p
(plist-put p
:latex-class latex-class
)))
854 (when latex-class-options
855 (setq p
(plist-put p
:latex-class-options latex-class-options
)))
857 (setq p
(org-export-add-options-to-plist p options
)))
859 (setq p
(plist-put p
:mathjax mathjax
)))
860 ;; Add macro definitions
861 (setq p
(plist-put p
:macro-date
"(eval (format-time-string \"$1\"))"))
862 (setq p
(plist-put p
:macro-time
"(eval (format-time-string \"$1\"))"))
863 (setq p
(plist-put p
:macro-property
"(eval (org-entry-get nil \"$1\" 'selective))"))
865 p
:macro-modification-time
866 (and (buffer-file-name)
867 (file-exists-p (buffer-file-name))
869 "(eval (format-time-string \"$1\" '"
870 (prin1-to-string (nth 5 (file-attributes
871 (buffer-file-name))))
873 (setq p
(plist-put p
:macro-input-file
(and (buffer-file-name)
874 (file-name-nondirectory
875 (buffer-file-name)))))
876 (while (setq val
(pop macros
))
877 (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val
)
880 (concat ":macro-" (downcase (match-string 1 val
))))
881 (org-export-interpolate-newlines (match-string 2 val
))))))
884 (defun org-export-interpolate-newlines (s)
885 (while (string-match "\\\\n" s
)
886 (setq s
(replace-match "\n" t t s
)))
889 (defvar org-export-allow-BIND-local nil
)
890 (defun org-export-confirm-letbind ()
891 "Can we use #+BIND values during export?
892 By default this will ask for confirmation by the user, to divert possible
895 ((not org-export-allow-BIND
) nil
)
896 ((eq org-export-allow-BIND t
) t
)
897 ((local-variable-p 'org-export-allow-BIND-local
(current-buffer))
898 org-export-allow-BIND-local
)
899 (t (org-set-local 'org-export-allow-BIND-local
900 (yes-or-no-p "Allow BIND values in this buffer? ")))))
902 (defun org-install-letbind ()
903 "Install the values from #+BIND lines as local variables."
904 (let ((letbind (plist-get org-export-opt-plist
:let-bind
))
906 (while (setq pair
(pop letbind
))
907 (org-set-local (car pair
) (nth 1 pair
)))))
909 (defun org-export-add-options-to-plist (p options
)
910 "Parse an OPTIONS line and set values in the property list P."
913 (let ((op org-export-plist-vars
))
914 (while (setq o
(pop op
))
916 (string-match (concat "\\(\\`\\|[ \t]\\)"
917 (regexp-quote (nth 1 o
))
918 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
920 (setq p
(plist-put p
(car o
)
921 (car (read-from-string
922 (match-string 2 options
))))))))))
925 (defun org-export-add-subtree-options (p pos
)
926 "Add options in subtree at position POS to property list P."
929 (when (org-at-heading-p)
931 ;; This is actually read in `org-export-get-title-from-subtree'
932 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
933 ;; (setq p (plist-put p :title a)))
934 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
935 (setq p
(plist-put p
:text a
)))
936 (when (setq a
(org-entry-get pos
"EXPORT_AUTHOR"))
937 (setq p
(plist-put p
:author a
)))
938 (when (setq a
(org-entry-get pos
"EXPORT_DATE"))
939 (setq p
(plist-put p
:date a
)))
940 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
941 (setq p
(org-export-add-options-to-plist p a
)))))
944 (defun org-export-directory (type plist
)
945 (let* ((val (plist-get plist
:publishing-directory
))
947 (or (cdr (assoc type val
)) ".")
951 (defun org-export-process-option-filters (plist)
952 (let ((functions org-export-options-filters
) f
)
953 (while (setq f
(pop functions
))
954 (setq plist
(funcall f plist
))))
958 (defun org-export (&optional arg
)
959 "Export dispatcher for Org-mode.
960 When `org-export-run-in-background' is non-nil, try to run the command
961 in the background. This will be done only for commands that write
962 to a file. For details see the docstring of `org-export-run-in-background'.
964 The prefix argument ARG will be passed to the exporter. However, if
965 ARG is a double universal prefix \\[universal-argument] \\[universal-argument], \
966 that means to inverse the
967 value of `org-export-run-in-background'.
969 If `org-export-initial-scope' is set to 'subtree, try to export
970 the current subtree, otherwise try to export the whole buffer.
971 Pressing `1' will switch between these two options."
973 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
974 (subtree-p (or (org-region-active-p)
975 (eq org-export-initial-scope
'subtree
)))
976 (regb (and (org-region-active-p) (region-beginning)))
977 (rege (and (org-region-active-p) (region-end)))
978 (help "[t] insert the export option template
979 \[v] limit export to visible part of outline tree
980 \[1] switch buffer/subtree export
981 \[SPC] publish enclosing subtree (with LaTeX_CLASS or EXPORT_FILE_NAME prop)
983 \[a/n/u] export as ASCII/Latin-1/UTF-8 [A/N/U] to temporary buffer
985 \[h] export as HTML [H] to temporary buffer [R] export region
986 \[b] export as HTML and open in browser
988 \[l] export as LaTeX [L] to temporary buffer
989 \[p] export as LaTeX and process to PDF [d] ... and open PDF file
991 \[D] export as DocBook [V] export as DocBook, process to PDF, and open
993 \[o] export as OpenDocument Text [O] ... and open
995 \[j] export as TaskJuggler [J] ... and open
997 \[m] export as Freemind mind map
999 \[g] export using Wes Hardaker's generic exporter
1001 \[i] export current file as iCalendar file
1002 \[I] export all agenda files as iCalendar files [c] ...as one combined file
1004 \[F] publish current file [P] publish current project
1005 \[X] publish a project... [E] publish every projects")
1007 '((?t org-insert-export-options-template nil
)
1008 (?v org-export-visible nil
)
1009 (?a org-export-as-ascii t
)
1010 (?A org-export-as-ascii-to-buffer t
)
1011 (?n org-export-as-latin1 t
)
1012 (?N org-export-as-latin1-to-buffer t
)
1013 (?u org-export-as-utf8 t
)
1014 (?U org-export-as-utf8-to-buffer t
)
1015 (?h org-export-as-html t
)
1016 (?b org-export-as-html-and-open t
)
1017 (?H org-export-as-html-to-buffer nil
)
1018 (?R org-export-region-as-html nil
)
1019 (?x org-export-as-xoxo t
)
1020 (?g org-export-generic t
)
1021 (?D org-export-as-docbook t
)
1022 (?V org-export-as-docbook-pdf-and-open t
)
1023 (?o org-export-as-odt t
)
1024 (?O org-export-as-odt-and-open t
)
1025 (?j org-export-as-taskjuggler t
)
1026 (?J org-export-as-taskjuggler-and-open t
)
1027 (?m org-export-as-freemind t
)
1028 (?l org-export-as-latex t
)
1029 (?p org-export-as-pdf t
)
1030 (?d org-export-as-pdf-and-open t
)
1031 (?L org-export-as-latex-to-buffer nil
)
1032 (?i org-export-icalendar-this-file t
)
1033 (?I org-export-icalendar-all-agenda-files t
)
1034 (?c org-export-icalendar-combine-agenda-files t
)
1035 (?F org-publish-current-file t
)
1036 (?P org-publish-current-project t
)
1038 (?E org-publish-all t
)))
1040 (cpos (point)) (cbuf (current-buffer)) bpos
)
1042 (save-window-excursion
1044 (message "Export subtree: ")
1045 (message "Export buffer: "))
1046 (delete-other-windows)
1047 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1049 (org-fit-window-to-buffer (get-buffer-window
1050 "*Org Export/Publishing Help*"))
1051 (while (eq (setq r1
(read-char-exclusive)) ?
1)
1053 (setq subtree-p nil
)
1054 (message "Export buffer: "))
1060 (setq regb
(and (org-region-active-p) (region-beginning)))
1061 (setq rege
(and (org-region-active-p) (region-end)))
1062 (message "Export subtree: "))))
1064 (let ((case-fold-search t
)
1065 (end (save-excursion (while (org-up-heading-safe)) (point))))
1066 (outline-next-heading)
1067 (if (re-search-backward
1068 "^[ \t]+\\(:latex_class:\\|:export_title:\\|:export_file_name:\\)[ \t]+\\S-"
1071 (org-back-to-heading t
)
1074 (message "Select command (for subtree): ")
1075 (setq r1
(read-char-exclusive)))
1076 (error "No enclosing node with LaTeX_CLASS or EXPORT_TITLE or EXPORT_FILE_NAME")
1078 (if (fboundp 'redisplay
) (redisplay)) ;; XEmacs does not have/need (redisplay)
1079 (and bpos
(goto-char bpos
))
1080 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1081 (unless (setq ass
(assq r2 cmds
))
1082 (error "No command associated with key %c" r1
))
1083 (if (and bg
(nth 2 ass
)
1084 (not (buffer-base-buffer))
1085 (not (org-region-active-p)))
1086 ;; execute in background
1087 (let ((p (start-process
1088 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1090 (expand-file-name invocation-name invocation-directory
)
1093 "--eval" "(require 'org-exp)"
1094 "--eval" "(setq org-wait .2)"
1096 "-f" (symbol-name (nth 1 ass
)))))
1097 (set-process-sentinel p
'org-export-process-sentinel
)
1098 (message "Background process \"%s\": started" p
))
1099 ;; set the mark correctly when exporting a subtree
1100 (if subtree-p
(let (deactivate-mark) (push-mark rege t t
) (goto-char regb
)))
1102 (call-interactively (nth 1 ass
))
1103 (when (and bpos
(get-buffer-window cbuf
))
1104 (let ((cw (selected-window)))
1105 (select-window (get-buffer-window cbuf
))
1108 (select-window cw
))))))
1110 (defun org-export-process-sentinel (process status
)
1111 (if (string-match "\n+\\'" status
)
1112 (setq status
(substring status
0 -
1)))
1113 (message "Background process \"%s\": %s" process status
))
1115 ;;; General functions for all backends
1117 (defvar org-export-target-aliases nil
1118 "Alist of targets with invisible aliases.")
1119 (defvar org-export-preferred-target-alist nil
1120 "Alist of section id's with preferred aliases.")
1121 (defvar org-export-id-target-alist nil
1122 "Alist of section id's with preferred aliases.")
1123 (defvar org-export-code-refs nil
1124 "Alist of code references and line numbers.")
1126 (defun org-export-preprocess-string (string &rest parameters
)
1127 "Cleanup STRING so that the true exported has a more consistent source.
1128 This function takes STRING, which should be a buffer-string of an org-file
1129 to export. It then creates a temporary buffer where it does its job.
1130 The result is then again returned as a string, and the exporter works
1131 on this string to produce the exported version."
1133 (let* ((org-export-current-backend (or (plist-get parameters
:for-backend
)
1134 org-export-current-backend
))
1135 (archived-trees (plist-get parameters
:archived-trees
))
1136 (inhibit-read-only t
)
1137 (drawers org-drawers
)
1138 (source-buffer (current-buffer))
1141 (setq org-export-target-aliases nil
1142 org-export-preferred-target-alist nil
1143 org-export-id-target-alist nil
1144 org-export-code-refs nil
)
1149 (setq case-fold-search t
)
1151 (let ((inhibit-read-only t
))
1152 (remove-text-properties (point-min) (point-max)
1155 ;; Remove license-to-kill stuff
1156 ;; The caller marks some stuff for killing, stuff that has been
1157 ;; used to create the page title, for example.
1158 (org-export-kill-licensed-text)
1160 (let ((org-inhibit-startup t
)) (org-mode))
1161 (setq case-fold-search t
)
1162 (org-clone-local-variables source-buffer
"^\\(org-\\|orgtbl-\\)")
1163 (org-install-letbind)
1166 (run-hooks 'org-export-preprocess-hook
)
1168 (untabify (point-min) (point-max))
1170 ;; Handle include files, and call a hook
1171 (org-export-handle-include-files-recurse)
1172 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1174 ;; Get rid of archived trees
1175 (org-export-remove-archived-trees archived-trees
)
1177 ;; Remove comment environment and comment subtrees
1178 (org-export-remove-comment-blocks-and-subtrees)
1180 ;; Get rid of excluded trees, and call a hook
1181 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1182 (plist-get parameters
:exclude-tags
))
1183 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1185 ;; Get rid of tasks, depending on configuration
1186 (org-export-remove-tasks (plist-get parameters
:tasks
))
1188 ;; Prepare footnotes for export. During that process, footnotes
1189 ;; actually included in the exported part of the buffer go
1190 ;; though some transformations:
1192 ;; 1. They have their label normalized (like "[N]");
1194 ;; 2. They get moved at the same place in the buffer (usually at
1195 ;; its end, but backends may define another place via
1196 ;; `org-footnote-insert-pos-for-preprocessor');
1198 ;; 3. The are stored in `org-export-footnotes-seen', while
1199 ;; `org-export-preprocess-string' is applied to their
1202 ;; Line-wise exporters ignore `org-export-footnotes-seen', as
1203 ;; they interpret footnotes at the moment they see them in the
1204 ;; buffer. Context-wise exporters grab all the info needed in
1205 ;; that variable and delete moved definitions (as described in
1207 (when (plist-get parameters
:footnotes
)
1208 (org-footnote-normalize nil parameters
))
1210 ;; Change lists ending. Other parts of export may insert blank
1211 ;; lines and lists' structure could be altered.
1212 (org-export-mark-list-end)
1214 ;; Process the macros
1215 (org-export-preprocess-apply-macros)
1216 (run-hooks 'org-export-preprocess-after-macros-hook
)
1218 ;; Export code blocks
1219 (org-export-blocks-preprocess)
1221 ;; Mark lists with properties
1222 (org-export-mark-list-properties)
1224 ;; Handle source code snippets
1225 (org-export-replace-src-segments-and-examples)
1227 ;; Protect short examples marked by a leading colon
1228 (org-export-protect-colon-examples)
1231 (org-export-convert-protected-spaces)
1233 ;; Find all headings and compute the targets for them
1234 (setq target-alist
(org-export-define-heading-targets target-alist
))
1236 (run-hooks 'org-export-preprocess-after-headline-targets-hook
)
1238 ;; Find HTML special classes for headlines
1239 (org-export-remember-html-container-classes)
1241 ;; Get rid of drawers
1242 (org-export-remove-or-extract-drawers
1243 drawers
(plist-get parameters
:drawers
))
1245 ;; Get the correct stuff before the first headline
1246 (when (plist-get parameters
:skip-before-1st-heading
)
1247 (goto-char (point-min))
1248 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1249 (delete-region (point-min) (match-beginning 0))
1250 (goto-char (point-min))
1252 (when (plist-get parameters
:add-text
)
1253 (goto-char (point-min))
1254 (insert (plist-get parameters
:add-text
) "\n"))
1256 ;; Remove todo-keywords before exporting, if the user has requested so
1257 (org-export-remove-headline-metadata parameters
)
1259 ;; Find targets in comments and move them out of comments,
1260 ;; but mark them as targets that should be invisible
1261 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1263 ;; Select and protect backend specific stuff, throw away stuff
1264 ;; that is specific for other backends
1265 (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook
)
1266 (org-export-select-backend-specific-text)
1268 ;; Protect quoted subtrees
1269 (org-export-protect-quoted-subtrees)
1271 ;; Remove clock lines
1272 (org-export-remove-clock-lines)
1274 ;; Protect verbatim elements
1275 (org-export-protect-verbatim)
1277 ;; Blockquotes, verse, and center
1278 (org-export-mark-blockquote-verse-center)
1279 (run-hooks 'org-export-preprocess-after-blockquote-hook
)
1281 ;; Remove timestamps, if the user has requested so
1282 (unless (plist-get parameters
:timestamps
)
1283 (org-export-remove-timestamps))
1285 ;; Attach captions to the correct object
1286 (setq target-alist
(org-export-attach-captions-and-attributes target-alist
))
1288 ;; Find matches for radio targets and turn them into internal links
1289 (org-export-mark-radio-links)
1290 (run-hooks 'org-export-preprocess-after-radio-targets-hook
)
1292 ;; Find all links that contain a newline and put them into a single line
1293 (org-export-concatenate-multiline-links)
1295 ;; Normalize links: Convert angle and plain links into bracket links
1296 ;; and expand link abbreviations
1297 (run-hooks 'org-export-preprocess-before-normalizing-links-hook
)
1298 (org-export-normalize-links)
1300 ;; Find all internal links. If they have a fuzzy match (i.e. not
1301 ;; a *dedicated* target match, let the link point to the
1302 ;; corresponding section.
1303 (org-export-target-internal-links target-alist
)
1305 ;; Find multiline emphasis and put them into single line
1306 (when (plist-get parameters
:emph-multiline
)
1307 (org-export-concatenate-multiline-emphasis))
1309 ;; Remove special table lines, and store alignment information
1310 (org-store-forced-table-alignment)
1311 (when org-export-table-remove-special-lines
1312 (org-export-remove-special-table-lines))
1315 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1317 ;; Backend-specific preprocessing
1318 (let* ((backend-name (symbol-name org-export-current-backend
))
1319 (f (intern (format "org-export-%s-preprocess" backend-name
))))
1320 (require (intern (concat "org-" backend-name
)) nil
)
1321 (funcall f parameters
))
1323 ;; Remove or replace comments
1324 (org-export-handle-comments (plist-get parameters
:comments
))
1326 ;; Remove #+TBLFM #+TBLNAME #+NAME #+RESULTS lines
1327 (org-export-handle-metalines)
1329 ;; Run the final hook
1330 (run-hooks 'org-export-preprocess-final-hook
)
1332 (setq rtn
(buffer-string)))
1335 (defun org-export-kill-licensed-text ()
1336 "Remove all text that is marked with a :org-license-to-kill property."
1338 (while (setq p
(text-property-any (point-min) (point-max)
1339 :org-license-to-kill t
))
1341 p
(or (next-single-property-change p
:org-license-to-kill
)
1344 (defvar org-export-define-heading-targets-headline-hook nil
1345 "Hook that is run when a headline was matched during target search.
1346 This is part of the preprocessing for export.")
1348 (defun org-export-define-heading-targets (target-alist)
1349 "Find all headings and define the targets for them.
1350 The new targets are added to TARGET-ALIST, which is also returned.
1351 Also find all ID and CUSTOM_ID properties and store them."
1352 (goto-char (point-min))
1353 (org-init-section-numbers)
1354 (let ((re (concat "^" org-outline-regexp
1356 "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
1357 level target last-section-target a id
)
1358 (while (re-search-forward re nil t
)
1359 (org-if-unprotected-at (match-beginning 0)
1362 (setq id
(org-match-string-no-properties 2))
1363 (push (cons id target
) target-alist
)
1364 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1366 (push (list last-section-target
)
1367 org-export-target-aliases
)
1368 (car org-export-target-aliases
))))
1369 (push (caar target-alist
) (cdr a
))
1370 (when (equal (match-string 1) "CUSTOM_ID")
1371 (if (not (assoc last-section-target
1372 org-export-preferred-target-alist
))
1373 (push (cons last-section-target id
)
1374 org-export-preferred-target-alist
)))
1375 (when (equal (match-string 1) "ID")
1376 (if (not (assoc last-section-target
1377 org-export-id-target-alist
))
1378 (push (cons last-section-target
(concat "ID-" id
))
1379 org-export-id-target-alist
))))
1380 (setq level
(org-reduced-level
1381 (save-excursion (goto-char (point-at-bol))
1382 (org-outline-level))))
1383 (setq target
(org-solidify-link-text
1384 (format "sec-%s" (replace-regexp-in-string
1386 (org-section-number level
)))))
1387 (setq last-section-target target
)
1388 (push (cons target target
) target-alist
)
1389 (add-text-properties
1390 (point-at-bol) (point-at-eol)
1391 (list 'target target
))
1392 (run-hooks 'org-export-define-heading-targets-headline-hook
)))))
1395 (defun org-export-handle-invisible-targets (target-alist)
1396 "Find targets in comments and move them out of comments.
1397 Mark them as invisible targets."
1399 (goto-char (point-min))
1400 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1401 ;; Check if the line before or after is a headline with a target
1402 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1403 (get-text-property (point-at-bol 2) 'target
)))
1405 ;; use the existing target in a neighboring line
1406 (setq tmp
(match-string 2))
1408 (and (looking-at "\n") (delete-char 1))
1409 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1411 (setq a
(or (assoc target org-export-target-aliases
)
1413 (push (list target
) org-export-target-aliases
)
1414 (car org-export-target-aliases
))))
1416 ;; Make an invisible target
1417 (replace-match "\\1(INVISIBLE)"))))
1420 (defun org-export-target-internal-links (target-alist)
1421 "Find all internal links and assign targets to them.
1422 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1423 let the link point to the corresponding section.
1424 This function also handles the id links, if they have a match in
1426 (goto-char (point-min))
1427 (while (re-search-forward org-bracket-link-regexp nil t
)
1428 (org-if-unprotected-at (1+ (match-beginning 0))
1429 (let* ((org-link-search-must-match-exact-headline t
)
1431 (desc (match-end 2))
1432 (link (org-link-unescape (match-string 1)))
1433 (slink (org-solidify-link-text link
))
1434 found props pos cref
1437 ((= (string-to-char link
) ?
#)
1438 ;; user wants exactly this link
1440 ((cdr (assoc slink target-alist
))
1441 (or (cdr (assoc (assoc slink target-alist
)
1442 org-export-preferred-target-alist
))
1443 (cdr (assoc slink target-alist
))))
1444 ((and (string-match "^id:" link
)
1445 (cdr (assoc (substring link
3) target-alist
))))
1446 ((string-match "^(\\(.*\\))$" link
)
1447 (setq cref
(match-string 1 link
))
1448 (concat "coderef:" cref
))
1449 ((string-match org-link-types-re link
) nil
)
1450 ((or (file-name-absolute-p link
)
1451 (string-match "^\\." link
))
1454 (let ((org-link-search-inhibit-query t
))
1456 (setq found
(condition-case nil
(org-link-search link
)
1459 (or (org-at-heading-p)
1460 (not (eq found
'dedicated
))))
1461 (or (get-text-property (point) 'target
)
1464 (1- (or (previous-single-property-change
1465 (point) 'target
) 0)))
1469 (goto-char (match-beginning 1))
1470 (setq props
(text-properties-at (point)))
1471 (delete-region (match-beginning 1) (match-end 1))
1474 (unless desc
(insert "][" link
))
1475 (add-text-properties pos
(point) props
))))))
1477 (defun org-export-remember-html-container-classes ()
1478 "Store the HTML_CONTAINER_CLASS properties in a text property."
1479 (goto-char (point-min))
1481 (while (re-search-forward
1482 "^[ \t]*:HTML_CONTAINER_CLASS:[ \t]+\\(.+\\)$" nil t
)
1483 (setq class
(match-string 1))
1485 (when (re-search-backward "^\\*" (point-min) t
)
1486 (org-back-to-heading t
)
1487 (put-text-property (point-at-bol) (point-at-eol)
1488 'html-container-class class
))))))
1490 (defvar org-export-format-drawer-function nil
1491 "Function to be called to format the contents of a drawer.
1492 The function must accept two parameters:
1493 NAME the drawer name, like \"PROPERTIES\"
1494 CONTENT the content of the drawer.
1495 You can check the export backend through `org-export-current-backend'.
1496 The function should return the text to be inserted into the buffer.
1497 If this is nil, `org-export-format-drawer' is used as a default.")
1499 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1500 "Remove drawers, or extract and format the content.
1501 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1502 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1503 whose content to keep. Any drawers that are in ALL-DRAWERS but not in
1504 EXP-DRAWERS will be removed."
1505 (goto-char (point-min))
1506 (let ((re (concat "^[ \t]*:\\("
1507 (mapconcat 'identity all-drawers
"\\|")
1509 name beg beg-content eol content
)
1510 (while (re-search-forward re nil t
)
1512 (setq name
(match-string 1))
1513 (setq beg
(match-beginning 0)
1514 beg-content
(1+ (point-at-eol))
1516 (if (not (and (re-search-forward
1517 "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t
)
1520 (goto-char (match-beginning 0))
1521 (and (looking-at ".*\n?") (replace-match ""))
1522 (setq content
(buffer-substring beg-content
(point)))
1523 (delete-region beg
(point))
1524 (when (or (eq exp-drawers t
)
1525 (member name exp-drawers
))
1526 (setq content
(funcall (or org-export-format-drawer-function
1527 'org-export-format-drawer
)
1529 (insert content
)))))))
1531 (defun org-export-format-drawer (name content
)
1532 "Format the content of a drawer as a colon example."
1533 (if (string-match "[ \t]+\\'" content
)
1534 (setq content
(substring content
(match-beginning 0))))
1535 (while (string-match "\\`[ \t]*\n" content
)
1536 (setq content
(substring content
(match-end 0))))
1537 (setq content
(org-remove-indentation content
))
1538 (setq content
(concat ": " (mapconcat 'identity
1539 (org-split-string content
"\n")
1542 (setq content
(concat " : " (upcase name
) "\n" content
))
1543 (org-add-props content nil
'org-protected t
))
1545 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1546 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1547 Both arguments are lists of tags.
1548 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1550 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1552 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1553 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1556 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1560 (goto-char (point-min))
1561 (when (and select-tags
1563 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1564 ;; At least one tree is marked for export, this means
1565 ;; all the unmarked stuff needs to go.
1566 ;; Dig out the trees that should be exported
1567 (goto-char (point-min))
1568 (outline-next-heading)
1570 (put-text-property beg
(point-max) :org-delete t
)
1571 (while (re-search-forward re-sel nil t
)
1572 (when (org-at-heading-p)
1573 (org-back-to-heading)
1574 (remove-text-properties
1575 (max (1- (point)) (point-min))
1576 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1578 (while (and (org-up-heading-safe)
1579 (get-text-property (point) :org-delete
))
1580 (remove-text-properties (max (1- (point)) (point-min))
1581 (point-at-eol) '(:org-delete t
)))
1583 ;; Remove the trees explicitly marked for noexport
1585 (goto-char (point-min))
1586 (while (re-search-forward re-excl nil t
)
1587 (when (org-at-heading-p)
1588 (org-back-to-heading t
)
1590 (org-end-of-subtree t t
)
1591 (delete-region beg
(point))
1592 (when (featurep 'org-inlinetask
)
1593 (org-inlinetask-remove-END-maybe)))))
1594 ;; Remove everything that is now still marked for deletion
1595 (goto-char (point-min))
1596 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1597 (setq end
(or (next-single-property-change beg
:org-delete
)
1599 (delete-region beg end
))))
1601 (defun org-export-remove-tasks (keep)
1602 "Remove tasks depending on configuration.
1603 When KEEP is nil, remove all tasks.
1604 When KEEP is `todo', remove the tasks that are DONE.
1605 When KEEP is `done', remove the tasks that are not yet done.
1606 When it is a list of strings, keep only tasks with these TODO keywords."
1607 (when (or (listp keep
) (memq keep
'(todo done nil
)))
1608 (let ((re (concat "^\\*+[ \t]+\\("
1611 (cond ((not keep
) org-todo-keywords-1
)
1612 ((eq keep
'todo
) org-done-keywords
)
1613 ((eq keep
'done
) org-not-done-keywords
)
1615 (org-delete-all keep
(copy-sequence
1616 org-todo-keywords-1
))))
1618 "\\)\\($\\|[ \t]\\)"))
1619 (case-fold-search nil
)
1621 (goto-char (point-min))
1622 (while (re-search-forward re nil t
)
1624 (setq beg
(match-beginning 0))
1625 (org-end-of-subtree t t
)
1626 (if (looking-at "^\\*+[ \t]+END[ \t]*$")
1627 ;; Kill the END line of the inline task
1628 (goto-char (min (point-max) (1+ (match-end 0)))))
1629 (delete-region beg
(point)))))))
1631 (defun org-export-remove-archived-trees (export-archived-trees)
1632 "Remove archived trees.
1633 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1634 When it is t, the entire archived tree will be exported.
1635 When it is nil the entire tree including the headline will be removed
1637 (let ((re-archive (concat ":" org-archive-tag
":"))
1639 (when (not (eq export-archived-trees t
))
1640 (goto-char (point-min))
1641 (while (re-search-forward re-archive nil t
)
1642 (if (not (org-at-heading-p t
))
1643 (goto-char (point-at-eol))
1644 (beginning-of-line 1)
1645 (setq a
(if export-archived-trees
1646 (1+ (point-at-eol)) (point))
1647 b
(org-end-of-subtree t
))
1648 (if (> b a
) (delete-region a b
)))))))
1650 (defun org-export-remove-headline-metadata (opts)
1651 "Remove meta data from the headline, according to user options."
1652 (let ((re org-complex-heading-regexp
)
1653 (todo (plist-get opts
:todo-keywords
))
1654 (tags (plist-get opts
:tags
))
1655 (pri (plist-get opts
:priority
))
1657 (case-fold-search nil
)
1659 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1660 (when (or (not todo
) (not tags
) (not pri
))
1661 (goto-char (point-min))
1662 (while (re-search-forward re nil t
)
1664 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1666 (replace-match rpl t t
))))))
1668 (defun org-export-remove-timestamps ()
1669 "Remove timestamps and keywords for export."
1670 (goto-char (point-min))
1671 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1674 (unless (save-match-data (org-at-table-p))
1676 (beginning-of-line 1)
1677 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1678 (replace-match ""))))))
1680 (defun org-export-remove-clock-lines ()
1681 "Remove clock lines for export."
1682 (goto-char (point-min))
1683 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1684 (while (re-search-forward re nil t
)
1686 (replace-match "")))))
1688 (defvar org-heading-keyword-regexp-format
) ; defined in org.el
1689 (defun org-export-protect-quoted-subtrees ()
1690 "Mark quoted subtrees with the protection property."
1691 (let ((org-re-quote (format org-heading-keyword-regexp-format
1693 (goto-char (point-min))
1694 (while (re-search-forward org-re-quote nil t
)
1695 (goto-char (match-beginning 0))
1697 (add-text-properties (point) (org-end-of-subtree t
)
1698 '(org-protected t
)))))
1700 (defun org-export-convert-protected-spaces ()
1701 "Convert strings like \\____ to protected spaces in all backends."
1702 (goto-char (point-min))
1703 (while (re-search-forward "\\\\__+" nil t
)
1704 (org-if-unprotected-1
1708 ((eq org-export-current-backend
'latex
)
1709 (format "\\hspace{%dex}" (- (match-end 0) (match-beginning 0))))
1710 ((eq org-export-current-backend
'html
)
1711 (org-add-props (match-string 0) nil
1712 'org-whitespace
(- (match-end 0) (match-beginning 0))))
1713 ;; ((eq org-export-current-backend 'docbook))
1714 ((eq org-export-current-backend
'ascii
)
1715 (org-add-props (match-string 0) '(org-whitespace t
)))
1716 (t (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
1720 (defun org-export-protect-verbatim ()
1721 "Mark verbatim snippets with the protection property."
1722 (goto-char (point-min))
1723 (while (re-search-forward org-verbatim-re nil t
)
1725 (add-text-properties (match-beginning 4) (match-end 4)
1726 '(org-protected t org-verbatim-emph t
))
1727 (goto-char (1+ (match-end 4))))))
1729 (defun org-export-protect-colon-examples ()
1730 "Protect lines starting with a colon."
1731 (goto-char (point-min))
1732 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1733 (while (re-search-forward re nil t
)
1734 (beginning-of-line 1)
1736 (while (looking-at re
)
1738 (or (eobp) (forward-char 1)))
1739 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1740 '(org-protected t
)))))
1742 (defvar org-export-backends
1743 '(docbook html beamer ascii latex
)
1744 "List of Org supported export backends.")
1746 (defun org-export-select-backend-specific-text ()
1747 (let ((formatters org-export-backends
)
1748 (case-fold-search t
)
1749 backend backend-name beg beg-content end end-content ind
)
1752 (setq backend
(pop formatters
)
1753 backend-name
(symbol-name backend
))
1755 ;; Handle #+BACKEND: stuff
1756 (goto-char (point-min))
1757 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" backend-name
1758 ":[ \t]*\\(.*\\)") nil t
)
1759 (if (not (eq backend org-export-current-backend
))
1760 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
1761 (let ((ind (get-text-property (point-at-bol) 'original-indentation
)))
1762 (replace-match "\\1\\2" t
)
1763 (add-text-properties
1764 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1765 `(org-protected t original-indentation
,ind org-native-text t
)))))
1766 ;; Delete #+ATTR_BACKEND: stuff of another backend. Those
1767 ;; matching the current backend will be taken care of by
1768 ;; `org-export-attach-captions-and-attributes'
1769 (goto-char (point-min))
1770 (while (re-search-forward (concat "^\\([ \t]*\\)#\\+ATTR_" backend-name
1771 ":[ \t]*\\(.*\\)") nil t
)
1772 (setq ind
(org-get-indentation))
1773 (when (not (eq backend org-export-current-backend
))
1774 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1775 ;; Handle #+BEGIN_BACKEND and #+END_BACKEND stuff
1776 (goto-char (point-min))
1777 (while (re-search-forward (concat "^[ \t]*#\\+BEGIN_" backend-name
"\\>.*\n?")
1779 (setq beg
(match-beginning 0) beg-content
(match-end 0))
1780 (setq ind
(or (get-text-property beg
'original-indentation
)
1781 (save-excursion (goto-char beg
) (org-get-indentation))))
1782 (when (re-search-forward (concat "^[ \t]*#\\+END_" backend-name
"\\>.*\n?")
1784 (setq end
(match-end 0) end-content
(match-beginning 0))
1785 (if (eq backend org-export-current-backend
)
1788 (add-text-properties
1789 beg-content end-content
1790 `(org-protected t original-indentation
,ind org-native-text t
))
1791 ;; strip protective commas
1792 (org-strip-protective-commas beg-content end-content
)
1793 (delete-region (match-beginning 0) (match-end 0))
1796 (delete-region (point) (1+ (point-at-eol)))))
1797 ;; No, this is for a different backend, kill it
1798 (delete-region beg end
)))))))
1800 (defun org-export-mark-blockquote-verse-center ()
1801 "Mark block quote and verse environments with special cookies.
1802 These special cookies will later be interpreted by the backend."
1804 (let (type t1 ind beg end beg1 end1 content
)
1805 (goto-char (point-min))
1806 (while (re-search-forward
1807 "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)"
1809 (setq ind
(length (match-string 1))
1810 type
(downcase (match-string 3))
1811 t1
(if (equal type
"quote") "blockquote" type
))
1812 (setq beg
(match-beginning 0)
1813 beg1
(1+ (match-end 0)))
1814 (when (re-search-forward (concat "^[ \t]*#\\+end_" type
"\\>.*") nil t
)
1815 (setq end1
(1- (match-beginning 0))
1816 end
(+ (point-at-eol) (if (looking-at "\n$") 1 0)))
1817 (setq content
(org-remove-indentation (buffer-substring beg1 end1
)))
1818 (setq content
(concat "ORG-" (upcase t1
) "-START\n"
1820 "ORG-" (upcase t1
) "-END\n"))
1821 (delete-region beg end
)
1822 (insert (org-add-props content nil
'original-indentation ind
))))))
1824 (defun org-export-mark-list-end ()
1825 "Mark all list endings with a special string."
1826 (unless (eq org-export-current-backend
'ascii
)
1829 ;; For each type allowing list export, find every list, remove
1830 ;; ending regexp if needed, and insert org-list-end.
1831 (goto-char (point-min))
1832 (while (re-search-forward (org-item-beginning-re) nil t
)
1833 (when (eq (nth 2 (org-list-context)) e
)
1834 (let* ((struct (org-list-struct))
1835 (bottom (org-list-get-bottom-point struct
))
1836 (top (point-at-bol))
1837 (top-ind (org-list-get-ind top struct
)))
1839 (when (and (not (looking-at "[ \t]*$"))
1840 (looking-at org-list-end-re
))
1842 (unless (bolp) (insert "\n"))
1843 ;; As org-list-end is inserted at column 0, it would end
1844 ;; by indentation any list. It can be problematic when
1845 ;; there are lists within lists: the inner list end would
1846 ;; also become the outer list end. To avoid this, text
1847 ;; property `original-indentation' is added, as
1848 ;; `org-list-struct' pays attention to it when reading a
1850 (insert (org-add-props
1851 "ORG-LIST-END-MARKER\n"
1852 (list 'original-indentation top-ind
)))))))
1853 (cons nil org-list-export-context
))))
1855 (defun org-export-mark-list-properties ()
1856 "Mark list with special properties.
1857 These special properties will later be interpreted by the backend."
1860 ;; Mark a list with 3 properties: `list-item' which is
1861 ;; position at beginning of line, `list-struct' which is
1862 ;; list structure, and `list-prevs' which is the alist of
1863 ;; item and its predecessor. Leave point at list ending.
1865 (let* ((struct (org-list-struct))
1866 (top (org-list-get-top-point struct
))
1867 (bottom (org-list-get-bottom-point struct
))
1868 (prevs (org-list-prevs-alist struct
))
1870 ;; Get every item and ending position, without dups and
1871 ;; without bottom point of list.
1875 (unless (memq pos poi
)
1877 (unless (or (= end bottom
) (memq end poi
))
1880 (setq poi
(sort poi
'<))
1881 ;; For every point of interest, mark the whole line with
1882 ;; its position in list.
1886 (add-text-properties (point-at-bol) (point-at-eol)
1887 (list 'list-item
(point-at-bol)
1889 'list-prevs prevs
)))
1891 ;; Take care of bottom point. As babel may have inserted
1892 ;; a new list in buffer, list ending isn't always
1893 ;; marked. Now mark every list ending and add properties
1894 ;; useful to line processing exporters.
1896 (when (or (looking-at "^ORG-LIST-END-MARKER\n")
1897 (and (not (looking-at "[ \t]*$"))
1898 (looking-at org-list-end-re
)))
1900 (unless (bolp) (insert "\n"))
1902 (org-add-props "ORG-LIST-END-MARKER\n" (list 'list-item bottom
1904 'list-prevs prevs
)))
1905 ;; Following property is used by LaTeX exporter.
1906 (add-text-properties top
(point) (list 'list-context ctxt
)))))))
1907 ;; Mark lists except for backends not interpreting them.
1908 (unless (eq org-export-current-backend
'ascii
)
1909 (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
1912 (goto-char (point-min))
1913 (while (re-search-forward (org-item-beginning-re) nil t
)
1914 (let ((context (nth 2 (org-list-context))))
1916 (funcall mark-list e
)
1917 (put-text-property (point-at-bol) (point-at-eol)
1918 'list-context context
)))))
1919 (cons nil org-list-export-context
))))))
1921 (defun org-export-attach-captions-and-attributes (target-alist)
1922 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1923 If the next thing following is a table, add the text properties to the first
1924 table line. If it is a link, add it to the line containing the link."
1925 (goto-char (point-min))
1926 (remove-text-properties (point-min) (point-max)
1927 '(org-caption nil org-attributes nil
))
1928 (let ((case-fold-search t
)
1929 (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
1931 "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend
) ":[ \t]+\\(.*\\)"
1933 "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
1935 "^[ \t]*\\(|[^-]\\)"
1937 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1938 cap shortn attr label end
)
1939 (while (re-search-forward re nil t
)
1941 ;; there is a caption
1944 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1))))
1945 (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap
)
1946 (setq shortn
(match-string 1 cap
)
1947 cap
(match-string 2 cap
)))
1948 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1949 ;; there is an attribute
1952 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2))))
1953 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1957 (setq label
(org-trim (match-string 3)))
1958 (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))))
1960 (setq end
(if (match-end 4)
1961 (let ((ee (org-table-end)))
1962 (prog1 (1- (marker-position ee
)) (move-marker ee nil
)))
1964 (add-text-properties (point-at-bol) end
1965 (list 'org-caption cap
1966 'org-caption-shortn shortn
1967 'org-attributes attr
1969 (if label
(push (cons label label
) target-alist
))
1971 (setq cap nil shortn nil attr nil label nil
)))))
1974 (defun org-export-remove-comment-blocks-and-subtrees ()
1975 "Remove the comment environment, and also commented subtrees."
1976 (let ((re-commented (format org-heading-keyword-regexp-format
1977 org-comment-string
))
1979 ;; Remove comment environment
1980 (goto-char (point-min))
1981 (setq case-fold-search t
)
1982 (while (re-search-forward
1983 "^#\\+begin_comment[ \t]*\n[^\000]*?\n#\\+end_comment\\>.*" nil t
)
1984 (replace-match "" t t
))
1985 ;; Remove subtrees that are commented
1986 (goto-char (point-min))
1987 (setq case-fold-search nil
)
1988 (while (re-search-forward re-commented nil t
)
1989 (goto-char (match-beginning 0))
1990 (delete-region (point) (org-end-of-subtree t
)))))
1992 (defun org-export-handle-comments (org-commentsp)
1993 "Remove comments, or convert to backend-specific format.
1994 ORG-COMMENTSP can be a format string for publishing comments.
1995 When it is nil, all comments will be removed."
1996 (let ((re "^[ \t]*#\\( \\|$\\)"))
1997 (goto-char (point-min))
1998 (while (re-search-forward re nil t
)
1999 (let ((pos (match-beginning 0))
2000 (end (progn (forward-line) (point))))
2001 (if (get-text-property pos
'org-protected
)
2003 (if (not org-commentsp
) (delete-region pos end
)
2004 (add-text-properties pos end
'(org-protected t
))
2007 (format org-commentsp
(buffer-substring (match-end 0) end
))
2008 nil
'org-protected t
)
2010 ;; Hack attack: previous implementation also removed keywords at
2011 ;; column 0. Brainlessly do it again.
2012 (goto-char (point-min))
2013 (while (re-search-forward "^#\\+" nil t
)
2014 (unless (get-text-property (point-at-bol) 'org-protected
)
2015 (delete-region (point-at-bol) (progn (forward-line) (point)))))))
2017 (defun org-export-handle-metalines ()
2018 "Remove tables and source blocks metalines.
2019 This function should only be called after all block processing
2021 (let ((re "^[ \t]*#\\+\\(tbl\\(?:name\\|fm\\)\\|results\\(?:\\[[a-z0-9]+\\]\\)?\\|name\\):\\(.*\n?\\)")
2022 (case-fold-search t
)
2024 (goto-char (point-min))
2025 (while (or (looking-at re
)
2026 (re-search-forward re nil t
))
2027 (setq pos
(match-beginning 0))
2028 (if (get-text-property (match-beginning 1) 'org-protected
)
2029 (goto-char (1+ pos
))
2030 (goto-char (1+ pos
))
2032 (goto-char (max (point-min) (1- pos
)))))))
2034 (defun org-export-mark-radio-links ()
2035 "Find all matches for radio targets and turn them into internal links."
2036 (let ((re-radio (and org-target-link-regexp
2037 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2038 (goto-char (point-min))
2040 (while (re-search-forward re-radio nil t
)
2043 (or (org-in-regexp org-bracket-link-regexp
)
2044 (org-in-regexp org-plain-link-re
)
2045 (org-in-regexp "<<[^<>]+>>")))
2047 (replace-match "\\1[[\\2]]")))))))
2049 (defun org-store-forced-table-alignment ()
2050 "Find table lines which force alignment, store the results in properties."
2051 (let (line cnt cookies
)
2052 (goto-char (point-min))
2053 (while (re-search-forward "|[ \t]*<\\([lrc]?[0-9]+\\|[lrc]\\)>[ \t]*|"
2055 ;; OK, this looks like a table line with an alignment cookie
2057 (setq line
(buffer-substring (point-at-bol) (point-at-eol)))
2058 (when (and (org-at-table-p)
2059 (org-table-cookie-line-p line
))
2060 (setq cnt
0 cookies nil
)
2064 (when (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'" x
)
2065 (let ((align (and (match-end 1)
2066 (downcase (match-string 1 x
))))
2067 (width (and (match-end 2)
2068 (string-to-number (match-string 2 x
)))))
2069 (push (cons cnt
(list align width
)) cookies
))))
2070 (org-split-string line
"[ \t]*|[ \t]*"))
2071 (add-text-properties (org-table-begin) (org-table-end)
2072 (list 'org-col-cookies cookies
))))
2073 (goto-char (point-at-eol)))))
2075 (defun org-export-remove-special-table-lines ()
2076 "Remove tables lines that are used for internal purposes.
2077 Also, store forced alignment information found in such lines."
2078 (goto-char (point-min))
2079 (while (re-search-forward "^[ \t]*|" nil t
)
2080 (org-if-unprotected-at (1- (point))
2081 (beginning-of-line 1)
2082 (if (or (looking-at "[ \t]*| *[!_^] *|")
2088 (or (and org-export-table-remove-empty-lines
(= (length f
) 0))
2090 "\\`<\\([0-9]\\|[lrc]\\|[lrc][0-9]+\\)>\\'" f
)))
2091 (org-split-string ;; FIXME, can't we do without splitting???
2092 (buffer-substring (point-at-bol) (point-at-eol))
2093 "[ \t]*|[ \t]*")))))
2094 (delete-region (max (point-min) (1- (point-at-bol)))
2098 (defun org-export-protect-sub-super (s)
2100 (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s
)
2101 (setq s
(replace-match "\\1\\\\\\2" nil nil s
)))
2104 (defun org-export-normalize-links ()
2105 "Convert all links to bracket links, and expand link abbreviations."
2106 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2107 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
2109 (goto-char (point-min))
2110 (while (re-search-forward org-bracket-link-regexp nil t
)
2111 (put-text-property (match-beginning 0) (match-end 0) 'org-normalized-link t
))
2112 (goto-char (point-min))
2113 (while (re-search-forward re-plain-link nil t
)
2114 (unless (get-text-property (match-beginning 0) 'org-normalized-link
)
2115 (goto-char (1- (match-end 0)))
2116 (org-if-unprotected-at (1+ (match-beginning 0))
2117 (let* ((s (concat (match-string 1)
2118 "[[" (match-string 2) ":" (match-string 3)
2119 "][" (match-string 2) ":" (org-export-protect-sub-super
2122 ;; added 'org-link face to links
2123 (put-text-property 0 (length s
) 'face
'org-link s
)
2124 (replace-match s t t
)))))
2125 (goto-char (point-min))
2126 (while (re-search-forward re-angle-link nil t
)
2127 (goto-char (1- (match-end 0)))
2129 (let* ((s (concat (match-string 1)
2130 "[[" (match-string 2) ":" (match-string 3)
2131 "][" (match-string 2) ":" (org-export-protect-sub-super
2134 (put-text-property 0 (length s
) 'face
'org-link s
)
2135 (replace-match s t t
))))
2136 (goto-char (point-min))
2137 (while (re-search-forward org-bracket-link-regexp nil t
)
2138 (goto-char (1- (match-end 0)))
2139 (setq nodesc
(not (match-end 3)))
2141 (let* ((xx (save-match-data
2143 (org-link-expand-abbrev (match-string 1)))))
2145 "[[" (org-add-props (copy-sequence xx
)
2146 nil
'org-protected t
'org-no-description nodesc
)
2150 (concat "[" (copy-sequence xx
)
2153 (put-text-property 0 (length s
) 'face
'org-link s
)
2154 (replace-match s t t
))))))
2156 (defun org-export-concatenate-multiline-links ()
2157 "Find multi-line links and put it all into a single line.
2158 This is to make sure that the line-processing export backends
2159 can work correctly."
2160 (goto-char (point-min))
2161 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2162 (org-if-unprotected-at (match-beginning 1)
2163 (replace-match "\\1 \\3")
2164 (goto-char (match-beginning 0)))))
2166 (defun org-export-concatenate-multiline-emphasis ()
2167 "Find multi-line emphasis and put it all into a single line.
2168 This is to make sure that the line-processing export backends
2169 can work correctly."
2170 (goto-char (point-min))
2171 (while (re-search-forward org-emph-re nil t
)
2172 (if (and (not (= (char-after (match-beginning 3))
2173 (char-after (match-beginning 4))))
2174 (save-excursion (goto-char (match-beginning 0))
2176 (and (not (org-at-table-p))
2177 (not (org-at-heading-p))))))
2179 (subst-char-in-region (match-beginning 0) (match-end 0)
2181 (goto-char (1- (match-end 0))))
2182 (goto-char (1+ (match-beginning 0))))))
2184 (defun org-export-grab-title-from-buffer ()
2185 "Get a title for the current document, from looking at the buffer."
2186 (let ((inhibit-read-only t
))
2188 (goto-char (point-min))
2189 (let ((end (if (looking-at org-outline-regexp
)
2191 (save-excursion (outline-next-heading) (point)))))
2192 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2193 ;; Mark the line so that it will not be exported as normal text.
2194 (unless (org-in-block-p org-list-forbidden-blocks
)
2196 (add-text-properties (match-beginning 0) (match-end 0)
2197 (list :org-license-to-kill t
))))
2198 ;; Return the title string
2199 (org-trim (match-string 0)))))))
2201 (defun org-export-get-title-from-subtree ()
2202 "Return subtree title and exclude it from export."
2203 (let ((rbeg (region-beginning)) (rend (region-end))
2204 (inhibit-read-only t
)
2205 (tags (plist-get (org-infile-export-plist) :tags
))
2209 (when (and (org-at-heading-p)
2210 (>= (org-end-of-subtree t t
) rend
))
2211 (when (plist-member org-export-opt-plist
:tags
)
2212 (setq tags
(or (plist-get org-export-opt-plist
:tags
) tags
)))
2213 ;; This is a subtree, we take the title from the first heading
2215 (looking-at org-todo-line-tags-regexp
)
2216 (setq title
(if (and (eq tags t
) (match-string 4))
2217 (format "%s\t%s" (match-string 3) (match-string 4))
2220 (add-text-properties (point) (1+ (point-at-eol))
2221 (list :org-license-to-kill t
)))
2222 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2225 (defun org-solidify-link-text (s &optional alist
)
2226 "Take link text and make a safe target out of it."
2231 (org-split-string s
"[^a-zA-Z0-9_\\.-]+") "-"))
2232 (a (assoc rtn alist
)))
2235 (defun org-get-min-level (lines &optional offset
)
2236 "Get the minimum level in LINES."
2237 (let ((re "^\\(\\*+\\) ") l
)
2239 (while (setq l
(pop lines
))
2240 (if (string-match re l
)
2241 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2245 ;; Variable holding the vector with section numbers
2246 (defvar org-section-numbers
(make-vector org-level-max
0))
2248 (defun org-init-section-numbers ()
2249 "Initialize the vector for the section numbers."
2251 (numbers (nreverse (org-split-string "" "\\.")))
2252 (depth (1- (length org-section-numbers
)))
2253 (i depth
) number-string
)
2256 (aset org-section-numbers i
0)
2257 (setq number-string
(or (car numbers
) "0"))
2258 (if (string-match "\\`[A-Z]\\'" number-string
)
2259 (aset org-section-numbers i
2260 (- (string-to-char number-string
) ?A -
1))
2261 (aset org-section-numbers i
(string-to-number number-string
)))
2265 (defun org-section-number (&optional level
)
2266 "Return a string with the current section number.
2267 When LEVEL is non-nil, increase section numbers on that level."
2268 (let* ((depth (1- (length org-section-numbers
)))
2270 (fmts (car org-export-section-number-format
))
2271 (term (cdr org-export-section-number-format
))
2276 (aset org-section-numbers
2277 level
(1+ (aref org-section-numbers level
))))
2278 (setq idx
(1+ level
))
2279 (while (<= idx depth
)
2281 (aset org-section-numbers idx
0))
2282 (setq idx
(1+ idx
))))
2284 (while (<= idx depth
)
2285 (when (> (aref org-section-numbers idx
) 0)
2286 (setq fmt
(or (pop fmts
) fmt
)
2288 n
(aref org-section-numbers idx
)
2290 (concat string sep
(org-number-to-counter n ctype
))
2291 (concat string
".0"))
2293 (setq idx
(1+ idx
)))
2295 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2296 (setq string
(replace-match "" t nil string
)))
2297 (if (string-match "\\(\\.0\\)+\\'" string
)
2298 (setq string
(replace-match "" t nil string
))))
2299 (concat string term
)))
2301 (defun org-number-to-counter (n type
)
2302 "Concert number N to a string counter, according to TYPE.
2303 TYPE must be a string, any of:
2307 I upper case roman numeral
2308 i lower case roman numeral"
2310 ((equal type
"1") (number-to-string n
))
2311 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2312 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2313 ((equal type
"I") (org-number-to-roman n
))
2314 ((equal type
"i") (downcase (org-number-to-roman n
)))
2315 (t (error "Invalid counter type `%s'" type
))))
2317 (defun org-number-to-roman (n)
2318 "Convert integer N into a roman numeral."
2319 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2320 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2321 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2325 (number-to-string n
)
2327 (if (>= n
(caar roman
))
2328 (setq n
(- n
(caar roman
))
2329 res
(concat res
(cdar roman
)))
2335 (defun org-export-preprocess-apply-macros ()
2336 "Replace macro references."
2337 (goto-char (point-min))
2338 (let (sy val key args args2 ind-str s n
)
2339 (while (re-search-forward
2340 "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}"
2342 (unless (save-match-data (save-excursion
2343 (goto-char (point-at-bol))
2344 (looking-at "[ \t]*#\\+macro")))
2345 ;; Get macro name (KEY), arguments (ARGS), and indentation of
2346 ;; current line (IND-STR) as strings.
2347 (setq key
(downcase (match-string 1))
2348 args
(match-string 3)
2349 ind-str
(save-match-data (save-excursion
2351 (looking-at "^\\([ \t]*\\).*")
2353 ;; When macro is defined, retrieve replacement text in VAL,
2354 ;; and proceed with expansion.
2355 (when (setq val
(or (plist-get org-export-opt-plist
2356 (intern (concat ":macro-" key
)))
2357 (plist-get org-export-opt-plist
2358 (intern (concat ":" key
)))))
2360 ;; If arguments are provided, first retrieve them properly
2361 ;; (in ARGS, as a list), then replace them in VAL.
2363 (setq args
(org-split-string args
",") args2 nil
)
2365 (while (string-match "\\\\\\'" (car args
))
2366 ;; Repair bad splits.
2367 (setcar (cdr args
) (concat (substring (car args
) 0 -
1)
2370 (push (pop args
) args2
))
2371 (setq args
(mapcar 'org-trim
(nreverse args2
)))
2373 (while (string-match "\\$\\([0-9]+\\)" val s
)
2374 (setq s
(1+ (match-beginning 0))
2375 n
(string-to-number (match-string 1 val
)))
2376 (and (>= (length args
) n
)
2377 (setq val
(replace-match (nth (1- n
) args
) t t val
)))))
2378 ;; VAL starts with "(eval": it is a sexp, `eval' it.
2379 (when (string-match "\\`(eval\\>" val
)
2380 (setq val
(eval (read val
))))
2381 ;; Ensure VAL is a string (or nil) and that each new line
2382 ;; is indented as the first one.
2384 (mapconcat 'identity
2386 (if (stringp val
) val
(format "%s" val
))
2388 (concat "\n" ind-str
)))))
2389 ;; Eventually do the replacement, if VAL isn't nil. Move
2390 ;; point at beginning of macro for recursive expansions.
2392 (replace-match val t t
)
2393 (goto-char (match-beginning 0))))))))
2395 (defun org-export-apply-macros-in-string (s)
2396 "Apply the macros in string S."
2400 (org-export-preprocess-apply-macros)
2405 (defun org-export-handle-include-files ()
2406 "Include the contents of include files, with proper formatting."
2407 (let ((case-fold-search t
)
2408 params file markup lang start end prefix prefix1 switches all minlevel currentlevel addlevel lines
)
2409 (goto-char (point-min))
2410 (while (re-search-forward "^#\\+include:[ \t]+\\(.*\\)" nil t
)
2411 (setq params
(read (concat "(" (match-string 1) ")"))
2412 prefix
(org-get-and-remove-property 'params
:prefix
)
2413 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2414 minlevel
(org-get-and-remove-property 'params
:minlevel
)
2415 addlevel
(org-get-and-remove-property 'params
:addlevel
)
2416 lines
(org-get-and-remove-property 'params
:lines
)
2417 file
(org-symname-or-string (pop params
))
2418 markup
(org-symname-or-string (pop params
))
2419 lang
(and (member markup
'("src" "SRC"))
2420 (org-symname-or-string (pop params
)))
2421 switches
(mapconcat #'(lambda (x) (format "%s" x
)) params
" ")
2423 (delete-region (match-beginning 0) (match-end 0))
2424 (setq currentlevel
(or (org-current-level) 0))
2426 (not (file-exists-p file
))
2427 (not (file-readable-p file
)))
2428 (insert (format "CANNOT INCLUDE FILE %s" file
))
2429 (setq all
(cons file all
))
2431 (if (equal (downcase markup
) "src")
2432 (setq start
(format "#+begin_src %s %s\n"
2433 (or lang
"fundamental")
2436 (setq start
(format "#+begin_%s %s\n" markup switches
)
2437 end
(format "#+end_%s" markup
))))
2438 (insert (or start
""))
2439 (insert (org-get-file-contents (expand-file-name file
)
2440 prefix prefix1 markup currentlevel minlevel addlevel lines
))
2441 (or (bolp) (newline))
2442 (insert (or end
""))))
2445 (defun org-export-handle-include-files-recurse ()
2446 "Recursively include files aborting on circular inclusion."
2447 (let ((now (list org-current-export-file
)) all
)
2449 (setq all
(append now all
))
2450 (setq now
(org-export-handle-include-files))
2453 (mapcar (lambda (el) (when (member el all
) el
)) now
))))
2455 (error "Recursive #+INCLUDE: %S" intersection
))))))
2457 (defun org-get-file-contents (file &optional prefix prefix1 markup minlevel parentlevel addlevel lines
)
2458 "Get the contents of FILE and return them as a string.
2459 If PREFIX is a string, prepend it to each line. If PREFIX1
2460 is a string, prepend it to the first line instead of PREFIX.
2461 If MARKUP, don't protect org-like lines, the exporter will
2462 take care of the block they are in. If ADDLEVEL is a number,
2463 demote included file to current heading level+ADDLEVEL.
2464 If LINES is a string specifying a range of lines,
2465 include only those lines."
2466 (if (stringp markup
) (setq markup
(downcase markup
)))
2468 (insert-file-contents file
)
2470 (let* ((lines (split-string lines
"-"))
2471 (lbeg (string-to-number (car lines
)))
2472 (lend (string-to-number (cadr lines
)))
2473 (beg (if (zerop lbeg
) (point-min)
2474 (goto-char (point-min))
2475 (forward-line (1- lbeg
))
2477 (end (if (zerop lend
) (point-max)
2478 (goto-char (point-min))
2479 (forward-line (1- lend
))
2481 (narrow-to-region beg end
)))
2482 (when (or prefix prefix1
)
2483 (goto-char (point-min))
2485 (insert (or prefix1 prefix
))
2487 (beginning-of-line 2)))
2489 (when (member markup
'("src" "example"))
2490 (goto-char (point-min))
2491 (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t
)
2492 (goto-char (match-beginning 0))
2496 (dotimes (lvl minlevel
)
2497 (org-map-region 'org-demote
(point-min) (point-max))))
2499 (let ((inclevel (or (if (org-before-first-heading-p)
2500 (1- (and (outline-next-heading)
2501 (org-current-level)))
2502 (1- (org-current-level)))
2504 (dotimes (level (- (+ parentlevel addlevel
) inclevel
))
2505 (org-map-region 'org-demote
(point-min) (point-max)))))
2508 (defun org-get-and-remove-property (listvar prop
)
2509 "Check if the value of LISTVAR contains PROP as a property.
2510 If yes, return the value of that property (i.e. the element following
2511 in the list) and remove property and value from the list in LISTVAR."
2512 (let ((list (symbol-value listvar
)) m v
)
2513 (when (setq m
(member prop list
))
2515 (if (equal (car list
) prop
)
2516 (set listvar
(cddr list
))
2517 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2519 (set listvar list
)))
2522 (defun org-symname-or-string (s)
2524 (if s
(symbol-name s
) s
)
2527 ;;; Fontification and line numbers for code examples
2529 (defvar org-export-last-code-line-counter-value
0)
2531 (defun org-export-replace-src-segments-and-examples ()
2532 "Replace source code segments with special code for export."
2533 (setq org-export-last-code-line-counter-value
0)
2534 (let ((case-fold-search t
)
2535 lang code trans opts indent caption
)
2536 (goto-char (point-min))
2537 (while (re-search-forward
2538 "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
2541 (if (not (match-string 4))
2542 (error "Source block missing language specification: %s"
2543 (let* ((body (match-string 6))
2544 (nothing (message "body:%s" body
))
2545 (preview (or (and (string-match
2546 "^[ \t]*\\([^\n\r]*\\)" body
)
2547 (match-string 1 body
)) body
)))
2548 (if (> (length preview
) 35)
2549 (concat (substring preview
0 32) "...")
2552 (setq lang
(match-string 4)
2553 opts
(match-string 5)
2554 code
(match-string 6)
2555 indent
(length (match-string 2))
2556 caption
(get-text-property 0 'org-caption
(match-string 0))))
2558 opts
(match-string 9)
2559 code
(match-string 10)
2560 indent
(length (match-string 8))
2561 caption
(get-text-property 0 'org-caption
(match-string 0))))
2563 (setq trans
(org-export-format-source-code-or-example
2564 lang code opts indent caption
))
2565 (replace-match trans t t
))))
2567 (defvar org-export-latex-verbatim-wrap
) ;; defined in org-latex.el
2568 (defvar org-export-latex-listings
) ;; defined in org-latex.el
2569 (defvar org-export-latex-listings-langs
) ;; defined in org-latex.el
2570 (defvar org-export-latex-listings-w-names
) ;; defined in org-latex.el
2571 (defvar org-export-latex-minted-langs
) ;; defined in org-latex.el
2572 (defvar org-export-latex-custom-lang-environments
) ;; defined in org-latex.el
2573 (defvar org-export-latex-listings-options
) ;; defined in org-latex.el
2574 (defvar org-export-latex-minted-options
) ;; defined in org-latex.el
2576 (defun org-remove-formatting-on-newlines-in-region (beg end
)
2577 "Remove formatting on newline characters."
2581 (while (progn (end-of-line) (< (point) end
))
2582 (put-text-property (point) (1+ (point)) 'face nil
)
2585 (defun org-export-format-source-code-or-example
2586 (lang code
&optional opts indent caption
)
2587 "Format CODE from language LANG and return it formatted for export.
2588 The CODE is marked up in `org-export-current-backend' format.
2590 Check if a function by name
2591 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
2592 use it as the custom formatter. Otherwise, use the default
2593 formatter. Default formatters are provided for docbook, html,
2594 latex and ascii backends. For example, use
2595 `org-html-format-source-code-or-example' to provide a custom
2596 formatter for export to \"html\".
2598 If LANG is nil, do not add any fontification.
2599 OPTS contains formatting options, like `-n' for triggering numbering lines,
2600 and `+n' for continuing previous numbering.
2601 Code formatting according to language currently only works for HTML.
2602 Numbering lines works for all three major backends (html, latex, and ascii).
2603 INDENT was the original indentation of the block."
2605 (let* ((backend-name (symbol-name org-export-current-backend
))
2607 (intern (format "org-%s-format-source-code-or-example"
2609 (backend-feature (intern (concat "org-" backend-name
)))
2611 (and (require (intern (concat "org-" backend-name
)) nil
)
2612 (fboundp backend-formatter
) backend-formatter
))
2613 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
2614 (setq opts
(or opts
"")
2615 num
(string-match "[-+]n\\>" opts
)
2616 cont
(string-match "\\+n\\>" opts
)
2617 rpllbl
(string-match "-r\\>" opts
)
2618 keepp
(string-match "-k\\>" opts
)
2619 textareap
(string-match "-t\\>" opts
)
2620 preserve-indentp
(or org-src-preserve-indentation
2621 (string-match "-i\\>" opts
))
2622 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2623 (string-to-number (match-string 1 opts
))
2625 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2626 (string-to-number (match-string 1 opts
))
2627 (org-count-lines code
))
2628 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2629 (match-string 1 opts
)))
2630 (when (and textareap
(eq org-export-current-backend
'html
))
2631 ;; we cannot use numbering or highlighting.
2632 (setq num nil cont nil lang nil
))
2633 (if keepp
(setq rpllbl
'keep
))
2634 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
2635 (when (string-match "^," rtn
)
2636 (setq rtn
(with-temp-buffer
2638 ;; Free up the protected lines
2639 (goto-char (point-min))
2640 (while (re-search-forward "^," nil t
)
2641 (if (or (equal lang
"org")
2643 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2647 ;; Now backend-specific coding
2651 (funcall backend-formatter rtn lang caption textareap cols rows num
2653 ((eq org-export-current-backend
'docbook
)
2654 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2655 (concat "<programlisting><![CDATA["
2657 "]]></programlisting>\n"))
2658 ((eq org-export-current-backend
'html
)
2659 ;; We are exporting to HTML
2661 (if (featurep 'xemacs
)
2663 (require 'htmlize nil t
))
2664 (when (not (fboundp 'htmlize-region-for-paste
))
2665 ;; we do not have htmlize.el, or an old version of it
2668 "htmlize.el 1.34 or later is needed for source code formatting")))
2671 (let* ((lang-m (when lang
2672 (or (cdr (assoc lang org-src-lang-modes
))
2674 (mode (and lang-m
(intern
2676 (if (symbolp lang-m
)
2677 (symbol-name lang-m
)
2680 (org-inhibit-startup t
)
2681 (org-startup-folded nil
))
2685 (if (functionp mode
)
2688 (font-lock-fontify-buffer)
2689 ;; markup each line separately
2690 (org-remove-formatting-on-newlines-in-region (point-min) (point-max))
2692 (set-buffer-modified-p nil
)
2693 (org-export-htmlize-region-for-paste
2694 (point-min) (point-max))))
2695 (if (string-match "<pre\\([^>]*\\)>\n*" rtn
)
2700 "<div class=\"org-src-container\">"
2702 "<label class=\"org-src-name\">%s</label>"
2706 (format "<pre class=\"src src-%s\">\n" lang
)
2708 (if caption
"</div>" "")))))
2711 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2713 rtn
"</textarea>\n</p>\n"))
2716 (goto-char (point-min))
2717 (while (re-search-forward "[<>&]" nil t
)
2718 (replace-match (cdr (assq (char-before)
2719 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2721 (setq rtn
(buffer-string)))
2722 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2724 (setq rtn
(org-export-number-lines rtn
1 1 num cont rpllbl fmt
)))
2725 (if (string-match "\\(\\`<[^>]*>\\)\n" rtn
)
2726 (setq rtn
(replace-match "\\1" t nil rtn
)))
2728 ((eq org-export-current-backend
'latex
)
2729 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2731 ((and lang org-export-latex-listings
)
2732 (let* ((make-option-string
2734 (concat (first pair
)
2735 (if (> (length (second pair
)) 0)
2736 (concat "=" (second pair
))))))
2737 (lang-sym (intern lang
))
2738 (minted-p (eq org-export-latex-listings
'minted
))
2739 (listings-p (not minted-p
))
2745 (minted-p org-export-latex-minted-langs
)
2746 (listings-p org-export-latex-listings-langs
))))
2752 org-export-latex-custom-lang-environments
))))
2754 (when (and listings-p
(not custom-environment
))
2759 (append org-export-latex-listings-options
2760 `(("language" ,backend-lang
))) ",")))
2761 (when (and caption org-export-latex-listings-w-names
)
2764 (replace-regexp-in-string "_" "\\\\_" caption
)))
2767 (format "\\begin{%s}\n%s\\end{%s}\n"
2768 custom-environment rtn custom-environment
))
2770 (format "\\begin{%s}\n%s\\end{%s}"
2771 "lstlisting" rtn
"lstlisting"))
2774 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2775 (mapconcat make-option-string
2776 org-export-latex-minted-options
",")
2777 backend-lang rtn
))))))
2778 (t (concat (car org-export-latex-verbatim-wrap
)
2779 rtn
(cdr org-export-latex-verbatim-wrap
)))))
2780 ((eq org-export-current-backend
'ascii
)
2781 ;; This is not HTML or LaTeX, so just make it an example.
2782 (setq rtn
(org-export-number-lines rtn
0 0 num cont rpllbl fmt
))
2783 (concat caption
"\n"
2786 (lambda (l) (concat " " l
))
2787 (org-split-string rtn
"\n")
2791 (error "Don't know how to markup source or example block in %s"
2792 (upcase backend-name
)))))
2795 "\n#+BEGIN_" backend-name
"\n"
2797 '(org-protected t org-example t org-native-text t
))
2798 "\n#+END_" backend-name
"\n"))
2799 (org-add-props rtn nil
'original-indentation indent
))))
2801 (defun org-export-number-lines (text &optional skip1 skip2 number cont
2802 replace-labels label-format preprocess
)
2803 "Apply line numbers to literal examples and handle code references.
2804 Handle user-specified options under info node `(org)Literal
2805 examples' and return the modified source block.
2807 TEXT contains the source or example block.
2809 SKIP1 and SKIP2 are the number of lines that are to be skipped at
2810 the beginning and end of TEXT. Use these to skip over
2811 backend-specific lines pre-pended or appended to the original
2814 NUMBER is non-nil if the literal example specifies \"+n\" or
2815 \"-n\" switch. If NUMBER is non-nil add line numbers.
2817 CONT is non-nil if the literal example specifies \"+n\" switch.
2818 If CONT is nil, start numbering this block from 1. Otherwise
2819 continue numbering from the last numbered block.
2821 REPLACE-LABELS is dual-purpose.
2822 1. It controls the retention of labels in the exported block.
2823 2. It specifies in what manner the links (or references) to a
2824 labeled line be formatted.
2826 REPLACE-LABELS is the symbol `keep' if the literal example
2827 specifies \"-k\" option, is numeric if the literal example
2828 specifies \"-r\" option and is nil otherwise.
2830 Handle REPLACE-LABELS as below:
2831 - If nil, retain labels in the exported block and use
2832 user-provided labels for referencing the labeled lines.
2833 - If it is a number, remove labels in the exported block and use
2834 one of line numbers or labels for referencing labeled lines based
2836 - If it is a keep, retain labels in the exported block and use
2837 one of line numbers or labels for referencing labeled lines
2838 based on NUMBER option.
2840 LABEL-FORMAT is the value of \"-l\" switch associated with
2841 literal example. See `org-coderef-label-format'.
2843 PREPROCESS is intended for backend-agnostic handling of source
2844 block numbering. When non-nil do the following:
2845 - do not number the lines
2846 - always strip the labels from exported block
2847 - do not make the labeled line a target of an incoming link.
2848 Instead mark the labeled line with `org-coderef' property and
2849 store the label in it."
2850 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2851 (if (and number
(not cont
)) (setq org-export-last-code-line-counter-value
0))
2854 (goto-char (point-max))
2855 (skip-chars-backward " \t\n\r")
2856 (delete-region (point) (point-max))
2857 (beginning-of-line (- 1 skip2
))
2858 (let* ((last (org-current-line))
2859 (n org-export-last-code-line-counter-value
)
2860 (nmax (+ n
(- last skip1
)))
2861 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2864 ((eq org-export-current-backend
'html
) (format "<span class=\"linenr\">%s</span>"
2866 ((eq org-export-current-backend
'ascii
) fmt
)
2867 ((eq org-export-current-backend
'latex
) fmt
)
2868 ((eq org-export-current-backend
'docbook
) fmt
)
2870 (label-format (or label-format org-coderef-label-format
))
2871 (label-pre (if (string-match "%s" label-format
)
2872 (substring label-format
0 (match-beginning 0))
2874 (label-post (if (string-match "%s" label-format
)
2875 (substring label-format
(match-end 0))
2879 ".*?\\S-.*?\\([ \t]*\\("
2880 (regexp-quote label-pre
)
2881 "\\([-a-zA-Z0-9_ ]+\\)"
2882 (regexp-quote label-post
)
2886 (org-goto-line (1+ skip1
))
2887 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2888 (when number
(incf n
))
2889 (if (or preprocess
(not number
))
2891 (insert (format fm n
)))
2892 (when (looking-at lbl-re
)
2893 (setq ref
(match-string 3))
2894 (cond ((numberp replace-labels
)
2895 ;; remove labels; use numbers for references when lines
2896 ;; are numbered, use labels otherwise
2897 (delete-region (match-beginning 1) (match-end 1))
2898 (push (cons ref
(if (> n
0) n ref
)) org-export-code-refs
))
2899 ((eq replace-labels
'keep
)
2900 ;; don't remove labels; use numbers for references when
2901 ;; lines are numbered, use labels otherwise
2902 (goto-char (match-beginning 2))
2903 (delete-region (match-beginning 2) (match-end 2))
2905 (insert "(" ref
")"))
2906 (push (cons ref
(if (> n
0) n
(concat "(" ref
")")))
2907 org-export-code-refs
))
2909 ;; don't remove labels and don't use numbers for
2911 (goto-char (match-beginning 2))
2912 (delete-region (match-beginning 2) (match-end 2))
2914 (insert "(" ref
")"))
2915 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
)))
2916 (when (and (eq org-export-current-backend
'html
) (not preprocess
))
2918 (beginning-of-line 1)
2919 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2922 (insert "</span>")))
2924 (add-text-properties
2925 (point-at-bol) (point-at-eol) (list 'org-coderef ref
)))))
2926 (setq org-export-last-code-line-counter-value n
)
2927 (goto-char (point-max))
2931 (defun org-search-todo-below (line lines level
)
2932 "Search the subtree below LINE for any TODO entries."
2933 (let ((rest (cdr (memq line lines
)))
2934 (re org-todo-line-regexp
)
2937 (while (setq line
(pop rest
))
2938 (if (string-match re line
)
2940 (setq lv
(- (match-end 1) (match-beginning 1))
2941 todo
(and (match-beginning 2)
2942 (not (member (match-string 2 line
)
2943 org-done-keywords
))))
2945 (if (<= lv level
) (throw 'exit nil
))
2946 (if todo
(throw 'exit t
))))))))
2949 (defun org-export-visible (type arg
)
2950 "Create a copy of the visible part of the current buffer, and export it.
2951 The copy is created in a temporary buffer and removed after use.
2952 TYPE is the final key (as a string) that also selects the export command in
2953 the \\<org-mode-map>\\[org-export] export dispatcher.
2954 As a special case, if the you type SPC at the prompt, the temporary
2955 org-mode file will not be removed but presented to you so that you can
2956 continue to use it. The prefix arg ARG is passed through to the exporting
2960 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]buffer with HTML [D]ocBook [l]atex [p]df [d]view pdf [L]atex buffer [x]OXO [ ]keep buffer")
2961 (read-char-exclusive))
2962 current-prefix-arg
))
2963 (if (not (member type
'(?a ?n ?u ?\C-a ?b ?\C-b ?h ?D ?x ?\ ?l ?p ?d ?L ?H ?R
)))
2964 (error "Invalid export key"))
2965 (let* ((binding (cdr (assoc type
2967 (?a . org-export-as-ascii
)
2968 (?A . org-export-as-ascii-to-buffer
)
2969 (?n . org-export-as-latin1
)
2970 (?N . org-export-as-latin1-to-buffer
)
2971 (?u . org-export-as-utf8
)
2972 (?U . org-export-as-utf8-to-buffer
)
2973 (?\C-a . org-export-as-ascii
)
2974 (?b . org-export-as-html-and-open
)
2975 (?\C-b . org-export-as-html-and-open
)
2976 (?h . org-export-as-html
)
2977 (?H . org-export-as-html-to-buffer
)
2978 (?R . org-export-region-as-html
)
2979 (?D . org-export-as-docbook
)
2981 (?l . org-export-as-latex
)
2982 (?p . org-export-as-pdf
)
2983 (?d . org-export-as-pdf-and-open
)
2984 (?L . org-export-as-latex-to-buffer
)
2986 (?x . org-export-as-xoxo
)))))
2987 (keepp (equal type ?\
))
2988 (file buffer-file-name
)
2989 (buffer (get-buffer-create "*Org Export Visible*"))
2991 ;; Need to hack the drawers here.
2993 (goto-char (point-min))
2994 (while (re-search-forward org-drawer-regexp nil t
)
2995 (goto-char (match-beginning 1))
2996 (or (outline-invisible-p) (org-flag-drawer nil
))))
2997 (with-current-buffer buffer
(erase-buffer))
2999 (setq s
(goto-char (point-min)))
3000 (while (not (= (point) (point-max)))
3001 (goto-char (org-find-invisible))
3002 (append-to-buffer buffer s
(point))
3003 (setq s
(goto-char (org-find-visible))))
3004 (org-cycle-hide-drawers 'all
)
3005 (goto-char (point-min))
3007 ;; Copy all comment lines to the end, to make sure #+ settings are
3008 ;; still available for the second export step. Kind of a hack, but
3009 ;; does do the trick.
3010 (if (looking-at "#[^\r\n]*")
3011 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
3012 (when (re-search-forward "^\\*+[ \t]+" nil t
)
3013 (while (re-search-backward "[\n\r]#[^\n\r]*" nil t
)
3014 (append-to-buffer buffer
(1+ (match-beginning 0))
3015 (min (point-max) (1+ (match-end 0)))))))
3017 (let ((buffer-file-name file
)
3018 (org-inhibit-startup t
))
3021 (unless keepp
(funcall binding arg
))))
3023 (kill-buffer buffer
)
3024 (switch-to-buffer-other-window buffer
)
3025 (goto-char (point-min)))))
3027 (defvar org-export-htmlized-org-css-url
) ;; defined in org-html.el
3029 (defun org-export-string (string fmt
&optional dir
)
3030 "Export STRING to FMT using existing export facilities.
3031 During export STRING is saved to a temporary file whose location
3032 could vary. Optional argument DIR can be used to force the
3033 directory in which the temporary file is created during export
3034 which can be useful for resolving relative paths. Dir defaults
3035 to the value of `temporary-file-directory'."
3036 (let ((temporary-file-directory (or dir temporary-file-directory
))
3037 (tmp-file (make-temp-file "org-")))
3041 (write-file tmp-file
)
3042 (org-load-modules-maybe)
3043 (unless org-local-vars
3044 (setq org-local-vars
(org-get-local-variables)))
3045 (eval ;; convert to fmt -- mimicking `org-run-like-in-org-mode'
3046 (list 'let org-local-vars
3047 (list (intern (format "org-export-as-%s" fmt
))
3048 nil nil nil
''string t
))))
3049 (delete-file tmp-file
))))
3052 (defun org-export-as-org (arg &optional hidden ext-plist
3053 to-buffer body-only pub-dir
)
3054 "Make a copy with not-exporting stuff removed.
3055 The purpose of this function is to provide a way to export the source
3056 Org file of a webpage in Org format, but with sensitive and/or irrelevant
3057 stuff removed. This command will remove the following:
3059 - archived trees (if the variable `org-export-with-archived-trees' is nil)
3060 - comment blocks and trees starting with the COMMENT keyword
3061 - only trees that are consistent with `org-export-select-tags'
3062 and `org-export-exclude-tags'.
3064 The only arguments that will be used are EXT-PLIST and PUB-DIR,
3065 all the others will be ignored (but are present so that the general
3066 mechanism to call publishing functions will work).
3068 EXT-PLIST is a property list with external parameters overriding
3069 org-mode's default settings, but still inferior to file-local
3070 settings. When PUB-DIR is set, use this as the publishing
3073 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
3075 (org-infile-export-plist)))
3076 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3077 (filename (concat (file-name-as-directory
3079 (org-export-directory :org opt-plist
)))
3080 (file-name-sans-extension
3081 (file-name-nondirectory bfname
))
3083 (filename (and filename
3084 (if (equal (file-truename filename
)
3085 (file-truename bfname
))
3086 (concat (file-name-sans-extension filename
)
3088 (file-name-extension filename
))
3090 (backup-inhibited t
)
3091 (buffer (find-file-noselect filename
))
3092 (region (buffer-string))
3095 (org-pop-to-buffer-same-window buffer
)
3098 (let ((org-inhibit-startup t
)) (org-mode))
3099 (org-install-letbind)
3101 ;; Get rid of archived trees
3102 (org-export-remove-archived-trees (plist-get opt-plist
:archived-trees
))
3104 ;; Remove comment environment and comment subtrees
3105 (org-export-remove-comment-blocks-and-subtrees)
3107 ;; Get rid of excluded trees
3108 (org-export-handle-export-tags (plist-get opt-plist
:select-tags
)
3109 (plist-get opt-plist
:exclude-tags
))
3111 (when (or (plist-get opt-plist
:plain-source
)
3112 (not (or (plist-get opt-plist
:plain-source
)
3113 (plist-get opt-plist
:htmlized-source
))))
3114 ;; Either nothing special is requested (default call)
3115 ;; or the plain source is explicitly requested
3118 (when (plist-get opt-plist
:htmlized-source
)
3119 ;; Make the htmlized version
3122 (font-lock-fontify-buffer)
3123 (let* ((htmlize-output-type 'css
)
3124 (newbuf (htmlize-buffer)))
3125 (with-current-buffer newbuf
3126 (when org-export-htmlized-org-css-url
3127 (goto-char (point-min))
3128 (and (re-search-forward
3129 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*"
3133 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
3134 org-export-htmlized-org-css-url
)
3136 (write-file (concat filename
".html")))
3137 (kill-buffer newbuf
)))
3138 (set-buffer-modified-p nil
)
3139 (if (equal to-buffer
'string
)
3140 (progn (setq str-ret
(buffer-string))
3141 (kill-buffer (current-buffer))
3143 (kill-buffer (current-buffer))))))
3145 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
3146 (defun org-get-current-options ()
3147 "Return a string with current options as keyword options.
3148 Does include HTML export options as well as TODO and CATEGORY stuff."
3149 (require 'org-archive
)
3158 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
3159 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
3161 #+EXPORT_SELECT_TAGS: %s
3162 #+EXPORT_EXCLUDE_TAGS: %s
3169 #+PRIORITIES: %c %c %c
3171 #+STARTUP: %s %s %s %s %s
3177 (buffer-name) (user-full-name) user-mail-address
3178 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
3179 org-export-default-language
3180 org-export-headline-levels
3181 org-export-with-section-numbers
3183 org-export-preserve-breaks
3184 org-export-html-expand
3185 org-export-with-fixed-width
3186 org-export-with-tables
3187 org-export-with-sub-superscripts
3188 org-export-with-special-strings
3189 org-export-with-footnotes
3190 org-export-with-emphasize
3191 org-export-with-timestamps
3192 org-export-with-TeX-macros
3193 org-export-with-LaTeX-fragments
3194 org-export-skip-text-before-1st-heading
3195 org-export-with-drawers
3196 org-export-with-todo-keywords
3197 org-export-with-priority
3198 org-export-with-tags
3199 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
3200 (mapconcat 'identity org-export-select-tags
" ")
3201 (mapconcat 'identity org-export-exclude-tags
" ")
3202 org-export-html-link-up
3203 org-export-html-link-home
3205 (file-name-sans-extension
3206 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3208 "TODO FEEDBACK VERIFY DONE"
3209 "Me Jason Marie DONE"
3210 org-highest-priority org-lowest-priority org-default-priority
3211 (mapconcat 'identity org-drawers
" ")
3212 (cdr (assoc org-startup-folded
3213 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3214 (if org-odd-levels-only
"odd" "oddeven")
3215 (if org-hide-leading-stars
"hidestars" "showstars")
3216 (if org-startup-align-all-tables
"align" "noalign")
3217 (cond ((eq org-log-done t
) "logdone")
3218 ((equal org-log-done
'note
) "lognotedone")
3219 ((not org-log-done
) "nologdone"))
3220 (or (mapconcat (lambda (x)
3222 ((equal :startgroup
(car x
)) "{")
3223 ((equal :endgroup
(car x
)) "}")
3224 ((equal :newline
(car x
)) "")
3225 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3227 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3228 (mapconcat 'identity org-file-tags
" ")
3229 org-archive-location
3230 "org file:~/org/%s.org"))
3233 (defun org-insert-export-options-template ()
3234 "Insert into the buffer a template with information for exporting."
3236 (if (not (bolp)) (newline))
3237 (let ((s (org-get-current-options)))
3238 (and (string-match "#\\+CATEGORY" s
)
3239 (setq s
(substring s
0 (match-beginning 0))))
3242 (defvar org-table-colgroup-info nil
)
3244 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
3245 "Check if the table has a marking column.
3246 If yes remove the column and the special lines."
3247 (setq org-table-colgroup-info nil
)
3250 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3253 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
3254 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
3257 ;; No special marking column
3259 (setq org-table-clean-did-remove-column nil
)
3264 ((org-table-colgroup-line-p x
)
3265 ;; This line contains colgroup info, extract it
3266 ;; and then discard the line
3267 (setq org-table-colgroup-info
3269 (cond ((member x
'("<" "<")) :start
)
3270 ((member x
'(">" ">")) :end
)
3271 ((member x
'("<>" "<>")) :startend
)))
3272 (org-split-string x
"[ \t]*|[ \t]*")))
3274 ((org-table-cookie-line-p x
)
3275 ;; This line contains formatting cookies, discard it
3279 ;; there is a special marking column
3280 (setq org-table-clean-did-remove-column t
)
3285 ((org-table-colgroup-line-p x
)
3286 ;; This line contains colgroup info, extract it
3287 ;; and then discard the line
3288 (setq org-table-colgroup-info
3290 (cond ((member x
'("<" "<")) :start
)
3291 ((member x
'(">" ">")) :end
)
3292 ((member x
'("<>" "<>")) :startend
)))
3293 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3295 ((org-table-cookie-line-p x
)
3296 ;; This line contains formatting cookies, discard it
3298 ((string-match "^[ \t]*| *\\([!_^/$]\\|\\\\\\$\\) *|" x
)
3301 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3302 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3303 ;; remove the first column
3304 (replace-match "\\1|" t nil x
))))
3307 (defun org-export-cleanup-toc-line (s)
3308 "Remove tags and timestamps from lines going into the toc."
3310 "" ; Return a string when argument is nil
3311 (when (memq org-export-with-tags
'(not-in-toc nil
))
3312 (if (string-match (org-re " +:[[:alnum:]_@#%:]+: *$") s
)
3313 (setq s
(replace-match "" t t s
))))
3314 (when org-export-remove-timestamps-from-toc
3315 (while (string-match org-maybe-keyword-time-regexp s
)
3316 (setq s
(replace-match "" t t s
))))
3317 (while (string-match org-bracket-link-regexp s
)
3318 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3320 (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s
)
3321 (setq s
(replace-match "" t t s
)))
3325 (defun org-get-text-property-any (pos prop
&optional object
)
3326 (or (get-text-property pos prop object
)
3327 (and (setq pos
(next-single-property-change pos prop object
))
3328 (get-text-property pos prop object
))))
3330 (defun org-export-get-coderef-format (path desc
)
3332 (if (and desc
(string-match
3333 (regexp-quote (concat "(" path
")"))
3335 (replace-match "%s" t t desc
)
3338 (defun org-export-push-to-kill-ring (format)
3339 "Push buffer content to kill ring.
3340 The depends on the variable `org-export-copy-to-kill-ring'."
3341 (when org-export-copy-to-kill-ring
3342 (org-kill-new (buffer-string))
3343 (when (fboundp 'x-set-selection
)
3344 (ignore-errors (x-set-selection 'PRIMARY
(buffer-string)))
3345 (ignore-errors (x-set-selection 'CLIPBOARD
(buffer-string))))
3346 (message "%s export done, pushed to kill ring and clipboard" format
)))
3350 ;;; org-exp.el ends here