org-exp.el 120 KB

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