org-exp.el 109 KB

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