org-exp.el 100 KB

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