org-exp.el 117 KB

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