org-exp.el 106 KB

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