org-exp.el 100 KB

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