org-exp.el 106 KB

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