org-exp.el 114 KB

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