org-exp.el 126 KB

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