org-exp.el 119 KB

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