org-exp.el 100 KB

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