org-exp.el 103 KB

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