org-exp.el 97 KB

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