org-exp.el 106 KB

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