org-exp.el 114 KB

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