org-exp.el 119 KB

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