org-exp.el 153 KB
 Carsten Dominik committed Apr 27, 2008 1 2 3 4 5 6 7 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. ;; Author: Carsten Dominik ;; Keywords: outlines, hypermedia, calendar, wp ;; Homepage: http://orgmode.org  Carsten Dominik committed Jul 25, 2008 8 ;; Version: 6.06b  Carsten Dominik committed Apr 27, 2008 9 10 11 ;; ;; This file is part of GNU Emacs. ;;  Glenn Morris committed May 06, 2008 12 ;; GNU Emacs is free software: you can redistribute it and/or modify  Carsten Dominik committed Apr 27, 2008 13 ;; it under the terms of the GNU General Public License as published by  Glenn Morris committed May 06, 2008 14 15 ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version.  Carsten Dominik committed Apr 27, 2008 16 17 18 19 20 21 22  ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License  Glenn Morris committed May 06, 2008 23 ;; along with GNU Emacs. If not, see .  Carsten Dominik committed Apr 27, 2008 24 25 26 27 28 29 30 31 32 33 34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Commentary: (require 'org) (require 'org-agenda) (eval-and-compile (require 'cl)) (declare-function org-export-latex-preprocess "org-export-latex" ()) (declare-function org-agenda-skip "org-agenda" ())  Glenn Morris committed May 15, 2008 35 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())  Carsten Dominik committed Jun 17, 2008 36 37 (declare-function htmlize-region "ext:htmlize" (beg end)) (defvar htmlize-buffer-places) ; from htmlize.el  Carsten Dominik committed Apr 27, 2008 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90  (defgroup org-export nil "Options for exporting org-listings." :tag "Org Export" :group 'org) (defgroup org-export-general nil "General options for exporting Org-mode files." :tag "Org Export General" :group 'org-export) ;; FIXME (defvar org-export-publishing-directory nil) (defcustom org-export-run-in-background nil "Non-nil means export and publishing commands will run in background. This works by starting up a separate Emacs process visiting the same file and doing the export from there. Not all export commands are affected by this - only the ones which actually write to a file, and that do not depend on the buffer state. If this option is nil, you can still get background export by calling org-export' with a double prefix arg: C-u C-u C-c C-e'. If this option is t, the double prefix can be used to exceptionally force an export command into the current process." :group 'org-export-general :type 'boolean) (defcustom org-export-with-special-strings t "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export. When this option is turned on, these strings will be exported as: Org HTML LaTeX -----+----------+-------- \\- ­ \\- -- – -- --- — --- ... … \ldots This option can also be set with the +OPTIONS line, e.g. \"-:nil\"." :group 'org-export-translation :type 'boolean) (defcustom org-export-language-setup '(("en" "Author" "Date" "Table of Contents") ("cs" "Autor" "Datum" "Obsah") ("da" "Ophavsmand" "Dato" "Indhold") ("de" "Autor" "Datum" "Inhaltsverzeichnis") ("es" "Autor" "Fecha" "\xcdndice") ("fr" "Auteur" "Date" "Table des mati\xe8res") ("it" "Autore" "Data" "Indice") ("nl" "Auteur" "Datum" "Inhoudsopgave")  Carsten Dominik committed Jun 17, 2008 91 92 93  ("no" "Forfatter" "Dato" "Innhold") ("nb" "Forfatter" "Dato" "Innhold") ;; nb = Norsk (bokm.l) ("nn" "Forfattar" "Dato" "Innhald") ;; nn = Norsk (nynorsk)  Carsten Dominik committed Apr 27, 2008 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111  ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll")) "Terms used in export text, translated to different languages. Use the variable org-export-default-language' to set the language, or use the +OPTION lines for a per-file setting." :group 'org-export-general :type '(repeat (list (string :tag "HTML language tag") (string :tag "Author") (string :tag "Date") (string :tag "Table of Contents")))) (defcustom org-export-default-language "en" "The default language of HTML export, as a string. This should have an association in org-export-language-setup'." :group 'org-export-general :type 'string)  Carsten Dominik committed Jun 17, 2008 112 (defcustom org-export-skip-text-before-1st-heading nil  Carsten Dominik committed Apr 27, 2008 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134  "Non-nil means, skip all text before the first headline when exporting. When nil, that text is exported as well." :group 'org-export-general :type 'boolean) (defcustom org-export-headline-levels 3 "The last level which is still exported as a headline. Inferior levels will produce itemize lists when exported. Note that a numeric prefix argument to an exporter function overrides this setting. This option can also be set with the +OPTIONS line, e.g. \"H:2\"." :group 'org-export-general :type 'number) (defcustom org-export-with-section-numbers t "Non-nil means, add section numbers to headlines when exporting. This option can also be set with the +OPTIONS line, e.g. \"num:t\"." :group 'org-export-general :type 'boolean)  Carsten Dominik committed Jun 17, 2008 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 (defcustom org-export-section-number-format '((("1" ".")) . "") "Format of section numbers for export. The variable has two components. 1. A list of lists, each indicating a counter type and a separator. The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\". It causes causes numeric, alphabetic, or roman counters, respectively. The separator is only used if another counter for a subsection is being added. If there are more numbered section levels than entries in this lists, then the last entry will be reused. 2. A terminator string that will be added after the entire section number." :group 'org-export-general :type '(cons (repeat (list (string :tag "Counter Type") (string :tag "Separator "))) (string :tag "Terminator")))  Carsten Dominik committed Apr 27, 2008 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 (defcustom org-export-with-toc t "Non-nil means, create a table of contents in exported files. The TOC contains headlines with levels up toorg-export-headline-levels'. When an integer, include levels up to N in the toc, this may then be different from org-export-headline-levels', but it will not be allowed to be larger than the number of headline levels. When nil, no table of contents is made. Headlines which contain any TODO items will be marked with \"(*)\" in ASCII export, and with red color in HTML output, if the option org-export-mark-todo-in-toc' is set. In HTML output, the TOC will be clickable. This option can also be set with the +OPTIONS line, e.g. \"toc:nil\" or \"toc:3\"." :group 'org-export-general :type '(choice (const :tag "No Table of Contents" nil) (const :tag "Full Table of Contents" t) (integer :tag "TOC to level"))) (defcustom org-export-mark-todo-in-toc nil "Non-nil means, mark TOC lines that contain any open TODO items." :group 'org-export-general :type 'boolean) (defcustom org-export-preserve-breaks nil "Non-nil means, preserve all line breaks when exporting. Normally, in HTML output paragraphs will be reformatted. In ASCII export, line breaks will always be preserved, regardless of this variable. This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"." :group 'org-export-general :type 'boolean) (defcustom org-export-with-archived-trees 'headline "Whether subtrees with the ARCHIVE tag should be exported. This can have three different values nil Do not export, pretend this tree is not present t Do export the entire tree headline Only export the headline, but skip the tree below it." :group 'org-export-general :group 'org-archive :type '(choice (const :tag "not at all" nil) (const :tag "headline only" 'headline) (const :tag "entirely" t))) (defcustom org-export-author-info t "Non-nil means, insert author name and email into the exported file. This option can also be set with the +OPTIONS line, e.g. \"author-info:nil\"." :group 'org-export-general :type 'boolean)  Carsten Dominik committed Jul 24, 2008 212 213 214 215 216 217 (defcustom org-export-creator-info t "Non-nil means, the postamle should contain a creator sentence. This sentence is \"HTML generated by org-mode XX in emacs XXX\"." :group 'org-export-general :type 'boolean)  Carsten Dominik committed Apr 27, 2008 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 (defcustom org-export-time-stamp-file t "Non-nil means, insert a time stamp into the exported file. The time stamp shows when the file was created. This option can also be set with the +OPTIONS line, e.g. \"timestamp:nil\"." :group 'org-export-general :type 'boolean) (defcustom org-export-with-timestamps t "If nil, do not export time stamps and associated keywords." :group 'org-export-general :type 'boolean) (defcustom org-export-remove-timestamps-from-toc t "If nil, remove timestamps from the table of contents entries." :group 'org-export-general :type 'boolean) (defcustom org-export-with-tags 'not-in-toc "If nil, do not export tags, just remove them from headlines. If this is the symbol not-in-toc', tags will be removed from table of contents entries, but still be shown in the headlines of the document. This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"." :group 'org-export-general :type '(choice (const :tag "Off" nil) (const :tag "Not in TOC" not-in-toc) (const :tag "On" t))) (defcustom org-export-with-drawers nil "Non-nil means, export with drawers like the property drawer. When t, all drawers are exported. This may also be a list of drawer names to export." :group 'org-export-general :type '(choice (const :tag "All drawers" t) (const :tag "None" nil) (repeat :tag "Selected drawers" (string :tag "Drawer name"))))  Carsten Dominik committed Jun 17, 2008 260 261 262 263 (defvar org-export-preprocess-hook nil "Hook for preprocessing an export buffer. Pretty much the first thing when exporting is running this hook.")  Carsten Dominik committed Apr 27, 2008 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 (defgroup org-export-translation nil "Options for translating special ascii sequences for the export backends." :tag "Org Export Translation" :group 'org-export) (defcustom org-export-with-emphasize t "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text. If the export target supports emphasizing text, the word will be typeset in bold, italic, or underlined, respectively. Works only for single words, but you can say: I *really* *mean* *this*. Not all export backends support this. This option can also be set with the +OPTIONS line, e.g. \"*:nil\"." :group 'org-export-translation :type 'boolean) (defcustom org-export-with-footnotes t "If nil, export [1] as a footnote marker. Lines starting with [1] will be formatted as footnotes. This option can also be set with the +OPTIONS line, e.g. \"f:nil\"." :group 'org-export-translation :type 'boolean) (defcustom org-export-with-sub-superscripts t "Non-nil means, interpret \"_\" and \"^\" for export. When this option is turned on, you can use TeX-like syntax for sub- and superscripts. Several characters after \"_\" or \"^\" will be considered as a single item - so grouping with {} is normally not needed. For example, the following things will be parsed as single sub- or superscripts. 10^24 or 10^tau several digits will be considered 1 item. 10^-12 or 10^-tau a leading sign with digits or a word x^2-y^3 will be read as x^2 - y^3, because items are terminated by almost any nonword/nondigit char. x_{i^2} or x^(2-i) braces or parenthesis do grouping. Still, ambiguity is possible - so when in doubt use {} to enclose the sub/superscript. If you set this variable to the symbol {}', the braces are *required* in order to trigger interpretations as sub/superscript. This can be helpful in documents that need \"_\" frequently in plain text. Not all export backends support this, but HTML does. This option can also be set with the +OPTIONS line, e.g. \"^:nil\"." :group 'org-export-translation :type '(choice (const :tag "Always interpret" t) (const :tag "Only with braces" {}) (const :tag "Never interpret" nil))) (defcustom org-export-with-special-strings t "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export. When this option is turned on, these strings will be exported as: \\- : ­ -- : – --- : — Not all export backends support this, but HTML does. This option can also be set with the +OPTIONS line, e.g. \"-:nil\"." :group 'org-export-translation :type 'boolean) (defcustom org-export-with-TeX-macros t "Non-nil means, interpret simple TeX-like macros when exporting. For example, HTML export converts \\alpha to α and \\AA to Å. No only real TeX macros will work here, but the standard HTML entities for math can be used as macro names as well. For a list of supported names in HTML export, see the constant org-html-entities'. Not all export backends support this. This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"." :group 'org-export-translation :group 'org-export-latex :type 'boolean) (defcustom org-export-with-LaTeX-fragments nil "Non-nil means, convert LaTeX fragments to images when exporting to HTML. When set, the exporter will find LaTeX environments if the \\begin line is the first non-white thing on a line. It will also find the math delimiters like $a=b$ and \$$a=b \$$ for inline math, $$a=b$$ and \$a=b \$ for display math. This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"." :group 'org-export-translation :group 'org-export-latex :type 'boolean) (defcustom org-export-with-fixed-width t "Non-nil means, lines starting with \":\" will be in fixed width font. This can be used to have pre-formatted text, fragments of code etc. For example: : ;; Some Lisp examples : (while (defc cnt) : (ding)) will be looking just like this in also HTML. See also the QUOTE keyword. Not all export backends support this. This option can also be set with the +OPTIONS line, e.g. \"::nil\"." :group 'org-export-translation :type 'boolean) (defcustom org-match-sexp-depth 3 "Number of stacked braces for sub/superscript matching. This has to be set before loading org.el to be effective." :group 'org-export-translation :type 'integer) (defgroup org-export-tables nil "Options for exporting tables in Org-mode." :tag "Org Export Tables" :group 'org-export) (defcustom org-export-with-tables t "If non-nil, lines starting with \"|\" define a table. For example: | Name | Address | Birthday | |-------------+----------+-----------| | Arthur Dent | England | 29.2.2100 | Not all export backends support this. This option can also be set with the +OPTIONS line, e.g. \"|:nil\"." :group 'org-export-tables :type 'boolean) (defcustom org-export-highlight-first-table-line t "Non-nil means, highlight the first table line. In HTML export, this means use
