org-exp.el 108 KB

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