org-exp.el 110 KB

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