instead of . In tables created with table.el, this applies to the first table line. In Org-mode tables, all lines before the first horizontal separator line will be formatted with tags." :group 'org-export-tables :type 'boolean) (defcustom org-export-table-remove-special-lines t "Remove special lines and marking characters in calculating tables. This removes the special marking character column from tables that are set up for spreadsheet calculations. It also removes the entire lines marked with !', _', or ^'. The lines with $' are kept, because the values of constants may be useful to have." :group 'org-export-tables :type 'boolean) (defcustom org-export-prefer-native-exporter-for-tables nil "Non-nil means, always export tables created with table.el natively. Natively means, use the HTML code generator in table.el. When nil, Org-mode's own HTML generator is used when possible (i.e. if the table does not use row- or column-spanning). This has the advantage, that the automatic HTML conversions for math symbols and sub/superscripts can be applied. Org-mode's HTML generator is also much faster." :group 'org-export-tables :type 'boolean) (defgroup org-export-ascii nil "Options specific for ASCII export of Org-mode files." :tag "Org Export ASCII" :group 'org-export) (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-) "Characters for underlining headings in ASCII export. In the given sequence, these characters will be used for level 1, 2, ..." :group 'org-export-ascii :type '(repeat character)) (defcustom org-export-ascii-bullets '(?* ?+ ?-) "Bullet characters for headlines converted to lists in ASCII export. The first character is used for the first lest level generated in this way, and so on. If there are more levels than characters given here, the list will be repeated. Note that plain lists will keep the same bullets as the have in the Org-mode file." :group 'org-export-ascii :type '(repeat character)) (defgroup org-export-xml nil "Options specific for XML export of Org-mode files." :tag "Org Export XML" :group 'org-export) (defgroup org-export-html nil "Options specific for HTML export of Org-mode files." :tag "Org Export HTML" :group 'org-export) (defcustom org-export-html-coding-system nil "Coding system for HTML export, defaults to buffer-file-coding-system." :group 'org-export-html :type 'coding-system) (defcustom org-export-html-extension "html" "The extension for exported HTML files." :group 'org-export-html :type 'string) (defcustom org-export-html-link-up "" "Where should the \"UP\" link of exported HTML pages lead?" :group 'org-export-html :type '(string :tag "File or URL")) (defcustom org-export-html-link-home "" "Where should the \"HOME\" link of exported HTML pages lead?" :group 'org-export-html :type '(string :tag "File or URL"))  Carsten Dominik committed Jul 24, 2008 475 (defconst org-export-html-style-default  Carsten Dominik committed Apr 27, 2008 476 "" "The default style specification for exported HTML files.  Carsten Dominik committed Jul 24, 2008 499 500 501 502 503 504 505 506 507 508 509 510 Please use the variables org-export-html-style' and org-export-html-style-extra' to add to this style.") (defcustom org-export-html-style "" "Org-wide style definitions for exported HTML files. This variable needs to contain the full HTML structure to provide a style, including the surrounding HTML tags. If you set the value of this variable, you should consider to include definitions for the following classes: title, todo, done, timestamp, timestamp-kwd, tag, target. For example, a valid value would be:  Carsten Dominik committed Apr 27, 2008 511 512 513 514 515   Carsten Dominik committed Jul 24, 2008 520 If you'd like to refer to en external style file, use something like  Carsten Dominik committed Apr 27, 2008 521 522 523 524  As the value of this option simply gets inserted into the HTML header,  Carsten Dominik committed Jul 24, 2008 525 526 you can \"misuse\" it to add arbitrary text to the header. See also the variable org-export-html-style-extra'."  Carsten Dominik committed Apr 27, 2008 527 528  :group 'org-export-html :type 'string)  Carsten Dominik committed Jul 26, 2008 529 530 ;;;###autoload (put 'org-export-html-style 'safe-local-variable 'stringp)  Carsten Dominik committed Apr 27, 2008 531   Carsten Dominik committed Jul 24, 2008 532 533 534 535 536 537 538 539 (defcustom org-export-html-style-extra "" "Additional style information for HTML export. The value of this variable is inserted into the HTML buffer right after the value of org-export-html-style'. Use this variable for per-file settings of style information, and do not forget to surround the style settings with tags." :group 'org-export-html :type 'string)  Carsten Dominik committed Jul 26, 2008 540 541 ;;;###autoload (put 'org-export-html-style-extra 'safe-local-variable 'stringp)  Carsten Dominik committed Apr 27, 2008 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618  (defcustom org-export-html-title-format "
\n" "Format for typesetting the document title in HTML export." :group 'org-export-html :type 'string) (defcustom org-export-html-toplevel-hlevel 2 "The level for level 1 headings in HTML export." :group 'org-export-html :type 'string) (defcustom org-export-html-link-org-files-as-html t "Non-nil means, make file links to file.org' point to file.html'. When org-mode is exporting an org-mode file to HTML, links to non-html files are directly put into a href tag in HTML. However, links to other Org-mode files (recognized by the extension .org.) should become links to the corresponding html file, assuming that the linked org-mode file will also be converted to HTML. When nil, the links still point to the plain .org' file." :group 'org-export-html :type 'boolean) (defcustom org-export-html-inline-images 'maybe "Non-nil means, inline images into exported HTML pages. This is done using an tag. When nil, an anchor with href is used to link to the image. If this option is maybe', then images in links with an empty description will be inlined, while images with a description will be linked only." :group 'org-export-html :type '(choice (const :tag "Never" nil) (const :tag "Always" t) (const :tag "When there is no description" maybe))) ;; FIXME: rename (defcustom org-export-html-expand t "Non-nil means, for HTML export, treat @<...> as HTML tag. When nil, these tags will be exported as plain text and therefore not be interpreted by a browser. This option can also be set with the +OPTIONS line, e.g. \"@:nil\"." :group 'org-export-html :type 'boolean) (defcustom org-export-html-table-tag "" "The HTML tag that is used to start a table. This must be a
\n" "The HTML tag used as timestamp delimiter for HTML-helper-mode." :group 'org-export-html :type 'string)  Carsten Dominik committed Jun 17, 2008 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 (defgroup org-export-htmlize nil "Options for processing examples with htmlize.el." :tag "Org Export Htmlize" :group 'org-export-html) (defcustom org-export-htmlize-output-type 'inline-css "Output type to be used by htmlize when formatting code snippets. Normally this is inline-css', but if you have defined to appropriate classes in your css style file, setting this to css' means that the fontification will use the class names. See also the function org-export-htmlize-generate-css'." :group 'org-export-htmlize :type '(choice (const css) (const inline-css))) (defcustom org-export-htmlize-css-font-prefix "org-" "The prefix for CSS class names for htmlize font specifications." :group 'org-export-htmlize :type 'string)  Carsten Dominik committed Apr 27, 2008 638 639 640 641 642 643 644 645 646 647 648 649 (defgroup org-export-icalendar nil "Options specific for iCalendar export of Org-mode files." :tag "Org Export iCalendar" :group 'org-export) (defcustom org-combined-agenda-icalendar-file "~/org.ics" "The file name for the iCalendar file covering all agenda files. This file is created with the command \$org-export-icalendar-all-agenda-files]. The file name should be absolute, the file will be overwritten without warning." :group 'org-export-icalendar :type 'file)  Carsten Dominik committed Jul 24, 2008 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 (defcustom org-icalendar-combined-name "OrgMode" "Calendar name for the combined iCalendar representing all agenda files." :group 'org-export-icalendar :type 'string) (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due) "Contexts where iCalendar export should use a deadline time stamp. This is a list with several symbols in it. Valid symbol are: event-if-todo Deadlines in TODO entries become calendar events. event-if-not-todo Deadlines in non-TODO entries become calendar events. todo-due Use deadlines in TODO entries as due-dates" :group 'org-export-icalendar :type '(set :greedy t (const :tag "Deadlines in non-TODO entries become events" event-if-not-todo) (const :tag "Deadline in TODO entries become events" event-if-todo) (const :tag "Deadlines in TODO entries become due-dates" todo-due))) (defcustom org-icalendar-use-scheduled '(todo-start) "Contexts where iCalendar export should use a scheduling time stamp. This is a list with several symbols in it. Valid symbol are: event-if-todo Scheduling time stamps in TODO entries become an event. event-if-not-todo Scheduling time stamps in non-TODO entries become an event. todo-start Scheduling time stamps in TODO entries become start date. Some calendar applications show TODO entries only after that date." :group 'org-export-icalendar :type '(set :greedy t (const :tag "SCHEDULED timestamps in non-TODO entries become events" event-if-not-todo) (const :tag "SCHEDULED timestamps in TODO entries become events" event-if-todo) (const :tag "SCHEDULED in TODO entries become start date" todo-start)))  Carsten Dominik committed Apr 27, 2008 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 (defcustom org-icalendar-include-todo nil "Non-nil means, export to iCalendar files should also cover TODO items." :group 'org-export-icalendar :type '(choice (const :tag "None" nil) (const :tag "Unfinished" t) (const :tag "All" all))) (defcustom org-icalendar-include-sexps t "Non-nil means, export to iCalendar files should also cover sexp entries. These are entries like in the diary, but directly in an Org-mode file." :group 'org-export-icalendar :type 'boolean) (defcustom org-icalendar-include-body 100 "Amount of text below headline to be included in iCalendar export. This is a number of characters that should maximally be included. Properties, scheduling and clocking lines will always be removed. The text will be inserted into the DESCRIPTION field." :group 'org-export-icalendar :type '(choice (const :tag "Nothing" nil) (const :tag "Everything" t) (integer :tag "Max characters")))  Carsten Dominik committed Jun 17, 2008 715 716 717 718 719 720 721 722 723 724 725 726 727 728 (defcustom org-icalendar-store-UID nil "Non-nil means, store any created UIDs in properties. The iCalendar standard requires that all entries have a unique identifyer. Org will create these identifiers as needed. When this variable is non-nil, the created UIDs will be stored in the ID property of the entry. Then the next time this entry is exported, it will be exported with the same UID, superceeding the previous form of it. This is essential for synchronization services. This variable is not turned on by default because we want to avoid creating a property drawer in every entry if people are only playing with this feature, or if they are only using it locally." :group 'org-export-icalendar :type 'boolean)  Carsten Dominik committed Apr 27, 2008 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 ;;;; Exporting ;;; Variables, constants, and parameter plists (defconst org-level-max 20) (defvar org-export-html-preamble nil "Preamble, to be inserted just after . Set by publishing functions.") (defvar org-export-html-postamble nil "Preamble, to be inserted just before . Set by publishing functions.") (defvar org-export-html-auto-preamble t "Should default preamble be inserted? Set by publishing functions.") (defvar org-export-html-auto-postamble t "Should default postamble be inserted? Set by publishing functions.") (defvar org-current-export-file nil) ; dynamically scoped parameter (defvar org-current-export-dir nil) ; dynamically scoped parameter (defconst org-export-plist-vars '((:link-up . org-export-html-link-up) (:link-home . org-export-html-link-home) (:language . org-export-default-language) (:customtime . org-display-custom-times) (:headline-levels . org-export-headline-levels) (:section-numbers . org-export-with-section-numbers)  Carsten Dominik committed Jun 17, 2008 753  (:section-number-format . org-export-section-number-format)  Carsten Dominik committed Apr 27, 2008 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768  (:table-of-contents . org-export-with-toc) (:preserve-breaks . org-export-preserve-breaks) (:archived-trees . org-export-with-archived-trees) (:emphasize . org-export-with-emphasize) (:sub-superscript . org-export-with-sub-superscripts) (:special-strings . org-export-with-special-strings) (:footnotes . org-export-with-footnotes) (:drawers . org-export-with-drawers) (:tags . org-export-with-tags) (:TeX-macros . org-export-with-TeX-macros) (:LaTeX-fragments . org-export-with-LaTeX-fragments) (:skip-before-1st-heading . org-export-skip-text-before-1st-heading) (:fixed-width . org-export-with-fixed-width) (:timestamps . org-export-with-timestamps) (:author-info . org-export-author-info)  Carsten Dominik committed Jul 24, 2008 769  (:creator-info . org-export-creator-info)  Carsten Dominik committed Apr 27, 2008 770 771 772 773  (:time-stamp-file . org-export-time-stamp-file) (:tables . org-export-with-tables) (:table-auto-headline . org-export-highlight-first-table-line) (:style . org-export-html-style)  Carsten Dominik committed Jul 24, 2008 774  (:style-extra . org-export-html-style-extra)  Carsten Dominik committed Apr 27, 2008 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819  (:agenda-style . org-agenda-export-html-style) (:convert-org-links . org-export-html-link-org-files-as-html) (:inline-images . org-export-html-inline-images) (:html-extension . org-export-html-extension) (:html-table-tag . org-export-html-table-tag) (:expand-quoted-html . org-export-html-expand) (:timestamp . org-export-html-with-timestamp) (:publishing-directory . org-export-publishing-directory) (:preamble . org-export-html-preamble) (:postamble . org-export-html-postamble) (:auto-preamble . org-export-html-auto-preamble) (:auto-postamble . org-export-html-auto-postamble) (:author . user-full-name) (:email . user-mail-address))) (defun org-default-export-plist () "Return the property list with default settings for the export variables." (let ((l org-export-plist-vars) rtn e) (while (setq e (pop l)) (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn)))) rtn)) (defvar org-export-inbuffer-options-extra nil "List of additional in-buffer options that should be detected. Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL, etc. Extensions can add to this list to get their options detected, and they can then add a function to org-export-options-filters' to process these options. Each element in this list must be a list, with the in-buffer keyword as car, and a property (a symbol) as the next element. All occurences of the keyword will be found, the values concatenated with a space character in between, and the result stored in the export options property list.") (defvar org-export-options-filters nil "Functions to be called to finalize the export/publishing options. All these options are stored in a property list, and each of the functions in this hook gets a chance to modify this property list. Each function must accept the property list as an argument, and must return the (possibly modified) list.") (defun org-infile-export-plist () "Return the property list with file-local settings for export." (save-excursion (save-restriction (widen)  Carsten Dominik committed Jun 17, 2008 820  (goto-char (point-min))  Carsten Dominik committed Apr 27, 2008 821 822 823  (let ((re (org-make-options-regexp (append '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"  Carsten Dominik committed Jun 17, 2008 824  "LINK_UP" "LINK_HOME" "SETUPFILE")  Carsten Dominik committed Apr 27, 2008 825  (mapcar 'car org-export-inbuffer-options-extra))))  Carsten Dominik committed Jun 17, 2008 826 827 828 829 830 831 832 833 834  p key val text options js-up js-main js-css js-opt a pr ext-setup-or-nil setup-contents (start 0)) (while (or (and ext-setup-or-nil (string-match re ext-setup-or-nil start) (setq start (match-end 0))) (and (setq ext-setup-or-nil nil start 0) (re-search-forward re nil t))) (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil)) val (org-match-string-no-properties 2 ext-setup-or-nil))  Carsten Dominik committed Apr 27, 2008 835 836 837 838 839 840 841 842 843 844 845 846  (cond ((setq a (assoc key org-export-inbuffer-options-extra)) (setq pr (nth 1 a)) (setq p (plist-put p pr (concat (plist-get p pr) " " val)))) ((string-equal key "TITLE") (setq p (plist-put p :title val))) ((string-equal key "AUTHOR")(setq p (plist-put p :author val))) ((string-equal key "EMAIL") (setq p (plist-put p :email val))) ((string-equal key "DATE") (setq p (plist-put p :date val))) ((string-equal key "LANGUAGE") (setq p (plist-put p :language val))) ((string-equal key "TEXT") (setq text (if text (concat text "\n" val) val))) ((string-equal key "OPTIONS")  Carsten Dominik committed Jun 17, 2008 847  (setq options (concat val " " options)))  Carsten Dominik committed Apr 27, 2008 848 849 850  ((string-equal key "LINK_UP") (setq p (plist-put p :link-up val))) ((string-equal key "LINK_HOME")  Carsten Dominik committed Jun 17, 2008 851 852 853 854 855 856 857 858 859 860 861 862 863  (setq p (plist-put p :link-home val))) ((equal key "SETUPFILE") (setq setup-contents (org-file-contents (expand-file-name (org-remove-double-quotes (org-trim val))) 'noerror)) (if (not ext-setup-or-nil) (setq ext-setup-or-nil setup-contents start 0) (setq ext-setup-or-nil (concat (substring ext-setup-or-nil 0 start) "\n" setup-contents "\n" (substring ext-setup-or-nil start)))))))  Carsten Dominik committed Apr 27, 2008 864 865  (setq p (plist-put p :text text)) (when options  Carsten Dominik committed Jun 17, 2008 866  (setq p (org-export-add-options-to-plist p options)))  Carsten Dominik committed Apr 27, 2008 867 868  p))))  Carsten Dominik committed Jun 17, 2008 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 (defun org-export-add-options-to-plist (p options) "Parse an OPTONS line and set values in the property list P." (let (o) (when options (let ((op '(("H" . :headline-levels) ("num" . :section-numbers) ("toc" . :table-of-contents) ("\\n" . :preserve-breaks) ("@" . :expand-quoted-html) (":" . :fixed-width) ("|" . :tables) ("^" . :sub-superscript) ("-" . :special-strings) ("f" . :footnotes) ("d" . :drawers) ("tags" . :tags) ("*" . :emphasize) ("TeX" . :TeX-macros) ("LaTeX" . :LaTeX-fragments) ("skip" . :skip-before-1st-heading) ("author" . :author-info)  Carsten Dominik committed Jul 25, 2008 890  ("creator" . :creator-info)  Carsten Dominik committed Jun 17, 2008 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916  ("timestamp" . :time-stamp-file))) o) (while (setq o (pop op)) (if (string-match (concat (regexp-quote (car o)) ":\$$[^ \t\n\r;,.]*\$$") options) (setq p (plist-put p (cdr o) (car (read-from-string (match-string 1 options)))))))))) p) (defun org-export-add-subtree-options (p pos) "Add options in subtree at position POS to property list P." (save-excursion (goto-char pos) (when (org-at-heading-p) (let (a) ;; This is actually read in org-export-get-title-from-subtree' ;; (when (setq a (org-entry-get pos "EXPORT_TITLE")) ;; (setq p (plist-put p :title a))) (when (setq a (org-entry-get pos "EXPORT_TEXT")) (setq p (plist-put p :text a))) (when (setq a (org-entry-get pos "EXPORT_OPTIONS")) (setq p (org-export-add-options-to-plist p a))))) p))  Carsten Dominik committed Apr 27, 2008 917 918 919 920 921 922 923 (defun org-export-directory (type plist) (let* ((val (plist-get plist :publishing-directory)) (dir (if (listp val) (or (cdr (assoc type val)) ".") val))) dir))  Carsten Dominik committed Jun 17, 2008 924 925 926 927 928 929 (defun org-export-process-option-filters (plist) (let ((functions org-export-options-filters) f) (while (setq f (pop functions)) (setq plist (funcall f plist)))) plist)  Carsten Dominik committed Apr 27, 2008 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 ;;;###autoload (defun org-export (&optional arg) "Export dispatcher for Org-mode. When org-export-run-in-background' is non-nil, try to run the command in the background. This will be done only for commands that write to a file. For details see the docstring of org-export-run-in-background'. The prefix argument ARG will be passed to the exporter. However, if ARG is a double universal prefix C-u C-u', that means to inverse the value of org-export-run-in-background'." (interactive "P") (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background)) (help "[t] insert the export option template \[v] limit export to visible part of outline tree \[a] export as ASCII \[h] export as HTML \[H] export as HTML to temporary buffer \[R] export region as HTML \[b] export as HTML and browse immediately \[x] export as XOXO \[l] export as LaTeX \[L] export as LaTeX to temporary buffer \[i] export current file as iCalendar file \[I] export all agenda files as iCalendar files \[c] export agenda files into combined iCalendar file \[F] publish current file \[P] publish current project \[X] publish... (project will be prompted for) \[A] publish all projects") (cmds '((?t org-insert-export-options-template nil) (?v org-export-visible nil) (?a org-export-as-ascii t) (?h org-export-as-html t) (?b org-export-as-html-and-open t) (?H org-export-as-html-to-buffer nil) (?R org-export-region-as-html nil) (?x org-export-as-xoxo t) (?l org-export-as-latex t) (?L org-export-as-latex-to-buffer nil) (?i org-export-icalendar-this-file t) (?I org-export-icalendar-all-agenda-files t) (?c org-export-icalendar-combine-agenda-files t) (?F org-publish-current-file t) (?P org-publish-current-project t) (?X org-publish t) (?A org-publish-all t))) r1 r2 ass) (save-window-excursion (delete-other-windows) (with-output-to-temp-buffer "*Org Export/Publishing Help*" (princ help)) (message "Select command: ") (setq r1 (read-char-exclusive))) (setq r2 (if (< r1 27) (+ r1 96) r1)) (unless (setq ass (assq r2 cmds)) (error "No command associated with key %c" r1)) (if (and bg (nth 2 ass)) ;; execute in background (let ((p (start-process (concat "Exporting " (file-name-nondirectory (buffer-file-name))) "*Org Processes*" (expand-file-name invocation-name invocation-directory) "-batch" "-l" user-init-file "--eval" "(require 'org-exp)" "--eval" "(setq org-wait .2)" (buffer-file-name) "-f" (symbol-name (nth 1 ass))))) (set-process-sentinel p 'org-export-process-sentinel) (message "Background process \"%s\": started" p)) ;; background processing not requested, or not possible (call-interactively (nth 1 ass))))) (defun org-export-process-sentinel (process status) (if (string-match "\n+\\'" status) (setq status (substring status 0 -1))) (message "Background process \"%s\": %s" process status)) (defconst org-html-entities '(("nbsp") ("iexcl") ("cent") ("pound") ("curren") ("yen") ("brvbar") ("vert" . "|") ("sect") ("uml") ("copy") ("ordf") ("laquo") ("not") ("shy") ("reg") ("macr") ("deg") ("plusmn") ("sup2") ("sup3") ("acute") ("micro") ("para") ("middot") ("odot"."o") ("star"."*") ("cedil") ("sup1") ("ordm") ("raquo") ("frac14") ("frac12") ("frac34") ("iquest") ("Agrave") ("Aacute") ("Acirc") ("Atilde") ("Auml") ("Aring") ("AA"."Å") ("AElig") ("Ccedil") ("Egrave") ("Eacute") ("Ecirc") ("Euml") ("Igrave") ("Iacute") ("Icirc") ("Iuml") ("ETH") ("Ntilde") ("Ograve") ("Oacute") ("Ocirc") ("Otilde") ("Ouml") ("times") ("Oslash") ("Ugrave") ("Uacute") ("Ucirc") ("Uuml") ("Yacute") ("THORN") ("szlig") ("agrave") ("aacute") ("acirc") ("atilde") ("auml") ("aring") ("aelig") ("ccedil") ("egrave") ("eacute") ("ecirc") ("euml") ("igrave") ("iacute") ("icirc") ("iuml") ("eth") ("ntilde") ("ograve") ("oacute") ("ocirc") ("otilde") ("ouml") ("divide") ("oslash") ("ugrave") ("uacute") ("ucirc") ("uuml") ("yacute") ("thorn") ("yuml") ("fnof") ("Alpha") ("Beta") ("Gamma") ("Delta") ("Epsilon") ("Zeta") ("Eta") ("Theta") ("Iota") ("Kappa") ("Lambda") ("Mu") ("Nu") ("Xi") ("Omicron") ("Pi") ("Rho") ("Sigma") ("Tau") ("Upsilon") ("Phi") ("Chi") ("Psi") ("Omega") ("alpha") ("beta") ("gamma") ("delta") ("epsilon") ("varepsilon"."ε") ("zeta") ("eta") ("theta") ("iota") ("kappa") ("lambda") ("mu") ("nu") ("xi") ("omicron") ("pi") ("rho") ("sigmaf") ("varsigma"."ς") ("sigma") ("tau") ("upsilon") ("phi") ("chi") ("psi") ("omega") ("thetasym") ("vartheta"."ϑ") ("upsih") ("piv") ("bull") ("bullet"."•") ("hellip") ("dots"."…") ("prime") ("Prime") ("oline") ("frasl") ("weierp") ("image") ("real") ("trade") ("alefsym") ("larr") ("leftarrow"."←") ("gets"."←") ("uarr") ("uparrow"."↑") ("rarr") ("to"."→") ("rightarrow"."→") ("darr")("downarrow"."↓") ("harr") ("leftrightarrow"."↔") ("crarr") ("hookleftarrow"."↵") ; has round hook, not quite CR ("lArr") ("Leftarrow"."⇐") ("uArr") ("Uparrow"."⇑") ("rArr") ("Rightarrow"."⇒") ("dArr") ("Downarrow"."⇓") ("hArr") ("Leftrightarrow"."⇔") ("forall") ("part") ("partial"."∂") ("exist") ("exists"."∃") ("empty") ("emptyset"."∅") ("nabla") ("isin") ("in"."∈") ("notin") ("ni") ("prod") ("sum") ("minus") ("lowast") ("ast"."∗") ("radic") ("prop") ("proptp"."∝") ("infin") ("infty"."∞") ("ang") ("angle"."∠") ("and") ("wedge"."∧") ("or") ("vee"."∨") ("cap") ("cup") ("int") ("there4") ("sim") ("cong") ("simeq"."≅") ("asymp")("approx"."≈") ("ne") ("neq"."≠") ("equiv") ("le") ("ge") ("sub") ("subset"."⊂") ("sup") ("supset"."⊃") ("nsub") ("sube") ("supe") ("oplus") ("otimes") ("perp") ("sdot") ("cdot"."⋅") ("lceil") ("rceil") ("lfloor") ("rfloor") ("lang") ("rang") ("loz") ("Diamond"."◊") ("spades") ("spadesuit"."♠") ("clubs") ("clubsuit"."♣") ("hearts") ("diamondsuit"."♥") ("diams") ("diamondsuit"."♦") ("smile"."☺") ("blacksmile"."☻") ("sad"."☹") ("quot") ("amp") ("lt") ("gt") ("OElig") ("oelig") ("Scaron") ("scaron") ("Yuml") ("circ") ("tilde") ("ensp") ("emsp") ("thinsp") ("zwnj") ("zwj") ("lrm") ("rlm") ("ndash") ("mdash") ("lsquo") ("rsquo") ("sbquo") ("ldquo") ("rdquo") ("bdquo") ("dagger") ("Dagger") ("permil") ("lsaquo") ("rsaquo") ("euro") ("arccos"."arccos") ("arcsin"."arcsin") ("arctan"."arctan") ("arg"."arg") ("cos"."cos") ("cosh"."cosh") ("cot"."cot") ("coth"."coth") ("csc"."csc") ("deg"."deg") ("det"."det") ("dim"."dim") ("exp"."exp") ("gcd"."gcd") ("hom"."hom") ("inf"."inf") ("ker"."ker") ("lg"."lg") ("lim"."lim") ("liminf"."liminf") ("limsup"."limsup") ("ln"."ln") ("log"."log") ("max"."max") ("min"."min") ("Pr"."Pr") ("sec"."sec") ("sin"."sin") ("sinh"."sinh") ("sup"."sup") ("tan"."tan") ("tanh"."tanh") ) "Entities for TeX->HTML translation. Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\"). In that case, \"\\ent\" will be translated to \"&other;\". The list contains HTML entities for Latin-1, Greek and other symbols. It is supplemented by a number of commonly used TeX macros with appropriate translations. There is currently no way for users to extend this.") ;;; General functions for all backends (defun org-export-preprocess-string (string &rest parameters) "Cleanup STRING so that that the true exported has a more consistent source. This function takes STRING, which should be a buffer-string of an org-file to export. It then creates a temporary buffer where it does its job. The result is then again returned as a string, and the exporter works on this string to produce the exported version." (interactive)  Carsten Dominik committed Jun 17, 2008 1323  (let* ((htmlp (plist-get parameters :for-html))  Carsten Dominik committed Apr 27, 2008 1324 1325 1326 1327 1328 1329  (asciip (plist-get parameters :for-ascii)) (latexp (plist-get parameters :for-LaTeX)) (archived-trees (plist-get parameters :archived-trees)) (inhibit-read-only t) (drawers org-drawers) (outline-regexp "\\*+ ")  Carsten Dominik committed Jun 17, 2008 1330  target-alist rtn)  Carsten Dominik committed Apr 27, 2008 1331 1332 1333 1334  (with-current-buffer (get-buffer-create " org-mode-tmp") (erase-buffer) (insert string)  Carsten Dominik committed Jun 17, 2008 1335 1336 1337 1338  (setq case-fold-search t) ;; Call the hook (run-hooks 'org-export-preprocess-hook)  Carsten Dominik committed Apr 27, 2008 1339 1340 1341  ;; Remove license-to-kill stuff ;; The caller markes some stuff fo killing, stuff that has been ;; used to create the page title, for example.  Carsten Dominik committed Jun 17, 2008 1342 1343  (org-export-kill-licensed-text)  Carsten Dominik committed Apr 27, 2008 1344  (let ((org-inhibit-startup t)) (org-mode))  Carsten Dominik committed Jun 17, 2008 1345  (setq case-fold-search t)  Carsten Dominik committed Apr 27, 2008 1346  (untabify (point-min) (point-max))  Carsten Dominik committed Jun 17, 2008 1347 1348 1349 1350 1351 1352 1353  ;; Handle incude files (org-export-handle-include-files) ;; Handle source code snippets (org-export-replace-src-segments)  Carsten Dominik committed Apr 27, 2008 1354  ;; Get rid of drawers  Carsten Dominik committed Jun 17, 2008 1355 1356 1357  (org-export-remove-or-extract-drawers drawers (plist-get parameters :drawers))  Carsten Dominik committed Apr 27, 2008 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367  ;; Get the correct stuff before the first headline (when (plist-get parameters :skip-before-1st-heading) (goto-char (point-min)) (when (re-search-forward "^\\*+[ \t]" nil t) (delete-region (point-min) (match-beginning 0)) (goto-char (point-min)) (insert "\n"))) (when (plist-get parameters :add-text) (goto-char (point-min)) (insert (plist-get parameters :add-text) "\n"))  Carsten Dominik committed Jun 17, 2008 1368   Carsten Dominik committed Apr 27, 2008 1369  ;; Get rid of archived trees  Carsten Dominik committed Jun 17, 2008 1370 1371  (org-export-remove-archived-trees archived-trees)  Carsten Dominik committed Apr 27, 2008 1372  ;; Find all headings and compute the targets for them  Carsten Dominik committed Jun 17, 2008 1373  (setq target-alist (org-export-define-heading-targets target-alist))  Carsten Dominik committed Apr 27, 2008 1374 1375 1376  ;; Find targets in comments and move them out of comments, ;; but mark them as targets that should be invisible  Carsten Dominik committed Jun 17, 2008 1377 1378 1379 1380  (setq target-alist (org-export-handle-invisible-targets target-alist)) ;; Protect examples (org-export-protect-examples)  Carsten Dominik committed Apr 27, 2008 1381 1382  ;; Protect backend specific stuff, throw away the others.  Carsten Dominik committed Jun 17, 2008 1383 1384  (org-export-select-backend-specific-text (cond (htmlp 'html) (latexp 'latex) (asciip 'ascii)))  Carsten Dominik committed Apr 27, 2008 1385 1386  ;; Protect quoted subtrees  Carsten Dominik committed Jun 17, 2008 1387  (org-export-protect-quoted-subtrees)  Carsten Dominik committed Apr 27, 2008 1388 1389  ;; Protect verbatim elements  Carsten Dominik committed Jun 17, 2008 1390  (org-export-protect-verbatim)  Carsten Dominik committed Apr 27, 2008 1391   Carsten Dominik committed Jun 17, 2008 1392 1393 1394 1395 1396  ;; Blockquotes and verse (org-export-mark-blockquote-and-verse) ;; Remove comment environment and comment subtrees (org-export-remove-comment-blocks-and-subtrees)  Carsten Dominik committed Apr 27, 2008 1397 1398 1399  ;; Remove special table lines (when org-export-table-remove-special-lines  Carsten Dominik committed Jun 17, 2008 1400  (org-export-remove-special-table-lines))  Carsten Dominik committed Apr 27, 2008 1401 1402 1403 1404 1405 1406  ;; Specific LaTeX stuff (when latexp (require 'org-export-latex nil) (org-export-latex-preprocess))  Carsten Dominik committed Jun 17, 2008 1407  ;; Specific ASCII stuff  Carsten Dominik committed Apr 27, 2008 1408  (when asciip  Carsten Dominik committed Jun 17, 2008 1409  (org-export-ascii-preprocess))  Carsten Dominik committed Apr 27, 2008 1410 1411 1412  ;; Specific HTML stuff (when htmlp  Carsten Dominik committed Jun 17, 2008 1413  (org-export-html-preprocess parameters))  Carsten Dominik committed Apr 27, 2008 1414 1415  ;; Remove or replace comments  Carsten Dominik committed Jun 17, 2008 1416  (org-export-handle-comments (plist-get parameters :comments))  Carsten Dominik committed Apr 27, 2008 1417 1418  ;; Find matches for radio targets and turn them into internal links  Carsten Dominik committed Jun 17, 2008 1419  (org-export-mark-radio-links)  Carsten Dominik committed Apr 27, 2008 1420 1421  ;; Find all links that contain a newline and put them into a single line  Carsten Dominik committed Jun 17, 2008 1422  (org-export-concatenate-multiline-links)  Carsten Dominik committed Apr 27, 2008 1423   Carsten Dominik committed Jul 24, 2008 1424 1425 1426 1427  ;; Normalize links: Convert angle and plain links into bracket links ;; and expand link abbreviations (org-export-normalize-links)  Carsten Dominik committed Apr 27, 2008 1428 1429  ;; Find all internal links. If they have a fuzzy match (i.e. not ;; a *dedicated* target match, let the link point to the  Carsten Dominik committed Jun 17, 2008 1430 1431  ;; corresponding section. (org-export-target-internal-links target-alist)  Carsten Dominik committed Apr 27, 2008 1432 1433  ;; Find multiline emphasis and put them into single line  Carsten Dominik committed Jun 17, 2008 1434 1435  (when (plist-get parameters :emph-multiline) (org-export-concatenate-multiline-emphasis))  Carsten Dominik committed Apr 27, 2008 1436 1437 1438 1439 1440  (setq rtn (buffer-string))) (kill-buffer " org-mode-tmp") rtn))  Carsten Dominik committed Jun 17, 2008 1441 1442 (defun org-export-kill-licensed-text () "Remove all text that is marked with a :org-license-to-kill property."  Carsten Dominik committed Jul 24, 2008 1443  (let (p q)  Carsten Dominik committed Jun 17, 2008 1444 1445  (while (setq p (text-property-any (point-min) (point-max) :org-license-to-kill t))  Carsten Dominik committed Jul 24, 2008 1446 1447 1448  (delete-region p (or (next-single-property-change p :org-license-to-kill) (point-max))))))  Carsten Dominik committed Jun 17, 2008 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501  (defun org-export-define-heading-targets (target-alist) "Find all headings and define the targets for them. The new targets are added to TARGET-ALIST, which is also returned." (goto-char (point-min)) (org-init-section-numbers) (let ((re (concat "^" org-outline-regexp)) level target) (while (re-search-forward re nil t) (setq level (org-reduced-level (save-excursion (goto-char (point-at-bol)) (org-outline-level)))) (setq target (org-solidify-link-text (format "sec-%s" (org-section-number level)))) (push (cons target target) target-alist) (add-text-properties (point-at-bol) (point-at-eol) (list 'target target)))) target-alist) (defun org-export-handle-invisible-targets (target-alist) "Find targets in comments and move them out of comments. Mark them as invisible targets." (let (target tmp) (goto-char (point-min)) (while (re-search-forward "^#.*?\$$<<\r\n]+\$$>>>?\\).*" nil t) ;; Check if the line before or after is a headline with a target (if (setq target (or (get-text-property (point-at-bol 0) 'target) (get-text-property (point-at-bol 2) 'target))) (progn ;; use the existing target in a neighboring line (setq tmp (match-string 2)) (replace-match "") (and (looking-at "\n") (delete-char 1)) (push (cons (org-solidify-link-text tmp) target) target-alist)) ;; Make an invisible target (replace-match "\\1(INVISIBLE)")))) target-alist) (defun org-export-target-internal-links (target-alist) "Find all internal links and assign target to them. If a link has a fuzzy match (i.e. not a *dedicated* target match), let the link point to the corresponding section." (goto-char (point-min)) (while (re-search-forward org-bracket-link-regexp nil t) (org-if-unprotected (let* ((md (match-data)) (desc (match-end 2)) (link (org-link-unescape (match-string 1))) (slink (org-solidify-link-text link)) found props pos (target  Carsten Dominik committed Jul 24, 2008 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520  (cond ((cdr (assoc slink target-alist))) ((string-match org-link-types-re link) nil) ((or (file-name-absolute-p link) (string-match "^\\." link)) nil) (t (save-excursion (setq found (condition-case nil (org-link-search link) (error nil))) (when (and found (or (org-on-heading-p) (not (eq found 'dedicated)))) (or (get-text-property (point) 'target) (get-text-property (max (point-min) (1- (previous-single-property-change (point) 'target))) 'target))))))))  Carsten Dominik committed Jun 17, 2008 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646  (when target (set-match-data md) (goto-char (match-beginning 1)) (setq props (text-properties-at (point))) (delete-region (match-beginning 1) (match-end 1)) (setq pos (point)) (insert target) (unless desc (insert "][" link)) (add-text-properties pos (point) props)))))) (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers) "Remove drawers, or extract the content. ALL-DRAWERS is a list of all drawer names valid in the current buffer. EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers whose content to keep." (unless (eq t exp-drawers) (goto-char (point-min)) (let ((re (concat "^[ \t]*:\$$" (mapconcat 'identity (org-delete-all exp-drawers (copy-sequence all-drawers)) "\\|") "\$$:[ \t]*\n\$$[^@]*?\n\$$?[ \t]*:END:[ \t]*\n"))) (while (re-search-forward re nil t) (replace-match ""))))) (defun org-export-remove-archived-trees (export-archived-trees) "Remove archived trees. When EXPORT-ARCHIVED-TREES is headline;, only the headline will be exported. When it is t, the entire archived tree will be exported. When it is nil the entire tree including the headline will be removed from the buffer." (let ((re-archive (concat ":" org-archive-tag ":")) a b) (when (not (eq export-archived-trees t)) (goto-char (point-min)) (while (re-search-forward re-archive nil t) (if (not (org-on-heading-p t)) (org-end-of-subtree t) (beginning-of-line 1) (setq a (if export-archived-trees (1+ (point-at-eol)) (point)) b (org-end-of-subtree t)) (if (> b a) (delete-region a b))))))) (defun org-export-protect-quoted-subtrees () "Mark quoted subtrees with the protection property." (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))) (goto-char (point-min)) (while (re-search-forward re-quote nil t) (goto-char (match-beginning 0)) (end-of-line 1) (add-text-properties (point) (org-end-of-subtree t) '(org-protected t))))) (defun org-export-protect-verbatim () "Mark verbatim snippets with the protection property." (goto-char (point-min)) (while (re-search-forward org-verbatim-re nil t) (add-text-properties (match-beginning 4) (match-end 4) '(org-protected t)) (goto-char (1+ (match-end 4))))) (defun org-export-protect-examples () "Protect code that should be exported as monospaced examples." (goto-char (point-min)) (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t) (goto-char (match-end 0)) (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp))) (insert ": ") (beginning-of-line 2))) (goto-char (point-min)) (while (re-search-forward "^[ \t]*:.*\$$\n[ \t]*:.*\$$*" nil t) (add-text-properties (match-beginning 0) (match-end 0) '(org-protected t)))) (defun org-export-select-backend-specific-text (backend) (let ((formatters '((html "HTML" "BEGIN_HTML" "END_HTML") (ascii "ASCII" "BEGIN_ASCII" "END_ASCII") (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX"))) fmt) (while formatters (setq fmt (pop formatters)) (when (eq (car fmt) backend) ;; This is selected code, put it into the file for real (goto-char (point-min)) (while (re-search-forward (concat "^#\\+" (cadr fmt) ":[ \t]*\$$.*\$$") nil t) (replace-match "\\1" t) (add-text-properties (point-at-bol) (min (1+ (point-at-eol)) (point-max)) '(org-protected t)))) (goto-char (point-min)) (while (re-search-forward (concat "^#\\+" (caddr fmt) "\\>.*\$$\\(\n.*\$$*?\n\\)#\\+" (cadddr fmt) "\\>.*\n?") nil t) (if (eq (car fmt) backend) ;; yes, keep this (add-text-properties (match-beginning 1) (1+ (match-end 1)) '(org-protected t)) ;; No, this is for a different backend, kill it (delete-region (match-beginning 0) (match-end 0))))))) (defun org-export-mark-blockquote-and-verse () "Mark block quote and verse environments with special cookies. These special cookies will later be interpreted by the backend." ;; Blockquotes (goto-char (point-min)) (while (re-search-forward "^#\\+\$$begin\\|end\$$_\$$block\$$?quote\\>.*" nil t) (replace-match (if (equal (downcase (match-string 1)) "end") "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START") t t)) ;; Verse (goto-char (point-min)) (while (re-search-forward "^#\\+\$$begin\\|end\$$_verse\\>.*" nil t) (replace-match (if (equal (downcase (match-string 1)) "end") "ORG-VERSE-END" "ORG-VERSE-START") t t))) (defun org-export-remove-comment-blocks-and-subtrees () "Remove the comment environment, and also commented subtrees."  Carsten Dominik committed Jul 24, 2008 1647 1648  (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>")) (case-fold-search nil))  Carsten Dominik committed Jun 17, 2008 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723  ;; Remove comment environment (goto-char (point-min)) (while (re-search-forward "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t) (replace-match "" t t)) ;; Remove subtrees that are commented (goto-char (point-min)) (while (re-search-forward re-commented nil t) (goto-char (match-beginning 0)) (delete-region (point) (org-end-of-subtree t))))) (defun org-export-handle-comments (commentsp) "Remove comments, or convert to backend-specific format. COMMENTSP can be a format string for publishing comments. When it is nil, all comments will be removed." (let ((re "^#\$$.*\n?\$$") pos) (goto-char (point-min)) (while (or (looking-at re) (re-search-forward re nil t)) (setq pos (match-beginning 0)) (if commentsp (progn (add-text-properties (match-beginning 0) (match-end 0) '(org-protected t)) (replace-match (format commentsp (match-string 1)) t t)) (goto-char (1+ pos)) (org-if-unprotected (replace-match "") (goto-char (max (point-min) (1- pos)))))))) (defun org-export-mark-radio-links () "Find all matches for radio targets and turn them into internal links." (let ((re-radio (and org-target-link-regexp (concat "\$$[^<]\$$\$$" org-target-link-regexp "\$$")))) (goto-char (point-min)) (when re-radio (while (re-search-forward re-radio nil t) (org-if-unprotected (replace-match "\\1[[\\2]]")))))) (defun org-export-remove-special-table-lines () "Remove tables lines that are used for internal purposes." (goto-char (point-min)) (while (re-search-forward "^[ \t]*|" nil t) (beginning-of-line 1) (if (or (looking-at "[ \t]*| *[!_^] *|") (and (looking-at ".*?| *<[0-9]+> *|") (not (looking-at ".*?| *[^ <|]")))) (delete-region (max (point-min) (1- (point-at-bol))) (point-at-eol)) (end-of-line 1)))) (defun org-export-normalize-links () "Convert all links to bracket links, and expand link abbreviations." (let ((re-plain-link (concat "\$$[^[<]\$$" org-plain-link-re)) (re-angle-link (concat "\$$[^[]\$$" org-angle-link-re))) (goto-char (point-min)) (while (re-search-forward re-plain-link nil t) (goto-char (1- (match-end 0))) (org-if-unprotected (let* ((s (concat (match-string 1) "[[" (match-string 2) ":" (match-string 3) "]]"))) ;; added 'org-link face to links (put-text-property 0 (length s) 'face 'org-link s) (replace-match s t t)))) (goto-char (point-min)) (while (re-search-forward re-angle-link nil t) (goto-char (1- (match-end 0))) (org-if-unprotected (let* ((s (concat (match-string 1) "[[" (match-string 2) ":" (match-string 3) "]]"))) (put-text-property 0 (length s) 'face 'org-link s) (replace-match s t t)))) (goto-char (point-min)) (while (re-search-forward org-bracket-link-regexp nil t)  Carsten Dominik committed Jul 24, 2008 1724  (goto-char (1- (match-end 0)))  Carsten Dominik committed Jun 17, 2008 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760  (org-if-unprotected (let* ((xx (save-match-data (org-link-expand-abbrev (match-string 1)))) (s (concat "[[" xx "]" (if (match-end 3) (match-string 2) (concat "[" xx "]")) "]"))) (put-text-property 0 (length s) 'face 'org-link s) (replace-match s t t)))))) (defun org-export-concatenate-multiline-links () "Find multi-line links and put it all into a single line. This is to make sure that the line-processing export backends can work correctly." (goto-char (point-min)) (while (re-search-forward "\$$\\(\\[\\|\$\$$\$[^]]*?\\)[ \t]*\n[ \t]*\$$[^]]*\$\\(\$\\|\$\$$\\)" nil t) (org-if-unprotected (replace-match "\\1 \\3") (goto-char (match-beginning 0))))) (defun org-export-concatenate-multiline-emphasis () "Find multi-line emphasis and put it all into a single line. This is to make sure that the line-processing export backends can work correctly." (goto-char (point-min)) (while (re-search-forward org-emph-re nil t) (if (not (= (char-after (match-beginning 3)) (char-after (match-beginning 4)))) (org-if-unprotected (subst-char-in-region (match-beginning 0) (match-end 0) ?\n ?\ t) (goto-char (1- (match-end 0)))) (goto-char (1+ (match-beginning 0))))))  Carsten Dominik committed Apr 27, 2008 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 (defun org-export-grab-title-from-buffer () "Get a title for the current document, from looking at the buffer." (let ((inhibit-read-only t)) (save-excursion (goto-char (point-min)) (let ((end (save-excursion (outline-next-heading) (point)))) (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t) ;; Mark the line so that it will not be exported as normal text. (org-unmodified (add-text-properties (match-beginning 0) (match-end 0) (list :org-license-to-kill t))) ;; Return the title string (org-trim (match-string 0))))))) (defun org-export-get-title-from-subtree () "Return subtree title and exclude it from export."  Carsten Dominik committed Jun 17, 2008 1777  (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))  Carsten Dominik committed Apr 27, 2008 1778  (save-excursion  Carsten Dominik committed Jun 17, 2008 1779  (goto-char rbeg)  Carsten Dominik committed Apr 27, 2008 1780  (when (and (org-at-heading-p)  Carsten Dominik committed Jun 17, 2008 1781  (>= (org-end-of-subtree t t) rend))  Carsten Dominik committed Apr 27, 2008 1782  ;; This is a subtree, we take the title from the first heading  Carsten Dominik committed Jun 17, 2008 1783  (goto-char rbeg)  Carsten Dominik committed Apr 27, 2008 1784 1785 1786 1787  (looking-at org-todo-line-regexp) (setq title (match-string 3)) (org-unmodified (add-text-properties (point) (1+ (point-at-eol))  Carsten Dominik committed Jun 17, 2008 1788 1789  (list :org-license-to-kill t))) (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))  Carsten Dominik committed Apr 27, 2008 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826  title)) (defun org-solidify-link-text (s &optional alist) "Take link text and make a safe target out of it." (save-match-data (let* ((rtn (mapconcat 'identity (org-split-string s "[ \t\r\n]+") "==")) (a (assoc rtn alist))) (or (cdr a) rtn)))) (defun org-get-min-level (lines) "Get the minimum level in LINES." (let ((re "^\$$\\*+\$$ ") l min) (catch 'exit (while (setq l (pop lines)) (if (string-match re l) (throw 'exit (org-tr-level (length (match-string 1 l)))))) 1))) ;; Variable holding the vector with section numbers (defvar org-section-numbers (make-vector org-level-max 0)) (defun org-init-section-numbers () "Initialize the vector for the section numbers." (let* ((level -1) (numbers (nreverse (org-split-string "" "\\."))) (depth (1- (length org-section-numbers))) (i depth) number-string) (while (>= i 0) (if (> i level) (aset org-section-numbers i 0) (setq number-string (or (car numbers) "0")) (if (string-match "\\[A-Z]\\'" number-string) (aset org-section-numbers i (- (string-to-char number-string) ?A -1))  Carsten Dominik committed Jun 17, 2008 1827  (aset org-section-numbers i (string-to-number number-string)))  Carsten Dominik committed Apr 27, 2008 1828 1829 1830 1831 1832 1833  (pop numbers)) (setq i (1- i))))) (defun org-section-number (&optional level) "Return a string with the current section number. When LEVEL is non-nil, increase section numbers on that level."  Carsten Dominik committed Jun 17, 2008 1834 1835 1836 1837 1838 1839  (let* ((depth (1- (length org-section-numbers))) (string "") (fmts (car org-export-section-number-format)) (term (cdr org-export-section-number-format)) (sep "") ctype fmt idx n)  Carsten Dominik committed Apr 27, 2008 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850  (when level (when (> level -1) (aset org-section-numbers level (1+ (aref org-section-numbers level)))) (setq idx (1+ level)) (while (<= idx depth) (if (not (= idx 1)) (aset org-section-numbers idx 0)) (setq idx (1+ idx)))) (setq idx 0) (while (<= idx depth)  Carsten Dominik committed Jun 17, 2008 1851 1852 1853 1854 1855 1856 1857 1858  (when (> (aref org-section-numbers idx) 0) (setq fmt (or (pop fmts) fmt) ctype (car fmt) n (aref org-section-numbers idx) string (if (> n 0) (concat string sep (org-number-to-counter n ctype)) (concat string ".0")) sep (nth 1 fmt)))  Carsten Dominik committed Apr 27, 2008 1859 1860 1861 1862 1863 1864  (setq idx (1+ idx))) (save-match-data (if (string-match "\\\$$[@0]\\.\$$+" string) (setq string (replace-match "" t nil string))) (if (string-match "\$$\\.0\$$+\\'" string) (setq string (replace-match "" t nil string))))  Carsten Dominik committed Jun 17, 2008 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906  (concat string term))) (defun org-number-to-counter (n type) "Concert number N to a string counter, according to TYPE. TYPE must be a string, any of: 1 number A A,B,.... a a,b,.... I uppper case roman numeral i lower case roman numeral" (cond ((equal type "1") (number-to-string n)) ((equal type "A") (char-to-string (+ ?A n -1))) ((equal type "a") (char-to-string (+ ?a n -1))) ((equal type "I") (org-number-to-roman n)) ((equal type "i") (downcase (org-number-to-roman n))) (t (error "Invalid counter type %s'" type)))) (defun org-number-to-roman (n) "Convert integer N into a roman numeral." (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD") ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL") ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV") ( 1 . "I"))) (res "")) (if (<= n 0) (number-to-string n) (while roman (if (>= n (caar roman)) (setq n (- n (caar roman)) res (concat res (cdar roman))) (pop roman))) res))) (org-number-to-roman 1961) ;;; Include files (defun org-export-handle-include-files () "Include the contents of include files, with proper formatting." (let ((case-fold-search t)  Carsten Dominik committed Jul 24, 2008 1907  params file markup lang start end prefix prefix1)  Carsten Dominik committed Jun 17, 2008 1908 1909 1910  (goto-char (point-min)) (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\$$.*\$$" nil t) (setq params (read (concat "(" (match-string 1) ")"))  Carsten Dominik committed Jul 24, 2008 1911 1912  prefix (org-get-and-remove-property 'params :prefix) prefix1 (org-get-and-remove-property 'params :prefix1)  Carsten Dominik committed Jun 17, 2008 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927  file (org-symname-or-string (pop params)) markup (org-symname-or-string (pop params)) lang (org-symname-or-string (pop params))) (delete-region (match-beginning 0) (match-end 0)) (if (or (not file) (not (file-exists-p file)) (not (file-readable-p file))) (insert (format "CANNOT INCLUDE FILE %s" file)) (when markup (if (equal (downcase markup) "src") (setq start (format "#+begin_src %s\n" (or lang "fundamental")) end "#+end_src") (setq start (format "#+begin_%s\n" markup) end (format "#+end_%s" markup)))) (insert (or start ""))  Carsten Dominik committed Jul 24, 2008 1928  (insert (org-get-file-contents (expand-file-name file) prefix prefix1))  Carsten Dominik committed Jun 17, 2008 1929 1930 1931  (or (bolp) (newline)) (insert (or end ""))))))  Carsten Dominik committed Jul 24, 2008 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 (defun org-get-file-contents (file &optional prefix prefix1) "Get the contents of FILE and return them as a string. If PREFIX is a string, prepend it to each line. If PREFIX1 is a string, prepend it to the first line instead of PREFIX." (with-temp-buffer (insert-file-contents file) (when (or prefix prefix1) (goto-char (point-min)) (while (not (eobp)) (insert (or prefix1 prefix)) (setq prefix1 nil) (beginning-of-line 2))) (buffer-string))) (defun org-get-and-remove-property (listvar prop) "Check if the value of LISTVAR contains PROP as a property. If yes, return the value of that property (i.e. the element following in the list) and remove property and value from the list in LISTVAR." (let ((list (symbol-value listvar)) m v) (when (setq m (member prop list)) (setq v (nth 1 m)) (if (equal (car list) prop) (set listvar (cddr list)) (setcdr (nthcdr (- (length list) (length m) 1) list) (cddr m)) (set listvar list))) v))  Carsten Dominik committed Jun 17, 2008 1960 1961 1962 1963 1964 1965 (defun org-symname-or-string (s) (if (symbolp s) (if s (symbol-name s) s) s)) ;;; Fontification of code  Carsten Dominik committed Jul 24, 2008 1966 ;; Currently only for the HTML backend, but who knows.... ` Carsten Dominik committed Jun 17, 2008 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998