Commit | Line | Data |
---|---|---|
20908596 CD |
1 | ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode |
2 | ||
49f70d46 | 3 | ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
1e4f816a | 4 | ;; Free Software Foundation, Inc. |
20908596 CD |
5 | |
6 | ;; Author: Carsten Dominik <carsten at orgmode dot org> | |
7 | ;; Keywords: outlines, hypermedia, calendar, wp | |
8 | ;; Homepage: http://orgmode.org | |
5dec9555 | 9 | ;; Version: 6.33x |
20908596 CD |
10 | ;; |
11 | ;; This file is part of GNU Emacs. | |
12 | ;; | |
b1fc2b50 | 13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
20908596 | 14 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
15 | ;; the Free Software Foundation, either version 3 of the License, or |
16 | ;; (at your option) any later version. | |
20908596 CD |
17 | |
18 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
20908596 CD |
25 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
26 | ;; | |
27 | ;;; Commentary: | |
28 | ||
29 | (require 'org) | |
8d642074 | 30 | (require 'org-macs) |
20908596 | 31 | (require 'org-agenda) |
c8d0cf5c | 32 | (require 'org-exp-blocks) |
8bfe682a | 33 | (require 'org-src) |
54a0dee5 | 34 | (eval-when-compile |
20908596 CD |
35 | (require 'cl)) |
36 | ||
c8d0cf5c CD |
37 | (declare-function org-export-latex-preprocess "org-latex" (parameters)) |
38 | (declare-function org-export-ascii-preprocess "org-ascii" (parameters)) | |
39 | (declare-function org-export-html-preprocess "org-html" (parameters)) | |
40 | (declare-function org-export-docbook-preprocess "org-docbook" (parameters)) | |
1371348a | 41 | (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ()) |
c8d0cf5c | 42 | (declare-function org-export-htmlize-region-for-paste "org-html" (beg end)) |
9d459fc5 | 43 | (declare-function htmlize-buffer "ext:htmlize" (&optional buffer)) |
8bfe682a | 44 | (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ()) |
c8d0cf5c | 45 | (autoload 'org-export-generic "org-export-generic" "Export using the generic exporter" t) |
20908596 CD |
46 | (defgroup org-export nil |
47 | "Options for exporting org-listings." | |
48 | :tag "Org Export" | |
49 | :group 'org) | |
50 | ||
51 | (defgroup org-export-general nil | |
52 | "General options for exporting Org-mode files." | |
53 | :tag "Org Export General" | |
54 | :group 'org-export) | |
55 | ||
c8d0cf5c CD |
56 | (defcustom org-export-allow-BIND 'confirm |
57 | "Non-nil means, allow #+BIND to define local variable values for export. | |
58 | This is a potential security risk, which is why the user must confirm the | |
59 | use of these lines." | |
60 | :group 'org-export-general | |
61 | :type '(choice | |
62 | (const :tag "Never" nil) | |
63 | (const :tag "Always" t) | |
64 | (const :tag "Make the user confirm for each file" confirm))) | |
65 | ||
20908596 CD |
66 | ;; FIXME |
67 | (defvar org-export-publishing-directory nil) | |
68 | ||
c8d0cf5c CD |
69 | (defcustom org-export-show-temporary-export-buffer t |
70 | "Non-nil means, show buffer after exporting to temp buffer. | |
71 | When Org exports to a file, the buffer visiting that file is ever | |
72 | shown, but remains buried. However, when exporting to a temporary | |
73 | buffer, that buffer is popped up in a second window. When this variable | |
74 | is nil, the buffer remains buried also in these cases." | |
75 | :group 'org-export-general | |
76 | :type 'boolean) | |
77 | ||
78 | (defcustom org-export-copy-to-kill-ring t | |
79 | "Non-nil means, exported stuff will also be pushed onto the kill ring." | |
80 | :group 'org-export-general | |
81 | :type 'boolean) | |
82 | ||
20908596 CD |
83 | (defcustom org-export-run-in-background nil |
84 | "Non-nil means export and publishing commands will run in background. | |
85 | This works by starting up a separate Emacs process visiting the same file | |
86 | and doing the export from there. | |
87 | Not all export commands are affected by this - only the ones which | |
88 | actually write to a file, and that do not depend on the buffer state. | |
89 | ||
90 | If this option is nil, you can still get background export by calling | |
91 | `org-export' with a double prefix arg: `C-u C-u C-c C-e'. | |
92 | ||
93 | If this option is t, the double prefix can be used to exceptionally | |
94 | force an export command into the current process." | |
95 | :group 'org-export-general | |
96 | :type 'boolean) | |
97 | ||
621f83e4 CD |
98 | (defcustom org-export-select-tags '("export") |
99 | "Tags that select a tree for export. | |
100 | If any such tag is found in a buffer, all trees that do not carry one | |
101 | of these tags will be deleted before export. | |
102 | Inside trees that are selected like this, you can still deselect a | |
93b62de8 | 103 | subtree by tagging it with one of the `org-export-exclude-tags'." |
621f83e4 CD |
104 | :group 'org-export-general |
105 | :type '(repeat (string :tag "Tag"))) | |
106 | ||
107 | (defcustom org-export-exclude-tags '("noexport") | |
108 | "Tags that exclude a tree from export. | |
109 | All trees carrying any of these tags will be excluded from export. | |
33306645 | 110 | This is without condition, so even subtrees inside that carry one of the |
621f83e4 CD |
111 | `org-export-select-tags' will be removed." |
112 | :group 'org-export-general | |
113 | :type '(repeat (string :tag "Tag"))) | |
114 | ||
c8d0cf5c CD |
115 | ;; FIXME: rename, this is a general variable |
116 | (defcustom org-export-html-expand t | |
117 | "Non-nil means, for HTML export, treat @<...> as HTML tag. | |
118 | When nil, these tags will be exported as plain text and therefore | |
119 | not be interpreted by a browser. | |
120 | ||
121 | This option can also be set with the +OPTIONS line, e.g. \"@:nil\"." | |
122 | :group 'org-export-html | |
123 | :group 'org-export-general | |
124 | :type 'boolean) | |
125 | ||
20908596 CD |
126 | (defcustom org-export-with-special-strings t |
127 | "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export. | |
128 | When this option is turned on, these strings will be exported as: | |
129 | ||
130 | Org HTML LaTeX | |
131 | -----+----------+-------- | |
132 | \\- ­ \\- | |
133 | -- – -- | |
134 | --- — --- | |
135 | ... … \ldots | |
136 | ||
137 | This option can also be set with the +OPTIONS line, e.g. \"-:nil\"." | |
138 | :group 'org-export-translation | |
139 | :type 'boolean) | |
140 | ||
c8d0cf5c CD |
141 | (defcustom org-export-html-link-up "" |
142 | "Where should the \"UP\" link of exported HTML pages lead?" | |
143 | :group 'org-export-html | |
144 | :group 'org-export-general | |
145 | :type '(string :tag "File or URL")) | |
146 | ||
147 | (defcustom org-export-html-link-home "" | |
148 | "Where should the \"HOME\" link of exported HTML pages lead?" | |
149 | :group 'org-export-html | |
150 | :group 'org-export-general | |
151 | :type '(string :tag "File or URL")) | |
152 | ||
20908596 | 153 | (defcustom org-export-language-setup |
93b62de8 CD |
154 | '(("en" "Author" "Date" "Table of Contents" "Footnotes") |
155 | ("ca" "Autor" "Data" "Índex" "Peus de pàgina") | |
156 | ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou") | |
157 | ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter") | |
158 | ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten") | |
159 | ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj") | |
160 | ("es" "Autor" "Fecha" "Índice" "Pies de página") | |
161 | ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet") | |
162 | ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page") | |
163 | ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet") | |
164 | ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar") | |
165 | ("it" "Autore" "Data" "Indice" "Note a piè di pagina") | |
166 | ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten") | |
167 | ("no" "Forfatter" "Dato" "Innhold" "Fotnoter") | |
168 | ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l) | |
169 | ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk) | |
170 | ("pl" "Autor" "Data" "Spis treści" "Przypis") | |
171 | ("sv" "Författare" "Datum" "Innehåll" "Fotnoter")) | |
20908596 CD |
172 | "Terms used in export text, translated to different languages. |
173 | Use the variable `org-export-default-language' to set the language, | |
174 | or use the +OPTION lines for a per-file setting." | |
175 | :group 'org-export-general | |
176 | :type '(repeat | |
177 | (list | |
178 | (string :tag "HTML language tag") | |
179 | (string :tag "Author") | |
180 | (string :tag "Date") | |
93b62de8 CD |
181 | (string :tag "Table of Contents") |
182 | (string :tag "Footnotes")))) | |
20908596 CD |
183 | |
184 | (defcustom org-export-default-language "en" | |
185 | "The default language of HTML export, as a string. | |
186 | This should have an association in `org-export-language-setup'." | |
187 | :group 'org-export-general | |
188 | :type 'string) | |
189 | ||
c8d0cf5c CD |
190 | (defvar org-export-page-description "" |
191 | "The page description, for the XHTML meta tag. | |
192 | This is best set with the #+DESCRIPTION line in a file, it does not make | |
193 | sense to set this globally.") | |
194 | ||
195 | (defvar org-export-page-keywords "" | |
196 | "The page description, for the XHTML meta tag. | |
197 | This is best set with the #+KEYWORDS line in a file, it does not make | |
198 | sense to set this globally.") | |
199 | ||
b349f79f | 200 | (defcustom org-export-skip-text-before-1st-heading nil |
20908596 CD |
201 | "Non-nil means, skip all text before the first headline when exporting. |
202 | When nil, that text is exported as well." | |
203 | :group 'org-export-general | |
204 | :type 'boolean) | |
205 | ||
206 | (defcustom org-export-headline-levels 3 | |
207 | "The last level which is still exported as a headline. | |
208 | Inferior levels will produce itemize lists when exported. | |
209 | Note that a numeric prefix argument to an exporter function overrides | |
210 | this setting. | |
211 | ||
212 | This option can also be set with the +OPTIONS line, e.g. \"H:2\"." | |
213 | :group 'org-export-general | |
c8d0cf5c | 214 | :type 'integer) |
20908596 CD |
215 | |
216 | (defcustom org-export-with-section-numbers t | |
217 | "Non-nil means, add section numbers to headlines when exporting. | |
218 | ||
219 | This option can also be set with the +OPTIONS line, e.g. \"num:t\"." | |
220 | :group 'org-export-general | |
221 | :type 'boolean) | |
222 | ||
b349f79f CD |
223 | (defcustom org-export-section-number-format '((("1" ".")) . "") |
224 | "Format of section numbers for export. | |
225 | The variable has two components. | |
226 | 1. A list of lists, each indicating a counter type and a separator. | |
227 | The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\". | |
228 | It causes causes numeric, alphabetic, or roman counters, respectively. | |
229 | The separator is only used if another counter for a subsection is being | |
230 | added. | |
231 | If there are more numbered section levels than entries in this lists, | |
232 | then the last entry will be reused. | |
233 | 2. A terminator string that will be added after the entire | |
234 | section number." | |
235 | :group 'org-export-general | |
236 | :type '(cons | |
237 | (repeat | |
238 | (list | |
239 | (string :tag "Counter Type") | |
240 | (string :tag "Separator "))) | |
241 | (string :tag "Terminator"))) | |
242 | ||
20908596 CD |
243 | (defcustom org-export-with-toc t |
244 | "Non-nil means, create a table of contents in exported files. | |
245 | The TOC contains headlines with levels up to`org-export-headline-levels'. | |
246 | When an integer, include levels up to N in the toc, this may then be | |
247 | different from `org-export-headline-levels', but it will not be allowed | |
248 | to be larger than the number of headline levels. | |
249 | When nil, no table of contents is made. | |
250 | ||
251 | Headlines which contain any TODO items will be marked with \"(*)\" in | |
252 | ASCII export, and with red color in HTML output, if the option | |
253 | `org-export-mark-todo-in-toc' is set. | |
254 | ||
255 | In HTML output, the TOC will be clickable. | |
256 | ||
257 | This option can also be set with the +OPTIONS line, e.g. \"toc:nil\" | |
258 | or \"toc:3\"." | |
259 | :group 'org-export-general | |
260 | :type '(choice | |
261 | (const :tag "No Table of Contents" nil) | |
262 | (const :tag "Full Table of Contents" t) | |
263 | (integer :tag "TOC to level"))) | |
264 | ||
265 | (defcustom org-export-mark-todo-in-toc nil | |
266 | "Non-nil means, mark TOC lines that contain any open TODO items." | |
267 | :group 'org-export-general | |
268 | :type 'boolean) | |
269 | ||
ff4be292 CD |
270 | (defcustom org-export-with-todo-keywords t |
271 | "Non-nil means, include TODO keywords in export. | |
272 | When nil, remove all these keywords from the export." | |
273 | :group 'org-export-general | |
274 | :type 'boolean) | |
275 | ||
276 | (defcustom org-export-with-priority nil | |
277 | "Non-nil means, include priority cookies in export. | |
278 | When nil, remove priority cookies for export." | |
279 | :group 'org-export-general | |
280 | :type 'boolean) | |
281 | ||
20908596 CD |
282 | (defcustom org-export-preserve-breaks nil |
283 | "Non-nil means, preserve all line breaks when exporting. | |
284 | Normally, in HTML output paragraphs will be reformatted. In ASCII | |
285 | export, line breaks will always be preserved, regardless of this variable. | |
286 | ||
287 | This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"." | |
288 | :group 'org-export-general | |
289 | :type 'boolean) | |
290 | ||
291 | (defcustom org-export-with-archived-trees 'headline | |
292 | "Whether subtrees with the ARCHIVE tag should be exported. | |
293 | This can have three different values | |
294 | nil Do not export, pretend this tree is not present | |
295 | t Do export the entire tree | |
296 | headline Only export the headline, but skip the tree below it." | |
297 | :group 'org-export-general | |
298 | :group 'org-archive | |
299 | :type '(choice | |
300 | (const :tag "not at all" nil) | |
301 | (const :tag "headline only" 'headline) | |
302 | (const :tag "entirely" t))) | |
303 | ||
304 | (defcustom org-export-author-info t | |
305 | "Non-nil means, insert author name and email into the exported file. | |
306 | ||
307 | This option can also be set with the +OPTIONS line, | |
308 | e.g. \"author-info:nil\"." | |
309 | :group 'org-export-general | |
310 | :type 'boolean) | |
311 | ||
2c3ad40d | 312 | (defcustom org-export-creator-info t |
33306645 | 313 | "Non-nil means, the postamble should contain a creator sentence. |
2c3ad40d CD |
314 | This sentence is \"HTML generated by org-mode XX in emacs XXX\"." |
315 | :group 'org-export-general | |
316 | :type 'boolean) | |
317 | ||
20908596 CD |
318 | (defcustom org-export-time-stamp-file t |
319 | "Non-nil means, insert a time stamp into the exported file. | |
320 | The time stamp shows when the file was created. | |
321 | ||
322 | This option can also be set with the +OPTIONS line, | |
323 | e.g. \"timestamp:nil\"." | |
324 | :group 'org-export-general | |
325 | :type 'boolean) | |
326 | ||
327 | (defcustom org-export-with-timestamps t | |
328 | "If nil, do not export time stamps and associated keywords." | |
329 | :group 'org-export-general | |
330 | :type 'boolean) | |
331 | ||
332 | (defcustom org-export-remove-timestamps-from-toc t | |
c8d0cf5c | 333 | "If t, remove timestamps from the table of contents entries." |
20908596 CD |
334 | :group 'org-export-general |
335 | :type 'boolean) | |
336 | ||
337 | (defcustom org-export-with-tags 'not-in-toc | |
338 | "If nil, do not export tags, just remove them from headlines. | |
339 | If this is the symbol `not-in-toc', tags will be removed from table of | |
340 | contents entries, but still be shown in the headlines of the document. | |
341 | ||
342 | This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"." | |
343 | :group 'org-export-general | |
344 | :type '(choice | |
345 | (const :tag "Off" nil) | |
346 | (const :tag "Not in TOC" not-in-toc) | |
347 | (const :tag "On" t))) | |
348 | ||
349 | (defcustom org-export-with-drawers nil | |
350 | "Non-nil means, export with drawers like the property drawer. | |
351 | When t, all drawers are exported. This may also be a list of | |
352 | drawer names to export." | |
353 | :group 'org-export-general | |
354 | :type '(choice | |
355 | (const :tag "All drawers" t) | |
356 | (const :tag "None" nil) | |
357 | (repeat :tag "Selected drawers" | |
358 | (string :tag "Drawer name")))) | |
359 | ||
b349f79f CD |
360 | (defvar org-export-preprocess-hook nil |
361 | "Hook for preprocessing an export buffer. | |
362 | Pretty much the first thing when exporting is running this hook.") | |
363 | ||
0bd48b37 CD |
364 | (defvar org-export-preprocess-after-include-files-hook nil |
365 | "Hook for preprocessing an export buffer. | |
366 | This is run after the contents of included files have been inserted.") | |
367 | ||
368 | (defvar org-export-preprocess-after-tree-selection-hook nil | |
369 | "Hook for preprocessing an export buffer. | |
370 | This is run after selection of trees to be exported has happened. | |
371 | This selection includes tags-based selection, as well as removal | |
372 | of commented and archived trees.") | |
373 | ||
c8d0cf5c CD |
374 | (defvar org-export-preprocess-after-blockquote-hook nil |
375 | "Hook for preprocessing an export buffer. | |
376 | This is run after blockquote/quote/verse/center have been marked | |
377 | with cookies.") | |
378 | ||
0bd48b37 CD |
379 | (defvar org-export-preprocess-before-backend-specifics-hook nil |
380 | "Hook run before backend-specific functions are called during preprocessing.") | |
381 | ||
382 | (defvar org-export-preprocess-final-hook nil | |
383 | "Hook for preprocessing an export buffer. | |
384 | This is run as the last thing in the preprocessing buffer, just before | |
385 | returning the buffer string to the backend.") | |
386 | ||
20908596 CD |
387 | (defgroup org-export-translation nil |
388 | "Options for translating special ascii sequences for the export backends." | |
389 | :tag "Org Export Translation" | |
390 | :group 'org-export) | |
391 | ||
392 | (defcustom org-export-with-emphasize t | |
393 | "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text. | |
394 | If the export target supports emphasizing text, the word will be | |
395 | typeset in bold, italic, or underlined, respectively. Works only for | |
396 | single words, but you can say: I *really* *mean* *this*. | |
397 | Not all export backends support this. | |
398 | ||
399 | This option can also be set with the +OPTIONS line, e.g. \"*:nil\"." | |
400 | :group 'org-export-translation | |
401 | :type 'boolean) | |
402 | ||
403 | (defcustom org-export-with-footnotes t | |
404 | "If nil, export [1] as a footnote marker. | |
405 | Lines starting with [1] will be formatted as footnotes. | |
406 | ||
407 | This option can also be set with the +OPTIONS line, e.g. \"f:nil\"." | |
408 | :group 'org-export-translation | |
409 | :type 'boolean) | |
410 | ||
411 | (defcustom org-export-with-sub-superscripts t | |
412 | "Non-nil means, interpret \"_\" and \"^\" for export. | |
413 | When this option is turned on, you can use TeX-like syntax for sub- and | |
414 | superscripts. Several characters after \"_\" or \"^\" will be | |
415 | considered as a single item - so grouping with {} is normally not | |
416 | needed. For example, the following things will be parsed as single | |
417 | sub- or superscripts. | |
418 | ||
419 | 10^24 or 10^tau several digits will be considered 1 item. | |
420 | 10^-12 or 10^-tau a leading sign with digits or a word | |
421 | x^2-y^3 will be read as x^2 - y^3, because items are | |
422 | terminated by almost any nonword/nondigit char. | |
423 | x_{i^2} or x^(2-i) braces or parenthesis do grouping. | |
424 | ||
425 | Still, ambiguity is possible - so when in doubt use {} to enclose the | |
426 | sub/superscript. If you set this variable to the symbol `{}', | |
427 | the braces are *required* in order to trigger interpretations as | |
428 | sub/superscript. This can be helpful in documents that need \"_\" | |
429 | frequently in plain text. | |
430 | ||
431 | Not all export backends support this, but HTML does. | |
432 | ||
433 | This option can also be set with the +OPTIONS line, e.g. \"^:nil\"." | |
434 | :group 'org-export-translation | |
435 | :type '(choice | |
436 | (const :tag "Always interpret" t) | |
437 | (const :tag "Only with braces" {}) | |
438 | (const :tag "Never interpret" nil))) | |
439 | ||
20908596 CD |
440 | (defcustom org-export-with-TeX-macros t |
441 | "Non-nil means, interpret simple TeX-like macros when exporting. | |
442 | For example, HTML export converts \\alpha to α and \\AA to Å. | |
0bd48b37 | 443 | Not only real TeX macros will work here, but the standard HTML entities |
20908596 CD |
444 | for math can be used as macro names as well. For a list of supported |
445 | names in HTML export, see the constant `org-html-entities'. | |
446 | Not all export backends support this. | |
447 | ||
448 | This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"." | |
449 | :group 'org-export-translation | |
450 | :group 'org-export-latex | |
451 | :type 'boolean) | |
452 | ||
453 | (defcustom org-export-with-LaTeX-fragments nil | |
454 | "Non-nil means, convert LaTeX fragments to images when exporting to HTML. | |
455 | When set, the exporter will find LaTeX environments if the \\begin line is | |
456 | the first non-white thing on a line. It will also find the math delimiters | |
457 | like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for | |
458 | display math. | |
459 | ||
c8d0cf5c CD |
460 | This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\". |
461 | ||
462 | The default is nil, because this option needs the `dvipng' program which | |
463 | is not available on all systems." | |
20908596 CD |
464 | :group 'org-export-translation |
465 | :group 'org-export-latex | |
466 | :type 'boolean) | |
467 | ||
468 | (defcustom org-export-with-fixed-width t | |
469 | "Non-nil means, lines starting with \":\" will be in fixed width font. | |
470 | This can be used to have pre-formatted text, fragments of code etc. For | |
471 | example: | |
472 | : ;; Some Lisp examples | |
473 | : (while (defc cnt) | |
474 | : (ding)) | |
475 | will be looking just like this in also HTML. See also the QUOTE keyword. | |
476 | Not all export backends support this. | |
477 | ||
478 | This option can also be set with the +OPTIONS line, e.g. \"::nil\"." | |
479 | :group 'org-export-translation | |
480 | :type 'boolean) | |
481 | ||
482 | (defcustom org-match-sexp-depth 3 | |
483 | "Number of stacked braces for sub/superscript matching. | |
484 | This has to be set before loading org.el to be effective." | |
485 | :group 'org-export-translation | |
486 | :type 'integer) | |
487 | ||
488 | (defgroup org-export-tables nil | |
489 | "Options for exporting tables in Org-mode." | |
490 | :tag "Org Export Tables" | |
491 | :group 'org-export) | |
492 | ||
493 | (defcustom org-export-with-tables t | |
494 | "If non-nil, lines starting with \"|\" define a table. | |
495 | For example: | |
496 | ||
497 | | Name | Address | Birthday | | |
498 | |-------------+----------+-----------| | |
499 | | Arthur Dent | England | 29.2.2100 | | |
500 | ||
501 | Not all export backends support this. | |
502 | ||
503 | This option can also be set with the +OPTIONS line, e.g. \"|:nil\"." | |
504 | :group 'org-export-tables | |
505 | :type 'boolean) | |
506 | ||
507 | (defcustom org-export-highlight-first-table-line t | |
508 | "Non-nil means, highlight the first table line. | |
509 | In HTML export, this means use <th> instead of <td>. | |
510 | In tables created with table.el, this applies to the first table line. | |
511 | In Org-mode tables, all lines before the first horizontal separator | |
512 | line will be formatted with <th> tags." | |
513 | :group 'org-export-tables | |
514 | :type 'boolean) | |
515 | ||
516 | (defcustom org-export-table-remove-special-lines t | |
517 | "Remove special lines and marking characters in calculating tables. | |
518 | This removes the special marking character column from tables that are set | |
519 | up for spreadsheet calculations. It also removes the entire lines | |
520 | marked with `!', `_', or `^'. The lines with `$' are kept, because | |
521 | the values of constants may be useful to have." | |
522 | :group 'org-export-tables | |
523 | :type 'boolean) | |
524 | ||
525 | (defcustom org-export-prefer-native-exporter-for-tables nil | |
526 | "Non-nil means, always export tables created with table.el natively. | |
527 | Natively means, use the HTML code generator in table.el. | |
528 | When nil, Org-mode's own HTML generator is used when possible (i.e. if | |
529 | the table does not use row- or column-spanning). This has the | |
530 | advantage, that the automatic HTML conversions for math symbols and | |
531 | sub/superscripts can be applied. Org-mode's HTML generator is also | |
532 | much faster." | |
533 | :group 'org-export-tables | |
534 | :type 'boolean) | |
535 | ||
20908596 CD |
536 | |
537 | (defgroup org-export-xml nil | |
538 | "Options specific for XML export of Org-mode files." | |
539 | :tag "Org Export XML" | |
540 | :group 'org-export) | |
541 | ||
20908596 CD |
542 | ;;;; Exporting |
543 | ||
544 | ;;; Variables, constants, and parameter plists | |
545 | ||
546 | (defconst org-level-max 20) | |
547 | ||
20908596 CD |
548 | (defvar org-current-export-file nil) ; dynamically scoped parameter |
549 | (defvar org-current-export-dir nil) ; dynamically scoped parameter | |
c8d0cf5c CD |
550 | (defvar org-export-opt-plist nil |
551 | "Contains the current option plist.") | |
552 | (defvar org-last-level nil) ; dynamically scoped variable | |
553 | (defvar org-min-level nil) ; dynamically scoped variable | |
554 | (defvar org-levels-open nil) ; dynamically scoped parameter | |
20908596 CD |
555 | |
556 | (defconst org-export-plist-vars | |
33306645 CD |
557 | '((:link-up nil org-export-html-link-up) |
558 | (:link-home nil org-export-html-link-home) | |
559 | (:language nil org-export-default-language) | |
c8d0cf5c CD |
560 | (:keywords nil org-export-page-keywords) |
561 | (:description nil org-export-page-description) | |
33306645 CD |
562 | (:customtime nil org-display-custom-times) |
563 | (:headline-levels "H" org-export-headline-levels) | |
564 | (:section-numbers "num" org-export-with-section-numbers) | |
565 | (:section-number-format nil org-export-section-number-format) | |
566 | (:table-of-contents "toc" org-export-with-toc) | |
567 | (:preserve-breaks "\\n" org-export-preserve-breaks) | |
568 | (:archived-trees nil org-export-with-archived-trees) | |
569 | (:emphasize "*" org-export-with-emphasize) | |
570 | (:sub-superscript "^" org-export-with-sub-superscripts) | |
571 | (:special-strings "-" org-export-with-special-strings) | |
572 | (:footnotes "f" org-export-with-footnotes) | |
573 | (:drawers "d" org-export-with-drawers) | |
574 | (:tags "tags" org-export-with-tags) | |
575 | (:todo-keywords "todo" org-export-with-todo-keywords) | |
576 | (:priority "pri" org-export-with-priority) | |
577 | (:TeX-macros "TeX" org-export-with-TeX-macros) | |
578 | (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments) | |
54a0dee5 | 579 | (:latex-listings nil org-export-latex-listings) |
33306645 CD |
580 | (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading) |
581 | (:fixed-width ":" org-export-with-fixed-width) | |
582 | (:timestamps "<" org-export-with-timestamps) | |
583 | (:author-info "author" org-export-author-info) | |
584 | (:creator-info "creator" org-export-creator-info) | |
585 | (:time-stamp-file "timestamp" org-export-time-stamp-file) | |
586 | (:tables "|" org-export-with-tables) | |
587 | (:table-auto-headline nil org-export-highlight-first-table-line) | |
588 | (:style-include-default nil org-export-html-style-include-default) | |
c8d0cf5c | 589 | (:style-include-scripts nil org-export-html-style-include-scripts) |
33306645 CD |
590 | (:style nil org-export-html-style) |
591 | (:style-extra nil org-export-html-style-extra) | |
592 | (:agenda-style nil org-agenda-export-html-style) | |
593 | (:convert-org-links nil org-export-html-link-org-files-as-html) | |
594 | (:inline-images nil org-export-html-inline-images) | |
595 | (:html-extension nil org-export-html-extension) | |
c8d0cf5c | 596 | (:xml-declaration nil org-export-html-xml-declaration) |
33306645 CD |
597 | (:html-table-tag nil org-export-html-table-tag) |
598 | (:expand-quoted-html "@" org-export-html-expand) | |
599 | (:timestamp nil org-export-html-with-timestamp) | |
600 | (:publishing-directory nil org-export-publishing-directory) | |
601 | (:preamble nil org-export-html-preamble) | |
602 | (:postamble nil org-export-html-postamble) | |
603 | (:auto-preamble nil org-export-html-auto-preamble) | |
604 | (:auto-postamble nil org-export-html-auto-postamble) | |
605 | (:author nil user-full-name) | |
606 | (:email nil user-mail-address) | |
607 | (:select-tags nil org-export-select-tags) | |
c8d0cf5c CD |
608 | (:exclude-tags nil org-export-exclude-tags) |
609 | ||
610 | (:latex-image-options nil org-export-latex-image-default-option)) | |
ff4be292 CD |
611 | "List of properties that represent export/publishing variables. |
612 | Each element is a list of 3 items: | |
613 | 1. The property that is used internally, and also for org-publish-project-alist | |
614 | 2. The string that can be used in the OPTION lines to set this option, | |
615 | or nil if this option cannot be changed in this way | |
616 | 3. The customization variable that sets the default for this option." | |
ff4be292 | 617 | ) |
20908596 CD |
618 | |
619 | (defun org-default-export-plist () | |
620 | "Return the property list with default settings for the export variables." | |
c8d0cf5c CD |
621 | (let* ((infile (org-infile-export-plist)) |
622 | (letbind (plist-get infile :let-bind)) | |
623 | (l org-export-plist-vars) rtn e s v) | |
20908596 | 624 | (while (setq e (pop l)) |
c8d0cf5c CD |
625 | (setq s (nth 2 e) |
626 | v (cond | |
627 | ((assq s letbind) (nth 1 (assq s letbind))) | |
628 | ((boundp s) (symbol-value s)) | |
629 | (t nil)) | |
630 | rtn (cons (car e) (cons v rtn)))) | |
20908596 CD |
631 | rtn)) |
632 | ||
633 | (defvar org-export-inbuffer-options-extra nil | |
634 | "List of additional in-buffer options that should be detected. | |
635 | Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL, | |
636 | etc. Extensions can add to this list to get their options detected, and they | |
637 | can then add a function to `org-export-options-filters' to process these | |
638 | options. | |
639 | Each element in this list must be a list, with the in-buffer keyword as car, | |
33306645 | 640 | and a property (a symbol) as the next element. All occurrences of the |
20908596 CD |
641 | keyword will be found, the values concatenated with a space character |
642 | in between, and the result stored in the export options property list.") | |
643 | ||
644 | (defvar org-export-options-filters nil | |
645 | "Functions to be called to finalize the export/publishing options. | |
646 | All these options are stored in a property list, and each of the functions | |
647 | in this hook gets a chance to modify this property list. Each function | |
648 | must accept the property list as an argument, and must return the (possibly | |
649 | modified) list.") | |
650 | ||
71d35b24 | 651 | ;; FIXME: should we fold case here? |
20908596 CD |
652 | (defun org-infile-export-plist () |
653 | "Return the property list with file-local settings for export." | |
654 | (save-excursion | |
655 | (save-restriction | |
656 | (widen) | |
b349f79f | 657 | (goto-char (point-min)) |
20908596 CD |
658 | (let ((re (org-make-options-regexp |
659 | (append | |
660 | '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE" | |
8d642074 CD |
661 | "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" |
662 | "LATEX_HEADER" "LATEX_CLASS" | |
c8d0cf5c CD |
663 | "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS" |
664 | "KEYWORDS" "DESCRIPTION" "MACRO" "BIND") | |
20908596 | 665 | (mapcar 'car org-export-inbuffer-options-extra)))) |
65c439fd | 666 | p key val text options a pr style |
8d642074 | 667 | latex-header latex-class macros letbind |
b349f79f CD |
668 | ext-setup-or-nil setup-contents (start 0)) |
669 | (while (or (and ext-setup-or-nil | |
670 | (string-match re ext-setup-or-nil start) | |
671 | (setq start (match-end 0))) | |
672 | (and (setq ext-setup-or-nil nil start 0) | |
673 | (re-search-forward re nil t))) | |
674 | (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil)) | |
675 | val (org-match-string-no-properties 2 ext-setup-or-nil)) | |
20908596 CD |
676 | (cond |
677 | ((setq a (assoc key org-export-inbuffer-options-extra)) | |
678 | (setq pr (nth 1 a)) | |
679 | (setq p (plist-put p pr (concat (plist-get p pr) " " val)))) | |
680 | ((string-equal key "TITLE") (setq p (plist-put p :title val))) | |
681 | ((string-equal key "AUTHOR")(setq p (plist-put p :author val))) | |
682 | ((string-equal key "EMAIL") (setq p (plist-put p :email val))) | |
683 | ((string-equal key "DATE") (setq p (plist-put p :date val))) | |
c8d0cf5c CD |
684 | ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val))) |
685 | ((string-equal key "DESCRIPTION") | |
686 | (setq p (plist-put p :description val))) | |
20908596 | 687 | ((string-equal key "LANGUAGE") (setq p (plist-put p :language val))) |
621f83e4 CD |
688 | ((string-equal key "STYLE") |
689 | (setq style (concat style "\n" val))) | |
690 | ((string-equal key "LATEX_HEADER") | |
691 | (setq latex-header (concat latex-header "\n" val))) | |
8d642074 CD |
692 | ((string-equal key "LATEX_CLASS") |
693 | (setq latex-class val)) | |
20908596 CD |
694 | ((string-equal key "TEXT") |
695 | (setq text (if text (concat text "\n" val) val))) | |
696 | ((string-equal key "OPTIONS") | |
b349f79f | 697 | (setq options (concat val " " options))) |
c8d0cf5c CD |
698 | ((string-equal key "BIND") |
699 | (push (read (concat "(" val ")")) letbind)) | |
20908596 CD |
700 | ((string-equal key "LINK_UP") |
701 | (setq p (plist-put p :link-up val))) | |
702 | ((string-equal key "LINK_HOME") | |
b349f79f | 703 | (setq p (plist-put p :link-home val))) |
621f83e4 CD |
704 | ((string-equal key "EXPORT_SELECT_TAGS") |
705 | (setq p (plist-put p :select-tags (org-split-string val)))) | |
706 | ((string-equal key "EXPORT_EXCLUDE_TAGS") | |
707 | (setq p (plist-put p :exclude-tags (org-split-string val)))) | |
c8d0cf5c CD |
708 | ((string-equal key "MACRO") |
709 | (push val macros)) | |
b349f79f CD |
710 | ((equal key "SETUPFILE") |
711 | (setq setup-contents (org-file-contents | |
712 | (expand-file-name | |
713 | (org-remove-double-quotes | |
714 | (org-trim val))) | |
715 | 'noerror)) | |
716 | (if (not ext-setup-or-nil) | |
717 | (setq ext-setup-or-nil setup-contents start 0) | |
718 | (setq ext-setup-or-nil | |
719 | (concat (substring ext-setup-or-nil 0 start) | |
720 | "\n" setup-contents "\n" | |
721 | (substring ext-setup-or-nil start))))))) | |
20908596 | 722 | (setq p (plist-put p :text text)) |
c8d0cf5c CD |
723 | (when (and letbind (org-export-confirm-letbind)) |
724 | (setq p (plist-put p :let-bind letbind))) | |
621f83e4 CD |
725 | (when style (setq p (plist-put p :style-extra style))) |
726 | (when latex-header | |
727 | (setq p (plist-put p :latex-header-extra (substring latex-header 1)))) | |
8d642074 CD |
728 | (when latex-class |
729 | (setq p (plist-put p :latex-class latex-class))) | |
20908596 | 730 | (when options |
b349f79f | 731 | (setq p (org-export-add-options-to-plist p options))) |
c8d0cf5c CD |
732 | ;; Add macro definitions |
733 | (setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))")) | |
734 | (setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))")) | |
735 | (setq p (plist-put | |
736 | p :macro-modification-time | |
737 | (and (buffer-file-name) | |
738 | (file-exists-p (buffer-file-name)) | |
739 | (concat | |
740 | "(eval (format-time-string \"$1\" '" | |
741 | (prin1-to-string (nth 5 (file-attributes | |
742 | (buffer-file-name)))) | |
743 | "))")))) | |
744 | (setq p (plist-put p :macro-input-file (and (buffer-file-name) | |
745 | (file-name-nondirectory | |
746 | (buffer-file-name))))) | |
747 | (while (setq val (pop macros)) | |
748 | (when (string-match "^\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)" val) | |
749 | (setq p (plist-put | |
750 | p (intern | |
751 | (concat ":macro-" (downcase (match-string 1 val)))) | |
54a0dee5 | 752 | (org-export-interpolate-newlines (match-string 2 val)))))) |
20908596 CD |
753 | p)))) |
754 | ||
54a0dee5 CD |
755 | (defun org-export-interpolate-newlines (s) |
756 | (while (string-match "\\\\n" s) | |
757 | (setq s (replace-match "\n" t t s))) | |
758 | s) | |
759 | ||
c8d0cf5c CD |
760 | (defvar org-export-allow-BIND-local nil) |
761 | (defun org-export-confirm-letbind () | |
762 | "Can we use #+BIND values during export? | |
763 | By default this will ask fro confirmation by the user, to divert possible | |
764 | security risks." | |
765 | (cond | |
766 | ((not org-export-allow-BIND) nil) | |
767 | ((eq org-export-allow-BIND t) t) | |
768 | ((local-variable-p 'org-export-allow-BIND-local (current-buffer)) | |
769 | org-export-allow-BIND-local) | |
770 | (t (org-set-local 'org-export-allow-BIND-local | |
771 | (yes-or-no-p "Allow BIND values in this buffer? "))))) | |
772 | ||
773 | (defun org-install-letbind () | |
774 | "Install the values from #+BIND lines as local variables." | |
775 | (let ((letbind (plist-get org-export-opt-plist :let-bind))) | |
776 | (while letbind | |
777 | (org-set-local (caar letbind) (nth 1 (pop letbind)))))) | |
778 | ||
b349f79f | 779 | (defun org-export-add-options-to-plist (p options) |
33306645 | 780 | "Parse an OPTIONS line and set values in the property list P." |
b349f79f CD |
781 | (let (o) |
782 | (when options | |
65c439fd | 783 | (let ((op org-export-plist-vars)) |
b349f79f | 784 | (while (setq o (pop op)) |
ff4be292 CD |
785 | (if (and (nth 1 o) |
786 | (string-match (concat (regexp-quote (nth 1 o)) | |
787 | ":\\([^ \t\n\r;,.]*\\)") | |
788 | options)) | |
789 | (setq p (plist-put p (car o) | |
b349f79f CD |
790 | (car (read-from-string |
791 | (match-string 1 options)))))))))) | |
792 | p) | |
ff4be292 | 793 | |
b349f79f CD |
794 | (defun org-export-add-subtree-options (p pos) |
795 | "Add options in subtree at position POS to property list P." | |
796 | (save-excursion | |
797 | (goto-char pos) | |
798 | (when (org-at-heading-p) | |
799 | (let (a) | |
800 | ;; This is actually read in `org-export-get-title-from-subtree' | |
801 | ;; (when (setq a (org-entry-get pos "EXPORT_TITLE")) | |
802 | ;; (setq p (plist-put p :title a))) | |
803 | (when (setq a (org-entry-get pos "EXPORT_TEXT")) | |
804 | (setq p (plist-put p :text a))) | |
c8d0cf5c CD |
805 | (when (setq a (org-entry-get pos "EXPORT_AUTHOR")) |
806 | (setq p (plist-put p :author a))) | |
807 | (when (setq a (org-entry-get pos "EXPORT_DATE")) | |
808 | (setq p (plist-put p :date a))) | |
b349f79f CD |
809 | (when (setq a (org-entry-get pos "EXPORT_OPTIONS")) |
810 | (setq p (org-export-add-options-to-plist p a))))) | |
811 | p)) | |
812 | ||
20908596 CD |
813 | (defun org-export-directory (type plist) |
814 | (let* ((val (plist-get plist :publishing-directory)) | |
815 | (dir (if (listp val) | |
816 | (or (cdr (assoc type val)) ".") | |
817 | val))) | |
818 | dir)) | |
819 | ||
b349f79f CD |
820 | (defun org-export-process-option-filters (plist) |
821 | (let ((functions org-export-options-filters) f) | |
822 | (while (setq f (pop functions)) | |
823 | (setq plist (funcall f plist)))) | |
824 | plist) | |
825 | ||
20908596 CD |
826 | ;;;###autoload |
827 | (defun org-export (&optional arg) | |
828 | "Export dispatcher for Org-mode. | |
829 | When `org-export-run-in-background' is non-nil, try to run the command | |
830 | in the background. This will be done only for commands that write | |
831 | to a file. For details see the docstring of `org-export-run-in-background'. | |
832 | ||
833 | The prefix argument ARG will be passed to the exporter. However, if | |
834 | ARG is a double universal prefix `C-u C-u', that means to inverse the | |
835 | value of `org-export-run-in-background'." | |
836 | (interactive "P") | |
837 | (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background)) | |
838 | (help "[t] insert the export option template | |
839 | \[v] limit export to visible part of outline tree | |
840 | ||
c8d0cf5c | 841 | \[a] export as ASCII [A] to temporary buffer |
20908596 | 842 | |
c8d0cf5c CD |
843 | \[h] export as HTML [H] to temporary buffer [R] export region |
844 | \[b] export as HTML and open in browser | |
20908596 | 845 | |
c8d0cf5c | 846 | \[l] export as LaTeX [L] to temporary buffer |
71d35b24 CD |
847 | \[p] export as LaTeX and process to PDF |
848 | \[d] export as LaTeX, process to PDF, and open the resulting PDF document | |
c8d0cf5c CD |
849 | |
850 | \[D] export as DocBook | |
851 | \[V] export as DocBook, process to PDF, and open the resulting PDF document | |
852 | ||
8bfe682a CD |
853 | \[m] export as Freemind mind map |
854 | ||
c8d0cf5c CD |
855 | \[x] export as XOXO |
856 | \[g] export using Wes Hardaker's generic exporter | |
20908596 CD |
857 | |
858 | \[i] export current file as iCalendar file | |
859 | \[I] export all agenda files as iCalendar files | |
860 | \[c] export agenda files into combined iCalendar file | |
861 | ||
c8d0cf5c CD |
862 | \[F] publish current file [P] publish current project |
863 | \[X] publish a project... [E] publish every projects") | |
20908596 CD |
864 | (cmds |
865 | '((?t org-insert-export-options-template nil) | |
866 | (?v org-export-visible nil) | |
867 | (?a org-export-as-ascii t) | |
c8d0cf5c | 868 | (?A org-export-as-ascii-to-buffer t) |
20908596 CD |
869 | (?h org-export-as-html t) |
870 | (?b org-export-as-html-and-open t) | |
871 | (?H org-export-as-html-to-buffer nil) | |
872 | (?R org-export-region-as-html nil) | |
873 | (?x org-export-as-xoxo t) | |
c8d0cf5c CD |
874 | (?g org-export-generic t) |
875 | (?D org-export-as-docbook t) | |
876 | (?V org-export-as-docbook-pdf-and-open t) | |
8bfe682a | 877 | (?m org-export-as-freemind t) |
20908596 | 878 | (?l org-export-as-latex t) |
71d35b24 CD |
879 | (?p org-export-as-pdf t) |
880 | (?d org-export-as-pdf-and-open t) | |
20908596 CD |
881 | (?L org-export-as-latex-to-buffer nil) |
882 | (?i org-export-icalendar-this-file t) | |
883 | (?I org-export-icalendar-all-agenda-files t) | |
884 | (?c org-export-icalendar-combine-agenda-files t) | |
885 | (?F org-publish-current-file t) | |
886 | (?P org-publish-current-project t) | |
887 | (?X org-publish t) | |
c8d0cf5c | 888 | (?E org-publish-all t))) |
20908596 | 889 | r1 r2 ass) |
c8d0cf5c CD |
890 | (save-excursion |
891 | (save-window-excursion | |
892 | (delete-other-windows) | |
893 | (with-output-to-temp-buffer "*Org Export/Publishing Help*" | |
894 | (princ help)) | |
895 | (org-fit-window-to-buffer (get-buffer-window | |
896 | "*Org Export/Publishing Help*")) | |
897 | (message "Select command: ") | |
898 | (setq r1 (read-char-exclusive)))) | |
20908596 CD |
899 | (setq r2 (if (< r1 27) (+ r1 96) r1)) |
900 | (unless (setq ass (assq r2 cmds)) | |
901 | (error "No command associated with key %c" r1)) | |
71d35b24 CD |
902 | (if (and bg (nth 2 ass) |
903 | (not (buffer-base-buffer)) | |
904 | (not (org-region-active-p))) | |
20908596 CD |
905 | ;; execute in background |
906 | (let ((p (start-process | |
907 | (concat "Exporting " (file-name-nondirectory (buffer-file-name))) | |
908 | "*Org Processes*" | |
909 | (expand-file-name invocation-name invocation-directory) | |
910 | "-batch" | |
911 | "-l" user-init-file | |
912 | "--eval" "(require 'org-exp)" | |
913 | "--eval" "(setq org-wait .2)" | |
914 | (buffer-file-name) | |
915 | "-f" (symbol-name (nth 1 ass))))) | |
916 | (set-process-sentinel p 'org-export-process-sentinel) | |
917 | (message "Background process \"%s\": started" p)) | |
918 | ;; background processing not requested, or not possible | |
919 | (call-interactively (nth 1 ass))))) | |
920 | ||
921 | (defun org-export-process-sentinel (process status) | |
922 | (if (string-match "\n+\\'" status) | |
923 | (setq status (substring status 0 -1))) | |
924 | (message "Background process \"%s\": %s" process status)) | |
925 | ||
926 | (defconst org-html-entities | |
927 | '(("nbsp") | |
928 | ("iexcl") | |
929 | ("cent") | |
930 | ("pound") | |
931 | ("curren") | |
932 | ("yen") | |
933 | ("brvbar") | |
934 | ("vert" . "|") | |
935 | ("sect") | |
936 | ("uml") | |
937 | ("copy") | |
938 | ("ordf") | |
939 | ("laquo") | |
940 | ("not") | |
941 | ("shy") | |
942 | ("reg") | |
943 | ("macr") | |
944 | ("deg") | |
c8d0cf5c | 945 | ("pm" . "±") |
20908596 CD |
946 | ("plusmn") |
947 | ("sup2") | |
948 | ("sup3") | |
949 | ("acute") | |
950 | ("micro") | |
951 | ("para") | |
952 | ("middot") | |
953 | ("odot"."o") | |
954 | ("star"."*") | |
955 | ("cedil") | |
956 | ("sup1") | |
957 | ("ordm") | |
958 | ("raquo") | |
959 | ("frac14") | |
960 | ("frac12") | |
961 | ("frac34") | |
962 | ("iquest") | |
963 | ("Agrave") | |
964 | ("Aacute") | |
965 | ("Acirc") | |
966 | ("Atilde") | |
967 | ("Auml") | |
968 | ("Aring") ("AA"."Å") | |
969 | ("AElig") | |
970 | ("Ccedil") | |
971 | ("Egrave") | |
972 | ("Eacute") | |
973 | ("Ecirc") | |
974 | ("Euml") | |
975 | ("Igrave") | |
976 | ("Iacute") | |
977 | ("Icirc") | |
978 | ("Iuml") | |
979 | ("ETH") | |
980 | ("Ntilde") | |
981 | ("Ograve") | |
982 | ("Oacute") | |
983 | ("Ocirc") | |
984 | ("Otilde") | |
985 | ("Ouml") | |
986 | ("times") | |
987 | ("Oslash") | |
988 | ("Ugrave") | |
989 | ("Uacute") | |
990 | ("Ucirc") | |
991 | ("Uuml") | |
992 | ("Yacute") | |
993 | ("THORN") | |
994 | ("szlig") | |
995 | ("agrave") | |
996 | ("aacute") | |
997 | ("acirc") | |
998 | ("atilde") | |
999 | ("auml") | |
1000 | ("aring") | |
1001 | ("aelig") | |
1002 | ("ccedil") | |
1003 | ("egrave") | |
1004 | ("eacute") | |
1005 | ("ecirc") | |
1006 | ("euml") | |
1007 | ("igrave") | |
1008 | ("iacute") | |
1009 | ("icirc") | |
1010 | ("iuml") | |
1011 | ("eth") | |
1012 | ("ntilde") | |
1013 | ("ograve") | |
1014 | ("oacute") | |
1015 | ("ocirc") | |
1016 | ("otilde") | |
1017 | ("ouml") | |
1018 | ("divide") | |
1019 | ("oslash") | |
1020 | ("ugrave") | |
1021 | ("uacute") | |
1022 | ("ucirc") | |
1023 | ("uuml") | |
1024 | ("yacute") | |
1025 | ("thorn") | |
1026 | ("yuml") | |
1027 | ("fnof") | |
1028 | ("Alpha") | |
1029 | ("Beta") | |
1030 | ("Gamma") | |
1031 | ("Delta") | |
1032 | ("Epsilon") | |
1033 | ("Zeta") | |
1034 | ("Eta") | |
1035 | ("Theta") | |
1036 | ("Iota") | |
1037 | ("Kappa") | |
1038 | ("Lambda") | |
1039 | ("Mu") | |
1040 | ("Nu") | |
1041 | ("Xi") | |
1042 | ("Omicron") | |
1043 | ("Pi") | |
1044 | ("Rho") | |
1045 | ("Sigma") | |
1046 | ("Tau") | |
1047 | ("Upsilon") | |
1048 | ("Phi") | |
1049 | ("Chi") | |
1050 | ("Psi") | |
1051 | ("Omega") | |
1052 | ("alpha") | |
1053 | ("beta") | |
1054 | ("gamma") | |
1055 | ("delta") | |
1056 | ("epsilon") | |
1057 | ("varepsilon"."ε") | |
1058 | ("zeta") | |
1059 | ("eta") | |
1060 | ("theta") | |
1061 | ("iota") | |
1062 | ("kappa") | |
1063 | ("lambda") | |
1064 | ("mu") | |
1065 | ("nu") | |
1066 | ("xi") | |
1067 | ("omicron") | |
1068 | ("pi") | |
1069 | ("rho") | |
1070 | ("sigmaf") ("varsigma"."ς") | |
1071 | ("sigma") | |
1072 | ("tau") | |
1073 | ("upsilon") | |
1074 | ("phi") | |
1075 | ("chi") | |
1076 | ("psi") | |
1077 | ("omega") | |
1078 | ("thetasym") ("vartheta"."ϑ") | |
1079 | ("upsih") | |
1080 | ("piv") | |
1081 | ("bull") ("bullet"."•") | |
1082 | ("hellip") ("dots"."…") | |
1083 | ("prime") | |
1084 | ("Prime") | |
1085 | ("oline") | |
1086 | ("frasl") | |
1087 | ("weierp") | |
1088 | ("image") | |
1089 | ("real") | |
1090 | ("trade") | |
1091 | ("alefsym") | |
1092 | ("larr") ("leftarrow"."←") ("gets"."←") | |
1093 | ("uarr") ("uparrow"."↑") | |
1094 | ("rarr") ("to"."→") ("rightarrow"."→") | |
1095 | ("darr")("downarrow"."↓") | |
1096 | ("harr") ("leftrightarrow"."↔") | |
1097 | ("crarr") ("hookleftarrow"."↵") ; has round hook, not quite CR | |
1098 | ("lArr") ("Leftarrow"."⇐") | |
1099 | ("uArr") ("Uparrow"."⇑") | |
1100 | ("rArr") ("Rightarrow"."⇒") | |
1101 | ("dArr") ("Downarrow"."⇓") | |
1102 | ("hArr") ("Leftrightarrow"."⇔") | |
1103 | ("forall") | |
1104 | ("part") ("partial"."∂") | |
1105 | ("exist") ("exists"."∃") | |
1106 | ("empty") ("emptyset"."∅") | |
1107 | ("nabla") | |
1108 | ("isin") ("in"."∈") | |
1109 | ("notin") | |
1110 | ("ni") | |
1111 | ("prod") | |
1112 | ("sum") | |
1113 | ("minus") | |
1114 | ("lowast") ("ast"."∗") | |
1115 | ("radic") | |
1116 | ("prop") ("proptp"."∝") | |
1117 | ("infin") ("infty"."∞") | |
1118 | ("ang") ("angle"."∠") | |
1119 | ("and") ("wedge"."∧") | |
1120 | ("or") ("vee"."∨") | |
1121 | ("cap") | |
1122 | ("cup") | |
1123 | ("int") | |
1124 | ("there4") | |
1125 | ("sim") | |
1126 | ("cong") ("simeq"."≅") | |
1127 | ("asymp")("approx"."≈") | |
1128 | ("ne") ("neq"."≠") | |
1129 | ("equiv") | |
1130 | ("le") | |
1131 | ("ge") | |
1132 | ("sub") ("subset"."⊂") | |
1133 | ("sup") ("supset"."⊃") | |
1134 | ("nsub") | |
1135 | ("sube") | |
1136 | ("supe") | |
1137 | ("oplus") | |
1138 | ("otimes") | |
1139 | ("perp") | |
1140 | ("sdot") ("cdot"."⋅") | |
1141 | ("lceil") | |
1142 | ("rceil") | |
1143 | ("lfloor") | |
1144 | ("rfloor") | |
1145 | ("lang") | |
1146 | ("rang") | |
1147 | ("loz") ("Diamond"."◊") | |
1148 | ("spades") ("spadesuit"."♠") | |
1149 | ("clubs") ("clubsuit"."♣") | |
1150 | ("hearts") ("diamondsuit"."♥") | |
1151 | ("diams") ("diamondsuit"."♦") | |
1152 | ("smile"."☺") ("blacksmile"."☻") ("sad"."☹") | |
1153 | ("quot") | |
1154 | ("amp") | |
1155 | ("lt") | |
1156 | ("gt") | |
1157 | ("OElig") | |
1158 | ("oelig") | |
1159 | ("Scaron") | |
1160 | ("scaron") | |
1161 | ("Yuml") | |
1162 | ("circ") | |
1163 | ("tilde") | |
1164 | ("ensp") | |
1165 | ("emsp") | |
1166 | ("thinsp") | |
1167 | ("zwnj") | |
1168 | ("zwj") | |
1169 | ("lrm") | |
1170 | ("rlm") | |
1171 | ("ndash") | |
1172 | ("mdash") | |
1173 | ("lsquo") | |
1174 | ("rsquo") | |
1175 | ("sbquo") | |
1176 | ("ldquo") | |
1177 | ("rdquo") | |
1178 | ("bdquo") | |
1179 | ("dagger") | |
1180 | ("Dagger") | |
1181 | ("permil") | |
1182 | ("lsaquo") | |
1183 | ("rsaquo") | |
1184 | ("euro") | |
1185 | ||
1186 | ("arccos"."arccos") | |
1187 | ("arcsin"."arcsin") | |
1188 | ("arctan"."arctan") | |
1189 | ("arg"."arg") | |
1190 | ("cos"."cos") | |
1191 | ("cosh"."cosh") | |
1192 | ("cot"."cot") | |
1193 | ("coth"."coth") | |
1194 | ("csc"."csc") | |
1195 | ("deg"."deg") | |
1196 | ("det"."det") | |
1197 | ("dim"."dim") | |
1198 | ("exp"."exp") | |
1199 | ("gcd"."gcd") | |
1200 | ("hom"."hom") | |
1201 | ("inf"."inf") | |
1202 | ("ker"."ker") | |
1203 | ("lg"."lg") | |
1204 | ("lim"."lim") | |
1205 | ("liminf"."liminf") | |
1206 | ("limsup"."limsup") | |
1207 | ("ln"."ln") | |
1208 | ("log"."log") | |
1209 | ("max"."max") | |
1210 | ("min"."min") | |
1211 | ("Pr"."Pr") | |
1212 | ("sec"."sec") | |
1213 | ("sin"."sin") | |
1214 | ("sinh"."sinh") | |
1215 | ("sup"."sup") | |
1216 | ("tan"."tan") | |
1217 | ("tanh"."tanh") | |
1218 | ) | |
1219 | "Entities for TeX->HTML translation. | |
1220 | Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to | |
1221 | \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\"). | |
1222 | In that case, \"\\ent\" will be translated to \"&other;\". | |
1223 | The list contains HTML entities for Latin-1, Greek and other symbols. | |
1224 | It is supplemented by a number of commonly used TeX macros with appropriate | |
1225 | translations. There is currently no way for users to extend this.") | |
1226 | ||
1227 | ;;; General functions for all backends | |
1228 | ||
ce4fdcb9 CD |
1229 | (defvar org-export-target-aliases nil |
1230 | "Alist of targets with invisible aliases.") | |
c8d0cf5c CD |
1231 | (defvar org-export-preferred-target-alist nil |
1232 | "Alist of section id's with preferred aliases.") | |
0bd48b37 CD |
1233 | (defvar org-export-code-refs nil |
1234 | "Alist of code references and line numbers") | |
ce4fdcb9 | 1235 | |
20908596 CD |
1236 | (defun org-export-preprocess-string (string &rest parameters) |
1237 | "Cleanup STRING so that that the true exported has a more consistent source. | |
1238 | This function takes STRING, which should be a buffer-string of an org-file | |
1239 | to export. It then creates a temporary buffer where it does its job. | |
1240 | The result is then again returned as a string, and the exporter works | |
1241 | on this string to produce the exported version." | |
1242 | (interactive) | |
b349f79f | 1243 | (let* ((htmlp (plist-get parameters :for-html)) |
20908596 CD |
1244 | (asciip (plist-get parameters :for-ascii)) |
1245 | (latexp (plist-get parameters :for-LaTeX)) | |
c8d0cf5c CD |
1246 | (docbookp (plist-get parameters :for-docbook)) |
1247 | (backend (cond (htmlp 'html) | |
1248 | (latexp 'latex) | |
1249 | (asciip 'ascii) | |
1250 | (docbookp 'docbook))) | |
20908596 CD |
1251 | (archived-trees (plist-get parameters :archived-trees)) |
1252 | (inhibit-read-only t) | |
1253 | (drawers org-drawers) | |
20908596 | 1254 | (outline-regexp "\\*+ ") |
b349f79f | 1255 | target-alist rtn) |
20908596 | 1256 | |
ce4fdcb9 | 1257 | (setq org-export-target-aliases nil) |
c8d0cf5c | 1258 | (setq org-export-preferred-target-alist nil) |
0bd48b37 | 1259 | (setq org-export-code-refs nil) |
ce4fdcb9 | 1260 | |
20908596 CD |
1261 | (with-current-buffer (get-buffer-create " org-mode-tmp") |
1262 | (erase-buffer) | |
1263 | (insert string) | |
b349f79f | 1264 | (setq case-fold-search t) |
b349f79f | 1265 | |
20908596 | 1266 | ;; Remove license-to-kill stuff |
33306645 | 1267 | ;; The caller marks some stuff for killing, stuff that has been |
20908596 | 1268 | ;; used to create the page title, for example. |
b349f79f | 1269 | (org-export-kill-licensed-text) |
ff4be292 | 1270 | |
20908596 | 1271 | (let ((org-inhibit-startup t)) (org-mode)) |
b349f79f | 1272 | (setq case-fold-search t) |
c8d0cf5c | 1273 | (org-install-letbind) |
0bd48b37 CD |
1274 | |
1275 | ;; Call the hook | |
1276 | (run-hooks 'org-export-preprocess-hook) | |
1277 | ||
c8d0cf5c CD |
1278 | ;; Process the macros |
1279 | (org-export-preprocess-apply-macros) | |
1280 | (run-hooks 'org-export-preprocess-after-macros-hook) | |
1281 | ||
20908596 | 1282 | (untabify (point-min) (point-max)) |
ff4be292 | 1283 | |
0bd48b37 | 1284 | ;; Handle include files, and call a hook |
b349f79f | 1285 | (org-export-handle-include-files) |
0bd48b37 | 1286 | (run-hooks 'org-export-preprocess-after-include-files-hook) |
ff4be292 | 1287 | |
0bd48b37 CD |
1288 | ;; Get rid of archived trees |
1289 | (org-export-remove-archived-trees archived-trees) | |
1290 | ||
1291 | ;; Remove comment environment and comment subtrees | |
1292 | (org-export-remove-comment-blocks-and-subtrees) | |
1293 | ||
1294 | ;; Get rid of excluded trees, and call a hook | |
621f83e4 CD |
1295 | (org-export-handle-export-tags (plist-get parameters :select-tags) |
1296 | (plist-get parameters :exclude-tags)) | |
0bd48b37 | 1297 | (run-hooks 'org-export-preprocess-after-tree-selection-hook) |
621f83e4 | 1298 | |
b349f79f | 1299 | ;; Handle source code snippets |
0bd48b37 CD |
1300 | (org-export-replace-src-segments-and-examples backend) |
1301 | ||
1302 | ;; Protect short examples marked by a leading colon | |
1303 | (org-export-protect-colon-examples) | |
1304 | ||
1305 | ;; Normalize footnotes | |
1306 | (when (plist-get parameters :footnotes) | |
1307 | (org-footnote-normalize nil t)) | |
33306645 | 1308 | |
db55f368 CD |
1309 | ;; Find all headings and compute the targets for them |
1310 | (setq target-alist (org-export-define-heading-targets target-alist)) | |
ff4be292 | 1311 | |
20908596 | 1312 | ;; Get rid of drawers |
8bfe682a CD |
1313 | (org-export-remove-or-extract-drawers |
1314 | drawers (plist-get parameters :drawers) backend) | |
ff4be292 | 1315 | |
20908596 CD |
1316 | ;; Get the correct stuff before the first headline |
1317 | (when (plist-get parameters :skip-before-1st-heading) | |
1318 | (goto-char (point-min)) | |
ee9d4ebe | 1319 | (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t) |
20908596 CD |
1320 | (delete-region (point-min) (match-beginning 0)) |
1321 | (goto-char (point-min)) | |
1322 | (insert "\n"))) | |
1323 | (when (plist-get parameters :add-text) | |
1324 | (goto-char (point-min)) | |
1325 | (insert (plist-get parameters :add-text) "\n")) | |
ff4be292 | 1326 | |
ff4be292 CD |
1327 | ;; Remove todo-keywords before exporting, if the user has requested so |
1328 | (org-export-remove-headline-metadata parameters) | |
20908596 CD |
1329 | |
1330 | ;; Find targets in comments and move them out of comments, | |
1331 | ;; but mark them as targets that should be invisible | |
b349f79f CD |
1332 | (setq target-alist (org-export-handle-invisible-targets target-alist)) |
1333 | ||
0bd48b37 CD |
1334 | ;; Select and protect backend specific stuff, throw away stuff |
1335 | ;; that is specific for other backends | |
db55f368 | 1336 | (org-export-select-backend-specific-text backend) |
20908596 CD |
1337 | |
1338 | ;; Protect quoted subtrees | |
b349f79f | 1339 | (org-export-protect-quoted-subtrees) |
20908596 | 1340 | |
c8d0cf5c CD |
1341 | ;; Remove clock lines |
1342 | (org-export-remove-clock-lines) | |
1343 | ||
20908596 | 1344 | ;; Protect verbatim elements |
b349f79f | 1345 | (org-export-protect-verbatim) |
20908596 | 1346 | |
c8d0cf5c CD |
1347 | ;; Blockquotes, verse, and center |
1348 | (org-export-mark-blockquote-verse-center) | |
1349 | (run-hooks 'org-export-preprocess-after-blockquote-hook) | |
b349f79f | 1350 | |
0bd48b37 | 1351 | ;; Remove timestamps, if the user has requested so |
0bd48b37 CD |
1352 | (unless (plist-get parameters :timestamps) |
1353 | (org-export-remove-timestamps)) | |
1354 | ||
33306645 | 1355 | ;; Attach captions to the correct object |
db55f368 CD |
1356 | (setq target-alist (org-export-attach-captions-and-attributes |
1357 | backend target-alist)) | |
1358 | ||
621f83e4 CD |
1359 | ;; Find matches for radio targets and turn them into internal links |
1360 | (org-export-mark-radio-links) | |
1361 | ||
1362 | ;; Find all links that contain a newline and put them into a single line | |
1363 | (org-export-concatenate-multiline-links) | |
1364 | ||
1365 | ;; Normalize links: Convert angle and plain links into bracket links | |
1366 | ;; and expand link abbreviations | |
1367 | (org-export-normalize-links) | |
1368 | ||
1369 | ;; Find all internal links. If they have a fuzzy match (i.e. not | |
1370 | ;; a *dedicated* target match, let the link point to the | |
1371 | ;; corresponding section. | |
1372 | (org-export-target-internal-links target-alist) | |
1373 | ||
1374 | ;; Find multiline emphasis and put them into single line | |
1375 | (when (plist-get parameters :emph-multiline) | |
1376 | (org-export-concatenate-multiline-emphasis)) | |
1377 | ||
20908596 CD |
1378 | ;; Remove special table lines |
1379 | (when org-export-table-remove-special-lines | |
b349f79f | 1380 | (org-export-remove-special-table-lines)) |
20908596 | 1381 | |
0bd48b37 CD |
1382 | ;; Another hook |
1383 | (run-hooks 'org-export-preprocess-before-backend-specifics-hook) | |
1384 | ||
1385 | ;; LaTeX-specific preprocessing | |
20908596 | 1386 | (when latexp |
c8d0cf5c CD |
1387 | (require 'org-latex nil) |
1388 | (org-export-latex-preprocess parameters)) | |
20908596 | 1389 | |
0bd48b37 | 1390 | ;; ASCII-specific preprocessing |
20908596 | 1391 | (when asciip |
c8d0cf5c | 1392 | (org-export-ascii-preprocess parameters)) |
20908596 | 1393 | |
0bd48b37 | 1394 | ;; HTML-specific preprocessing |
20908596 | 1395 | (when htmlp |
b349f79f | 1396 | (org-export-html-preprocess parameters)) |
20908596 | 1397 | |
c8d0cf5c CD |
1398 | ;; DocBook-specific preprocessing |
1399 | (when docbookp | |
1400 | (require 'org-docbook nil) | |
1401 | (org-export-docbook-preprocess parameters)) | |
1402 | ||
20908596 | 1403 | ;; Remove or replace comments |
b349f79f | 1404 | (org-export-handle-comments (plist-get parameters :comments)) |
20908596 | 1405 | |
0bd48b37 CD |
1406 | ;; Run the final hook |
1407 | (run-hooks 'org-export-preprocess-final-hook) | |
1408 | ||
20908596 CD |
1409 | (setq rtn (buffer-string))) |
1410 | (kill-buffer " org-mode-tmp") | |
1411 | rtn)) | |
1412 | ||
b349f79f CD |
1413 | (defun org-export-kill-licensed-text () |
1414 | "Remove all text that is marked with a :org-license-to-kill property." | |
65c439fd | 1415 | (let (p) |
b349f79f CD |
1416 | (while (setq p (text-property-any (point-min) (point-max) |
1417 | :org-license-to-kill t)) | |
2c3ad40d CD |
1418 | (delete-region |
1419 | p (or (next-single-property-change p :org-license-to-kill) | |
1420 | (point-max)))))) | |
b349f79f CD |
1421 | |
1422 | (defun org-export-define-heading-targets (target-alist) | |
1423 | "Find all headings and define the targets for them. | |
1424 | The new targets are added to TARGET-ALIST, which is also returned." | |
1425 | (goto-char (point-min)) | |
1426 | (org-init-section-numbers) | |
db55f368 | 1427 | (let ((re (concat "^" org-outline-regexp |
c8d0cf5c CD |
1428 | "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)")) |
1429 | level target last-section-target a id) | |
b349f79f | 1430 | (while (re-search-forward re nil t) |
c8d0cf5c | 1431 | (if (match-end 2) |
0bd48b37 | 1432 | (progn |
c8d0cf5c CD |
1433 | (setq id (org-match-string-no-properties 2)) |
1434 | (push (cons id target) target-alist) | |
0bd48b37 CD |
1435 | (setq a (or (assoc last-section-target org-export-target-aliases) |
1436 | (progn | |
1437 | (push (list last-section-target) | |
1438 | org-export-target-aliases) | |
1439 | (car org-export-target-aliases)))) | |
c8d0cf5c CD |
1440 | (push (caar target-alist) (cdr a)) |
1441 | (when (equal (match-string 1) "CUSTOM_ID") | |
1442 | (if (not (assoc last-section-target | |
1443 | org-export-preferred-target-alist)) | |
1444 | (push (cons last-section-target id) | |
1445 | org-export-preferred-target-alist)))) | |
db55f368 CD |
1446 | (setq level (org-reduced-level |
1447 | (save-excursion (goto-char (point-at-bol)) | |
1448 | (org-outline-level)))) | |
1449 | (setq target (org-solidify-link-text | |
1450 | (format "sec-%s" (org-section-number level)))) | |
0bd48b37 | 1451 | (setq last-section-target target) |
db55f368 CD |
1452 | (push (cons target target) target-alist) |
1453 | (add-text-properties | |
1454 | (point-at-bol) (point-at-eol) | |
1455 | (list 'target target))))) | |
b349f79f CD |
1456 | target-alist) |
1457 | ||
1458 | (defun org-export-handle-invisible-targets (target-alist) | |
1459 | "Find targets in comments and move them out of comments. | |
1460 | Mark them as invisible targets." | |
ce4fdcb9 | 1461 | (let (target tmp a) |
b349f79f CD |
1462 | (goto-char (point-min)) |
1463 | (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t) | |
1464 | ;; Check if the line before or after is a headline with a target | |
1465 | (if (setq target (or (get-text-property (point-at-bol 0) 'target) | |
1466 | (get-text-property (point-at-bol 2) 'target))) | |
1467 | (progn | |
1468 | ;; use the existing target in a neighboring line | |
1469 | (setq tmp (match-string 2)) | |
1470 | (replace-match "") | |
1471 | (and (looking-at "\n") (delete-char 1)) | |
ce4fdcb9 CD |
1472 | (push (cons (setq tmp (org-solidify-link-text tmp)) target) |
1473 | target-alist) | |
1474 | (setq a (or (assoc target org-export-target-aliases) | |
1475 | (progn | |
1476 | (push (list target) org-export-target-aliases) | |
1477 | (car org-export-target-aliases)))) | |
1478 | (push tmp (cdr a))) | |
b349f79f CD |
1479 | ;; Make an invisible target |
1480 | (replace-match "\\1(INVISIBLE)")))) | |
1481 | target-alist) | |
1482 | ||
1483 | (defun org-export-target-internal-links (target-alist) | |
db55f368 | 1484 | "Find all internal links and assign targets to them. |
b349f79f | 1485 | If a link has a fuzzy match (i.e. not a *dedicated* target match), |
db55f368 CD |
1486 | let the link point to the corresponding section. |
1487 | This function also handles the id links, if they have a match in | |
1488 | the current file." | |
b349f79f CD |
1489 | (goto-char (point-min)) |
1490 | (while (re-search-forward org-bracket-link-regexp nil t) | |
1491 | (org-if-unprotected | |
1492 | (let* ((md (match-data)) | |
1493 | (desc (match-end 2)) | |
1494 | (link (org-link-unescape (match-string 1))) | |
1495 | (slink (org-solidify-link-text link)) | |
0bd48b37 | 1496 | found props pos cref |
b349f79f | 1497 | (target |
2c3ad40d | 1498 | (cond |
c8d0cf5c CD |
1499 | ((= (string-to-char link) ?#) |
1500 | ;; user wants exactly this link | |
1501 | link) | |
1502 | ((cdr (assoc slink target-alist)) | |
1503 | (or (cdr (assoc (assoc slink target-alist) | |
1504 | org-export-preferred-target-alist)) | |
1505 | (cdr (assoc slink target-alist)))) | |
db55f368 CD |
1506 | ((and (string-match "^id:" link) |
1507 | (cdr (assoc (substring link 3) target-alist)))) | |
0bd48b37 CD |
1508 | ((string-match "^(\\(.*\\))$" link) |
1509 | (setq cref (match-string 1 link)) | |
1510 | (concat "coderef:" cref)) | |
2c3ad40d CD |
1511 | ((string-match org-link-types-re link) nil) |
1512 | ((or (file-name-absolute-p link) | |
1513 | (string-match "^\\." link)) | |
1514 | nil) | |
1515 | (t | |
1516 | (save-excursion | |
1517 | (setq found (condition-case nil (org-link-search link) | |
1518 | (error nil))) | |
1519 | (when (and found | |
1520 | (or (org-on-heading-p) | |
1521 | (not (eq found 'dedicated)))) | |
1522 | (or (get-text-property (point) 'target) | |
1523 | (get-text-property | |
1524 | (max (point-min) | |
ce4fdcb9 CD |
1525 | (1- (or (previous-single-property-change |
1526 | (point) 'target) 0))) | |
2c3ad40d | 1527 | 'target)))))))) |
b349f79f CD |
1528 | (when target |
1529 | (set-match-data md) | |
1530 | (goto-char (match-beginning 1)) | |
1531 | (setq props (text-properties-at (point))) | |
1532 | (delete-region (match-beginning 1) (match-end 1)) | |
1533 | (setq pos (point)) | |
1534 | (insert target) | |
1535 | (unless desc (insert "][" link)) | |
1536 | (add-text-properties pos (point) props)))))) | |
1537 | ||
8bfe682a CD |
1538 | (defvar org-export-format-drawer-function nil |
1539 | "Function to be called to format the contents of a drawer. | |
1540 | The function must accept three parameters: | |
1541 | BACKEND one of the symbols html, docbook, latex, ascii, xoxo | |
1542 | NAME the drawer name, like \"PROPERTIES\" | |
1543 | CONTENT the content of the drawer. | |
1544 | The function should return the text to be inserted into the buffer. | |
1545 | If this is nil, `org-export-format-drawer' is used as a default.") | |
1546 | ||
1547 | (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers backend) | |
1548 | "Remove drawers, or extract and format the content. | |
b349f79f CD |
1549 | ALL-DRAWERS is a list of all drawer names valid in the current buffer. |
1550 | EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers | |
8bfe682a CD |
1551 | whose content to keep. Any drawers that are in ALL-DRAWERS but not in |
1552 | EXP-DRAWERS will be removed. | |
1553 | BACKEND is the current export backend." | |
1554 | (goto-char (point-min)) | |
1555 | (let ((re (concat "^[ \t]*:\\(" | |
1556 | (mapconcat 'identity all-drawers "\\|") | |
1557 | "\\):[ \t]*$")) | |
1558 | name beg beg-content eol content) | |
1559 | (while (re-search-forward re nil t) | |
1560 | (org-if-unprotected | |
1561 | (setq name (match-string 1)) | |
1562 | (setq beg (match-beginning 0) | |
1563 | beg-content (1+ (point-at-eol)) | |
1564 | eol (point-at-eol)) | |
1565 | (if (not (and (re-search-forward | |
1566 | "^\\([ \t]*:END:[ \t]*\n?\\)\\|^\\*+[ \t]" nil t) | |
1567 | (match-end 1))) | |
1568 | (goto-char eol) | |
1569 | (goto-char (match-beginning 0)) | |
1570 | (and (looking-at ".*\n?") (replace-match "")) | |
1571 | (setq content (buffer-substring beg-content (point))) | |
1572 | (delete-region beg (point)) | |
1573 | (when (or (eq exp-drawers t) | |
1574 | (member name exp-drawers)) | |
1575 | (setq content (funcall (or org-export-format-drawer-function | |
1576 | 'org-export-format-drawer) | |
1577 | name content backend)) | |
1578 | (insert content))))))) | |
1579 | ||
1580 | (defun org-export-format-drawer (name content backend) | |
1581 | "Format the content of a drawer as a colon example." | |
1582 | (if (string-match "[ \t]+\\'" content) | |
1583 | (setq content (substring content (match-beginning 0)))) | |
1584 | (while (string-match "\\`[ \t]*\n" content) | |
1585 | (setq content (substring content (match-end 0)))) | |
1586 | (setq content (org-remove-indentation content)) | |
1587 | (setq content (concat ": " (mapconcat 'identity | |
1588 | (org-split-string content "\n") | |
1589 | "\n: ") | |
1590 | "\n")) | |
1591 | (setq content (concat " : " (upcase name) "\n" content)) | |
1592 | (org-add-props content nil 'org-protected t)) | |
b349f79f | 1593 | |
621f83e4 CD |
1594 | (defun org-export-handle-export-tags (select-tags exclude-tags) |
1595 | "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS. | |
1596 | Both arguments are lists of tags. | |
1597 | If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG | |
1598 | will be removed. | |
1599 | After that, all subtrees that are marked by EXCLUDE-TAGS will be | |
1600 | removed as well." | |
1601 | (remove-text-properties (point-min) (point-max) '(:org-delete t)) | |
1602 | (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote | |
1603 | select-tags "\\|") | |
1604 | "\\):")) | |
1605 | (re-excl (concat ":\\(" (mapconcat 'regexp-quote | |
1606 | exclude-tags "\\|") | |
1607 | "\\):")) | |
1608 | beg end cont) | |
1609 | (goto-char (point-min)) | |
1610 | (when (and select-tags | |
1611 | (re-search-forward | |
1612 | (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t)) | |
1613 | ;; At least one tree is marked for export, this means | |
1614 | ;; all the unmarked stuff needs to go. | |
1615 | ;; Dig out the trees that should be exported | |
1616 | (goto-char (point-min)) | |
1617 | (outline-next-heading) | |
1618 | (setq beg (point)) | |
1619 | (put-text-property beg (point-max) :org-delete t) | |
1620 | (while (re-search-forward re-sel nil t) | |
1621 | (when (org-on-heading-p) | |
1622 | (org-back-to-heading) | |
1623 | (remove-text-properties | |
1624 | (max (1- (point)) (point-min)) | |
1625 | (setq cont (save-excursion (org-end-of-subtree t t))) | |
1626 | '(:org-delete t)) | |
1627 | (while (and (org-up-heading-safe) | |
1628 | (get-text-property (point) :org-delete)) | |
1629 | (remove-text-properties (max (1- (point)) (point-min)) | |
1630 | (point-at-eol) '(:org-delete t))) | |
1631 | (goto-char cont)))) | |
1632 | ;; Remove the trees explicitly marked for noexport | |
1633 | (when exclude-tags | |
1634 | (goto-char (point-min)) | |
1635 | (while (re-search-forward re-excl nil t) | |
1636 | (when (org-at-heading-p) | |
1637 | (org-back-to-heading t) | |
1638 | (setq beg (point)) | |
8bfe682a CD |
1639 | (org-end-of-subtree t t) |
1640 | (delete-region beg (point)) | |
1641 | (when (featurep 'org-inlinetask) | |
1642 | (org-inlinetask-remove-END-maybe))))) | |
621f83e4 CD |
1643 | ;; Remove everything that is now still marked for deletion |
1644 | (goto-char (point-min)) | |
1645 | (while (setq beg (text-property-any (point-min) (point-max) :org-delete t)) | |
1646 | (setq end (or (next-single-property-change beg :org-delete) | |
1647 | (point-max))) | |
1648 | (delete-region beg end)))) | |
1649 | ||
b349f79f CD |
1650 | (defun org-export-remove-archived-trees (export-archived-trees) |
1651 | "Remove archived trees. | |
1652 | When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported. | |
1653 | When it is t, the entire archived tree will be exported. | |
1654 | When it is nil the entire tree including the headline will be removed | |
1655 | from the buffer." | |
1656 | (let ((re-archive (concat ":" org-archive-tag ":")) | |
1657 | a b) | |
1658 | (when (not (eq export-archived-trees t)) | |
1659 | (goto-char (point-min)) | |
1660 | (while (re-search-forward re-archive nil t) | |
1661 | (if (not (org-on-heading-p t)) | |
1662 | (org-end-of-subtree t) | |
1663 | (beginning-of-line 1) | |
1664 | (setq a (if export-archived-trees | |
1665 | (1+ (point-at-eol)) (point)) | |
1666 | b (org-end-of-subtree t)) | |
1667 | (if (> b a) (delete-region a b))))))) | |
1668 | ||
ff4be292 CD |
1669 | (defun org-export-remove-headline-metadata (opts) |
1670 | "Remove meta data from the headline, according to user options." | |
1671 | (let ((re org-complex-heading-regexp) | |
1672 | (todo (plist-get opts :todo-keywords)) | |
1673 | (tags (plist-get opts :tags)) | |
1674 | (pri (plist-get opts :priority)) | |
db55f368 | 1675 | (elts '(1 2 3 4 5)) |
65c439fd | 1676 | rpl) |
db55f368 | 1677 | (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5)))) |
ff4be292 | 1678 | (when (or (not todo) (not tags) (not pri)) |
ff4be292 CD |
1679 | (goto-char (point-min)) |
1680 | (while (re-search-forward re nil t) | |
0bd48b37 CD |
1681 | (org-if-unprotected |
1682 | (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) "")) | |
1683 | elts " ")) | |
1684 | (replace-match rpl t t)))))) | |
1685 | ||
1686 | (defun org-export-remove-timestamps () | |
1687 | "Remove timestamps and keywords for export." | |
c8d0cf5c | 1688 | (goto-char (point-min)) |
0bd48b37 CD |
1689 | (while (re-search-forward org-maybe-keyword-time-regexp nil t) |
1690 | (backward-char 1) | |
1691 | (org-if-unprotected | |
1e4f816a CD |
1692 | (unless (save-match-data (org-at-table-p)) |
1693 | (replace-match "") | |
1694 | (beginning-of-line 1) | |
1695 | (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n") | |
1696 | (replace-match "")))))) | |
0bd48b37 CD |
1697 | |
1698 | (defun org-export-remove-clock-lines () | |
c8d0cf5c CD |
1699 | "Remove clock lines for export." |
1700 | (goto-char (point-min)) | |
0bd48b37 CD |
1701 | (let ((re (concat "^[ \t]*" org-clock-string ".*\n?"))) |
1702 | (while (re-search-forward re nil t) | |
1703 | (org-if-unprotected | |
1704 | (replace-match ""))))) | |
ff4be292 | 1705 | |
b349f79f CD |
1706 | (defun org-export-protect-quoted-subtrees () |
1707 | "Mark quoted subtrees with the protection property." | |
1708 | (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))) | |
1709 | (goto-char (point-min)) | |
1710 | (while (re-search-forward re-quote nil t) | |
1711 | (goto-char (match-beginning 0)) | |
1712 | (end-of-line 1) | |
1713 | (add-text-properties (point) (org-end-of-subtree t) | |
1714 | '(org-protected t))))) | |
1715 | ||
1716 | (defun org-export-protect-verbatim () | |
1717 | "Mark verbatim snippets with the protection property." | |
1718 | (goto-char (point-min)) | |
1719 | (while (re-search-forward org-verbatim-re nil t) | |
8bfe682a CD |
1720 | (org-if-unprotected |
1721 | (add-text-properties (match-beginning 4) (match-end 4) | |
1722 | '(org-protected t org-verbatim-emph t)) | |
1723 | (goto-char (1+ (match-end 4)))))) | |
b349f79f | 1724 | |
0bd48b37 CD |
1725 | (defun org-export-protect-colon-examples () |
1726 | "Protect lines starting with a colon." | |
b349f79f | 1727 | (goto-char (point-min)) |
65c439fd | 1728 | (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg) |
0bd48b37 CD |
1729 | (while (re-search-forward re nil t) |
1730 | (beginning-of-line 1) | |
1731 | (setq beg (point)) | |
1732 | (while (looking-at re) | |
1733 | (end-of-line 1) | |
1734 | (or (eobp) (forward-char 1))) | |
1735 | (add-text-properties beg (if (bolp) (1- (point)) (point)) | |
1736 | '(org-protected t))))) | |
b349f79f CD |
1737 | |
1738 | (defun org-export-select-backend-specific-text (backend) | |
1739 | (let ((formatters | |
c8d0cf5c CD |
1740 | '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK") |
1741 | (html "HTML" "BEGIN_HTML" "END_HTML") | |
b349f79f CD |
1742 | (ascii "ASCII" "BEGIN_ASCII" "END_ASCII") |
1743 | (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX"))) | |
0bd48b37 | 1744 | (case-fold-search t) |
54a0dee5 | 1745 | fmt beg beg-content end end-content) |
b349f79f CD |
1746 | |
1747 | (while formatters | |
1748 | (setq fmt (pop formatters)) | |
1749 | (when (eq (car fmt) backend) | |
1750 | ;; This is selected code, put it into the file for real | |
1751 | (goto-char (point-min)) | |
c8d0cf5c | 1752 | (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt) |
b349f79f | 1753 | ":[ \t]*\\(.*\\)") nil t) |
c8d0cf5c | 1754 | (replace-match "\\1\\2" t) |
b349f79f CD |
1755 | (add-text-properties |
1756 | (point-at-bol) (min (1+ (point-at-eol)) (point-max)) | |
1757 | '(org-protected t)))) | |
1758 | (goto-char (point-min)) | |
54a0dee5 CD |
1759 | (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?") |
1760 | nil t) | |
1761 | (setq beg (match-beginning 0) beg-content (match-end 0)) | |
1762 | (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?") | |
1763 | nil t) | |
1764 | (setq end (match-end 0) end-content (match-beginning 0)) | |
1765 | (if (eq (car fmt) backend) | |
1766 | ;; yes, keep this | |
8bfe682a CD |
1767 | (progn |
1768 | (add-text-properties beg-content end-content '(org-protected t)) | |
1769 | (delete-region (match-beginning 0) (match-end 0)) | |
1770 | (save-excursion | |
1771 | (goto-char beg) | |
1772 | (delete-region (point) (1+ (point-at-eol))))) | |
54a0dee5 CD |
1773 | ;; No, this is for a different backend, kill it |
1774 | (delete-region beg end))))))) | |
b349f79f | 1775 | |
c8d0cf5c | 1776 | (defun org-export-mark-blockquote-verse-center () |
b349f79f CD |
1777 | "Mark block quote and verse environments with special cookies. |
1778 | These special cookies will later be interpreted by the backend." | |
1779 | ;; Blockquotes | |
c8d0cf5c CD |
1780 | (let (type t1 ind beg end beg1 end1 content) |
1781 | (goto-char (point-min)) | |
1782 | (while (re-search-forward | |
1783 | "^\\([ \t]*\\)#\\+\\(begin_\\(\\(block\\)?quote\\|verse\\|center\\)\\>.*\\)" | |
1784 | nil t) | |
1785 | (setq ind (length (match-string 1)) | |
1786 | type (downcase (match-string 3)) | |
1787 | t1 (if (equal type "quote") "blockquote" type)) | |
1788 | (setq beg (match-beginning 0) | |
1789 | beg1 (1+ (match-end 0))) | |
1790 | (when (re-search-forward (concat "^[ \t]*#\\+end_" type "\\>.*") nil t) | |
1791 | (setq end (1+ (point-at-eol)) | |
1792 | end1 (1- (match-beginning 0))) | |
1793 | (setq content (org-remove-indentation (buffer-substring beg1 end1))) | |
1794 | (setq content (concat "ORG-" (upcase t1) "-START\n" | |
1795 | content "\n" | |
1796 | "ORG-" (upcase t1) "-END\n")) | |
1797 | (delete-region beg end) | |
1798 | (insert (org-add-props content nil 'original-indentation ind)))))) | |
b349f79f | 1799 | |
db55f368 CD |
1800 | (defun org-export-attach-captions-and-attributes (backend target-alist) |
1801 | "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties. | |
1802 | If the next thing following is a table, add the text properties to the first | |
1803 | table line. If it is a link, add it to the line containing the link." | |
1804 | (goto-char (point-min)) | |
1805 | (remove-text-properties (point-min) (point-max) | |
1806 | '(org-caption nil org-attributes nil)) | |
1807 | (let ((case-fold-search t) | |
c8d0cf5c | 1808 | (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)" |
db55f368 | 1809 | "\\|" |
c8d0cf5c | 1810 | "^[ \t]*#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)" |
db55f368 | 1811 | "\\|" |
c8d0cf5c | 1812 | "^[ \t]*#\\+label:[ \t]+\\(.*\\)" |
db55f368 CD |
1813 | "\\|" |
1814 | "^[ \t]*|[^-]" | |
1815 | "\\|" | |
1816 | "^[ \t]*\\[\\[.*\\]\\][ \t]*$")) | |
1817 | cap attr label) | |
1818 | (while (re-search-forward re nil t) | |
1819 | (cond | |
1820 | ((match-end 1) | |
1821 | (setq cap (concat cap (if cap " " "") (org-trim (match-string 1))))) | |
1822 | ((match-end 2) | |
1823 | (setq attr (concat attr (if attr " " "") (org-trim (match-string 2))))) | |
1824 | ((match-end 3) | |
1825 | (setq label (org-trim (match-string 3)))) | |
1826 | (t | |
1827 | (add-text-properties (point-at-bol) (point-at-eol) | |
1828 | (list 'org-caption cap | |
1829 | 'org-attributes attr | |
1830 | 'org-label label)) | |
1831 | (if label (push (cons label label) target-alist)) | |
1832 | (setq cap nil attr nil label nil))))) | |
1833 | target-alist) | |
1834 | ||
b349f79f CD |
1835 | (defun org-export-remove-comment-blocks-and-subtrees () |
1836 | "Remove the comment environment, and also commented subtrees." | |
2c3ad40d | 1837 | (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>")) |
33306645 | 1838 | (case-fold-search nil)) |
b349f79f CD |
1839 | ;; Remove comment environment |
1840 | (goto-char (point-min)) | |
1841 | (while (re-search-forward | |
1842 | "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t) | |
1843 | (replace-match "" t t)) | |
1844 | ;; Remove subtrees that are commented | |
1845 | (goto-char (point-min)) | |
1846 | (while (re-search-forward re-commented nil t) | |
1847 | (goto-char (match-beginning 0)) | |
1848 | (delete-region (point) (org-end-of-subtree t))))) | |
1849 | ||
1850 | (defun org-export-handle-comments (commentsp) | |
1851 | "Remove comments, or convert to backend-specific format. | |
1852 | COMMENTSP can be a format string for publishing comments. | |
1853 | When it is nil, all comments will be removed." | |
c8d0cf5c | 1854 | (let ((re "^\\(#\\|[ \t]*#\\+\\)\\(.*\n?\\)") |
b349f79f CD |
1855 | pos) |
1856 | (goto-char (point-min)) | |
1857 | (while (or (looking-at re) | |
1858 | (re-search-forward re nil t)) | |
1859 | (setq pos (match-beginning 0)) | |
c8d0cf5c CD |
1860 | (if (and commentsp |
1861 | (not (equal (char-before (match-end 1)) ?+))) | |
b349f79f CD |
1862 | (progn (add-text-properties |
1863 | (match-beginning 0) (match-end 0) '(org-protected t)) | |
c8d0cf5c | 1864 | (replace-match (format commentsp (match-string 2)) t t)) |
b349f79f CD |
1865 | (goto-char (1+ pos)) |
1866 | (org-if-unprotected | |
1867 | (replace-match "") | |
1868 | (goto-char (max (point-min) (1- pos)))))))) | |
1869 | ||
1870 | (defun org-export-mark-radio-links () | |
1871 | "Find all matches for radio targets and turn them into internal links." | |
1872 | (let ((re-radio (and org-target-link-regexp | |
1873 | (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))) | |
1874 | (goto-char (point-min)) | |
1875 | (when re-radio | |
1876 | (while (re-search-forward re-radio nil t) | |
c8d0cf5c CD |
1877 | (unless |
1878 | (save-match-data | |
1879 | (or (org-in-regexp org-bracket-link-regexp) | |
1880 | (org-in-regexp org-plain-link-re))) | |
1881 | (org-if-unprotected | |
1882 | (replace-match "\\1[[\\2]]"))))))) | |
b349f79f CD |
1883 | |
1884 | (defun org-export-remove-special-table-lines () | |
1885 | "Remove tables lines that are used for internal purposes." | |
1886 | (goto-char (point-min)) | |
1887 | (while (re-search-forward "^[ \t]*|" nil t) | |
1888 | (beginning-of-line 1) | |
1889 | (if (or (looking-at "[ \t]*| *[!_^] *|") | |
8d642074 CD |
1890 | (not |
1891 | (memq | |
1892 | nil | |
1893 | (mapcar | |
1894 | (lambda (f) | |
1895 | (or (= (length f) 0) | |
1896 | (string-match | |
1897 | "\\`<\\([0-9]\\|[rl]\\|[rl][0-9]+\\)>\\'" f))) | |
1898 | (org-split-string ;; FIXME, can't we do this without splitting??? | |
1899 | (buffer-substring (point-at-bol) (point-at-eol)) | |
1900 | "[ \t]*|[ \t]*"))))) | |
b349f79f CD |
1901 | (delete-region (max (point-min) (1- (point-at-bol))) |
1902 | (point-at-eol)) | |
1903 | (end-of-line 1)))) | |
1904 | ||
54a0dee5 CD |
1905 | (defun org-export-protect-sub-super (s) |
1906 | (save-match-data | |
1907 | (while (string-match "\\([^\\\\]\\)\\([_^]\\)" s) | |
1908 | (setq s (replace-match "\\1\\\\\\2" nil nil s))) | |
1909 | s)) | |
1910 | ||
b349f79f CD |
1911 | (defun org-export-normalize-links () |
1912 | "Convert all links to bracket links, and expand link abbreviations." | |
1913 | (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re)) | |
c8d0cf5c CD |
1914 | (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)) |
1915 | nodesc) | |
b349f79f CD |
1916 | (goto-char (point-min)) |
1917 | (while (re-search-forward re-plain-link nil t) | |
1918 | (goto-char (1- (match-end 0))) | |
c8d0cf5c | 1919 | (org-if-unprotected-at (1+ (match-beginning 0)) |
54a0dee5 CD |
1920 | (let* ((s (concat (match-string 1) |
1921 | "[[" (match-string 2) ":" (match-string 3) | |
1922 | "][" (match-string 2) ":" (org-export-protect-sub-super | |
1923 | (match-string 3)) | |
1924 | "]]"))) | |
b349f79f CD |
1925 | ;; added 'org-link face to links |
1926 | (put-text-property 0 (length s) 'face 'org-link s) | |
1927 | (replace-match s t t)))) | |
1928 | (goto-char (point-min)) | |
1929 | (while (re-search-forward re-angle-link nil t) | |
1930 | (goto-char (1- (match-end 0))) | |
1931 | (org-if-unprotected | |
54a0dee5 CD |
1932 | (let* ((s (concat (match-string 1) |
1933 | "[[" (match-string 2) ":" (match-string 3) | |
1934 | "][" (match-string 2) ":" (org-export-protect-sub-super | |
1935 | (match-string 3)) | |
1936 | "]]"))) | |
b349f79f CD |
1937 | (put-text-property 0 (length s) 'face 'org-link s) |
1938 | (replace-match s t t)))) | |
1939 | (goto-char (point-min)) | |
1940 | (while (re-search-forward org-bracket-link-regexp nil t) | |
2c3ad40d | 1941 | (goto-char (1- (match-end 0))) |
c8d0cf5c | 1942 | (setq nodesc (not (match-end 3))) |
b349f79f CD |
1943 | (org-if-unprotected |
1944 | (let* ((xx (save-match-data | |
ce4fdcb9 CD |
1945 | (org-translate-link |
1946 | (org-link-expand-abbrev (match-string 1))))) | |
b349f79f | 1947 | (s (concat |
0bd48b37 | 1948 | "[[" (org-add-props (copy-sequence xx) |
c8d0cf5c | 1949 | nil 'org-protected t 'org-no-description nodesc) |
0bd48b37 | 1950 | "]" |
b349f79f CD |
1951 | (if (match-end 3) |
1952 | (match-string 2) | |
c8d0cf5c | 1953 | (concat "[" (copy-sequence xx) |
0bd48b37 | 1954 | "]")) |
b349f79f CD |
1955 | "]"))) |
1956 | (put-text-property 0 (length s) 'face 'org-link s) | |
1957 | (replace-match s t t)))))) | |
ff4be292 | 1958 | |
b349f79f CD |
1959 | (defun org-export-concatenate-multiline-links () |
1960 | "Find multi-line links and put it all into a single line. | |
1961 | This is to make sure that the line-processing export backends | |
1962 | can work correctly." | |
1963 | (goto-char (point-min)) | |
1964 | (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t) | |
1965 | (org-if-unprotected | |
1966 | (replace-match "\\1 \\3") | |
1967 | (goto-char (match-beginning 0))))) | |
1968 | ||
1969 | (defun org-export-concatenate-multiline-emphasis () | |
1970 | "Find multi-line emphasis and put it all into a single line. | |
1971 | This is to make sure that the line-processing export backends | |
1972 | can work correctly." | |
1973 | (goto-char (point-min)) | |
1974 | (while (re-search-forward org-emph-re nil t) | |
0bd48b37 CD |
1975 | (if (and (not (= (char-after (match-beginning 3)) |
1976 | (char-after (match-beginning 4)))) | |
1977 | (save-excursion (goto-char (match-beginning 0)) | |
1978 | (save-match-data (not (org-at-table-p))))) | |
b349f79f CD |
1979 | (org-if-unprotected |
1980 | (subst-char-in-region (match-beginning 0) (match-end 0) | |
1981 | ?\n ?\ t) | |
1982 | (goto-char (1- (match-end 0)))) | |
1983 | (goto-char (1+ (match-beginning 0)))))) | |
1984 | ||
20908596 CD |
1985 | (defun org-export-grab-title-from-buffer () |
1986 | "Get a title for the current document, from looking at the buffer." | |
1987 | (let ((inhibit-read-only t)) | |
1988 | (save-excursion | |
1989 | (goto-char (point-min)) | |
621f83e4 CD |
1990 | (let ((end (if (looking-at org-outline-regexp) |
1991 | (point) | |
1992 | (save-excursion (outline-next-heading) (point))))) | |
20908596 CD |
1993 | (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t) |
1994 | ;; Mark the line so that it will not be exported as normal text. | |
1995 | (org-unmodified | |
1996 | (add-text-properties (match-beginning 0) (match-end 0) | |
1997 | (list :org-license-to-kill t))) | |
1998 | ;; Return the title string | |
1999 | (org-trim (match-string 0))))))) | |
2000 | ||
2001 | (defun org-export-get-title-from-subtree () | |
2002 | "Return subtree title and exclude it from export." | |
65c439fd | 2003 | (let (title (rbeg (region-beginning)) (rend (region-end))) |
20908596 | 2004 | (save-excursion |
b349f79f | 2005 | (goto-char rbeg) |
20908596 | 2006 | (when (and (org-at-heading-p) |
b349f79f | 2007 | (>= (org-end-of-subtree t t) rend)) |
20908596 | 2008 | ;; This is a subtree, we take the title from the first heading |
b349f79f | 2009 | (goto-char rbeg) |
20908596 CD |
2010 | (looking-at org-todo-line-regexp) |
2011 | (setq title (match-string 3)) | |
2012 | (org-unmodified | |
2013 | (add-text-properties (point) (1+ (point-at-eol)) | |
b349f79f CD |
2014 | (list :org-license-to-kill t))) |
2015 | (setq title (or (org-entry-get nil "EXPORT_TITLE") title)))) | |
20908596 CD |
2016 | title)) |
2017 | ||
2018 | (defun org-solidify-link-text (s &optional alist) | |
2019 | "Take link text and make a safe target out of it." | |
2020 | (save-match-data | |
2021 | (let* ((rtn | |
2022 | (mapconcat | |
2023 | 'identity | |
2024 | (org-split-string s "[ \t\r\n]+") "==")) | |
2025 | (a (assoc rtn alist))) | |
2026 | (or (cdr a) rtn)))) | |
2027 | ||
c8d0cf5c | 2028 | (defun org-get-min-level (lines &optional offset) |
20908596 | 2029 | "Get the minimum level in LINES." |
65c439fd | 2030 | (let ((re "^\\(\\*+\\) ") l) |
20908596 CD |
2031 | (catch 'exit |
2032 | (while (setq l (pop lines)) | |
2033 | (if (string-match re l) | |
c8d0cf5c CD |
2034 | (throw 'exit (org-tr-level (- (length (match-string 1 l)) |
2035 | (or offset 0)))))) | |
20908596 CD |
2036 | 1))) |
2037 | ||
2038 | ;; Variable holding the vector with section numbers | |
2039 | (defvar org-section-numbers (make-vector org-level-max 0)) | |
2040 | ||
2041 | (defun org-init-section-numbers () | |
2042 | "Initialize the vector for the section numbers." | |
2043 | (let* ((level -1) | |
2044 | (numbers (nreverse (org-split-string "" "\\."))) | |
2045 | (depth (1- (length org-section-numbers))) | |
2046 | (i depth) number-string) | |
2047 | (while (>= i 0) | |
2048 | (if (> i level) | |
2049 | (aset org-section-numbers i 0) | |
2050 | (setq number-string (or (car numbers) "0")) | |
2051 | (if (string-match "\\`[A-Z]\\'" number-string) | |
2052 | (aset org-section-numbers i | |
2053 | (- (string-to-char number-string) ?A -1)) | |
b349f79f | 2054 | (aset org-section-numbers i (string-to-number number-string))) |
20908596 CD |
2055 | (pop numbers)) |
2056 | (setq i (1- i))))) | |
2057 | ||
2058 | (defun org-section-number (&optional level) | |
2059 | "Return a string with the current section number. | |
2060 | When LEVEL is non-nil, increase section numbers on that level." | |
b349f79f CD |
2061 | (let* ((depth (1- (length org-section-numbers))) |
2062 | (string "") | |
2063 | (fmts (car org-export-section-number-format)) | |
2064 | (term (cdr org-export-section-number-format)) | |
2065 | (sep "") | |
2066 | ctype fmt idx n) | |
20908596 CD |
2067 | (when level |
2068 | (when (> level -1) | |
2069 | (aset org-section-numbers | |
2070 | level (1+ (aref org-section-numbers level)))) | |
2071 | (setq idx (1+ level)) | |
2072 | (while (<= idx depth) | |
2073 | (if (not (= idx 1)) | |
2074 | (aset org-section-numbers idx 0)) | |
2075 | (setq idx (1+ idx)))) | |
2076 | (setq idx 0) | |
2077 | (while (<= idx depth) | |
b349f79f CD |
2078 | (when (> (aref org-section-numbers idx) 0) |
2079 | (setq fmt (or (pop fmts) fmt) | |
2080 | ctype (car fmt) | |
2081 | n (aref org-section-numbers idx) | |
2082 | string (if (> n 0) | |
2083 | (concat string sep (org-number-to-counter n ctype)) | |
2084 | (concat string ".0")) | |
2085 | sep (nth 1 fmt))) | |
20908596 CD |
2086 | (setq idx (1+ idx))) |
2087 | (save-match-data | |
2088 | (if (string-match "\\`\\([@0]\\.\\)+" string) | |
2089 | (setq string (replace-match "" t nil string))) | |
2090 | (if (string-match "\\(\\.0\\)+\\'" string) | |
2091 | (setq string (replace-match "" t nil string)))) | |
b349f79f CD |
2092 | (concat string term))) |
2093 | ||
2094 | (defun org-number-to-counter (n type) | |
2095 | "Concert number N to a string counter, according to TYPE. | |
2096 | TYPE must be a string, any of: | |
2097 | 1 number | |
2098 | A A,B,.... | |
2099 | a a,b,.... | |
33306645 | 2100 | I upper case roman numeral |
b349f79f CD |
2101 | i lower case roman numeral" |
2102 | (cond | |
2103 | ((equal type "1") (number-to-string n)) | |
2104 | ((equal type "A") (char-to-string (+ ?A n -1))) | |
2105 | ((equal type "a") (char-to-string (+ ?a n -1))) | |
2106 | ((equal type "I") (org-number-to-roman n)) | |
2107 | ((equal type "i") (downcase (org-number-to-roman n))) | |
2108 | (t (error "Invalid counter type `%s'" type)))) | |
2109 | ||
2110 | (defun org-number-to-roman (n) | |
2111 | "Convert integer N into a roman numeral." | |
2112 | (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD") | |
2113 | ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL") | |
2114 | ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV") | |
2115 | ( 1 . "I"))) | |
2116 | (res "")) | |
2117 | (if (<= n 0) | |
2118 | (number-to-string n) | |
2119 | (while roman | |
2120 | (if (>= n (caar roman)) | |
2121 | (setq n (- n (caar roman)) | |
2122 | res (concat res (cdar roman))) | |
2123 | (pop roman))) | |
2124 | res))) | |
2125 | ||
c8d0cf5c | 2126 | ;;; Macros |
ff4be292 | 2127 | |
c8d0cf5c CD |
2128 | (defun org-export-preprocess-apply-macros () |
2129 | "Replace macro references." | |
2130 | (goto-char (point-min)) | |
2131 | (let (sy val key args args2 s n) | |
2132 | (while (re-search-forward | |
54a0dee5 | 2133 | "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ \t\n]*\\([^\000]*?\\))\\)?}}}" |
c8d0cf5c | 2134 | nil t) |
8d642074 CD |
2135 | (unless (save-match-data |
2136 | (save-excursion | |
2137 | (goto-char (point-at-bol)) | |
2138 | (looking-at "[ \t]*#\\+macro"))) | |
2139 | (setq key (downcase (match-string 1)) | |
2140 | args (match-string 3)) | |
2141 | (when (setq val (or (plist-get org-export-opt-plist | |
2142 | (intern (concat ":macro-" key))) | |
2143 | (plist-get org-export-opt-plist | |
2144 | (intern (concat ":" key))))) | |
2145 | (save-match-data | |
2146 | (when args | |
2147 | (setq args (org-split-string args ",[ \t\n]*") args2 nil) | |
2148 | (setq args (mapcar 'org-trim args)) | |
2149 | (while args | |
2150 | (while (string-match "\\\\\\'" (car args)) | |
2151 | ;; repair bad splits | |
2152 | (setcar (cdr args) (concat (substring (car args) 0 -1) | |
2153 | ";" (nth 1 args))) | |
2154 | (pop args)) | |
2155 | (push (pop args) args2)) | |
2156 | (setq args (nreverse args2)) | |
2157 | (setq s 0) | |
2158 | (while (string-match "\\$\\([0-9]+\\)" val s) | |
2159 | (setq s (1+ (match-beginning 0)) | |
2160 | n (string-to-number (match-string 1 val))) | |
2161 | (and (>= (length args) n) | |
2162 | (setq val (replace-match (nth (1- n) args) t t val))))) | |
2163 | (when (string-match "\\`(eval\\>" val) | |
2164 | (setq val (eval (read val)))) | |
2165 | (if (and val (not (stringp val))) | |
2166 | (setq val (format "%s" val)))) | |
2167 | (and (stringp val) | |
2168 | (prog1 (replace-match val t t) | |
2169 | (goto-char (match-beginning 0))))))))) | |
c8d0cf5c CD |
2170 | |
2171 | (defun org-export-apply-macros-in-string (s) | |
2172 | "Apply the macros in string S." | |
2173 | (when s | |
2174 | (with-temp-buffer | |
2175 | (insert s) | |
2176 | (org-export-preprocess-apply-macros) | |
2177 | (buffer-string)))) | |
b349f79f CD |
2178 | |
2179 | ;;; Include files | |
2180 | ||
2181 | (defun org-export-handle-include-files () | |
2182 | "Include the contents of include files, with proper formatting." | |
2183 | (let ((case-fold-search t) | |
0bd48b37 | 2184 | params file markup lang start end prefix prefix1 switches) |
b349f79f CD |
2185 | (goto-char (point-min)) |
2186 | (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t) | |
2187 | (setq params (read (concat "(" (match-string 1) ")")) | |
2c3ad40d CD |
2188 | prefix (org-get-and-remove-property 'params :prefix) |
2189 | prefix1 (org-get-and-remove-property 'params :prefix1) | |
b349f79f CD |
2190 | file (org-symname-or-string (pop params)) |
2191 | markup (org-symname-or-string (pop params)) | |
0bd48b37 CD |
2192 | lang (and (member markup '("src" "SRC")) |
2193 | (org-symname-or-string (pop params))) | |
54a0dee5 CD |
2194 | switches (mapconcat '(lambda (x) (format "%s" x)) params " ") |
2195 | start nil end nil) | |
b349f79f CD |
2196 | (delete-region (match-beginning 0) (match-end 0)) |
2197 | (if (or (not file) | |
2198 | (not (file-exists-p file)) | |
2199 | (not (file-readable-p file))) | |
2200 | (insert (format "CANNOT INCLUDE FILE %s" file)) | |
2201 | (when markup | |
2202 | (if (equal (downcase markup) "src") | |
0bd48b37 CD |
2203 | (setq start (format "#+begin_src %s %s\n" |
2204 | (or lang "fundamental") | |
2205 | (or switches "")) | |
b349f79f | 2206 | end "#+end_src") |
0bd48b37 | 2207 | (setq start (format "#+begin_%s %s\n" markup switches) |
b349f79f CD |
2208 | end (format "#+end_%s" markup)))) |
2209 | (insert (or start "")) | |
54a0dee5 CD |
2210 | (insert (org-get-file-contents (expand-file-name file) |
2211 | prefix prefix1 markup)) | |
b349f79f CD |
2212 | (or (bolp) (newline)) |
2213 | (insert (or end "")))))) | |
2214 | ||
c8d0cf5c | 2215 | (defun org-get-file-contents (file &optional prefix prefix1 markup) |
2c3ad40d CD |
2216 | "Get the contents of FILE and return them as a string. |
2217 | If PREFIX is a string, prepend it to each line. If PREFIX1 | |
c8d0cf5c CD |
2218 | is a string, prepend it to the first line instead of PREFIX. |
2219 | If MARKUP, don't protect org-like lines, the exporter will | |
2220 | take care of the block they are in." | |
54a0dee5 | 2221 | (if (stringp markup) (setq markup (downcase markup))) |
2c3ad40d CD |
2222 | (with-temp-buffer |
2223 | (insert-file-contents file) | |
2224 | (when (or prefix prefix1) | |
2225 | (goto-char (point-min)) | |
2226 | (while (not (eobp)) | |
2227 | (insert (or prefix1 prefix)) | |
2228 | (setq prefix1 nil) | |
2229 | (beginning-of-line 2))) | |
c8d0cf5c | 2230 | (buffer-string) |
54a0dee5 | 2231 | (when (member markup '("src" "example")) |
c8d0cf5c | 2232 | (goto-char (point-min)) |
54a0dee5 | 2233 | (while (re-search-forward "^\\([*#]\\|[ \t]*#\\+\\)" nil t) |
c8d0cf5c CD |
2234 | (goto-char (match-beginning 0)) |
2235 | (insert ",") | |
2236 | (end-of-line 1))) | |
2c3ad40d CD |
2237 | (buffer-string))) |
2238 | ||
2239 | (defun org-get-and-remove-property (listvar prop) | |
2240 | "Check if the value of LISTVAR contains PROP as a property. | |
2241 | If yes, return the value of that property (i.e. the element following | |
2242 | in the list) and remove property and value from the list in LISTVAR." | |
2243 | (let ((list (symbol-value listvar)) m v) | |
2244 | (when (setq m (member prop list)) | |
2245 | (setq v (nth 1 m)) | |
2246 | (if (equal (car list) prop) | |
2247 | (set listvar (cddr list)) | |
2248 | (setcdr (nthcdr (- (length list) (length m) 1) list) | |
2249 | (cddr m)) | |
2250 | (set listvar list))) | |
2251 | v)) | |
2252 | ||
b349f79f CD |
2253 | (defun org-symname-or-string (s) |
2254 | (if (symbolp s) | |
2255 | (if s (symbol-name s) s) | |
2256 | s)) | |
2257 | ||
0bd48b37 CD |
2258 | ;;; Fontification and line numbers for code examples |
2259 | ||
2260 | (defvar org-export-last-code-line-counter-value 0) | |
2261 | ||
2262 | (defun org-export-replace-src-segments-and-examples (backend) | |
b349f79f | 2263 | "Replace source code segments with special code for export." |
0bd48b37 | 2264 | (setq org-export-last-code-line-counter-value 0) |
b349f79f | 2265 | (let ((case-fold-search t) |
c8d0cf5c | 2266 | lang code trans opts indent) |
b349f79f CD |
2267 | (goto-char (point-min)) |
2268 | (while (re-search-forward | |
c8d0cf5c | 2269 | "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)" |
b349f79f | 2270 | nil t) |
0bd48b37 CD |
2271 | (if (match-end 1) |
2272 | ;; src segments | |
c8d0cf5c CD |
2273 | (setq lang (match-string 3) |
2274 | opts (match-string 4) | |
2275 | code (match-string 5) | |
2276 | indent (length (match-string 2))) | |
0bd48b37 | 2277 | (setq lang nil |
c8d0cf5c CD |
2278 | opts (match-string 8) |
2279 | code (match-string 9) | |
2280 | indent (length (match-string 7)))) | |
0bd48b37 CD |
2281 | |
2282 | (setq trans (org-export-format-source-code-or-example | |
c8d0cf5c | 2283 | backend lang code opts indent)) |
b349f79f CD |
2284 | (replace-match trans t t)))) |
2285 | ||
0bd48b37 CD |
2286 | (defvar htmlp) ;; dynamically scoped |
2287 | (defvar latexp) ;; dynamically scoped | |
c8d0cf5c | 2288 | (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el |
54a0dee5 CD |
2289 | (defvar org-export-latex-listings) ;; defined in org-latex.el |
2290 | (defvar org-export-latex-listings-langs) ;; defined in org-latex.el | |
b349f79f | 2291 | |
c8d0cf5c CD |
2292 | (defun org-export-format-source-code-or-example |
2293 | (backend lang code &optional opts indent) | |
b349f79f | 2294 | "Format CODE from language LANG and return it formatted for export. |
0bd48b37 | 2295 | If LANG is nil, do not add any fontification. |
8bfe682a CD |
2296 | OPTS contains formatting options, like `-n' for triggering numbering lines, |
2297 | and `+n' for continuing previous numbering. | |
0bd48b37 | 2298 | Code formatting according to language currently only works for HTML. |
c8d0cf5c CD |
2299 | Numbering lines works for all three major backends (html, latex, and ascii). |
2300 | INDENT was the original indentation of the block." | |
b349f79f | 2301 | (save-match-data |
8bfe682a | 2302 | (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt) |
0bd48b37 CD |
2303 | (setq opts (or opts "") |
2304 | num (string-match "[-+]n\\>" opts) | |
2305 | cont (string-match "\\+n\\>" opts) | |
2306 | rpllbl (string-match "-r\\>" opts) | |
2307 | keepp (string-match "-k\\>" opts) | |
2308 | textareap (string-match "-t\\>" opts) | |
8bfe682a CD |
2309 | preserve-indentp (or org-src-preserve-indentation |
2310 | (string-match "-i\\>" opts)) | |
0bd48b37 CD |
2311 | cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts) |
2312 | (string-to-number (match-string 1 opts)) | |
2313 | 80) | |
2314 | rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts) | |
2315 | (string-to-number (match-string 1 opts)) | |
2316 | (org-count-lines code)) | |
2317 | fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts) | |
2318 | (match-string 1 opts))) | |
2319 | (when (and textareap (eq backend 'html)) | |
2320 | ;; we cannot use numbering or highlighting. | |
2321 | (setq num nil cont nil lang nil)) | |
2322 | (if keepp (setq rpllbl 'keep)) | |
8bfe682a | 2323 | (setq rtn (if preserve-indentp code (org-remove-indentation code))) |
c8d0cf5c | 2324 | (when (string-match "^," rtn) |
0bd48b37 CD |
2325 | (setq rtn (with-temp-buffer |
2326 | (insert rtn) | |
2327 | ;; Free up the protected lines | |
2328 | (goto-char (point-min)) | |
2329 | (while (re-search-forward "^," nil t) | |
c8d0cf5c CD |
2330 | (if (or (equal lang "org") |
2331 | (save-match-data | |
2332 | (looking-at "\\([*#]\\|[ \t]*#\\+\\)"))) | |
2333 | (replace-match "")) | |
0bd48b37 CD |
2334 | (end-of-line 1)) |
2335 | (buffer-string)))) | |
2336 | ;; Now backend-specific coding | |
c8d0cf5c CD |
2337 | (setq rtn |
2338 | (cond | |
2339 | ((eq backend 'docbook) | |
2340 | (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt)) | |
2341 | (concat "\n#+BEGIN_DOCBOOK\n" | |
2342 | (org-add-props (concat "<programlisting><![CDATA[" | |
2343 | rtn | |
2344 | "]]>\n</programlisting>\n") | |
2345 | '(org-protected t)) | |
2346 | "#+END_DOCBOOK\n")) | |
2347 | ((eq backend 'html) | |
2348 | ;; We are exporting to HTML | |
2349 | (when lang | |
2350 | (require 'htmlize nil t) | |
2351 | (when (not (fboundp 'htmlize-region-for-paste)) | |
2352 | ;; we do not have htmlize.el, or an old version of it | |
2353 | (setq lang nil) | |
2354 | (message | |
2355 | "htmlize.el 1.34 or later is needed for source code formatting"))) | |
2356 | ||
2357 | (if lang | |
54a0dee5 CD |
2358 | (let* ((lang-m (when lang |
2359 | (or (cdr (assoc lang org-src-lang-modes)) | |
2360 | lang))) | |
2361 | (mode (and lang-m (intern | |
2362 | (concat | |
2363 | (if (symbolp lang-m) | |
2364 | (symbol-name lang-m) | |
2365 | lang-m) | |
2366 | "-mode")))) | |
c8d0cf5c CD |
2367 | (org-inhibit-startup t) |
2368 | (org-startup-folded nil)) | |
2369 | (setq rtn | |
2370 | (with-temp-buffer | |
2371 | (insert rtn) | |
2372 | (if (functionp mode) | |
2373 | (funcall mode) | |
2374 | (fundamental-mode)) | |
2375 | (font-lock-fontify-buffer) | |
2376 | (org-src-mode) | |
2377 | (set-buffer-modified-p nil) | |
2378 | (org-export-htmlize-region-for-paste | |
2379 | (point-min) (point-max)))) | |
2380 | (if (string-match "<pre\\([^>]*\\)>\n*" rtn) | |
2381 | (setq rtn (replace-match | |
2382 | (format "<pre class=\"src src-%s\">\n" lang) | |
2383 | t t rtn)))) | |
2384 | (if textareap | |
2385 | (setq rtn (concat | |
2386 | (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n" | |
2387 | cols rows) | |
2388 | rtn "</textarea>\n</p>\n")) | |
2389 | (with-temp-buffer | |
2390 | (insert rtn) | |
2391 | (goto-char (point-min)) | |
2392 | (while (re-search-forward "[<>&]" nil t) | |
2393 | (replace-match (cdr (assq (char-before) | |
2394 | '((?&."&")(?<."<")(?>.">")))) | |
2395 | t t)) | |
2396 | (setq rtn (buffer-string))) | |
2397 | (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n")))) | |
2398 | (unless textareap | |
2399 | (setq rtn (org-export-number-lines rtn 'html 1 1 num | |
2400 | cont rpllbl fmt))) | |
2401 | (if (string-match "\\(\\`<[^>]*>\\)\n" rtn) | |
2402 | (setq rtn (replace-match "\\1" t nil rtn))) | |
2403 | (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n")) | |
2404 | ((eq backend 'latex) | |
2405 | (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt)) | |
2406 | (concat "\n#+BEGIN_LaTeX\n" | |
54a0dee5 CD |
2407 | (org-add-props |
2408 | (if org-export-latex-listings | |
2409 | (concat | |
2410 | (if lang | |
2411 | (let* | |
2412 | ((lang-sym (intern lang)) | |
2413 | (lstlang | |
2414 | (or (cadr | |
2415 | (assq | |
2416 | lang-sym | |
2417 | org-export-latex-listings-langs)) | |
2418 | lang))) | |
2419 | (format "\\lstset{language=%s}\n" lstlang)) | |
2420 | "") | |
2421 | "\\begin{lstlisting}\n" | |
2422 | rtn "\\end{lstlisting}\n") | |
2423 | (concat (car org-export-latex-verbatim-wrap) | |
2424 | rtn (cdr org-export-latex-verbatim-wrap))) | |
c8d0cf5c CD |
2425 | '(org-protected t)) |
2426 | "#+END_LaTeX\n\n")) | |
2427 | ((eq backend 'ascii) | |
2428 | ;; This is not HTML or LaTeX, so just make it an example. | |
2429 | (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt)) | |
2430 | (concat "#+BEGIN_ASCII\n" | |
2431 | (org-add-props | |
2432 | (concat | |
2433 | (mapconcat | |
2434 | (lambda (l) (concat " " l)) | |
2435 | (org-split-string rtn "\n") | |
2436 | "\n") | |
2437 | "\n") | |
2438 | '(org-protected t)) | |
2439 | "#+END_ASCII\n")))) | |
2440 | (org-add-props rtn nil 'original-indentation indent)))) | |
0bd48b37 CD |
2441 | |
2442 | (defun org-export-number-lines (text backend | |
2443 | &optional skip1 skip2 number cont | |
2444 | replace-labels label-format) | |
0bd48b37 CD |
2445 | (setq skip1 (or skip1 0) skip2 (or skip2 0)) |
2446 | (if (not cont) (setq org-export-last-code-line-counter-value 0)) | |
2447 | (with-temp-buffer | |
2448 | (insert text) | |
2449 | (goto-char (point-max)) | |
2450 | (skip-chars-backward " \t\n\r") | |
2451 | (delete-region (point) (point-max)) | |
2452 | (beginning-of-line (- 1 skip2)) | |
2453 | (let* ((last (org-current-line)) | |
2454 | (n org-export-last-code-line-counter-value) | |
2455 | (nmax (+ n (- last skip1))) | |
2456 | (fmt (format "%%%dd: " (length (number-to-string nmax)))) | |
2457 | (fm | |
2458 | (cond | |
2459 | ((eq backend 'html) (format "<span class=\"linenr\">%s</span>" | |
2460 | fmt)) | |
2461 | ((eq backend 'ascii) fmt) | |
2462 | ((eq backend 'latex) fmt) | |
c8d0cf5c | 2463 | ((eq backend 'docbook) fmt) |
0bd48b37 CD |
2464 | (t ""))) |
2465 | (label-format (or label-format org-coderef-label-format)) | |
2466 | (label-pre (if (string-match "%s" label-format) | |
2467 | (substring label-format 0 (match-beginning 0)) | |
2468 | label-format)) | |
2469 | (label-post (if (string-match "%s" label-format) | |
2470 | (substring label-format (match-end 0)) | |
2471 | "")) | |
2472 | (lbl-re | |
c8d0cf5c | 2473 | (concat |
0bd48b37 CD |
2474 | ".*?\\S-.*?\\([ \t]*\\(" |
2475 | (regexp-quote label-pre) | |
c8d0cf5c | 2476 | "\\([-a-zA-Z0-9_ ]+\\)" |
0bd48b37 CD |
2477 | (regexp-quote label-post) |
2478 | "\\)\\)")) | |
2479 | ref) | |
2480 | ||
54a0dee5 | 2481 | (org-goto-line (1+ skip1)) |
0bd48b37 CD |
2482 | (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax)) |
2483 | (if number | |
2484 | (insert (format fm (incf n))) | |
2485 | (forward-char 1)) | |
c8d0cf5c | 2486 | (when (looking-at lbl-re) |
0bd48b37 | 2487 | (setq ref (match-string 3)) |
c8d0cf5c CD |
2488 | (cond ((numberp replace-labels) |
2489 | ;; remove labels; use numbers for references when lines | |
2490 | ;; are numbered, use labels otherwise | |
2491 | (delete-region (match-beginning 1) (match-end 1)) | |
2492 | (push (cons ref (if (> n 0) n ref)) org-export-code-refs)) | |
2493 | ((eq replace-labels 'keep) | |
2494 | ;; don't remove labels; use numbers for references when | |
2495 | ;; lines are numbered, use labels otherwise | |
2496 | (goto-char (match-beginning 2)) | |
2497 | (delete-region (match-beginning 2) (match-end 2)) | |
2498 | (insert "(" ref ")") | |
2499 | (push (cons ref (if (> n 0) n (concat "(" ref ")"))) | |
2500 | org-export-code-refs)) | |
2501 | (t | |
2502 | ;; don't remove labels and don't use numbers for | |
2503 | ;; references | |
2504 | (goto-char (match-beginning 2)) | |
2505 | (delete-region (match-beginning 2) (match-end 2)) | |
2506 | (insert "(" ref ")") | |
2507 | (push (cons ref (concat "(" ref ")")) org-export-code-refs))) | |
0bd48b37 CD |
2508 | (when (eq backend 'html) |
2509 | (save-excursion | |
2510 | (beginning-of-line 1) | |
2511 | (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">" | |
2512 | ref)) | |
2513 | (end-of-line 1) | |
2514 | (insert "</span>"))))) | |
2515 | (setq org-export-last-code-line-counter-value n) | |
2516 | (goto-char (point-max)) | |
2517 | (newline) | |
2518 | (buffer-string)))) | |
20908596 | 2519 | |
20908596 CD |
2520 | (defun org-search-todo-below (line lines level) |
2521 | "Search the subtree below LINE for any TODO entries." | |
2522 | (let ((rest (cdr (memq line lines))) | |
2523 | (re org-todo-line-regexp) | |
2524 | line lv todo) | |
2525 | (catch 'exit | |
2526 | (while (setq line (pop rest)) | |
2527 | (if (string-match re line) | |
2528 | (progn | |
2529 | (setq lv (- (match-end 1) (match-beginning 1)) | |
2530 | todo (and (match-beginning 2) | |
2531 | (not (member (match-string 2 line) | |
2532 | org-done-keywords)))) | |
2533 | ; TODO, not DONE | |
2534 | (if (<= lv level) (throw 'exit nil)) | |
2535 | (if todo (throw 'exit t)))))))) | |
2536 | ||
20908596 CD |
2537 | ;;;###autoload |
2538 | (defun org-export-visible (type arg) | |
2539 | "Create a copy of the visible part of the current buffer, and export it. | |
2540 | The copy is created in a temporary buffer and removed after use. | |
2541 | TYPE is the final key (as a string) that also select the export command in | |
2542 | the `C-c C-e' export dispatcher. | |
88dbda51 JB |
2543 | |
2544 | As a special case, if you type SPC at the prompt, the temporary org-mode | |
2545 | file will not be removed but presented to you so that you can continue to | |
2546 | use it. The prefix arg ARG is passed through to the exporting command." | |
20908596 CD |
2547 | (interactive |
2548 | (list (progn | |
c8d0cf5c | 2549 | (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer") |
20908596 CD |
2550 | (read-char-exclusive)) |
2551 | current-prefix-arg)) | |
c8d0cf5c | 2552 | (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ ))) |
20908596 CD |
2553 | (error "Invalid export key")) |
2554 | (let* ((binding (cdr (assoc type | |
2555 | '((?a . org-export-as-ascii) | |
c8d0cf5c | 2556 | (?A . org-export-as-ascii-to-buffer) |
20908596 CD |
2557 | (?\C-a . org-export-as-ascii) |
2558 | (?b . org-export-as-html-and-open) | |
2559 | (?\C-b . org-export-as-html-and-open) | |
2560 | (?h . org-export-as-html) | |
2561 | (?H . org-export-as-html-to-buffer) | |
2562 | (?R . org-export-region-as-html) | |
c8d0cf5c | 2563 | (?D . org-export-as-docbook) |
20908596 CD |
2564 | (?x . org-export-as-xoxo))))) |
2565 | (keepp (equal type ?\ )) | |
2566 | (file buffer-file-name) | |
2567 | (buffer (get-buffer-create "*Org Export Visible*")) | |
2568 | s e) | |
2569 | ;; Need to hack the drawers here. | |
2570 | (save-excursion | |
2571 | (goto-char (point-min)) | |
2572 | (while (re-search-forward org-drawer-regexp nil t) | |
2573 | (goto-char (match-beginning 1)) | |
2574 | (or (org-invisible-p) (org-flag-drawer nil)))) | |
2575 | (with-current-buffer buffer (erase-buffer)) | |
2576 | (save-excursion | |
2577 | (setq s (goto-char (point-min))) | |
2578 | (while (not (= (point) (point-max))) | |
2579 | (goto-char (org-find-invisible)) | |
2580 | (append-to-buffer buffer s (point)) | |
2581 | (setq s (goto-char (org-find-visible)))) | |
2582 | (org-cycle-hide-drawers 'all) | |
2583 | (goto-char (point-min)) | |
2584 | (unless keepp | |
2585 | ;; Copy all comment lines to the end, to make sure #+ settings are | |
2586 | ;; still available for the second export step. Kind of a hack, but | |
2587 | ;; does do the trick. | |
2588 | (if (looking-at "#[^\r\n]*") | |
2589 | (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0)))) | |
2590 | (while (re-search-forward "[\n\r]#[^\n\r]*" nil t) | |
2591 | (append-to-buffer buffer (1+ (match-beginning 0)) | |
2592 | (min (point-max) (1+ (match-end 0)))))) | |
2593 | (set-buffer buffer) | |
2594 | (let ((buffer-file-name file) | |
2595 | (org-inhibit-startup t)) | |
2596 | (org-mode) | |
2597 | (show-all) | |
2598 | (unless keepp (funcall binding arg)))) | |
2599 | (if (not keepp) | |
2600 | (kill-buffer buffer) | |
2601 | (switch-to-buffer-other-window buffer) | |
2602 | (goto-char (point-min))))) | |
2603 | ||
2604 | (defun org-find-visible () | |
2605 | (let ((s (point))) | |
2606 | (while (and (not (= (point-max) (setq s (next-overlay-change s)))) | |
2607 | (get-char-property s 'invisible))) | |
2608 | s)) | |
2609 | (defun org-find-invisible () | |
2610 | (let ((s (point))) | |
2611 | (while (and (not (= (point-max) (setq s (next-overlay-change s)))) | |
2612 | (not (get-char-property s 'invisible)))) | |
2613 | s)) | |
2614 | ||
c8d0cf5c CD |
2615 | (defvar org-export-htmlized-org-css-url) ;; defined in org-html.el |
2616 | ||
2617 | ;;;###autoload | |
2618 | (defun org-export-as-org (arg &optional hidden ext-plist | |
2619 | to-buffer body-only pub-dir) | |
2620 | "Make a copy with not-exporting stuff removed. | |
2621 | The purpose of this function is to provide a way to export the source | |
2622 | Org file of a webpage in Org format, but with sensitive and/or irrelevant | |
2623 | stuff removed. This command will remove the following: | |
2624 | ||
2625 | - archived trees (if the variable `org-export-with-archived-trees' is nil) | |
2626 | - comment blocks and trees starting with the COMMENT keyword | |
2627 | - only trees that are consistent with `org-export-select-tags' | |
2628 | and `org-export-exclude-tags'. | |
2629 | ||
2630 | The only arguments that will be used are EXT-PLIST and PUB-DIR, | |
2631 | all the others will be ignored (but are present so that the general | |
2632 | mechanism to call publishing functions will work). | |
2633 | ||
2634 | EXT-PLIST is a property list with external parameters overriding | |
2635 | org-mode's default settings, but still inferior to file-local | |
2636 | settings. When PUB-DIR is set, use this as the publishing | |
2637 | directory." | |
2638 | (interactive "P") | |
2639 | (let* ((opt-plist (org-combine-plists (org-default-export-plist) | |
2640 | ext-plist | |
2641 | (org-infile-export-plist))) | |
2642 | (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer)))) | |
2643 | (filename (concat (file-name-as-directory | |
2644 | (or pub-dir | |
2645 | (org-export-directory :org opt-plist))) | |
2646 | (file-name-sans-extension | |
2647 | (file-name-nondirectory bfname)) | |
2648 | ".org")) | |
2649 | (filename (and filename | |
2650 | (if (equal (file-truename filename) | |
2651 | (file-truename bfname)) | |
2652 | (concat (file-name-sans-extension filename) | |
2653 | "-source." | |
2654 | (file-name-extension filename)) | |
2655 | filename))) | |
2656 | (backup-inhibited t) | |
2657 | (buffer (find-file-noselect filename)) | |
2658 | (region (buffer-string))) | |
2659 | (save-excursion | |
2660 | (switch-to-buffer buffer) | |
2661 | (erase-buffer) | |
2662 | (insert region) | |
2663 | (let ((org-inhibit-startup t)) (org-mode)) | |
2664 | (org-install-letbind) | |
2665 | ||
2666 | ;; Get rid of archived trees | |
2667 | (org-export-remove-archived-trees (plist-get opt-plist :archived-trees)) | |
2668 | ||
2669 | ;; Remove comment environment and comment subtrees | |
2670 | (org-export-remove-comment-blocks-and-subtrees) | |
2671 | ||
2672 | ;; Get rid of excluded trees | |
2673 | (org-export-handle-export-tags (plist-get opt-plist :select-tags) | |
2674 | (plist-get opt-plist :exclude-tags)) | |
2675 | ||
2676 | (when (or (plist-get opt-plist :plain-source) | |
2677 | (not (or (plist-get opt-plist :plain-source) | |
2678 | (plist-get opt-plist :htmlized-source)))) | |
2679 | ;; Either nothing special is requested (default call) | |
2680 | ;; or the plain source is explicitly requested | |
2681 | ;; so: save it | |
2682 | (save-buffer)) | |
2683 | (when (plist-get opt-plist :htmlized-source) | |
2684 | ;; Make the htmlized version | |
2685 | (require 'htmlize) | |
2686 | (require 'org-html) | |
2687 | (font-lock-fontify-buffer) | |
2688 | (let* ((htmlize-output-type 'css) | |
2689 | (newbuf (htmlize-buffer))) | |
2690 | (with-current-buffer newbuf | |
2691 | (when org-export-htmlized-org-css-url | |
2692 | (goto-char (point-min)) | |
2693 | (and (re-search-forward | |
2694 | "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*" | |
2695 | nil t) | |
2696 | (replace-match | |
2697 | (format | |
2698 | "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">" | |
2699 | org-export-htmlized-org-css-url) | |
2700 | t t))) | |
2701 | (write-file (concat filename ".html"))) | |
2702 | (kill-buffer newbuf))) | |
2703 | (set-buffer-modified-p nil) | |
2704 | (kill-buffer (current-buffer))))) | |
20908596 | 2705 | |
33306645 | 2706 | (defvar org-archive-location) ;; gets loaded with the org-archive require. |
20908596 CD |
2707 | (defun org-get-current-options () |
2708 | "Return a string with current options as keyword options. | |
2709 | Does include HTML export options as well as TODO and CATEGORY stuff." | |
2710 | (require 'org-archive) | |
2711 | (format | |
2712 | "#+TITLE: %s | |
2713 | #+AUTHOR: %s | |
2714 | #+EMAIL: %s | |
2715 | #+DATE: %s | |
c8d0cf5c CD |
2716 | #+DESCRIPTION: |
2717 | #+KEYWORDS: | |
20908596 | 2718 | #+LANGUAGE: %s |
0bd48b37 CD |
2719 | #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s |
2720 | #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s | |
20908596 | 2721 | %s |
621f83e4 | 2722 | #+EXPORT_SELECT_TAGS: %s |
93b62de8 | 2723 | #+EXPORT_EXCLUDE_TAGS: %s |
20908596 CD |
2724 | #+LINK_UP: %s |
2725 | #+LINK_HOME: %s | |
2726 | #+CATEGORY: %s | |
2727 | #+SEQ_TODO: %s | |
2728 | #+TYP_TODO: %s | |
2729 | #+PRIORITIES: %c %c %c | |
2730 | #+DRAWERS: %s | |
2731 | #+STARTUP: %s %s %s %s %s | |
2732 | #+TAGS: %s | |
b349f79f | 2733 | #+FILETAGS: %s |
20908596 CD |
2734 | #+ARCHIVE: %s |
2735 | #+LINK: %s | |
2736 | " | |
2737 | (buffer-name) (user-full-name) user-mail-address | |
621f83e4 | 2738 | (format-time-string (substring (car org-time-stamp-formats) 1 -1)) |
20908596 CD |
2739 | org-export-default-language |
2740 | org-export-headline-levels | |
2741 | org-export-with-section-numbers | |
2742 | org-export-with-toc | |
2743 | org-export-preserve-breaks | |
2744 | org-export-html-expand | |
2745 | org-export-with-fixed-width | |
2746 | org-export-with-tables | |
2747 | org-export-with-sub-superscripts | |
2748 | org-export-with-special-strings | |
2749 | org-export-with-footnotes | |
2750 | org-export-with-emphasize | |
0bd48b37 | 2751 | org-export-with-timestamps |
20908596 CD |
2752 | org-export-with-TeX-macros |
2753 | org-export-with-LaTeX-fragments | |
2754 | org-export-skip-text-before-1st-heading | |
2755 | org-export-with-drawers | |
ff4be292 CD |
2756 | org-export-with-todo-keywords |
2757 | org-export-with-priority | |
20908596 | 2758 | org-export-with-tags |
b349f79f | 2759 | (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "") |
621f83e4 CD |
2760 | (mapconcat 'identity org-export-select-tags " ") |
2761 | (mapconcat 'identity org-export-exclude-tags " ") | |
20908596 CD |
2762 | org-export-html-link-up |
2763 | org-export-html-link-home | |
d6685abc CD |
2764 | (or (ignore-errors |
2765 | (file-name-sans-extension | |
2766 | (file-name-nondirectory (buffer-file-name (buffer-base-buffer))))) | |
2767 | "NOFILENAME") | |
20908596 CD |
2768 | "TODO FEEDBACK VERIFY DONE" |
2769 | "Me Jason Marie DONE" | |
2770 | org-highest-priority org-lowest-priority org-default-priority | |
2771 | (mapconcat 'identity org-drawers " ") | |
2772 | (cdr (assoc org-startup-folded | |
2773 | '((nil . "showall") (t . "overview") (content . "content")))) | |
2774 | (if org-odd-levels-only "odd" "oddeven") | |
2775 | (if org-hide-leading-stars "hidestars" "showstars") | |
2776 | (if org-startup-align-all-tables "align" "noalign") | |
2777 | (cond ((eq org-log-done t) "logdone") | |
2778 | ((equal org-log-done 'note) "lognotedone") | |
2779 | ((not org-log-done) "nologdone")) | |
2780 | (or (mapconcat (lambda (x) | |
2781 | (cond | |
8bfe682a CD |
2782 | ((equal :startgroup (car x)) "{") |
2783 | ((equal :endgroup (car x)) "}") | |
2784 | ((equal :newline (car x)) "") | |
20908596 CD |
2785 | ((cdr x) (format "%s(%c)" (car x) (cdr x))) |
2786 | (t (car x)))) | |
2787 | (or org-tag-alist (org-get-buffer-tags)) " ") "") | |
b349f79f | 2788 | (mapconcat 'identity org-file-tags " ") |
20908596 CD |
2789 | org-archive-location |
2790 | "org file:~/org/%s.org" | |
2791 | )) | |
2792 | ||
2793 | ;;;###autoload | |
2794 | (defun org-insert-export-options-template () | |
2795 | "Insert into the buffer a template with information for exporting." | |
2796 | (interactive) | |
2797 | (if (not (bolp)) (newline)) | |
2798 | (let ((s (org-get-current-options))) | |
2799 | (and (string-match "#\\+CATEGORY" s) | |
2800 | (setq s (substring s 0 (match-beginning 0)))) | |
2801 | (insert s))) | |
2802 | ||
20908596 | 2803 | (defvar org-table-colgroup-info nil) |
20908596 | 2804 | |
0bd48b37 | 2805 | (defun org-table-clean-before-export (lines &optional maybe-quoted) |
20908596 CD |
2806 | "Check if the table has a marking column. |
2807 | If yes remove the column and the special lines." | |
2808 | (setq org-table-colgroup-info nil) | |
2809 | (if (memq nil | |
2810 | (mapcar | |
2811 | (lambda (x) (or (string-match "^[ \t]*|-" x) | |
0bd48b37 CD |
2812 | (string-match |
2813 | (if maybe-quoted | |
2814 | "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|" | |
2815 | "^[ \t]*| *\\([\#!$*_^ /]\\) *|") | |
2816 | x))) | |
20908596 CD |
2817 | lines)) |
2818 | (progn | |
2819 | (setq org-table-clean-did-remove-column nil) | |
2820 | (delq nil | |
2821 | (mapcar | |
2822 | (lambda (x) | |
2823 | (cond | |
2824 | ((string-match "^[ \t]*| */ *|" x) | |
2825 | (setq org-table-colgroup-info | |
2826 | (mapcar (lambda (x) | |
2827 | (cond ((member x '("<" "<")) :start) | |
2828 | ((member x '(">" ">")) :end) | |
2829 | ((member x '("<>" "<>")) :startend) | |
2830 | (t nil))) | |
2831 | (org-split-string x "[ \t]*|[ \t]*"))) | |
2832 | nil) | |
2833 | (t x))) | |
2834 | lines))) | |
2835 | (setq org-table-clean-did-remove-column t) | |
2836 | (delq nil | |
2837 | (mapcar | |
2838 | (lambda (x) | |
2839 | (cond | |
2840 | ((string-match "^[ \t]*| */ *|" x) | |
2841 | (setq org-table-colgroup-info | |
2842 | (mapcar (lambda (x) | |
2843 | (cond ((member x '("<" "<")) :start) | |
2844 | ((member x '(">" ">")) :end) | |
2845 | ((member x '("<>" "<>")) :startend) | |
2846 | (t nil))) | |
2847 | (cdr (org-split-string x "[ \t]*|[ \t]*")))) | |
2848 | nil) | |
2849 | ((string-match "^[ \t]*| *[!_^/] *|" x) | |
2850 | nil) ; ignore this line | |
2851 | ((or (string-match "^\\([ \t]*\\)|-+\\+" x) | |
2852 | (string-match "^\\([ \t]*\\)|[^|]*|" x)) | |
2853 | ;; remove the first column | |
2854 | (replace-match "\\1|" t nil x)))) | |
2855 | lines)))) | |
2856 | ||
20908596 | 2857 | (defun org-export-cleanup-toc-line (s) |
33306645 | 2858 | "Remove tags and timestamps from lines going into the toc." |
20908596 CD |
2859 | (when (memq org-export-with-tags '(not-in-toc nil)) |
2860 | (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s) | |
2861 | (setq s (replace-match "" t t s)))) | |
2862 | (when org-export-remove-timestamps-from-toc | |
2863 | (while (string-match org-maybe-keyword-time-regexp s) | |
2864 | (setq s (replace-match "" t t s)))) | |
2865 | (while (string-match org-bracket-link-regexp s) | |
2866 | (setq s (replace-match (match-string (if (match-end 3) 3 1) s) | |
2867 | t t s))) | |
8d642074 CD |
2868 | (while (string-match "\\[\\([0-9]\\|fn:[^]]*\\)\\]" s) |
2869 | (setq s (replace-match "" t t s))) | |
20908596 CD |
2870 | s) |
2871 | ||
20908596 CD |
2872 | (defun org-create-multibrace-regexp (left right n) |
2873 | "Create a regular expression which will match a balanced sexp. | |
2874 | Opening delimiter is LEFT, and closing delimiter is RIGHT, both given | |
2875 | as single character strings. | |
2876 | The regexp returned will match the entire expression including the | |
2877 | delimiters. It will also define a single group which contains the | |
2878 | match except for the outermost delimiters. The maximum depth of | |
2879 | stacked delimiters is N. Escaping delimiters is not possible." | |
c8d0cf5c | 2880 | (let* ((nothing (concat "[^" left right "]*?")) |
20908596 CD |
2881 | (or "\\|") |
2882 | (re nothing) | |
2883 | (next (concat "\\(?:" nothing left nothing right "\\)+" nothing))) | |
2884 | (while (> n 1) | |
2885 | (setq n (1- n) | |
2886 | re (concat re or next) | |
2887 | next (concat "\\(?:" nothing left next right "\\)+" nothing))) | |
2888 | (concat left "\\(" re "\\)" right))) | |
2889 | ||
2890 | (defvar org-match-substring-regexp | |
2891 | (concat | |
2892 | "\\([^\\]\\)\\([_^]\\)\\(" | |
2893 | "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)" | |
2894 | "\\|" | |
2895 | "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)" | |
2896 | "\\|" | |
2897 | "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)") | |
2898 | "The regular expression matching a sub- or superscript.") | |
2899 | ||
2900 | (defvar org-match-substring-with-braces-regexp | |
2901 | (concat | |
2902 | "\\([^\\]\\)\\([_^]\\)\\(" | |
2903 | "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)" | |
2904 | "\\)") | |
2905 | "The regular expression matching a sub- or superscript, forcing braces.") | |
2906 | ||
20908596 CD |
2907 | |
2908 | (defun org-get-text-property-any (pos prop &optional object) | |
2909 | (or (get-text-property pos prop object) | |
2910 | (and (setq pos (next-single-property-change pos prop object)) | |
2911 | (get-text-property pos prop object)))) | |
2912 | ||
c8d0cf5c CD |
2913 | (defun org-export-get-coderef-format (path desc) |
2914 | (save-match-data | |
2915 | (if (and desc (string-match | |
2916 | (regexp-quote (concat "(" path ")")) | |
2917 | desc)) | |
2918 | (replace-match "%s" t t desc) | |
2919 | (or desc "%s")))) | |
2920 | ||
2921 | (defun org-export-push-to-kill-ring (format) | |
2922 | "Push buffer content to kill ring. | |
2923 | The depends on the variable `org-export-copy-to-kill'." | |
2924 | (when org-export-copy-to-kill-ring | |
2925 | (org-kill-new (buffer-string)) | |
2926 | (when (fboundp 'x-set-selection) | |
2927 | (ignore-errors (x-set-selection 'PRIMARY (buffer-string))) | |
2928 | (ignore-errors (x-set-selection 'CLIPBOARD (buffer-string)))) | |
2929 | (message "%s export done, pushed to kill ring and clipboard" format))) | |
20908596 CD |
2930 | |
2931 | (provide 'org-exp) | |
2932 | ||
b349f79f | 2933 | ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95 |
20908596 | 2934 | |
b349f79f | 2935 | ;;; org-exp.el ends here |
8bfe682a | 2936 |