org-exp.el 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859
  1. ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 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. ;; Version: 6.02b
  7. ;;
  8. ;; This file is part of GNU Emacs.
  9. ;;
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 3, or (at your option)
  13. ;; any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Commentary:
  25. (require 'org)
  26. (require 'org-agenda)
  27. (eval-and-compile
  28. (require 'cl))
  29. (declare-function org-export-latex-preprocess "org-export-latex" ())
  30. (declare-function org-agenda-skip "org-agenda" ())
  31. (declare-function org-infojs-options-inbuffer-template "org-infojs" ())
  32. (defgroup org-export nil
  33. "Options for exporting org-listings."
  34. :tag "Org Export"
  35. :group 'org)
  36. (defgroup org-export-general nil
  37. "General options for exporting Org-mode files."
  38. :tag "Org Export General"
  39. :group 'org-export)
  40. ;; FIXME
  41. (defvar org-export-publishing-directory nil)
  42. (defcustom org-export-run-in-background nil
  43. "Non-nil means export and publishing commands will run in background.
  44. This works by starting up a separate Emacs process visiting the same file
  45. and doing the export from there.
  46. Not all export commands are affected by this - only the ones which
  47. actually write to a file, and that do not depend on the buffer state.
  48. If this option is nil, you can still get background export by calling
  49. `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
  50. If this option is t, the double prefix can be used to exceptionally
  51. force an export command into the current process."
  52. :group 'org-export-general
  53. :type 'boolean)
  54. (defcustom org-export-with-special-strings t
  55. "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
  56. When this option is turned on, these strings will be exported as:
  57. Org HTML LaTeX
  58. -----+----------+--------
  59. \\- &shy; \\-
  60. -- &ndash; --
  61. --- &mdash; ---
  62. ... &hellip; \ldots
  63. This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
  64. :group 'org-export-translation
  65. :type 'boolean)
  66. (defcustom org-export-language-setup
  67. '(("en" "Author" "Date" "Table of Contents")
  68. ("cs" "Autor" "Datum" "Obsah")
  69. ("da" "Ophavsmand" "Dato" "Indhold")
  70. ("de" "Autor" "Datum" "Inhaltsverzeichnis")
  71. ("es" "Autor" "Fecha" "\xcdndice")
  72. ("fr" "Auteur" "Date" "Table des mati\xe8res")
  73. ("it" "Autore" "Data" "Indice")
  74. ("nl" "Auteur" "Datum" "Inhoudsopgave")
  75. ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
  76. ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
  77. "Terms used in export text, translated to different languages.
  78. Use the variable `org-export-default-language' to set the language,
  79. or use the +OPTION lines for a per-file setting."
  80. :group 'org-export-general
  81. :type '(repeat
  82. (list
  83. (string :tag "HTML language tag")
  84. (string :tag "Author")
  85. (string :tag "Date")
  86. (string :tag "Table of Contents"))))
  87. (defcustom org-export-default-language "en"
  88. "The default language of HTML export, as a string.
  89. This should have an association in `org-export-language-setup'."
  90. :group 'org-export-general
  91. :type 'string)
  92. (defcustom org-export-skip-text-before-1st-heading t
  93. "Non-nil means, skip all text before the first headline when exporting.
  94. When nil, that text is exported as well."
  95. :group 'org-export-general
  96. :type 'boolean)
  97. (defcustom org-export-headline-levels 3
  98. "The last level which is still exported as a headline.
  99. Inferior levels will produce itemize lists when exported.
  100. Note that a numeric prefix argument to an exporter function overrides
  101. this setting.
  102. This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
  103. :group 'org-export-general
  104. :type 'number)
  105. (defcustom org-export-with-section-numbers t
  106. "Non-nil means, add section numbers to headlines when exporting.
  107. This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
  108. :group 'org-export-general
  109. :type 'boolean)
  110. (defcustom org-export-with-toc t
  111. "Non-nil means, create a table of contents in exported files.
  112. The TOC contains headlines with levels up to`org-export-headline-levels'.
  113. When an integer, include levels up to N in the toc, this may then be
  114. different from `org-export-headline-levels', but it will not be allowed
  115. to be larger than the number of headline levels.
  116. When nil, no table of contents is made.
  117. Headlines which contain any TODO items will be marked with \"(*)\" in
  118. ASCII export, and with red color in HTML output, if the option
  119. `org-export-mark-todo-in-toc' is set.
  120. In HTML output, the TOC will be clickable.
  121. This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
  122. or \"toc:3\"."
  123. :group 'org-export-general
  124. :type '(choice
  125. (const :tag "No Table of Contents" nil)
  126. (const :tag "Full Table of Contents" t)
  127. (integer :tag "TOC to level")))
  128. (defcustom org-export-mark-todo-in-toc nil
  129. "Non-nil means, mark TOC lines that contain any open TODO items."
  130. :group 'org-export-general
  131. :type 'boolean)
  132. (defcustom org-export-preserve-breaks nil
  133. "Non-nil means, preserve all line breaks when exporting.
  134. Normally, in HTML output paragraphs will be reformatted. In ASCII
  135. export, line breaks will always be preserved, regardless of this variable.
  136. This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
  137. :group 'org-export-general
  138. :type 'boolean)
  139. (defcustom org-export-with-archived-trees 'headline
  140. "Whether subtrees with the ARCHIVE tag should be exported.
  141. This can have three different values
  142. nil Do not export, pretend this tree is not present
  143. t Do export the entire tree
  144. headline Only export the headline, but skip the tree below it."
  145. :group 'org-export-general
  146. :group 'org-archive
  147. :type '(choice
  148. (const :tag "not at all" nil)
  149. (const :tag "headline only" 'headline)
  150. (const :tag "entirely" t)))
  151. (defcustom org-export-author-info t
  152. "Non-nil means, insert author name and email into the exported file.
  153. This option can also be set with the +OPTIONS line,
  154. e.g. \"author-info:nil\"."
  155. :group 'org-export-general
  156. :type 'boolean)
  157. (defcustom org-export-time-stamp-file t
  158. "Non-nil means, insert a time stamp into the exported file.
  159. The time stamp shows when the file was created.
  160. This option can also be set with the +OPTIONS line,
  161. e.g. \"timestamp:nil\"."
  162. :group 'org-export-general
  163. :type 'boolean)
  164. (defcustom org-export-with-timestamps t
  165. "If nil, do not export time stamps and associated keywords."
  166. :group 'org-export-general
  167. :type 'boolean)
  168. (defcustom org-export-remove-timestamps-from-toc t
  169. "If nil, remove timestamps from the table of contents entries."
  170. :group 'org-export-general
  171. :type 'boolean)
  172. (defcustom org-export-with-tags 'not-in-toc
  173. "If nil, do not export tags, just remove them from headlines.
  174. If this is the symbol `not-in-toc', tags will be removed from table of
  175. contents entries, but still be shown in the headlines of the document.
  176. This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
  177. :group 'org-export-general
  178. :type '(choice
  179. (const :tag "Off" nil)
  180. (const :tag "Not in TOC" not-in-toc)
  181. (const :tag "On" t)))
  182. (defcustom org-export-with-drawers nil
  183. "Non-nil means, export with drawers like the property drawer.
  184. When t, all drawers are exported. This may also be a list of
  185. drawer names to export."
  186. :group 'org-export-general
  187. :type '(choice
  188. (const :tag "All drawers" t)
  189. (const :tag "None" nil)
  190. (repeat :tag "Selected drawers"
  191. (string :tag "Drawer name"))))
  192. (defvar org-export-preprocess-hook nil
  193. "Hook for preprocessing an export buffer.
  194. Pretty much the first thing when exporting is running this hook.")
  195. (defgroup org-export-translation nil
  196. "Options for translating special ascii sequences for the export backends."
  197. :tag "Org Export Translation"
  198. :group 'org-export)
  199. (defcustom org-export-with-emphasize t
  200. "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
  201. If the export target supports emphasizing text, the word will be
  202. typeset in bold, italic, or underlined, respectively. Works only for
  203. single words, but you can say: I *really* *mean* *this*.
  204. Not all export backends support this.
  205. This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
  206. :group 'org-export-translation
  207. :type 'boolean)
  208. (defcustom org-export-with-footnotes t
  209. "If nil, export [1] as a footnote marker.
  210. Lines starting with [1] will be formatted as footnotes.
  211. This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
  212. :group 'org-export-translation
  213. :type 'boolean)
  214. (defcustom org-export-with-sub-superscripts t
  215. "Non-nil means, interpret \"_\" and \"^\" for export.
  216. When this option is turned on, you can use TeX-like syntax for sub- and
  217. superscripts. Several characters after \"_\" or \"^\" will be
  218. considered as a single item - so grouping with {} is normally not
  219. needed. For example, the following things will be parsed as single
  220. sub- or superscripts.
  221. 10^24 or 10^tau several digits will be considered 1 item.
  222. 10^-12 or 10^-tau a leading sign with digits or a word
  223. x^2-y^3 will be read as x^2 - y^3, because items are
  224. terminated by almost any nonword/nondigit char.
  225. x_{i^2} or x^(2-i) braces or parenthesis do grouping.
  226. Still, ambiguity is possible - so when in doubt use {} to enclose the
  227. sub/superscript. If you set this variable to the symbol `{}',
  228. the braces are *required* in order to trigger interpretations as
  229. sub/superscript. This can be helpful in documents that need \"_\"
  230. frequently in plain text.
  231. Not all export backends support this, but HTML does.
  232. This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
  233. :group 'org-export-translation
  234. :type '(choice
  235. (const :tag "Always interpret" t)
  236. (const :tag "Only with braces" {})
  237. (const :tag "Never interpret" nil)))
  238. (defcustom org-export-with-special-strings t
  239. "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
  240. When this option is turned on, these strings will be exported as:
  241. \\- : &shy;
  242. -- : &ndash;
  243. --- : &mdash;
  244. Not all export backends support this, but HTML does.
  245. This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
  246. :group 'org-export-translation
  247. :type 'boolean)
  248. (defcustom org-export-with-TeX-macros t
  249. "Non-nil means, interpret simple TeX-like macros when exporting.
  250. For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
  251. No only real TeX macros will work here, but the standard HTML entities
  252. for math can be used as macro names as well. For a list of supported
  253. names in HTML export, see the constant `org-html-entities'.
  254. Not all export backends support this.
  255. This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
  256. :group 'org-export-translation
  257. :group 'org-export-latex
  258. :type 'boolean)
  259. (defcustom org-export-with-LaTeX-fragments nil
  260. "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
  261. When set, the exporter will find LaTeX environments if the \\begin line is
  262. the first non-white thing on a line. It will also find the math delimiters
  263. like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
  264. display math.
  265. This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
  266. :group 'org-export-translation
  267. :group 'org-export-latex
  268. :type 'boolean)
  269. (defcustom org-export-with-fixed-width t
  270. "Non-nil means, lines starting with \":\" will be in fixed width font.
  271. This can be used to have pre-formatted text, fragments of code etc. For
  272. example:
  273. : ;; Some Lisp examples
  274. : (while (defc cnt)
  275. : (ding))
  276. will be looking just like this in also HTML. See also the QUOTE keyword.
  277. Not all export backends support this.
  278. This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
  279. :group 'org-export-translation
  280. :type 'boolean)
  281. (defcustom org-match-sexp-depth 3
  282. "Number of stacked braces for sub/superscript matching.
  283. This has to be set before loading org.el to be effective."
  284. :group 'org-export-translation
  285. :type 'integer)
  286. (defgroup org-export-tables nil
  287. "Options for exporting tables in Org-mode."
  288. :tag "Org Export Tables"
  289. :group 'org-export)
  290. (defcustom org-export-with-tables t
  291. "If non-nil, lines starting with \"|\" define a table.
  292. For example:
  293. | Name | Address | Birthday |
  294. |-------------+----------+-----------|
  295. | Arthur Dent | England | 29.2.2100 |
  296. Not all export backends support this.
  297. This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
  298. :group 'org-export-tables
  299. :type 'boolean)
  300. (defcustom org-export-highlight-first-table-line t
  301. "Non-nil means, highlight the first table line.
  302. In HTML export, this means use <th> instead of <td>.
  303. In tables created with table.el, this applies to the first table line.
  304. In Org-mode tables, all lines before the first horizontal separator
  305. line will be formatted with <th> tags."
  306. :group 'org-export-tables
  307. :type 'boolean)
  308. (defcustom org-export-table-remove-special-lines t
  309. "Remove special lines and marking characters in calculating tables.
  310. This removes the special marking character column from tables that are set
  311. up for spreadsheet calculations. It also removes the entire lines
  312. marked with `!', `_', or `^'. The lines with `$' are kept, because
  313. the values of constants may be useful to have."
  314. :group 'org-export-tables
  315. :type 'boolean)
  316. (defcustom org-export-prefer-native-exporter-for-tables nil
  317. "Non-nil means, always export tables created with table.el natively.
  318. Natively means, use the HTML code generator in table.el.
  319. When nil, Org-mode's own HTML generator is used when possible (i.e. if
  320. the table does not use row- or column-spanning). This has the
  321. advantage, that the automatic HTML conversions for math symbols and
  322. sub/superscripts can be applied. Org-mode's HTML generator is also
  323. much faster."
  324. :group 'org-export-tables
  325. :type 'boolean)
  326. (defgroup org-export-ascii nil
  327. "Options specific for ASCII export of Org-mode files."
  328. :tag "Org Export ASCII"
  329. :group 'org-export)
  330. (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
  331. "Characters for underlining headings in ASCII export.
  332. In the given sequence, these characters will be used for level 1, 2, ..."
  333. :group 'org-export-ascii
  334. :type '(repeat character))
  335. (defcustom org-export-ascii-bullets '(?* ?+ ?-)
  336. "Bullet characters for headlines converted to lists in ASCII export.
  337. The first character is used for the first lest level generated in this
  338. way, and so on. If there are more levels than characters given here,
  339. the list will be repeated.
  340. Note that plain lists will keep the same bullets as the have in the
  341. Org-mode file."
  342. :group 'org-export-ascii
  343. :type '(repeat character))
  344. (defgroup org-export-xml nil
  345. "Options specific for XML export of Org-mode files."
  346. :tag "Org Export XML"
  347. :group 'org-export)
  348. (defgroup org-export-html nil
  349. "Options specific for HTML export of Org-mode files."
  350. :tag "Org Export HTML"
  351. :group 'org-export)
  352. (defcustom org-export-html-coding-system nil
  353. "Coding system for HTML export, defaults to buffer-file-coding-system."
  354. :group 'org-export-html
  355. :type 'coding-system)
  356. (defcustom org-export-html-extension "html"
  357. "The extension for exported HTML files."
  358. :group 'org-export-html
  359. :type 'string)
  360. (defcustom org-export-html-link-up ""
  361. "Where should the \"UP\" link of exported HTML pages lead?"
  362. :group 'org-export-html
  363. :type '(string :tag "File or URL"))
  364. (defcustom org-export-html-link-home ""
  365. "Where should the \"HOME\" link of exported HTML pages lead?"
  366. :group 'org-export-html
  367. :type '(string :tag "File or URL"))
  368. (defcustom org-export-html-style
  369. "<style type=\"text/css\">
  370. html {
  371. font-family: Times, serif;
  372. font-size: 12pt;
  373. }
  374. .title { text-align: center; }
  375. .todo { color: red; }
  376. .done { color: green; }
  377. .timestamp { color: grey }
  378. .timestamp-kwd { color: CadetBlue }
  379. .tag { background-color:lightblue; font-weight:normal }
  380. .target { }
  381. pre {
  382. border: 1pt solid #AEBDCC;
  383. background-color: #F3F5F7;
  384. padding: 5pt;
  385. font-family: courier, monospace;
  386. }
  387. table { border-collapse: collapse; }
  388. td, th {
  389. vertical-align: top;
  390. <!--border: 1pt solid #ADB9CC;-->
  391. }
  392. </style>"
  393. "The default style specification for exported HTML files.
  394. Since there are different ways of setting style information, this variable
  395. needs to contain the full HTML structure to provide a style, including the
  396. surrounding HTML tags. The style specifications should include definitions
  397. for new classes todo, done, title, and deadline. For example, valid values
  398. would be:
  399. <style type=\"text/css\">
  400. p { font-weight: normal; color: gray; }
  401. h1 { color: black; }
  402. .title { text-align: center; }
  403. .todo, .deadline { color: red; }
  404. .done { color: green; }
  405. </style>
  406. or, if you want to keep the style in a file,
  407. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  408. As the value of this option simply gets inserted into the HTML <head> header,
  409. you can \"misuse\" it to add arbitrary text to the header."
  410. :group 'org-export-html
  411. :type 'string)
  412. (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
  413. "Format for typesetting the document title in HTML export."
  414. :group 'org-export-html
  415. :type 'string)
  416. (defcustom org-export-html-toplevel-hlevel 2
  417. "The <H> level for level 1 headings in HTML export."
  418. :group 'org-export-html
  419. :type 'string)
  420. (defcustom org-export-html-link-org-files-as-html t
  421. "Non-nil means, make file links to `file.org' point to `file.html'.
  422. When org-mode is exporting an org-mode file to HTML, links to
  423. non-html files are directly put into a href tag in HTML.
  424. However, links to other Org-mode files (recognized by the
  425. extension `.org.) should become links to the corresponding html
  426. file, assuming that the linked org-mode file will also be
  427. converted to HTML.
  428. When nil, the links still point to the plain `.org' file."
  429. :group 'org-export-html
  430. :type 'boolean)
  431. (defcustom org-export-html-inline-images 'maybe
  432. "Non-nil means, inline images into exported HTML pages.
  433. This is done using an <img> tag. When nil, an anchor with href is used to
  434. link to the image. If this option is `maybe', then images in links with
  435. an empty description will be inlined, while images with a description will
  436. be linked only."
  437. :group 'org-export-html
  438. :type '(choice (const :tag "Never" nil)
  439. (const :tag "Always" t)
  440. (const :tag "When there is no description" maybe)))
  441. ;; FIXME: rename
  442. (defcustom org-export-html-expand t
  443. "Non-nil means, for HTML export, treat @<...> as HTML tag.
  444. When nil, these tags will be exported as plain text and therefore
  445. not be interpreted by a browser.
  446. This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
  447. :group 'org-export-html
  448. :type 'boolean)
  449. (defcustom org-export-html-table-tag
  450. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  451. "The HTML tag that is used to start a table.
  452. This must be a <table> tag, but you may change the options like
  453. borders and spacing."
  454. :group 'org-export-html
  455. :type 'string)
  456. (defcustom org-export-table-header-tags '("<th>" . "</th>")
  457. "The opening tag for table header fields.
  458. This is customizable so that alignment options can be specified."
  459. :group 'org-export-tables
  460. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  461. (defcustom org-export-table-data-tags '("<td>" . "</td>")
  462. "The opening tag for table data fields.
  463. This is customizable so that alignment options can be specified."
  464. :group 'org-export-tables
  465. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  466. (defcustom org-export-html-with-timestamp nil
  467. "If non-nil, write `org-export-html-html-helper-timestamp'
  468. into the exported HTML text. Otherwise, the buffer will just be saved
  469. to a file."
  470. :group 'org-export-html
  471. :type 'boolean)
  472. (defcustom org-export-html-html-helper-timestamp
  473. "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
  474. "The HTML tag used as timestamp delimiter for HTML-helper-mode."
  475. :group 'org-export-html
  476. :type 'string)
  477. (defgroup org-export-icalendar nil
  478. "Options specific for iCalendar export of Org-mode files."
  479. :tag "Org Export iCalendar"
  480. :group 'org-export)
  481. (defcustom org-combined-agenda-icalendar-file "~/org.ics"
  482. "The file name for the iCalendar file covering all agenda files.
  483. This file is created with the command \\[org-export-icalendar-all-agenda-files].
  484. The file name should be absolute, the file will be overwritten without warning."
  485. :group 'org-export-icalendar
  486. :type 'file)
  487. (defcustom org-icalendar-include-todo nil
  488. "Non-nil means, export to iCalendar files should also cover TODO items."
  489. :group 'org-export-icalendar
  490. :type '(choice
  491. (const :tag "None" nil)
  492. (const :tag "Unfinished" t)
  493. (const :tag "All" all)))
  494. (defcustom org-icalendar-include-sexps t
  495. "Non-nil means, export to iCalendar files should also cover sexp entries.
  496. These are entries like in the diary, but directly in an Org-mode file."
  497. :group 'org-export-icalendar
  498. :type 'boolean)
  499. (defcustom org-icalendar-include-body 100
  500. "Amount of text below headline to be included in iCalendar export.
  501. This is a number of characters that should maximally be included.
  502. Properties, scheduling and clocking lines will always be removed.
  503. The text will be inserted into the DESCRIPTION field."
  504. :group 'org-export-icalendar
  505. :type '(choice
  506. (const :tag "Nothing" nil)
  507. (const :tag "Everything" t)
  508. (integer :tag "Max characters")))
  509. (defcustom org-icalendar-combined-name "OrgMode"
  510. "Calendar name for the combined iCalendar representing all agenda files."
  511. :group 'org-export-icalendar
  512. :type 'string)
  513. ;;;; Exporting
  514. ;;; Variables, constants, and parameter plists
  515. (defconst org-level-max 20)
  516. (defvar org-export-html-preamble nil
  517. "Preamble, to be inserted just after <body>. Set by publishing functions.")
  518. (defvar org-export-html-postamble nil
  519. "Preamble, to be inserted just before </body>. Set by publishing functions.")
  520. (defvar org-export-html-auto-preamble t
  521. "Should default preamble be inserted? Set by publishing functions.")
  522. (defvar org-export-html-auto-postamble t
  523. "Should default postamble be inserted? Set by publishing functions.")
  524. (defvar org-current-export-file nil) ; dynamically scoped parameter
  525. (defvar org-current-export-dir nil) ; dynamically scoped parameter
  526. (defconst org-export-plist-vars
  527. '((:link-up . org-export-html-link-up)
  528. (:link-home . org-export-html-link-home)
  529. (:language . org-export-default-language)
  530. (:customtime . org-display-custom-times)
  531. (:headline-levels . org-export-headline-levels)
  532. (:section-numbers . org-export-with-section-numbers)
  533. (:table-of-contents . org-export-with-toc)
  534. (:preserve-breaks . org-export-preserve-breaks)
  535. (:archived-trees . org-export-with-archived-trees)
  536. (:emphasize . org-export-with-emphasize)
  537. (:sub-superscript . org-export-with-sub-superscripts)
  538. (:special-strings . org-export-with-special-strings)
  539. (:footnotes . org-export-with-footnotes)
  540. (:drawers . org-export-with-drawers)
  541. (:tags . org-export-with-tags)
  542. (:TeX-macros . org-export-with-TeX-macros)
  543. (:LaTeX-fragments . org-export-with-LaTeX-fragments)
  544. (:skip-before-1st-heading . org-export-skip-text-before-1st-heading)
  545. (:fixed-width . org-export-with-fixed-width)
  546. (:timestamps . org-export-with-timestamps)
  547. (:author-info . org-export-author-info)
  548. (:time-stamp-file . org-export-time-stamp-file)
  549. (:tables . org-export-with-tables)
  550. (:table-auto-headline . org-export-highlight-first-table-line)
  551. (:style . org-export-html-style)
  552. (:agenda-style . org-agenda-export-html-style)
  553. (:convert-org-links . org-export-html-link-org-files-as-html)
  554. (:inline-images . org-export-html-inline-images)
  555. (:html-extension . org-export-html-extension)
  556. (:html-table-tag . org-export-html-table-tag)
  557. (:expand-quoted-html . org-export-html-expand)
  558. (:timestamp . org-export-html-with-timestamp)
  559. (:publishing-directory . org-export-publishing-directory)
  560. (:preamble . org-export-html-preamble)
  561. (:postamble . org-export-html-postamble)
  562. (:auto-preamble . org-export-html-auto-preamble)
  563. (:auto-postamble . org-export-html-auto-postamble)
  564. (:author . user-full-name)
  565. (:email . user-mail-address)))
  566. (defun org-default-export-plist ()
  567. "Return the property list with default settings for the export variables."
  568. (let ((l org-export-plist-vars) rtn e)
  569. (while (setq e (pop l))
  570. (setq rtn (cons (car e) (cons (symbol-value (cdr e)) rtn))))
  571. rtn))
  572. (defvar org-export-inbuffer-options-extra nil
  573. "List of additional in-buffer options that should be detected.
  574. Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
  575. etc. Extensions can add to this list to get their options detected, and they
  576. can then add a function to `org-export-options-filters' to process these
  577. options.
  578. Each element in this list must be a list, with the in-buffer keyword as car,
  579. and a property (a symbol) as the next element. All occurences of the
  580. keyword will be found, the values concatenated with a space character
  581. in between, and the result stored in the export options property list.")
  582. (defvar org-export-options-filters nil
  583. "Functions to be called to finalize the export/publishing options.
  584. All these options are stored in a property list, and each of the functions
  585. in this hook gets a chance to modify this property list. Each function
  586. must accept the property list as an argument, and must return the (possibly
  587. modified) list.")
  588. (defun org-infile-export-plist ()
  589. "Return the property list with file-local settings for export."
  590. (save-excursion
  591. (save-restriction
  592. (widen)
  593. (goto-char 0)
  594. (let ((re (org-make-options-regexp
  595. (append
  596. '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
  597. "LINK_UP" "LINK_HOME")
  598. (mapcar 'car org-export-inbuffer-options-extra))))
  599. p key val text options js-up js-main js-css js-opt a pr)
  600. (while (re-search-forward re nil t)
  601. (setq key (org-match-string-no-properties 1)
  602. val (org-match-string-no-properties 2))
  603. (cond
  604. ((setq a (assoc key org-export-inbuffer-options-extra))
  605. (setq pr (nth 1 a))
  606. (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
  607. ((string-equal key "TITLE") (setq p (plist-put p :title val)))
  608. ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
  609. ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
  610. ((string-equal key "DATE") (setq p (plist-put p :date val)))
  611. ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
  612. ((string-equal key "TEXT")
  613. (setq text (if text (concat text "\n" val) val)))
  614. ((string-equal key "OPTIONS")
  615. (setq options (concat options " " val)))
  616. ((string-equal key "LINK_UP")
  617. (setq p (plist-put p :link-up val)))
  618. ((string-equal key "LINK_HOME")
  619. (setq p (plist-put p :link-home val)))))
  620. (setq p (plist-put p :text text))
  621. (when options
  622. (let ((op '(("H" . :headline-levels)
  623. ("num" . :section-numbers)
  624. ("toc" . :table-of-contents)
  625. ("\\n" . :preserve-breaks)
  626. ("@" . :expand-quoted-html)
  627. (":" . :fixed-width)
  628. ("|" . :tables)
  629. ("^" . :sub-superscript)
  630. ("-" . :special-strings)
  631. ("f" . :footnotes)
  632. ("d" . :drawers)
  633. ("tags" . :tags)
  634. ("*" . :emphasize)
  635. ("TeX" . :TeX-macros)
  636. ("LaTeX" . :LaTeX-fragments)
  637. ("skip" . :skip-before-1st-heading)
  638. ("author" . :author-info)
  639. ("timestamp" . :time-stamp-file)))
  640. o)
  641. (while (setq o (pop op))
  642. (if (string-match (concat (regexp-quote (car o))
  643. ":\\([^ \t\n\r;,.]*\\)")
  644. options)
  645. (setq p (plist-put p (cdr o)
  646. (car (read-from-string
  647. (match-string 1 options)))))))))
  648. p))))
  649. (defun org-export-directory (type plist)
  650. (let* ((val (plist-get plist :publishing-directory))
  651. (dir (if (listp val)
  652. (or (cdr (assoc type val)) ".")
  653. val)))
  654. dir))
  655. (defun org-export-process-option-filters (plist)
  656. (let ((functions org-export-options-filters) f)
  657. (while (setq f (pop functions))
  658. (setq plist (funcall f plist))))
  659. plist)
  660. ;;;###autoload
  661. (defun org-export (&optional arg)
  662. "Export dispatcher for Org-mode.
  663. When `org-export-run-in-background' is non-nil, try to run the command
  664. in the background. This will be done only for commands that write
  665. to a file. For details see the docstring of `org-export-run-in-background'.
  666. The prefix argument ARG will be passed to the exporter. However, if
  667. ARG is a double universal prefix `C-u C-u', that means to inverse the
  668. value of `org-export-run-in-background'."
  669. (interactive "P")
  670. (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
  671. (help "[t] insert the export option template
  672. \[v] limit export to visible part of outline tree
  673. \[a] export as ASCII
  674. \[h] export as HTML
  675. \[H] export as HTML to temporary buffer
  676. \[R] export region as HTML
  677. \[b] export as HTML and browse immediately
  678. \[x] export as XOXO
  679. \[l] export as LaTeX
  680. \[L] export as LaTeX to temporary buffer
  681. \[i] export current file as iCalendar file
  682. \[I] export all agenda files as iCalendar files
  683. \[c] export agenda files into combined iCalendar file
  684. \[F] publish current file
  685. \[P] publish current project
  686. \[X] publish... (project will be prompted for)
  687. \[A] publish all projects")
  688. (cmds
  689. '((?t org-insert-export-options-template nil)
  690. (?v org-export-visible nil)
  691. (?a org-export-as-ascii t)
  692. (?h org-export-as-html t)
  693. (?b org-export-as-html-and-open t)
  694. (?H org-export-as-html-to-buffer nil)
  695. (?R org-export-region-as-html nil)
  696. (?x org-export-as-xoxo t)
  697. (?l org-export-as-latex t)
  698. (?L org-export-as-latex-to-buffer nil)
  699. (?i org-export-icalendar-this-file t)
  700. (?I org-export-icalendar-all-agenda-files t)
  701. (?c org-export-icalendar-combine-agenda-files t)
  702. (?F org-publish-current-file t)
  703. (?P org-publish-current-project t)
  704. (?X org-publish t)
  705. (?A org-publish-all t)))
  706. r1 r2 ass)
  707. (save-window-excursion
  708. (delete-other-windows)
  709. (with-output-to-temp-buffer "*Org Export/Publishing Help*"
  710. (princ help))
  711. (message "Select command: ")
  712. (setq r1 (read-char-exclusive)))
  713. (setq r2 (if (< r1 27) (+ r1 96) r1))
  714. (unless (setq ass (assq r2 cmds))
  715. (error "No command associated with key %c" r1))
  716. (if (and bg (nth 2 ass))
  717. ;; execute in background
  718. (let ((p (start-process
  719. (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
  720. "*Org Processes*"
  721. (expand-file-name invocation-name invocation-directory)
  722. "-batch"
  723. "-l" user-init-file
  724. "--eval" "(require 'org-exp)"
  725. "--eval" "(setq org-wait .2)"
  726. (buffer-file-name)
  727. "-f" (symbol-name (nth 1 ass)))))
  728. (set-process-sentinel p 'org-export-process-sentinel)
  729. (message "Background process \"%s\": started" p))
  730. ;; background processing not requested, or not possible
  731. (call-interactively (nth 1 ass)))))
  732. (defun org-export-process-sentinel (process status)
  733. (if (string-match "\n+\\'" status)
  734. (setq status (substring status 0 -1)))
  735. (message "Background process \"%s\": %s" process status))
  736. (defconst org-html-entities
  737. '(("nbsp")
  738. ("iexcl")
  739. ("cent")
  740. ("pound")
  741. ("curren")
  742. ("yen")
  743. ("brvbar")
  744. ("vert" . "&#124;")
  745. ("sect")
  746. ("uml")
  747. ("copy")
  748. ("ordf")
  749. ("laquo")
  750. ("not")
  751. ("shy")
  752. ("reg")
  753. ("macr")
  754. ("deg")
  755. ("plusmn")
  756. ("sup2")
  757. ("sup3")
  758. ("acute")
  759. ("micro")
  760. ("para")
  761. ("middot")
  762. ("odot"."o")
  763. ("star"."*")
  764. ("cedil")
  765. ("sup1")
  766. ("ordm")
  767. ("raquo")
  768. ("frac14")
  769. ("frac12")
  770. ("frac34")
  771. ("iquest")
  772. ("Agrave")
  773. ("Aacute")
  774. ("Acirc")
  775. ("Atilde")
  776. ("Auml")
  777. ("Aring") ("AA"."&Aring;")
  778. ("AElig")
  779. ("Ccedil")
  780. ("Egrave")
  781. ("Eacute")
  782. ("Ecirc")
  783. ("Euml")
  784. ("Igrave")
  785. ("Iacute")
  786. ("Icirc")
  787. ("Iuml")
  788. ("ETH")
  789. ("Ntilde")
  790. ("Ograve")
  791. ("Oacute")
  792. ("Ocirc")
  793. ("Otilde")
  794. ("Ouml")
  795. ("times")
  796. ("Oslash")
  797. ("Ugrave")
  798. ("Uacute")
  799. ("Ucirc")
  800. ("Uuml")
  801. ("Yacute")
  802. ("THORN")
  803. ("szlig")
  804. ("agrave")
  805. ("aacute")
  806. ("acirc")
  807. ("atilde")
  808. ("auml")
  809. ("aring")
  810. ("aelig")
  811. ("ccedil")
  812. ("egrave")
  813. ("eacute")
  814. ("ecirc")
  815. ("euml")
  816. ("igrave")
  817. ("iacute")
  818. ("icirc")
  819. ("iuml")
  820. ("eth")
  821. ("ntilde")
  822. ("ograve")
  823. ("oacute")
  824. ("ocirc")
  825. ("otilde")
  826. ("ouml")
  827. ("divide")
  828. ("oslash")
  829. ("ugrave")
  830. ("uacute")
  831. ("ucirc")
  832. ("uuml")
  833. ("yacute")
  834. ("thorn")
  835. ("yuml")
  836. ("fnof")
  837. ("Alpha")
  838. ("Beta")
  839. ("Gamma")
  840. ("Delta")
  841. ("Epsilon")
  842. ("Zeta")
  843. ("Eta")
  844. ("Theta")
  845. ("Iota")
  846. ("Kappa")
  847. ("Lambda")
  848. ("Mu")
  849. ("Nu")
  850. ("Xi")
  851. ("Omicron")
  852. ("Pi")
  853. ("Rho")
  854. ("Sigma")
  855. ("Tau")
  856. ("Upsilon")
  857. ("Phi")
  858. ("Chi")
  859. ("Psi")
  860. ("Omega")
  861. ("alpha")
  862. ("beta")
  863. ("gamma")
  864. ("delta")
  865. ("epsilon")
  866. ("varepsilon"."&epsilon;")
  867. ("zeta")
  868. ("eta")
  869. ("theta")
  870. ("iota")
  871. ("kappa")
  872. ("lambda")
  873. ("mu")
  874. ("nu")
  875. ("xi")
  876. ("omicron")
  877. ("pi")
  878. ("rho")
  879. ("sigmaf") ("varsigma"."&sigmaf;")
  880. ("sigma")
  881. ("tau")
  882. ("upsilon")
  883. ("phi")
  884. ("chi")
  885. ("psi")
  886. ("omega")
  887. ("thetasym") ("vartheta"."&thetasym;")
  888. ("upsih")
  889. ("piv")
  890. ("bull") ("bullet"."&bull;")
  891. ("hellip") ("dots"."&hellip;")
  892. ("prime")
  893. ("Prime")
  894. ("oline")
  895. ("frasl")
  896. ("weierp")
  897. ("image")
  898. ("real")
  899. ("trade")
  900. ("alefsym")
  901. ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
  902. ("uarr") ("uparrow"."&uarr;")
  903. ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
  904. ("darr")("downarrow"."&darr;")
  905. ("harr") ("leftrightarrow"."&harr;")
  906. ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
  907. ("lArr") ("Leftarrow"."&lArr;")
  908. ("uArr") ("Uparrow"."&uArr;")
  909. ("rArr") ("Rightarrow"."&rArr;")
  910. ("dArr") ("Downarrow"."&dArr;")
  911. ("hArr") ("Leftrightarrow"."&hArr;")
  912. ("forall")
  913. ("part") ("partial"."&part;")
  914. ("exist") ("exists"."&exist;")
  915. ("empty") ("emptyset"."&empty;")
  916. ("nabla")
  917. ("isin") ("in"."&isin;")
  918. ("notin")
  919. ("ni")
  920. ("prod")
  921. ("sum")
  922. ("minus")
  923. ("lowast") ("ast"."&lowast;")
  924. ("radic")
  925. ("prop") ("proptp"."&prop;")
  926. ("infin") ("infty"."&infin;")
  927. ("ang") ("angle"."&ang;")
  928. ("and") ("wedge"."&and;")
  929. ("or") ("vee"."&or;")
  930. ("cap")
  931. ("cup")
  932. ("int")
  933. ("there4")
  934. ("sim")
  935. ("cong") ("simeq"."&cong;")
  936. ("asymp")("approx"."&asymp;")
  937. ("ne") ("neq"."&ne;")
  938. ("equiv")
  939. ("le")
  940. ("ge")
  941. ("sub") ("subset"."&sub;")
  942. ("sup") ("supset"."&sup;")
  943. ("nsub")
  944. ("sube")
  945. ("supe")
  946. ("oplus")
  947. ("otimes")
  948. ("perp")
  949. ("sdot") ("cdot"."&sdot;")
  950. ("lceil")
  951. ("rceil")
  952. ("lfloor")
  953. ("rfloor")
  954. ("lang")
  955. ("rang")
  956. ("loz") ("Diamond"."&loz;")
  957. ("spades") ("spadesuit"."&spades;")
  958. ("clubs") ("clubsuit"."&clubs;")
  959. ("hearts") ("diamondsuit"."&hearts;")
  960. ("diams") ("diamondsuit"."&diams;")
  961. ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
  962. ("quot")
  963. ("amp")
  964. ("lt")
  965. ("gt")
  966. ("OElig")
  967. ("oelig")
  968. ("Scaron")
  969. ("scaron")
  970. ("Yuml")
  971. ("circ")
  972. ("tilde")
  973. ("ensp")
  974. ("emsp")
  975. ("thinsp")
  976. ("zwnj")
  977. ("zwj")
  978. ("lrm")
  979. ("rlm")
  980. ("ndash")
  981. ("mdash")
  982. ("lsquo")
  983. ("rsquo")
  984. ("sbquo")
  985. ("ldquo")
  986. ("rdquo")
  987. ("bdquo")
  988. ("dagger")
  989. ("Dagger")
  990. ("permil")
  991. ("lsaquo")
  992. ("rsaquo")
  993. ("euro")
  994. ("arccos"."arccos")
  995. ("arcsin"."arcsin")
  996. ("arctan"."arctan")
  997. ("arg"."arg")
  998. ("cos"."cos")
  999. ("cosh"."cosh")
  1000. ("cot"."cot")
  1001. ("coth"."coth")
  1002. ("csc"."csc")
  1003. ("deg"."deg")
  1004. ("det"."det")
  1005. ("dim"."dim")
  1006. ("exp"."exp")
  1007. ("gcd"."gcd")
  1008. ("hom"."hom")
  1009. ("inf"."inf")
  1010. ("ker"."ker")
  1011. ("lg"."lg")
  1012. ("lim"."lim")
  1013. ("liminf"."liminf")
  1014. ("limsup"."limsup")
  1015. ("ln"."ln")
  1016. ("log"."log")
  1017. ("max"."max")
  1018. ("min"."min")
  1019. ("Pr"."Pr")
  1020. ("sec"."sec")
  1021. ("sin"."sin")
  1022. ("sinh"."sinh")
  1023. ("sup"."sup")
  1024. ("tan"."tan")
  1025. ("tanh"."tanh")
  1026. )
  1027. "Entities for TeX->HTML translation.
  1028. Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
  1029. \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
  1030. In that case, \"\\ent\" will be translated to \"&other;\".
  1031. The list contains HTML entities for Latin-1, Greek and other symbols.
  1032. It is supplemented by a number of commonly used TeX macros with appropriate
  1033. translations. There is currently no way for users to extend this.")
  1034. ;;; General functions for all backends
  1035. (defun org-export-preprocess-string (string &rest parameters)
  1036. "Cleanup STRING so that that the true exported has a more consistent source.
  1037. This function takes STRING, which should be a buffer-string of an org-file
  1038. to export. It then creates a temporary buffer where it does its job.
  1039. The result is then again returned as a string, and the exporter works
  1040. on this string to produce the exported version."
  1041. (interactive)
  1042. (let* ((re-radio (and org-target-link-regexp
  1043. (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))
  1044. (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
  1045. (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
  1046. (re-archive (concat ":" org-archive-tag ":"))
  1047. (re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))
  1048. (re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
  1049. (htmlp (plist-get parameters :for-html))
  1050. (asciip (plist-get parameters :for-ascii))
  1051. (latexp (plist-get parameters :for-LaTeX))
  1052. (commentsp (plist-get parameters :comments))
  1053. (archived-trees (plist-get parameters :archived-trees))
  1054. (inhibit-read-only t)
  1055. (drawers org-drawers)
  1056. (exp-drawers (plist-get parameters :drawers))
  1057. (outline-regexp "\\*+ ")
  1058. target-alist tmp target level
  1059. a b xx rtn p)
  1060. (with-current-buffer (get-buffer-create " org-mode-tmp")
  1061. (erase-buffer)
  1062. (insert string)
  1063. ;; Call the hook
  1064. (run-hooks 'org-export-preprocess-hook)
  1065. ;; Remove license-to-kill stuff
  1066. ;; The caller markes some stuff fo killing, stuff that has been
  1067. ;; used to create the page title, for example.
  1068. (while (setq p (text-property-any (point-min) (point-max)
  1069. :org-license-to-kill t))
  1070. (delete-region p (next-single-property-change p :org-license-to-kill)))
  1071. (let ((org-inhibit-startup t)) (org-mode))
  1072. (untabify (point-min) (point-max))
  1073. ;; Handle source code snippets
  1074. (org-export-replace-src-segments)
  1075. ;; Get rid of drawers
  1076. (unless (eq t exp-drawers)
  1077. (goto-char (point-min))
  1078. (let ((re (concat "^[ \t]*:\\("
  1079. (mapconcat
  1080. 'identity
  1081. (org-delete-all exp-drawers
  1082. (copy-sequence drawers))
  1083. "\\|")
  1084. "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
  1085. (while (re-search-forward re nil t)
  1086. (replace-match ""))))
  1087. ;; Get the correct stuff before the first headline
  1088. (when (plist-get parameters :skip-before-1st-heading)
  1089. (goto-char (point-min))
  1090. (when (re-search-forward "^\\*+[ \t]" nil t)
  1091. (delete-region (point-min) (match-beginning 0))
  1092. (goto-char (point-min))
  1093. (insert "\n")))
  1094. (when (plist-get parameters :add-text)
  1095. (goto-char (point-min))
  1096. (insert (plist-get parameters :add-text) "\n"))
  1097. ;; Get rid of archived trees
  1098. (when (not (eq archived-trees t))
  1099. (goto-char (point-min))
  1100. (while (re-search-forward re-archive nil t)
  1101. (if (not (org-on-heading-p t))
  1102. (org-end-of-subtree t)
  1103. (beginning-of-line 1)
  1104. (setq a (if archived-trees
  1105. (1+ (point-at-eol)) (point))
  1106. b (org-end-of-subtree t))
  1107. (if (> b a) (delete-region a b)))))
  1108. ;; Find all headings and compute the targets for them
  1109. (goto-char (point-min))
  1110. (org-init-section-numbers)
  1111. (let ((re (concat "^" org-outline-regexp)))
  1112. (while (re-search-forward re nil t)
  1113. (setq level (org-reduced-level
  1114. (save-excursion (goto-char (point-at-bol))
  1115. (org-outline-level))))
  1116. (setq target (org-solidify-link-text
  1117. (format "sec-%s" (org-section-number level))))
  1118. (push (cons target target) target-alist)
  1119. (add-text-properties
  1120. (point-at-bol) (point-at-eol)
  1121. (list 'target target))))
  1122. ;; Find targets in comments and move them out of comments,
  1123. ;; but mark them as targets that should be invisible
  1124. (goto-char (point-min))
  1125. (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
  1126. ;; Check if the line before or after is a headline with a target
  1127. (if (setq target (or (get-text-property (point-at-bol 0) 'target)
  1128. (get-text-property (point-at-bol 2) 'target)))
  1129. (progn
  1130. ;; use the existing target in a neighboring line
  1131. (setq tmp (match-string 2))
  1132. (replace-match "")
  1133. (and (looking-at "\n") (delete-char 1))
  1134. (push (cons (org-solidify-link-text tmp) target)
  1135. target-alist))
  1136. ;; Make an invisible target
  1137. (replace-match "\\1(INVISIBLE)")))
  1138. ;; Protect backend specific stuff, throw away the others.
  1139. (let ((formatters
  1140. `((,htmlp "HTML" "BEGIN_HTML" "END_HTML")
  1141. (,asciip "ASCII" "BEGIN_ASCII" "END_ASCII")
  1142. (,latexp "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
  1143. fmt)
  1144. (goto-char (point-min))
  1145. (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
  1146. (goto-char (match-end 0))
  1147. (while (not (looking-at "#\\+END_EXAMPLE"))
  1148. (insert ": ")
  1149. (beginning-of-line 2)))
  1150. (goto-char (point-min))
  1151. (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
  1152. (add-text-properties (match-beginning 0) (match-end 0)
  1153. '(org-protected t)))
  1154. (while formatters
  1155. (setq fmt (pop formatters))
  1156. (when (car fmt)
  1157. (goto-char (point-min))
  1158. (while (re-search-forward (concat "^#\\+" (cadr fmt)
  1159. ":[ \t]*\\(.*\\)") nil t)
  1160. (replace-match "\\1" t)
  1161. (add-text-properties
  1162. (point-at-bol) (min (1+ (point-at-eol)) (point-max))
  1163. '(org-protected t))))
  1164. (goto-char (point-min))
  1165. (while (re-search-forward
  1166. (concat "^#\\+"
  1167. (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
  1168. (cadddr fmt) "\\>.*\n?") nil t)
  1169. (if (car fmt)
  1170. (add-text-properties (match-beginning 1) (1+ (match-end 1))
  1171. '(org-protected t))
  1172. (delete-region (match-beginning 0) (match-end 0))))))
  1173. ;; Protect quoted subtrees
  1174. (goto-char (point-min))
  1175. (while (re-search-forward re-quote nil t)
  1176. (goto-char (match-beginning 0))
  1177. (end-of-line 1)
  1178. (add-text-properties (point) (org-end-of-subtree t)
  1179. '(org-protected t)))
  1180. ;; Protect verbatim elements
  1181. (goto-char (point-min))
  1182. (while (re-search-forward org-verbatim-re nil t)
  1183. (add-text-properties (match-beginning 4) (match-end 4)
  1184. '(org-protected t))
  1185. (goto-char (1+ (match-end 4))))
  1186. ;; Blockquotes
  1187. (goto-char (point-min))
  1188. (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)quote\\>.*" nil t)
  1189. (replace-match (if (equal (downcase (match-string 1)) "end")
  1190. "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
  1191. t t))
  1192. ;; Remove subtrees that are commented
  1193. (goto-char (point-min))
  1194. (while (re-search-forward re-commented nil t)
  1195. (goto-char (match-beginning 0))
  1196. (delete-region (point) (org-end-of-subtree t)))
  1197. ;; Remove special table lines
  1198. (when org-export-table-remove-special-lines
  1199. (goto-char (point-min))
  1200. (while (re-search-forward "^[ \t]*|" nil t)
  1201. (beginning-of-line 1)
  1202. (if (or (looking-at "[ \t]*| *[!_^] *|")
  1203. (and (looking-at ".*?| *<[0-9]+> *|")
  1204. (not (looking-at ".*?| *[^ <|]"))))
  1205. (delete-region (max (point-min) (1- (point-at-bol)))
  1206. (point-at-eol))
  1207. (end-of-line 1))))
  1208. ;; Specific LaTeX stuff
  1209. (when latexp
  1210. (require 'org-export-latex nil)
  1211. (org-export-latex-preprocess))
  1212. (when asciip
  1213. (org-export-ascii-clean-string))
  1214. ;; Specific HTML stuff
  1215. (when htmlp
  1216. ;; Convert LaTeX fragments to images
  1217. (when (plist-get parameters :LaTeX-fragments)
  1218. (org-format-latex
  1219. (concat "ltxpng/" (file-name-sans-extension
  1220. (file-name-nondirectory
  1221. org-current-export-file)))
  1222. org-current-export-dir nil "Creating LaTeX image %s"))
  1223. (message "Exporting..."))
  1224. ;; Remove or replace comments
  1225. (goto-char (point-min))
  1226. (while (re-search-forward "^#\\(.*\n?\\)" nil t)
  1227. (if commentsp
  1228. (progn (add-text-properties
  1229. (match-beginning 0) (match-end 0) '(org-protected t))
  1230. (replace-match (format commentsp (match-string 1)) t t))
  1231. (replace-match "")))
  1232. ;; Find matches for radio targets and turn them into internal links
  1233. (goto-char (point-min))
  1234. (when re-radio
  1235. (while (re-search-forward re-radio nil t)
  1236. (org-if-unprotected
  1237. (replace-match "\\1[[\\2]]"))))
  1238. ;; Find all links that contain a newline and put them into a single line
  1239. (goto-char (point-min))
  1240. (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
  1241. (org-if-unprotected
  1242. (replace-match "\\1 \\3")
  1243. (goto-char (match-beginning 0))))
  1244. ;; Find all internal links. If they have a fuzzy match (i.e. not
  1245. ;; a *dedicated* target match, let the link point to the
  1246. ;; correspinding section.
  1247. (goto-char (point-min))
  1248. (while (re-search-forward org-bracket-link-regexp nil t)
  1249. (org-if-unprotected
  1250. (let* ((md (match-data))
  1251. (desc (match-end 2))
  1252. (link (org-link-unescape (match-string 1)))
  1253. (slink (org-solidify-link-text link))
  1254. found props pos
  1255. (target
  1256. (or (cdr (assoc slink target-alist))
  1257. (save-excursion
  1258. (unless (string-match org-link-types-re link)
  1259. (setq found (condition-case nil (org-link-search link)
  1260. (error nil)))
  1261. (when (and found
  1262. (or (org-on-heading-p)
  1263. (not (eq found 'dedicated))))
  1264. (or (get-text-property (point) 'target)
  1265. (get-text-property
  1266. (max (point-min)
  1267. (1- (previous-single-property-change
  1268. (point) 'target)))
  1269. 'target))))))))
  1270. (when target
  1271. (set-match-data md)
  1272. (goto-char (match-beginning 1))
  1273. (setq props (text-properties-at (point)))
  1274. (delete-region (match-beginning 1) (match-end 1))
  1275. (setq pos (point))
  1276. (insert target)
  1277. (unless desc (insert "][" link))
  1278. (add-text-properties pos (point) props)))))
  1279. ;; Normalize links: Convert angle and plain links into bracket links
  1280. ;; Expand link abbreviations
  1281. (goto-char (point-min))
  1282. (while (re-search-forward re-plain-link nil t)
  1283. (goto-char (1- (match-end 0)))
  1284. (org-if-unprotected
  1285. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1286. ":" (match-string 3) "]]")))
  1287. ;; added 'org-link face to links
  1288. (put-text-property 0 (length s) 'face 'org-link s)
  1289. (replace-match s t t))))
  1290. (goto-char (point-min))
  1291. (while (re-search-forward re-angle-link nil t)
  1292. (goto-char (1- (match-end 0)))
  1293. (org-if-unprotected
  1294. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1295. ":" (match-string 3) "]]")))
  1296. (put-text-property 0 (length s) 'face 'org-link s)
  1297. (replace-match s t t))))
  1298. (goto-char (point-min))
  1299. (while (re-search-forward org-bracket-link-regexp nil t)
  1300. (org-if-unprotected
  1301. (let* ((s (concat "[[" (setq xx (save-match-data
  1302. (org-link-expand-abbrev (match-string 1))))
  1303. "]"
  1304. (if (match-end 3)
  1305. (match-string 2)
  1306. (concat "[" xx "]"))
  1307. "]")))
  1308. (put-text-property 0 (length s) 'face 'org-link s)
  1309. (replace-match s t t))))
  1310. ;; Find multiline emphasis and put them into single line
  1311. (when (plist-get parameters :emph-multiline)
  1312. (goto-char (point-min))
  1313. (while (re-search-forward org-emph-re nil t)
  1314. (if (not (= (char-after (match-beginning 3))
  1315. (char-after (match-beginning 4))))
  1316. (org-if-unprotected
  1317. (subst-char-in-region (match-beginning 0) (match-end 0)
  1318. ?\n ?\ t)
  1319. (goto-char (1- (match-end 0))))
  1320. (goto-char (1+ (match-beginning 0))))))
  1321. (setq rtn (buffer-string)))
  1322. (kill-buffer " org-mode-tmp")
  1323. rtn))
  1324. (defun org-export-grab-title-from-buffer ()
  1325. "Get a title for the current document, from looking at the buffer."
  1326. (let ((inhibit-read-only t))
  1327. (save-excursion
  1328. (goto-char (point-min))
  1329. (let ((end (save-excursion (outline-next-heading) (point))))
  1330. (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
  1331. ;; Mark the line so that it will not be exported as normal text.
  1332. (org-unmodified
  1333. (add-text-properties (match-beginning 0) (match-end 0)
  1334. (list :org-license-to-kill t)))
  1335. ;; Return the title string
  1336. (org-trim (match-string 0)))))))
  1337. (defun org-export-get-title-from-subtree ()
  1338. "Return subtree title and exclude it from export."
  1339. (let (title (m (mark)))
  1340. (save-excursion
  1341. (goto-char (region-beginning))
  1342. (when (and (org-at-heading-p)
  1343. (>= (org-end-of-subtree t t) (region-end)))
  1344. ;; This is a subtree, we take the title from the first heading
  1345. (goto-char (region-beginning))
  1346. (looking-at org-todo-line-regexp)
  1347. (setq title (match-string 3))
  1348. (org-unmodified
  1349. (add-text-properties (point) (1+ (point-at-eol))
  1350. (list :org-license-to-kill t)))))
  1351. title))
  1352. (defun org-solidify-link-text (s &optional alist)
  1353. "Take link text and make a safe target out of it."
  1354. (save-match-data
  1355. (let* ((rtn
  1356. (mapconcat
  1357. 'identity
  1358. (org-split-string s "[ \t\r\n]+") "=="))
  1359. (a (assoc rtn alist)))
  1360. (or (cdr a) rtn))))
  1361. (defun org-get-min-level (lines)
  1362. "Get the minimum level in LINES."
  1363. (let ((re "^\\(\\*+\\) ") l min)
  1364. (catch 'exit
  1365. (while (setq l (pop lines))
  1366. (if (string-match re l)
  1367. (throw 'exit (org-tr-level (length (match-string 1 l))))))
  1368. 1)))
  1369. ;; Variable holding the vector with section numbers
  1370. (defvar org-section-numbers (make-vector org-level-max 0))
  1371. (defun org-init-section-numbers ()
  1372. "Initialize the vector for the section numbers."
  1373. (let* ((level -1)
  1374. (numbers (nreverse (org-split-string "" "\\.")))
  1375. (depth (1- (length org-section-numbers)))
  1376. (i depth) number-string)
  1377. (while (>= i 0)
  1378. (if (> i level)
  1379. (aset org-section-numbers i 0)
  1380. (setq number-string (or (car numbers) "0"))
  1381. (if (string-match "\\`[A-Z]\\'" number-string)
  1382. (aset org-section-numbers i
  1383. (- (string-to-char number-string) ?A -1))
  1384. (aset org-section-numbers i (string-to-number number-string)))
  1385. (pop numbers))
  1386. (setq i (1- i)))))
  1387. (defun org-section-number (&optional level)
  1388. "Return a string with the current section number.
  1389. When LEVEL is non-nil, increase section numbers on that level."
  1390. (let* ((depth (1- (length org-section-numbers))) idx n (string ""))
  1391. (when level
  1392. (when (> level -1)
  1393. (aset org-section-numbers
  1394. level (1+ (aref org-section-numbers level))))
  1395. (setq idx (1+ level))
  1396. (while (<= idx depth)
  1397. (if (not (= idx 1))
  1398. (aset org-section-numbers idx 0))
  1399. (setq idx (1+ idx))))
  1400. (setq idx 0)
  1401. (while (<= idx depth)
  1402. (setq n (aref org-section-numbers idx))
  1403. (setq string (concat string (if (not (string= string "")) "." "")
  1404. (int-to-string n)))
  1405. (setq idx (1+ idx)))
  1406. (save-match-data
  1407. (if (string-match "\\`\\([@0]\\.\\)+" string)
  1408. (setq string (replace-match "" t nil string)))
  1409. (if (string-match "\\(\\.0\\)+\\'" string)
  1410. (setq string (replace-match "" t nil string))))
  1411. string))
  1412. ;;; Fontification of code
  1413. ;; Currently only for th HTML backend, but who knows....
  1414. (defun org-export-replace-src-segments ()
  1415. "Replace source code segments with special code for export."
  1416. (let (lang code trans)
  1417. (goto-char (point-min))
  1418. (while (re-search-forward
  1419. "^#\\+BEGIN_SRC[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
  1420. nil t)
  1421. (setq lang (match-string 1) code (match-string 2)
  1422. trans (org-export-format-source-code lang code))
  1423. (replace-match trans t t))))
  1424. (defvar htmlp) ;; dynamically scoped from org-exp.el
  1425. (defun org-export-format-source-code (lang code)
  1426. "Format CODE from language LANG and return it formatted for export.
  1427. Currently, this only does something for HTML export, for all other
  1428. backends, it converts the segment into an EXAMPLE segment."
  1429. (save-match-data
  1430. (cond
  1431. (htmlp
  1432. ;; We are exporting to HTML
  1433. (condition-case nil (require 'htmlize) (nil t))
  1434. (if (not (fboundp 'htmlize-region-for-paste))
  1435. (progn
  1436. ;; we do not have htmlize.el, or an old version of it
  1437. (message
  1438. "htmlize.el 1.34 or later is needed for source code formatting")
  1439. (concat "#+BEGIN_EXAMPLE\n" code
  1440. (if (string-match "\n\\'" code) "" "\n")
  1441. "#+END_EXAMPLE\n"))
  1442. ;; ok, we are good to go
  1443. (let* ((mode (and lang (intern (concat lang "-mode"))))
  1444. (org-startup-folded nil)
  1445. (htmltext
  1446. (with-temp-buffer
  1447. (insert code)
  1448. (if (functionp mode)
  1449. (funcall mode)
  1450. (fundamental-mode))
  1451. (when (eq major-mode 'org-mode)
  1452. ;; Free up the protected stuff
  1453. (goto-char (point-min))
  1454. (while (re-search-forward "^@\\([*#]\\|[ \t]*:\\)" nil t)
  1455. (replace-match "\\1"))
  1456. (org-mode))
  1457. (font-lock-fontify-buffer)
  1458. ;; silence the byte-compiler
  1459. (when (fboundp 'htmlize-region-for-paste)
  1460. ;; transform the region to HTML
  1461. (htmlize-region-for-paste (point-min) (point-max))))))
  1462. (if (string-match "<pre\\([^>]*\\)>\n?" htmltext)
  1463. (setq htmltext (replace-match "<pre class=\"src\">"
  1464. t t htmltext)))
  1465. (concat "#+BEGIN_HTML\n" htmltext "\n#+END_HTML\n"))))
  1466. (t
  1467. ;; This is not HTML, so just make it an example.
  1468. (concat "#+BEGIN_EXAMPLE\n" code
  1469. (if (string-match "\n\\'" code) "" "\n")
  1470. "#+END_EXAMPLE\n")))))
  1471. ;;; ASCII export
  1472. (defvar org-last-level nil) ; dynamically scoped variable
  1473. (defvar org-min-level nil) ; dynamically scoped variable
  1474. (defvar org-levels-open nil) ; dynamically scoped parameter
  1475. (defvar org-ascii-current-indentation nil) ; For communication
  1476. ;;;###autoload
  1477. (defun org-export-as-ascii (arg)
  1478. "Export the outline as a pretty ASCII file.
  1479. If there is an active region, export only the region.
  1480. The prefix ARG specifies how many levels of the outline should become
  1481. underlined headlines. The default is 3."
  1482. (interactive "P")
  1483. (setq-default org-todo-line-regexp org-todo-line-regexp)
  1484. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  1485. (org-infile-export-plist)))
  1486. (region-p (org-region-active-p))
  1487. (subtree-p
  1488. (when region-p
  1489. (save-excursion
  1490. (goto-char (region-beginning))
  1491. (and (org-at-heading-p)
  1492. (>= (org-end-of-subtree t t) (region-end))))))
  1493. (custom-times org-display-custom-times)
  1494. (org-ascii-current-indentation '(0 . 0))
  1495. (level 0) line txt
  1496. (umax nil)
  1497. (umax-toc nil)
  1498. (case-fold-search nil)
  1499. (filename (concat (file-name-as-directory
  1500. (org-export-directory :ascii opt-plist))
  1501. (file-name-sans-extension
  1502. (or (and subtree-p
  1503. (org-entry-get (region-beginning)
  1504. "EXPORT_FILE_NAME" t))
  1505. (file-name-nondirectory buffer-file-name)))
  1506. ".txt"))
  1507. (filename (if (equal (file-truename filename)
  1508. (file-truename buffer-file-name))
  1509. (concat filename ".txt")
  1510. filename))
  1511. (buffer (find-file-noselect filename))
  1512. (org-levels-open (make-vector org-level-max nil))
  1513. (odd org-odd-levels-only)
  1514. (date (plist-get opt-plist :date))
  1515. (author (plist-get opt-plist :author))
  1516. (title (or (and subtree-p (org-export-get-title-from-subtree))
  1517. (plist-get opt-plist :title)
  1518. (and (not
  1519. (plist-get opt-plist :skip-before-1st-heading))
  1520. (org-export-grab-title-from-buffer))
  1521. (file-name-sans-extension
  1522. (file-name-nondirectory buffer-file-name))))
  1523. (email (plist-get opt-plist :email))
  1524. (language (plist-get opt-plist :language))
  1525. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  1526. ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
  1527. (todo nil)
  1528. (lang-words nil)
  1529. (region
  1530. (buffer-substring
  1531. (if (org-region-active-p) (region-beginning) (point-min))
  1532. (if (org-region-active-p) (region-end) (point-max))))
  1533. (lines (org-split-string
  1534. (org-export-preprocess-string
  1535. region
  1536. :for-ascii t
  1537. :skip-before-1st-heading
  1538. (plist-get opt-plist :skip-before-1st-heading)
  1539. :drawers (plist-get opt-plist :drawers)
  1540. :verbatim-multiline t
  1541. :archived-trees
  1542. (plist-get opt-plist :archived-trees)
  1543. :add-text (plist-get opt-plist :text))
  1544. "\n"))
  1545. thetoc have-headings first-heading-pos
  1546. table-open table-buffer)
  1547. (let ((inhibit-read-only t))
  1548. (org-unmodified
  1549. (remove-text-properties (point-min) (point-max)
  1550. '(:org-license-to-kill t))))
  1551. (setq org-min-level (org-get-min-level lines))
  1552. (setq org-last-level org-min-level)
  1553. (org-init-section-numbers)
  1554. (find-file-noselect filename)
  1555. (setq lang-words (or (assoc language org-export-language-setup)
  1556. (assoc "en" org-export-language-setup)))
  1557. (switch-to-buffer-other-window buffer)
  1558. (erase-buffer)
  1559. (fundamental-mode)
  1560. ;; create local variables for all options, to make sure all called
  1561. ;; functions get the correct information
  1562. (mapc (lambda (x)
  1563. (set (make-local-variable (cdr x))
  1564. (plist-get opt-plist (car x))))
  1565. org-export-plist-vars)
  1566. (org-set-local 'org-odd-levels-only odd)
  1567. (setq umax (if arg (prefix-numeric-value arg)
  1568. org-export-headline-levels))
  1569. (setq umax-toc (if (integerp org-export-with-toc)
  1570. (min org-export-with-toc umax)
  1571. umax))
  1572. ;; File header
  1573. (if title (org-insert-centered title ?=))
  1574. (insert "\n")
  1575. (if (and (or author email)
  1576. org-export-author-info)
  1577. (insert (concat (nth 1 lang-words) ": " (or author "")
  1578. (if email (concat " <" email ">") "")
  1579. "\n")))
  1580. (cond
  1581. ((and date (string-match "%" date))
  1582. (setq date (format-time-string date)))
  1583. (date)
  1584. (t (setq date (format-time-string "%Y/%m/%d %X"))))
  1585. (if (and date org-export-time-stamp-file)
  1586. (insert (concat (nth 2 lang-words) ": " date"\n")))
  1587. (insert "\n\n")
  1588. (if org-export-with-toc
  1589. (progn
  1590. (push (concat (nth 3 lang-words) "\n") thetoc)
  1591. (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
  1592. (mapc '(lambda (line)
  1593. (if (string-match org-todo-line-regexp
  1594. line)
  1595. ;; This is a headline
  1596. (progn
  1597. (setq have-headings t)
  1598. (setq level (- (match-end 1) (match-beginning 1))
  1599. level (org-tr-level level)
  1600. txt (match-string 3 line)
  1601. todo
  1602. (or (and org-export-mark-todo-in-toc
  1603. (match-beginning 2)
  1604. (not (member (match-string 2 line)
  1605. org-done-keywords)))
  1606. ; TODO, not DONE
  1607. (and org-export-mark-todo-in-toc
  1608. (= level umax-toc)
  1609. (org-search-todo-below
  1610. line lines level))))
  1611. (setq txt (org-html-expand-for-ascii txt))
  1612. (while (string-match org-bracket-link-regexp txt)
  1613. (setq txt
  1614. (replace-match
  1615. (match-string (if (match-end 2) 3 1) txt)
  1616. t t txt)))
  1617. (if (and (memq org-export-with-tags '(not-in-toc nil))
  1618. (string-match
  1619. (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
  1620. txt))
  1621. (setq txt (replace-match "" t t txt)))
  1622. (if (string-match quote-re0 txt)
  1623. (setq txt (replace-match "" t t txt)))
  1624. (if org-export-with-section-numbers
  1625. (setq txt (concat (org-section-number level)
  1626. " " txt)))
  1627. (if (<= level umax-toc)
  1628. (progn
  1629. (push
  1630. (concat
  1631. (make-string
  1632. (* (max 0 (- level org-min-level)) 4) ?\ )
  1633. (format (if todo "%s (*)\n" "%s\n") txt))
  1634. thetoc)
  1635. (setq org-last-level level))
  1636. ))))
  1637. lines)
  1638. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  1639. (org-init-section-numbers)
  1640. (while (setq line (pop lines))
  1641. ;; Remove the quoted HTML tags.
  1642. (setq line (org-html-expand-for-ascii line))
  1643. ;; Remove targets
  1644. (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
  1645. (setq line (replace-match "" t t line)))
  1646. ;; Replace internal links
  1647. (while (string-match org-bracket-link-regexp line)
  1648. (setq line (replace-match
  1649. (if (match-end 3) "[\\3]" "[\\1]")
  1650. t nil line)))
  1651. (when custom-times
  1652. (setq line (org-translate-time line)))
  1653. (cond
  1654. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  1655. ;; a Headline
  1656. (setq first-heading-pos (or first-heading-pos (point)))
  1657. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  1658. txt (match-string 2 line))
  1659. (org-ascii-level-start level txt umax lines))
  1660. ((and org-export-with-tables
  1661. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  1662. (if (not table-open)
  1663. ;; New table starts
  1664. (setq table-open t table-buffer nil))
  1665. ;; Accumulate lines
  1666. (setq table-buffer (cons line table-buffer))
  1667. (when (or (not lines)
  1668. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  1669. (car lines))))
  1670. (setq table-open nil
  1671. table-buffer (nreverse table-buffer))
  1672. (insert (mapconcat
  1673. (lambda (x)
  1674. (org-fix-indentation x org-ascii-current-indentation))
  1675. (org-format-table-ascii table-buffer)
  1676. "\n") "\n")))
  1677. (t
  1678. (setq line (org-fix-indentation line org-ascii-current-indentation))
  1679. (if (and org-export-with-fixed-width
  1680. (string-match "^\\([ \t]*\\)\\(:\\)" line))
  1681. (setq line (replace-match "\\1" nil nil line)))
  1682. (insert line "\n"))))
  1683. (normal-mode)
  1684. ;; insert the table of contents
  1685. (when thetoc
  1686. (goto-char (point-min))
  1687. (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
  1688. (progn
  1689. (goto-char (match-beginning 0))
  1690. (replace-match ""))
  1691. (goto-char first-heading-pos))
  1692. (mapc 'insert thetoc)
  1693. (or (looking-at "[ \t]*\n[ \t]*\n")
  1694. (insert "\n\n")))
  1695. ;; Convert whitespace place holders
  1696. (goto-char (point-min))
  1697. (let (beg end)
  1698. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  1699. (setq end (next-single-property-change beg 'org-whitespace))
  1700. (goto-char beg)
  1701. (delete-region beg end)
  1702. (insert (make-string (- end beg) ?\ ))))
  1703. (save-buffer)
  1704. ;; remove display and invisible chars
  1705. (let (beg end)
  1706. (goto-char (point-min))
  1707. (while (setq beg (next-single-property-change (point) 'display))
  1708. (setq end (next-single-property-change beg 'display))
  1709. (delete-region beg end)
  1710. (goto-char beg)
  1711. (insert "=>"))
  1712. (goto-char (point-min))
  1713. (while (setq beg (next-single-property-change (point) 'org-cwidth))
  1714. (setq end (next-single-property-change beg 'org-cwidth))
  1715. (delete-region beg end)
  1716. (goto-char beg)))
  1717. (goto-char (point-min))))
  1718. (defun org-export-ascii-clean-string ()
  1719. "Do extra work for ASCII export"
  1720. (goto-char (point-min))
  1721. (while (re-search-forward org-verbatim-re nil t)
  1722. (goto-char (match-end 2))
  1723. (backward-delete-char 1) (insert "'")
  1724. (goto-char (match-beginning 2))
  1725. (delete-char 1) (insert "`")
  1726. (goto-char (match-end 2))))
  1727. (defun org-search-todo-below (line lines level)
  1728. "Search the subtree below LINE for any TODO entries."
  1729. (let ((rest (cdr (memq line lines)))
  1730. (re org-todo-line-regexp)
  1731. line lv todo)
  1732. (catch 'exit
  1733. (while (setq line (pop rest))
  1734. (if (string-match re line)
  1735. (progn
  1736. (setq lv (- (match-end 1) (match-beginning 1))
  1737. todo (and (match-beginning 2)
  1738. (not (member (match-string 2 line)
  1739. org-done-keywords))))
  1740. ; TODO, not DONE
  1741. (if (<= lv level) (throw 'exit nil))
  1742. (if todo (throw 'exit t))))))))
  1743. (defun org-html-expand-for-ascii (line)
  1744. "Handle quoted HTML for ASCII export."
  1745. (if org-export-html-expand
  1746. (while (string-match "@<[^<>\n]*>" line)
  1747. ;; We just remove the tags for now.
  1748. (setq line (replace-match "" nil nil line))))
  1749. line)
  1750. (defun org-insert-centered (s &optional underline)
  1751. "Insert the string S centered and underline it with character UNDERLINE."
  1752. (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
  1753. (insert (make-string ind ?\ ) s "\n")
  1754. (if underline
  1755. (insert (make-string ind ?\ )
  1756. (make-string (string-width s) underline)
  1757. "\n"))))
  1758. (defun org-ascii-level-start (level title umax &optional lines)
  1759. "Insert a new level in ASCII export."
  1760. (let (char (n (- level umax 1)) (ind 0))
  1761. (if (> level umax)
  1762. (progn
  1763. (insert (make-string (* 2 n) ?\ )
  1764. (char-to-string (nth (% n (length org-export-ascii-bullets))
  1765. org-export-ascii-bullets))
  1766. " " title "\n")
  1767. ;; find the indentation of the next non-empty line
  1768. (catch 'stop
  1769. (while lines
  1770. (if (string-match "^\\* " (car lines)) (throw 'stop nil))
  1771. (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
  1772. (throw 'stop (setq ind (org-get-indentation (car lines)))))
  1773. (pop lines)))
  1774. (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
  1775. (if (or (not (equal (char-before) ?\n))
  1776. (not (equal (char-before (1- (point))) ?\n)))
  1777. (insert "\n"))
  1778. (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
  1779. (unless org-export-with-tags
  1780. (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  1781. (setq title (replace-match "" t t title))))
  1782. (if org-export-with-section-numbers
  1783. (setq title (concat (org-section-number level) " " title)))
  1784. (insert title "\n" (make-string (string-width title) char) "\n")
  1785. (setq org-ascii-current-indentation '(0 . 0)))))
  1786. ;;;###autoload
  1787. (defun org-export-visible (type arg)
  1788. "Create a copy of the visible part of the current buffer, and export it.
  1789. The copy is created in a temporary buffer and removed after use.
  1790. TYPE is the final key (as a string) that also select the export command in
  1791. the `C-c C-e' export dispatcher.
  1792. As a special case, if the you type SPC at the prompt, the temporary
  1793. org-mode file will not be removed but presented to you so that you can
  1794. continue to use it. The prefix arg ARG is passed through to the exporting
  1795. command."
  1796. (interactive
  1797. (list (progn
  1798. (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
  1799. (read-char-exclusive))
  1800. current-prefix-arg))
  1801. (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
  1802. (error "Invalid export key"))
  1803. (let* ((binding (cdr (assoc type
  1804. '((?a . org-export-as-ascii)
  1805. (?\C-a . org-export-as-ascii)
  1806. (?b . org-export-as-html-and-open)
  1807. (?\C-b . org-export-as-html-and-open)
  1808. (?h . org-export-as-html)
  1809. (?H . org-export-as-html-to-buffer)
  1810. (?R . org-export-region-as-html)
  1811. (?x . org-export-as-xoxo)))))
  1812. (keepp (equal type ?\ ))
  1813. (file buffer-file-name)
  1814. (buffer (get-buffer-create "*Org Export Visible*"))
  1815. s e)
  1816. ;; Need to hack the drawers here.
  1817. (save-excursion
  1818. (goto-char (point-min))
  1819. (while (re-search-forward org-drawer-regexp nil t)
  1820. (goto-char (match-beginning 1))
  1821. (or (org-invisible-p) (org-flag-drawer nil))))
  1822. (with-current-buffer buffer (erase-buffer))
  1823. (save-excursion
  1824. (setq s (goto-char (point-min)))
  1825. (while (not (= (point) (point-max)))
  1826. (goto-char (org-find-invisible))
  1827. (append-to-buffer buffer s (point))
  1828. (setq s (goto-char (org-find-visible))))
  1829. (org-cycle-hide-drawers 'all)
  1830. (goto-char (point-min))
  1831. (unless keepp
  1832. ;; Copy all comment lines to the end, to make sure #+ settings are
  1833. ;; still available for the second export step. Kind of a hack, but
  1834. ;; does do the trick.
  1835. (if (looking-at "#[^\r\n]*")
  1836. (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
  1837. (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
  1838. (append-to-buffer buffer (1+ (match-beginning 0))
  1839. (min (point-max) (1+ (match-end 0))))))
  1840. (set-buffer buffer)
  1841. (let ((buffer-file-name file)
  1842. (org-inhibit-startup t))
  1843. (org-mode)
  1844. (show-all)
  1845. (unless keepp (funcall binding arg))))
  1846. (if (not keepp)
  1847. (kill-buffer buffer)
  1848. (switch-to-buffer-other-window buffer)
  1849. (goto-char (point-min)))))
  1850. (defun org-find-visible ()
  1851. (let ((s (point)))
  1852. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  1853. (get-char-property s 'invisible)))
  1854. s))
  1855. (defun org-find-invisible ()
  1856. (let ((s (point)))
  1857. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  1858. (not (get-char-property s 'invisible))))
  1859. s))
  1860. ;;; HTML export
  1861. (defvar org-archive-location) ;; gets loades with the org-archive require.
  1862. (defun org-get-current-options ()
  1863. "Return a string with current options as keyword options.
  1864. Does include HTML export options as well as TODO and CATEGORY stuff."
  1865. (require 'org-archive)
  1866. (format
  1867. "#+TITLE: %s
  1868. #+AUTHOR: %s
  1869. #+EMAIL: %s
  1870. #+DATE: %s
  1871. #+LANGUAGE: %s
  1872. #+TEXT: Some descriptive text to be emitted. Several lines OK.
  1873. #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s tags:%s
  1874. %s
  1875. #+LINK_UP: %s
  1876. #+LINK_HOME: %s
  1877. #+CATEGORY: %s
  1878. #+SEQ_TODO: %s
  1879. #+TYP_TODO: %s
  1880. #+PRIORITIES: %c %c %c
  1881. #+DRAWERS: %s
  1882. #+STARTUP: %s %s %s %s %s
  1883. #+TAGS: %s
  1884. #+ARCHIVE: %s
  1885. #+LINK: %s
  1886. "
  1887. (buffer-name) (user-full-name) user-mail-address
  1888. (format-time-string (car org-time-stamp-formats))
  1889. org-export-default-language
  1890. org-export-headline-levels
  1891. org-export-with-section-numbers
  1892. org-export-with-toc
  1893. org-export-preserve-breaks
  1894. org-export-html-expand
  1895. org-export-with-fixed-width
  1896. org-export-with-tables
  1897. org-export-with-sub-superscripts
  1898. org-export-with-special-strings
  1899. org-export-with-footnotes
  1900. org-export-with-emphasize
  1901. org-export-with-TeX-macros
  1902. org-export-with-LaTeX-fragments
  1903. org-export-skip-text-before-1st-heading
  1904. org-export-with-drawers
  1905. org-export-with-tags
  1906. (if (featurep 'org-infojs) (org-infojs-options-inbuffer-template) "")
  1907. org-export-html-link-up
  1908. org-export-html-link-home
  1909. (file-name-nondirectory buffer-file-name)
  1910. "TODO FEEDBACK VERIFY DONE"
  1911. "Me Jason Marie DONE"
  1912. org-highest-priority org-lowest-priority org-default-priority
  1913. (mapconcat 'identity org-drawers " ")
  1914. (cdr (assoc org-startup-folded
  1915. '((nil . "showall") (t . "overview") (content . "content"))))
  1916. (if org-odd-levels-only "odd" "oddeven")
  1917. (if org-hide-leading-stars "hidestars" "showstars")
  1918. (if org-startup-align-all-tables "align" "noalign")
  1919. (cond ((eq org-log-done t) "logdone")
  1920. ((equal org-log-done 'note) "lognotedone")
  1921. ((not org-log-done) "nologdone"))
  1922. (or (mapconcat (lambda (x)
  1923. (cond
  1924. ((equal '(:startgroup) x) "{")
  1925. ((equal '(:endgroup) x) "}")
  1926. ((cdr x) (format "%s(%c)" (car x) (cdr x)))
  1927. (t (car x))))
  1928. (or org-tag-alist (org-get-buffer-tags)) " ") "")
  1929. org-archive-location
  1930. "org file:~/org/%s.org"
  1931. ))
  1932. ;;;###autoload
  1933. (defun org-insert-export-options-template ()
  1934. "Insert into the buffer a template with information for exporting."
  1935. (interactive)
  1936. (if (not (bolp)) (newline))
  1937. (let ((s (org-get-current-options)))
  1938. (and (string-match "#\\+CATEGORY" s)
  1939. (setq s (substring s 0 (match-beginning 0))))
  1940. (insert s)))
  1941. ;;;###autoload
  1942. (defun org-export-as-html-and-open (arg)
  1943. "Export the outline as HTML and immediately open it with a browser.
  1944. If there is an active region, export only the region.
  1945. The prefix ARG specifies how many levels of the outline should become
  1946. headlines. The default is 3. Lower levels will become bulleted lists."
  1947. (interactive "P")
  1948. (org-export-as-html arg 'hidden)
  1949. (org-open-file buffer-file-name))
  1950. ;;;###autoload
  1951. (defun org-export-as-html-batch ()
  1952. "Call `org-export-as-html', may be used in batch processing as
  1953. emacs --batch
  1954. --load=$HOME/lib/emacs/org.el
  1955. --eval \"(setq org-export-headline-levels 2)\"
  1956. --visit=MyFile --funcall org-export-as-html-batch"
  1957. (org-export-as-html org-export-headline-levels 'hidden))
  1958. ;;;###autoload
  1959. (defun org-export-as-html-to-buffer (arg)
  1960. "Call `org-exort-as-html` with output to a temporary buffer.
  1961. No file is created. The prefix ARG is passed through to `org-export-as-html'."
  1962. (interactive "P")
  1963. (org-export-as-html arg nil nil "*Org HTML Export*")
  1964. (switch-to-buffer-other-window "*Org HTML Export*"))
  1965. ;;;###autoload
  1966. (defun org-replace-region-by-html (beg end)
  1967. "Assume the current region has org-mode syntax, and convert it to HTML.
  1968. This can be used in any buffer. For example, you could write an
  1969. itemized list in org-mode syntax in an HTML buffer and then use this
  1970. command to convert it."
  1971. (interactive "r")
  1972. (let (reg html buf pop-up-frames)
  1973. (save-window-excursion
  1974. (if (org-mode-p)
  1975. (setq html (org-export-region-as-html
  1976. beg end t 'string))
  1977. (setq reg (buffer-substring beg end)
  1978. buf (get-buffer-create "*Org tmp*"))
  1979. (with-current-buffer buf
  1980. (erase-buffer)
  1981. (insert reg)
  1982. (org-mode)
  1983. (setq html (org-export-region-as-html
  1984. (point-min) (point-max) t 'string)))
  1985. (kill-buffer buf)))
  1986. (delete-region beg end)
  1987. (insert html)))
  1988. ;;;###autoload
  1989. (defun org-export-region-as-html (beg end &optional body-only buffer)
  1990. "Convert region from BEG to END in org-mode buffer to HTML.
  1991. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  1992. contents, and only produce the region of converted text, useful for
  1993. cut-and-paste operations.
  1994. If BUFFER is a buffer or a string, use/create that buffer as a target
  1995. of the converted HTML. If BUFFER is the symbol `string', return the
  1996. produced HTML as a string and leave not buffer behind. For example,
  1997. a Lisp program could call this function in the following way:
  1998. (setq html (org-export-region-as-html beg end t 'string))
  1999. When called interactively, the output buffer is selected, and shown
  2000. in a window. A non-interactive call will only return the buffer."
  2001. (interactive "r\nP")
  2002. (when (interactive-p)
  2003. (setq buffer "*Org HTML Export*"))
  2004. (let ((transient-mark-mode t) (zmacs-regions t)
  2005. rtn)
  2006. (goto-char end)
  2007. (set-mark (point)) ;; to activate the region
  2008. (goto-char beg)
  2009. (setq rtn (org-export-as-html
  2010. nil nil nil
  2011. buffer body-only))
  2012. (if (fboundp 'deactivate-mark) (deactivate-mark))
  2013. (if (and (interactive-p) (bufferp rtn))
  2014. (switch-to-buffer-other-window rtn)
  2015. rtn)))
  2016. (defvar html-table-tag nil) ; dynamically scoped into this.
  2017. ;;;###autoload
  2018. (defun org-export-as-html (arg &optional hidden ext-plist
  2019. to-buffer body-only pub-dir)
  2020. "Export the outline as a pretty HTML file.
  2021. If there is an active region, export only the region. The prefix
  2022. ARG specifies how many levels of the outline should become
  2023. headlines. The default is 3. Lower levels will become bulleted
  2024. lists. When HIDDEN is non-nil, don't display the HTML buffer.
  2025. EXT-PLIST is a property list with external parameters overriding
  2026. org-mode's default settings, but still inferior to file-local
  2027. settings. When TO-BUFFER is non-nil, create a buffer with that
  2028. name and export to that buffer. If TO-BUFFER is the symbol
  2029. `string', don't leave any buffer behind but just return the
  2030. resulting HTML as a string. When BODY-ONLY is set, don't produce
  2031. the file header and footer, simply return the content of
  2032. <body>...</body>, without even the body tags themselves. When
  2033. PUB-DIR is set, use this as the publishing directory."
  2034. (interactive "P")
  2035. ;; Make sure we have a file name when we need it.
  2036. (when (and (not (or to-buffer body-only))
  2037. (not buffer-file-name))
  2038. (if (buffer-base-buffer)
  2039. (org-set-local 'buffer-file-name
  2040. (with-current-buffer (buffer-base-buffer)
  2041. buffer-file-name))
  2042. (error "Need a file name to be able to export.")))
  2043. (message "Exporting...")
  2044. (setq-default org-todo-line-regexp org-todo-line-regexp)
  2045. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  2046. (setq-default org-done-keywords org-done-keywords)
  2047. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  2048. (let* ((opt-plist
  2049. (org-export-process-option-filters
  2050. (org-combine-plists (org-default-export-plist)
  2051. ext-plist
  2052. (org-infile-export-plist))))
  2053. (style (plist-get opt-plist :style))
  2054. (html-extension (plist-get opt-plist :html-extension))
  2055. (link-validate (plist-get opt-plist :link-validation-function))
  2056. valid thetoc have-headings first-heading-pos
  2057. (odd org-odd-levels-only)
  2058. (region-p (org-region-active-p))
  2059. (subtree-p
  2060. (when region-p
  2061. (save-excursion
  2062. (goto-char (region-beginning))
  2063. (and (org-at-heading-p)
  2064. (>= (org-end-of-subtree t t) (region-end))))))
  2065. ;; The following two are dynamically scoped into other
  2066. ;; routines below.
  2067. (org-current-export-dir
  2068. (or pub-dir (org-export-directory :html opt-plist)))
  2069. (org-current-export-file buffer-file-name)
  2070. (level 0) (line "") (origline "") txt todo
  2071. (umax nil)
  2072. (umax-toc nil)
  2073. (filename (if to-buffer nil
  2074. (expand-file-name
  2075. (concat
  2076. (file-name-sans-extension
  2077. (or (and subtree-p
  2078. (org-entry-get (region-beginning)
  2079. "EXPORT_FILE_NAME" t))
  2080. (file-name-nondirectory buffer-file-name)))
  2081. "." html-extension)
  2082. (file-name-as-directory
  2083. (or pub-dir (org-export-directory :html opt-plist))))))
  2084. (current-dir (if buffer-file-name
  2085. (file-name-directory buffer-file-name)
  2086. default-directory))
  2087. (buffer (if to-buffer
  2088. (cond
  2089. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  2090. (t (get-buffer-create to-buffer)))
  2091. (find-file-noselect filename)))
  2092. (org-levels-open (make-vector org-level-max nil))
  2093. (date (plist-get opt-plist :date))
  2094. (author (plist-get opt-plist :author))
  2095. (title (or (and subtree-p (org-export-get-title-from-subtree))
  2096. (plist-get opt-plist :title)
  2097. (and (not
  2098. (plist-get opt-plist :skip-before-1st-heading))
  2099. (org-export-grab-title-from-buffer))
  2100. (and buffer-file-name
  2101. (file-name-sans-extension
  2102. (file-name-nondirectory buffer-file-name)))
  2103. "UNTITLED"))
  2104. (html-table-tag (plist-get opt-plist :html-table-tag))
  2105. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  2106. (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
  2107. (inquote nil)
  2108. (infixed nil)
  2109. (in-local-list nil)
  2110. (local-list-num nil)
  2111. (local-list-indent nil)
  2112. (llt org-plain-list-ordered-item-terminator)
  2113. (email (plist-get opt-plist :email))
  2114. (language (plist-get opt-plist :language))
  2115. (lang-words nil)
  2116. (head-count 0) cnt
  2117. (start 0)
  2118. (coding-system (and (boundp 'buffer-file-coding-system)
  2119. buffer-file-coding-system))
  2120. (coding-system-for-write (or org-export-html-coding-system
  2121. coding-system))
  2122. (save-buffer-coding-system (or org-export-html-coding-system
  2123. coding-system))
  2124. (charset (and coding-system-for-write
  2125. (fboundp 'coding-system-get)
  2126. (coding-system-get coding-system-for-write
  2127. 'mime-charset)))
  2128. (region
  2129. (buffer-substring
  2130. (if region-p (region-beginning) (point-min))
  2131. (if region-p (region-end) (point-max))))
  2132. (lines
  2133. (org-split-string
  2134. (org-export-preprocess-string
  2135. region
  2136. :emph-multiline t
  2137. :for-html t
  2138. :skip-before-1st-heading
  2139. (plist-get opt-plist :skip-before-1st-heading)
  2140. :drawers (plist-get opt-plist :drawers)
  2141. :archived-trees
  2142. (plist-get opt-plist :archived-trees)
  2143. :add-text
  2144. (plist-get opt-plist :text)
  2145. :LaTeX-fragments
  2146. (plist-get opt-plist :LaTeX-fragments))
  2147. "[\r\n]"))
  2148. table-open type
  2149. table-buffer table-orig-buffer
  2150. ind start-is-num starter didclose
  2151. rpl path desc descp desc1 desc2 link
  2152. snumber fnc
  2153. )
  2154. (let ((inhibit-read-only t))
  2155. (org-unmodified
  2156. (remove-text-properties (point-min) (point-max)
  2157. '(:org-license-to-kill t))))
  2158. (message "Exporting...")
  2159. (setq org-min-level (org-get-min-level lines))
  2160. (setq org-last-level org-min-level)
  2161. (org-init-section-numbers)
  2162. (cond
  2163. ((and date (string-match "%" date))
  2164. (setq date (format-time-string date)))
  2165. (date)
  2166. (t (setq date (format-time-string "%Y/%m/%d %X"))))
  2167. ;; Get the language-dependent settings
  2168. (setq lang-words (or (assoc language org-export-language-setup)
  2169. (assoc "en" org-export-language-setup)))
  2170. ;; Switch to the output buffer
  2171. (set-buffer buffer)
  2172. (let ((inhibit-read-only t)) (erase-buffer))
  2173. (fundamental-mode)
  2174. (and (fboundp 'set-buffer-file-coding-system)
  2175. (set-buffer-file-coding-system coding-system-for-write))
  2176. (let ((case-fold-search nil)
  2177. (org-odd-levels-only odd))
  2178. ;; create local variables for all options, to make sure all called
  2179. ;; functions get the correct information
  2180. (mapc (lambda (x)
  2181. (set (make-local-variable (cdr x))
  2182. (plist-get opt-plist (car x))))
  2183. org-export-plist-vars)
  2184. (setq umax (if arg (prefix-numeric-value arg)
  2185. org-export-headline-levels))
  2186. (setq umax-toc (if (integerp org-export-with-toc)
  2187. (min org-export-with-toc umax)
  2188. umax))
  2189. (unless body-only
  2190. ;; File header
  2191. (insert (format
  2192. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  2193. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  2194. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  2195. lang=\"%s\" xml:lang=\"%s\">
  2196. <head>
  2197. <title>%s</title>
  2198. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  2199. <meta name=\"generator\" content=\"Org-mode\"/>
  2200. <meta name=\"generated\" content=\"%s\"/>
  2201. <meta name=\"author\" content=\"%s\"/>
  2202. %s
  2203. </head><body>
  2204. "
  2205. language language (org-html-expand title)
  2206. (or charset "iso-8859-1") date author style))
  2207. (insert (or (plist-get opt-plist :preamble) ""))
  2208. (when (plist-get opt-plist :auto-preamble)
  2209. (if title (insert (format org-export-html-title-format
  2210. (org-html-expand title))))))
  2211. (if (and org-export-with-toc (not body-only))
  2212. (progn
  2213. (push (format "<h%d>%s</h%d>\n"
  2214. org-export-html-toplevel-hlevel
  2215. (nth 3 lang-words)
  2216. org-export-html-toplevel-hlevel)
  2217. thetoc)
  2218. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  2219. (push "<ul>\n<li>" thetoc)
  2220. (setq lines
  2221. (mapcar '(lambda (line)
  2222. (if (string-match org-todo-line-regexp line)
  2223. ;; This is a headline
  2224. (progn
  2225. (setq have-headings t)
  2226. (setq level (- (match-end 1) (match-beginning 1))
  2227. level (org-tr-level level)
  2228. txt (save-match-data
  2229. (org-html-expand
  2230. (org-export-cleanup-toc-line
  2231. (match-string 3 line))))
  2232. todo
  2233. (or (and org-export-mark-todo-in-toc
  2234. (match-beginning 2)
  2235. (not (member (match-string 2 line)
  2236. org-done-keywords)))
  2237. ; TODO, not DONE
  2238. (and org-export-mark-todo-in-toc
  2239. (= level umax-toc)
  2240. (org-search-todo-below
  2241. line lines level))))
  2242. (if (string-match
  2243. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  2244. (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
  2245. (if (string-match quote-re0 txt)
  2246. (setq txt (replace-match "" t t txt)))
  2247. (setq snumber (org-section-number level))
  2248. (if org-export-with-section-numbers
  2249. (setq txt (concat snumber " " txt)))
  2250. (if (<= level (max umax umax-toc))
  2251. (setq head-count (+ head-count 1)))
  2252. (if (<= level umax-toc)
  2253. (progn
  2254. (if (> level org-last-level)
  2255. (progn
  2256. (setq cnt (- level org-last-level))
  2257. (while (>= (setq cnt (1- cnt)) 0)
  2258. (push "\n<ul>\n<li>" thetoc))
  2259. (push "\n" thetoc)))
  2260. (if (< level org-last-level)
  2261. (progn
  2262. (setq cnt (- org-last-level level))
  2263. (while (>= (setq cnt (1- cnt)) 0)
  2264. (push "</li>\n</ul>" thetoc))
  2265. (push "\n" thetoc)))
  2266. ;; Check for targets
  2267. (while (string-match org-any-target-regexp line)
  2268. (setq line (replace-match
  2269. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  2270. t t line)))
  2271. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  2272. (setq txt (replace-match "" t t txt)))
  2273. (push
  2274. (format
  2275. (if todo
  2276. "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
  2277. "</li>\n<li><a href=\"#sec-%s\">%s</a>")
  2278. snumber txt) thetoc)
  2279. (setq org-last-level level))
  2280. )))
  2281. line)
  2282. lines))
  2283. (while (> org-last-level (1- org-min-level))
  2284. (setq org-last-level (1- org-last-level))
  2285. (push "</li>\n</ul>\n" thetoc))
  2286. (push "</div>\n" thetoc)
  2287. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  2288. (setq head-count 0)
  2289. (org-init-section-numbers)
  2290. (while (setq line (pop lines) origline line)
  2291. (catch 'nextline
  2292. ;; end of quote section?
  2293. (when (and inquote (string-match "^\\*+ " line))
  2294. (insert "</pre>\n")
  2295. (setq inquote nil))
  2296. ;; inside a quote section?
  2297. (when inquote
  2298. (insert (org-html-protect line) "\n")
  2299. (throw 'nextline nil))
  2300. ;; verbatim lines
  2301. (when (and org-export-with-fixed-width
  2302. (string-match "^[ \t]*:\\(.*\\)" line))
  2303. (when (not infixed)
  2304. (setq infixed t)
  2305. (insert "<pre>\n"))
  2306. (insert (org-html-protect (match-string 1 line)) "\n")
  2307. (when (and lines
  2308. (not (string-match "^[ \t]*\\(:.*\\)"
  2309. (car lines))))
  2310. (setq infixed nil)
  2311. (insert "</pre>\n"))
  2312. (throw 'nextline nil))
  2313. ;; Protected HTML
  2314. (when (get-text-property 0 'org-protected line)
  2315. (let (par)
  2316. (when (re-search-backward
  2317. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  2318. (setq par (match-string 1))
  2319. (replace-match "\\2\n"))
  2320. (insert line "\n")
  2321. (while (and lines
  2322. (not (string-match "^[ \t]*:" (car lines)))
  2323. (or (= (length (car lines)) 0)
  2324. (get-text-property 0 'org-protected (car lines))))
  2325. (insert (pop lines) "\n"))
  2326. (and par (insert "<p>\n")))
  2327. (throw 'nextline nil))
  2328. ;; Horizontal line
  2329. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
  2330. (insert "\n<hr/>\n")
  2331. (throw 'nextline nil))
  2332. ;; Blockquotes
  2333. (when (equal "ORG-BLOCKQUOTE-START" line)
  2334. (insert "<blockquote>\n<p>\n")
  2335. (throw 'nextline nil))
  2336. (when (equal "ORG-BLOCKQUOTE-END" line)
  2337. (insert "</p>\n</blockquote>\n")
  2338. (throw 'nextline nil))
  2339. ;; make targets to anchors
  2340. (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
  2341. (cond
  2342. ((match-end 2)
  2343. (setq line (replace-match
  2344. (concat "@<a name=\""
  2345. (org-solidify-link-text (match-string 1 line))
  2346. "\">\\nbsp@</a>")
  2347. t t line)))
  2348. ((and org-export-with-toc (equal (string-to-char line) ?*))
  2349. ;; FIXME: NOT DEPENDENT on TOC?????????????????????
  2350. (setq line (replace-match
  2351. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  2352. ; (concat "@<i>" (match-string 1 line) "@</i> ")
  2353. t t line)))
  2354. (t
  2355. (setq line (replace-match
  2356. (concat "@<a name=\""
  2357. (org-solidify-link-text (match-string 1 line))
  2358. "\" class=\"target\">" (match-string 1 line) "@</a> ")
  2359. t t line)))))
  2360. (setq line (org-html-handle-time-stamps line))
  2361. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  2362. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  2363. ;; Also handle sub_superscripts and checkboxes
  2364. (or (string-match org-table-hline-regexp line)
  2365. (setq line (org-html-expand line)))
  2366. ;; Format the links
  2367. (setq start 0)
  2368. (while (string-match org-bracket-link-analytic-regexp line start)
  2369. (setq start (match-beginning 0))
  2370. (setq type (if (match-end 2) (match-string 2 line) "internal"))
  2371. (setq path (match-string 3 line))
  2372. (setq desc1 (if (match-end 5) (match-string 5 line))
  2373. desc2 (if (match-end 2) (concat type ":" path) path)
  2374. descp (and desc1 (not (equal desc1 desc2)))
  2375. desc (or desc1 desc2))
  2376. ;; Make an image out of the description if that is so wanted
  2377. (when (and descp (org-file-image-p desc))
  2378. (save-match-data
  2379. (if (string-match "^file:" desc)
  2380. (setq desc (substring desc (match-end 0)))))
  2381. (setq desc (concat "<img src=\"" desc "\"/>")))
  2382. ;; FIXME: do we need to unescape here somewhere?
  2383. (cond
  2384. ((equal type "internal")
  2385. (setq rpl
  2386. (concat
  2387. "<a href=\"#"
  2388. (org-solidify-link-text
  2389. (save-match-data (org-link-unescape path)) nil)
  2390. "\">" desc "</a>")))
  2391. ((member type '("http" "https"))
  2392. ;; standard URL, just check if we need to inline an image
  2393. (if (and (or (eq t org-export-html-inline-images)
  2394. (and org-export-html-inline-images (not descp)))
  2395. (org-file-image-p path))
  2396. (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
  2397. (setq link (concat type ":" path))
  2398. (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
  2399. ((member type '("ftp" "mailto" "news"))
  2400. ;; standard URL
  2401. (setq link (concat type ":" path))
  2402. (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
  2403. ((string= type "file")
  2404. ;; FILE link
  2405. (let* ((filename path)
  2406. (abs-p (file-name-absolute-p filename))
  2407. thefile file-is-image-p search)
  2408. (save-match-data
  2409. (if (string-match "::\\(.*\\)" filename)
  2410. (setq search (match-string 1 filename)
  2411. filename (replace-match "" t nil filename)))
  2412. (setq valid
  2413. (if (functionp link-validate)
  2414. (funcall link-validate filename current-dir)
  2415. t))
  2416. (setq file-is-image-p (org-file-image-p filename))
  2417. (setq thefile (if abs-p (expand-file-name filename) filename))
  2418. (when (and org-export-html-link-org-files-as-html
  2419. (string-match "\\.org$" thefile))
  2420. (setq thefile (concat (substring thefile 0
  2421. (match-beginning 0))
  2422. "." html-extension))
  2423. (if (and search
  2424. ;; make sure this is can be used as target search
  2425. (not (string-match "^[0-9]*$" search))
  2426. (not (string-match "^\\*" search))
  2427. (not (string-match "^/.*/$" search)))
  2428. (setq thefile (concat thefile "#"
  2429. (org-solidify-link-text
  2430. (org-link-unescape search)))))
  2431. (when (string-match "^file:" desc)
  2432. (setq desc (replace-match "" t t desc))
  2433. (if (string-match "\\.org$" desc)
  2434. (setq desc (replace-match "" t t desc))))))
  2435. (setq rpl (if (and file-is-image-p
  2436. (or (eq t org-export-html-inline-images)
  2437. (and org-export-html-inline-images
  2438. (not descp))))
  2439. (concat "<img src=\"" thefile "\"/>")
  2440. (concat "<a href=\"" thefile "\">" desc "</a>")))
  2441. (if (not valid) (setq rpl desc))))
  2442. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  2443. (setq rpl
  2444. (save-match-data
  2445. (funcall fnc (org-link-unescape path) desc1 'html))))
  2446. (t
  2447. ;; just publish the path, as default
  2448. (setq rpl (concat "<i>&lt;" type ":"
  2449. (save-match-data (org-link-unescape path))
  2450. "&gt;</i>"))))
  2451. (setq line (replace-match rpl t t line)
  2452. start (+ start (length rpl))))
  2453. ;; TODO items
  2454. (if (and (string-match org-todo-line-regexp line)
  2455. (match-beginning 2))
  2456. (setq line
  2457. (concat (substring line 0 (match-beginning 2))
  2458. "<span class=\""
  2459. (if (member (match-string 2 line)
  2460. org-done-keywords)
  2461. "done" "todo")
  2462. "\">" (match-string 2 line)
  2463. "</span>" (substring line (match-end 2)))))
  2464. ;; Does this contain a reference to a footnote?
  2465. (when org-export-with-footnotes
  2466. (setq start 0)
  2467. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
  2468. (if (get-text-property (match-beginning 2) 'org-protected line)
  2469. (setq start (match-end 2))
  2470. (let ((n (match-string 2 line)))
  2471. (setq line
  2472. (replace-match
  2473. (format
  2474. "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
  2475. (match-string 1 line) n n n)
  2476. t t line))))))
  2477. (cond
  2478. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  2479. ;; This is a headline
  2480. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  2481. txt (match-string 2 line))
  2482. (if (string-match quote-re0 txt)
  2483. (setq txt (replace-match "" t t txt)))
  2484. (if (<= level (max umax umax-toc))
  2485. (setq head-count (+ head-count 1)))
  2486. (when in-local-list
  2487. ;; Close any local lists before inserting a new header line
  2488. (while local-list-num
  2489. (org-close-li)
  2490. (insert (if (car local-list-num) "</ol>\n" "</ul>"))
  2491. (pop local-list-num))
  2492. (setq local-list-indent nil
  2493. in-local-list nil))
  2494. (setq first-heading-pos (or first-heading-pos (point)))
  2495. (org-html-level-start level txt umax
  2496. (and org-export-with-toc (<= level umax))
  2497. head-count)
  2498. ;; QUOTES
  2499. (when (string-match quote-re line)
  2500. (insert "<pre>")
  2501. (setq inquote t)))
  2502. ((and org-export-with-tables
  2503. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  2504. (if (not table-open)
  2505. ;; New table starts
  2506. (setq table-open t table-buffer nil table-orig-buffer nil))
  2507. ;; Accumulate lines
  2508. (setq table-buffer (cons line table-buffer)
  2509. table-orig-buffer (cons origline table-orig-buffer))
  2510. (when (or (not lines)
  2511. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  2512. (car lines))))
  2513. (setq table-open nil
  2514. table-buffer (nreverse table-buffer)
  2515. table-orig-buffer (nreverse table-orig-buffer))
  2516. (org-close-par-maybe)
  2517. (insert (org-format-table-html table-buffer table-orig-buffer))))
  2518. (t
  2519. ;; Normal lines
  2520. (when (string-match
  2521. (cond
  2522. ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2523. ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2524. ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2525. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
  2526. line)
  2527. (setq ind (org-get-string-indentation line)
  2528. start-is-num (match-beginning 4)
  2529. starter (if (match-beginning 2)
  2530. (substring (match-string 2 line) 0 -1))
  2531. line (substring line (match-beginning 5)))
  2532. (unless (string-match "[^ \t]" line)
  2533. ;; empty line. Pretend indentation is large.
  2534. (setq ind (if org-empty-line-terminates-plain-lists
  2535. 0
  2536. (1+ (or (car local-list-indent) 1)))))
  2537. (setq didclose nil)
  2538. (while (and in-local-list
  2539. (or (and (= ind (car local-list-indent))
  2540. (not starter))
  2541. (< ind (car local-list-indent))))
  2542. (setq didclose t)
  2543. (org-close-li)
  2544. (insert (if (car local-list-num) "</ol>\n" "</ul>"))
  2545. (pop local-list-num) (pop local-list-indent)
  2546. (setq in-local-list local-list-indent))
  2547. (cond
  2548. ((and starter
  2549. (or (not in-local-list)
  2550. (> ind (car local-list-indent))))
  2551. ;; Start new (level of) list
  2552. (org-close-par-maybe)
  2553. (insert (if start-is-num "<ol>\n<li>\n" "<ul>\n<li>\n"))
  2554. (push start-is-num local-list-num)
  2555. (push ind local-list-indent)
  2556. (setq in-local-list t))
  2557. (starter
  2558. ;; continue current list
  2559. (org-close-li)
  2560. (insert "<li>\n"))
  2561. (didclose
  2562. ;; we did close a list, normal text follows: need <p>
  2563. (org-open-par)))
  2564. (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
  2565. (setq line
  2566. (replace-match
  2567. (if (equal (match-string 1 line) "X")
  2568. "<b>[X]</b>"
  2569. "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
  2570. t t line))))
  2571. ;; Empty lines start a new paragraph. If hand-formatted lists
  2572. ;; are not fully interpreted, lines starting with "-", "+", "*"
  2573. ;; also start a new paragraph.
  2574. (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
  2575. ;; Is this the start of a footnote?
  2576. (when org-export-with-footnotes
  2577. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
  2578. (org-close-par-maybe)
  2579. (let ((n (match-string 1 line)))
  2580. (setq line (replace-match
  2581. (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
  2582. ;; Check if the line break needs to be conserved
  2583. (cond
  2584. ((string-match "\\\\\\\\[ \t]*$" line)
  2585. (setq line (replace-match "<br/>" t t line)))
  2586. (org-export-preserve-breaks
  2587. (setq line (concat line "<br/>"))))
  2588. (insert line "\n")))))
  2589. ;; Properly close all local lists and other lists
  2590. (when inquote (insert "</pre>\n"))
  2591. (when in-local-list
  2592. ;; Close any local lists before inserting a new header line
  2593. (while local-list-num
  2594. (org-close-li)
  2595. (insert (if (car local-list-num) "</ol>\n" "</ul>\n"))
  2596. (pop local-list-num))
  2597. (setq local-list-indent nil
  2598. in-local-list nil))
  2599. (org-html-level-start 1 nil umax
  2600. (and org-export-with-toc (<= level umax))
  2601. head-count)
  2602. ;; the </div> to lose the last text-... div.
  2603. (insert "</div>\n")
  2604. (unless body-only
  2605. (when (plist-get opt-plist :auto-postamble)
  2606. (insert "<div id=\"postamble\">")
  2607. (when (and org-export-author-info author)
  2608. (insert "<p class=\"author\"> "
  2609. (nth 1 lang-words) ": " author "\n")
  2610. (when email
  2611. (if (listp (split-string email ",+ *"))
  2612. (mapc (lambda(e)
  2613. (insert "<a href=\"mailto:" e "\">&lt;"
  2614. e "&gt;</a>\n"))
  2615. (split-string email ",+ *"))
  2616. (insert "<a href=\"mailto:" email "\">&lt;"
  2617. email "&gt;</a>\n")))
  2618. (insert "</p>\n"))
  2619. (when (and date org-export-time-stamp-file)
  2620. (insert "<p class=\"date\"> "
  2621. (nth 2 lang-words) ": "
  2622. date "</p>\n"))
  2623. (insert "</div>"))
  2624. (if org-export-html-with-timestamp
  2625. (insert org-export-html-html-helper-timestamp))
  2626. (insert (or (plist-get opt-plist :postamble) ""))
  2627. (insert "</body>\n</html>\n"))
  2628. (normal-mode)
  2629. (if (eq major-mode default-major-mode) (html-mode))
  2630. ;; insert the table of contents
  2631. (goto-char (point-min))
  2632. (when thetoc
  2633. (if (or (re-search-forward
  2634. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  2635. (re-search-forward
  2636. "\\[TABLE-OF-CONTENTS\\]" nil t))
  2637. (progn
  2638. (goto-char (match-beginning 0))
  2639. (replace-match ""))
  2640. (goto-char first-heading-pos)
  2641. (when (looking-at "\\s-*</p>")
  2642. (goto-char (match-end 0))
  2643. (insert "\n")))
  2644. (insert "<div id=\"table-of-contents\">\n")
  2645. (mapc 'insert thetoc)
  2646. (insert "</div>\n"))
  2647. ;; remove empty paragraphs and lists
  2648. (goto-char (point-min))
  2649. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  2650. (replace-match ""))
  2651. (goto-char (point-min))
  2652. (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
  2653. (replace-match ""))
  2654. (goto-char (point-min))
  2655. (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
  2656. (replace-match ""))
  2657. ;; Convert whitespace place holders
  2658. (goto-char (point-min))
  2659. (let (beg end n)
  2660. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  2661. (setq n (get-text-property beg 'org-whitespace)
  2662. end (next-single-property-change beg 'org-whitespace))
  2663. (goto-char beg)
  2664. (delete-region beg end)
  2665. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  2666. (make-string n ?x)))))
  2667. (or to-buffer (save-buffer))
  2668. (goto-char (point-min))
  2669. (message "Exporting... done")
  2670. (if (eq to-buffer 'string)
  2671. (prog1 (buffer-substring (point-min) (point-max))
  2672. (kill-buffer (current-buffer)))
  2673. (current-buffer)))))
  2674. (defvar org-table-colgroup-info nil)
  2675. (defun org-format-table-ascii (lines)
  2676. "Format a table for ascii export."
  2677. (if (stringp lines)
  2678. (setq lines (org-split-string lines "\n")))
  2679. (if (not (string-match "^[ \t]*|" (car lines)))
  2680. ;; Table made by table.el - test for spanning
  2681. lines
  2682. ;; A normal org table
  2683. ;; Get rid of hlines at beginning and end
  2684. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2685. (setq lines (nreverse lines))
  2686. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2687. (setq lines (nreverse lines))
  2688. (when org-export-table-remove-special-lines
  2689. ;; Check if the table has a marking column. If yes remove the
  2690. ;; column and the special lines
  2691. (setq lines (org-table-clean-before-export lines)))
  2692. ;; Get rid of the vertical lines except for grouping
  2693. (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
  2694. rtn line vl1 start)
  2695. (while (setq line (pop lines))
  2696. (if (string-match org-table-hline-regexp line)
  2697. (and (string-match "|\\(.*\\)|" line)
  2698. (setq line (replace-match " \\1" t nil line)))
  2699. (setq start 0 vl1 vl)
  2700. (while (string-match "|" line start)
  2701. (setq start (match-end 0))
  2702. (or (pop vl1) (setq line (replace-match " " t t line)))))
  2703. (push line rtn))
  2704. (nreverse rtn))))
  2705. (defun org-colgroup-info-to-vline-list (info)
  2706. (let (vl new last)
  2707. (while info
  2708. (setq last new new (pop info))
  2709. (if (or (memq last '(:end :startend))
  2710. (memq new '(:start :startend)))
  2711. (push t vl)
  2712. (push nil vl)))
  2713. (setq vl (nreverse vl))
  2714. (and vl (setcar vl nil))
  2715. vl))
  2716. (defvar org-table-number-regexp) ; defined in org-table.el
  2717. (defun org-format-table-html (lines olines)
  2718. "Find out which HTML converter to use and return the HTML code."
  2719. (if (stringp lines)
  2720. (setq lines (org-split-string lines "\n")))
  2721. (if (string-match "^[ \t]*|" (car lines))
  2722. ;; A normal org table
  2723. (org-format-org-table-html lines)
  2724. ;; Table made by table.el - test for spanning
  2725. (let* ((hlines (delq nil (mapcar
  2726. (lambda (x)
  2727. (if (string-match "^[ \t]*\\+-" x) x
  2728. nil))
  2729. lines)))
  2730. (first (car hlines))
  2731. (ll (and (string-match "\\S-+" first)
  2732. (match-string 0 first)))
  2733. (re (concat "^[ \t]*" (regexp-quote ll)))
  2734. (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
  2735. hlines))))
  2736. (if (and (not spanning)
  2737. (not org-export-prefer-native-exporter-for-tables))
  2738. ;; We can use my own converter with HTML conversions
  2739. (org-format-table-table-html lines)
  2740. ;; Need to use the code generator in table.el, with the original text.
  2741. (org-format-table-table-html-using-table-generate-source olines)))))
  2742. (defvar org-table-number-fraction) ; defined in org-table.el
  2743. (defun org-format-org-table-html (lines &optional splice)
  2744. "Format a table into HTML."
  2745. (require 'org-table)
  2746. ;; Get rid of hlines at beginning and end
  2747. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2748. (setq lines (nreverse lines))
  2749. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2750. (setq lines (nreverse lines))
  2751. (when org-export-table-remove-special-lines
  2752. ;; Check if the table has a marking column. If yes remove the
  2753. ;; column and the special lines
  2754. (setq lines (org-table-clean-before-export lines)))
  2755. (let ((head (and org-export-highlight-first-table-line
  2756. (delq nil (mapcar
  2757. (lambda (x) (string-match "^[ \t]*|-" x))
  2758. (cdr lines)))))
  2759. (nlines 0) fnum i
  2760. tbopen line fields html gr colgropen)
  2761. (if splice (setq head nil))
  2762. (unless splice (push (if head "<thead>" "<tbody>") html))
  2763. (setq tbopen t)
  2764. (while (setq line (pop lines))
  2765. (catch 'next-line
  2766. (if (string-match "^[ \t]*|-" line)
  2767. (progn
  2768. (unless splice
  2769. (push (if head "</thead>" "</tbody>") html)
  2770. (if lines (push "<tbody>" html) (setq tbopen nil)))
  2771. (setq head nil) ;; head ends here, first time around
  2772. ;; ignore this line
  2773. (throw 'next-line t)))
  2774. ;; Break the line into fields
  2775. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  2776. (unless fnum (setq fnum (make-vector (length fields) 0)))
  2777. (setq nlines (1+ nlines) i -1)
  2778. (push (concat "<tr>"
  2779. (mapconcat
  2780. (lambda (x)
  2781. (setq i (1+ i))
  2782. (if (and (< i nlines)
  2783. (string-match org-table-number-regexp x))
  2784. (incf (aref fnum i)))
  2785. (if head
  2786. (concat (car org-export-table-header-tags) x
  2787. (cdr org-export-table-header-tags))
  2788. (concat (car org-export-table-data-tags) x
  2789. (cdr org-export-table-data-tags))))
  2790. fields "")
  2791. "</tr>")
  2792. html)))
  2793. (unless splice (if tbopen (push "</tbody>" html)))
  2794. (unless splice (push "</table>\n" html))
  2795. (setq html (nreverse html))
  2796. (unless splice
  2797. ;; Put in col tags with the alignment (unfortuntely often ignored...)
  2798. (push (mapconcat
  2799. (lambda (x)
  2800. (setq gr (pop org-table-colgroup-info))
  2801. (format "%s<col align=\"%s\"></col>%s"
  2802. (if (memq gr '(:start :startend))
  2803. (prog1
  2804. (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
  2805. (setq colgropen t))
  2806. "")
  2807. (if (> (/ (float x) nlines) org-table-number-fraction)
  2808. "right" "left")
  2809. (if (memq gr '(:end :startend))
  2810. (progn (setq colgropen nil) "</colgroup>")
  2811. "")))
  2812. fnum "")
  2813. html)
  2814. (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
  2815. (push html-table-tag html))
  2816. (concat (mapconcat 'identity html "\n") "\n")))
  2817. (defun org-table-clean-before-export (lines)
  2818. "Check if the table has a marking column.
  2819. If yes remove the column and the special lines."
  2820. (setq org-table-colgroup-info nil)
  2821. (if (memq nil
  2822. (mapcar
  2823. (lambda (x) (or (string-match "^[ \t]*|-" x)
  2824. (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
  2825. lines))
  2826. (progn
  2827. (setq org-table-clean-did-remove-column nil)
  2828. (delq nil
  2829. (mapcar
  2830. (lambda (x)
  2831. (cond
  2832. ((string-match "^[ \t]*| */ *|" x)
  2833. (setq org-table-colgroup-info
  2834. (mapcar (lambda (x)
  2835. (cond ((member x '("<" "&lt;")) :start)
  2836. ((member x '(">" "&gt;")) :end)
  2837. ((member x '("<>" "&lt;&gt;")) :startend)
  2838. (t nil)))
  2839. (org-split-string x "[ \t]*|[ \t]*")))
  2840. nil)
  2841. (t x)))
  2842. lines)))
  2843. (setq org-table-clean-did-remove-column t)
  2844. (delq nil
  2845. (mapcar
  2846. (lambda (x)
  2847. (cond
  2848. ((string-match "^[ \t]*| */ *|" x)
  2849. (setq org-table-colgroup-info
  2850. (mapcar (lambda (x)
  2851. (cond ((member x '("<" "&lt;")) :start)
  2852. ((member x '(">" "&gt;")) :end)
  2853. ((member x '("<>" "&lt;&gt;")) :startend)
  2854. (t nil)))
  2855. (cdr (org-split-string x "[ \t]*|[ \t]*"))))
  2856. nil)
  2857. ((string-match "^[ \t]*| *[!_^/] *|" x)
  2858. nil) ; ignore this line
  2859. ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
  2860. (string-match "^\\([ \t]*\\)|[^|]*|" x))
  2861. ;; remove the first column
  2862. (replace-match "\\1|" t nil x))))
  2863. lines))))
  2864. (defun org-format-table-table-html (lines)
  2865. "Format a table generated by table.el into HTML.
  2866. This conversion does *not* use `table-generate-source' from table.el.
  2867. This has the advantage that Org-mode's HTML conversions can be used.
  2868. But it has the disadvantage, that no cell- or row-spanning is allowed."
  2869. (let (line field-buffer
  2870. (head org-export-highlight-first-table-line)
  2871. fields html empty)
  2872. (setq html (concat html-table-tag "\n"))
  2873. (while (setq line (pop lines))
  2874. (setq empty "&nbsp;")
  2875. (catch 'next-line
  2876. (if (string-match "^[ \t]*\\+-" line)
  2877. (progn
  2878. (if field-buffer
  2879. (progn
  2880. (setq
  2881. html
  2882. (concat
  2883. html
  2884. "<tr>"
  2885. (mapconcat
  2886. (lambda (x)
  2887. (if (equal x "") (setq x empty))
  2888. (if head
  2889. (concat (car org-export-table-header-tags) x
  2890. (cdr org-export-table-header-tags))
  2891. (concat (car org-export-table-data-tags) x
  2892. (cdr org-export-table-data-tags))))
  2893. field-buffer "\n")
  2894. "</tr>\n"))
  2895. (setq head nil)
  2896. (setq field-buffer nil)))
  2897. ;; Ignore this line
  2898. (throw 'next-line t)))
  2899. ;; Break the line into fields and store the fields
  2900. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  2901. (if field-buffer
  2902. (setq field-buffer (mapcar
  2903. (lambda (x)
  2904. (concat x "<br/>" (pop fields)))
  2905. field-buffer))
  2906. (setq field-buffer fields))))
  2907. (setq html (concat html "</table>\n"))
  2908. html))
  2909. (defun org-format-table-table-html-using-table-generate-source (lines)
  2910. "Format a table into html, using `table-generate-source' from table.el.
  2911. This has the advantage that cell- or row-spanning is allowed.
  2912. But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
  2913. (require 'table)
  2914. (with-current-buffer (get-buffer-create " org-tmp1 ")
  2915. (erase-buffer)
  2916. (insert (mapconcat 'identity lines "\n"))
  2917. (goto-char (point-min))
  2918. (if (not (re-search-forward "|[^+]" nil t))
  2919. (error "Error processing table"))
  2920. (table-recognize-table)
  2921. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  2922. (table-generate-source 'html " org-tmp2 ")
  2923. (set-buffer " org-tmp2 ")
  2924. (buffer-substring (point-min) (point-max))))
  2925. (defun org-html-handle-time-stamps (s)
  2926. "Format time stamps in string S, or remove them."
  2927. (catch 'exit
  2928. (let (r b)
  2929. (while (string-match org-maybe-keyword-time-regexp s)
  2930. (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
  2931. ;; never export CLOCK
  2932. (throw 'exit ""))
  2933. (or b (setq b (substring s 0 (match-beginning 0))))
  2934. (if (not org-export-with-timestamps)
  2935. (setq r (concat r (substring s 0 (match-beginning 0)))
  2936. s (substring s (match-end 0)))
  2937. (setq r (concat
  2938. r (substring s 0 (match-beginning 0))
  2939. (if (match-end 1)
  2940. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  2941. (match-string 1 s)))
  2942. (format " @<span class=\"timestamp\">%s@</span>"
  2943. (substring
  2944. (org-translate-time (match-string 3 s)) 1 -1)))
  2945. s (substring s (match-end 0)))))
  2946. ;; Line break if line started and ended with time stamp stuff
  2947. (if (not r)
  2948. s
  2949. (setq r (concat r s))
  2950. (unless (string-match "\\S-" (concat b s))
  2951. (setq r (concat r "@<br/>")))
  2952. r))))
  2953. (defun org-html-protect (s)
  2954. ;; convert & to &amp;, < to &lt; and > to &gt;
  2955. (let ((start 0))
  2956. (while (string-match "&" s start)
  2957. (setq s (replace-match "&amp;" t t s)
  2958. start (1+ (match-beginning 0))))
  2959. (while (string-match "<" s)
  2960. (setq s (replace-match "&lt;" t t s)))
  2961. (while (string-match ">" s)
  2962. (setq s (replace-match "&gt;" t t s))))
  2963. s)
  2964. (defun org-export-cleanup-toc-line (s)
  2965. "Remove tags and time staps from lines going into the toc."
  2966. (when (memq org-export-with-tags '(not-in-toc nil))
  2967. (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
  2968. (setq s (replace-match "" t t s))))
  2969. (when org-export-remove-timestamps-from-toc
  2970. (while (string-match org-maybe-keyword-time-regexp s)
  2971. (setq s (replace-match "" t t s))))
  2972. (while (string-match org-bracket-link-regexp s)
  2973. (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
  2974. t t s)))
  2975. s)
  2976. (defun org-html-expand (string)
  2977. "Prepare STRING for HTML export. Applies all active conversions.
  2978. If there are links in the string, don't modify these."
  2979. (let* ((re (concat org-bracket-link-regexp "\\|"
  2980. (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
  2981. m s l res)
  2982. (while (setq m (string-match re string))
  2983. (setq s (substring string 0 m)
  2984. l (match-string 0 string)
  2985. string (substring string (match-end 0)))
  2986. (push (org-html-do-expand s) res)
  2987. (push l res))
  2988. (push (org-html-do-expand string) res)
  2989. (apply 'concat (nreverse res))))
  2990. (defun org-html-do-expand (s)
  2991. "Apply all active conversions to translate special ASCII to HTML."
  2992. (setq s (org-html-protect s))
  2993. (if org-export-html-expand
  2994. (let ((start 0))
  2995. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  2996. (setq s (replace-match "<\\1>" t nil s)))))
  2997. (if org-export-with-emphasize
  2998. (setq s (org-export-html-convert-emphasize s)))
  2999. (if org-export-with-special-strings
  3000. (setq s (org-export-html-convert-special-strings s)))
  3001. (if org-export-with-sub-superscripts
  3002. (setq s (org-export-html-convert-sub-super s)))
  3003. (if org-export-with-TeX-macros
  3004. (let ((start 0) wd ass)
  3005. (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
  3006. (if (get-text-property (match-beginning 0) 'org-protected s)
  3007. (setq start (match-end 0))
  3008. (setq wd (match-string 1 s))
  3009. (if (setq ass (assoc wd org-html-entities))
  3010. (setq s (replace-match (or (cdr ass)
  3011. (concat "&" (car ass) ";"))
  3012. t t s))
  3013. (setq start (+ start (length wd))))))))
  3014. s)
  3015. (defun org-create-multibrace-regexp (left right n)
  3016. "Create a regular expression which will match a balanced sexp.
  3017. Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
  3018. as single character strings.
  3019. The regexp returned will match the entire expression including the
  3020. delimiters. It will also define a single group which contains the
  3021. match except for the outermost delimiters. The maximum depth of
  3022. stacked delimiters is N. Escaping delimiters is not possible."
  3023. (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
  3024. (or "\\|")
  3025. (re nothing)
  3026. (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
  3027. (while (> n 1)
  3028. (setq n (1- n)
  3029. re (concat re or next)
  3030. next (concat "\\(?:" nothing left next right "\\)+" nothing)))
  3031. (concat left "\\(" re "\\)" right)))
  3032. (defvar org-match-substring-regexp
  3033. (concat
  3034. "\\([^\\]\\)\\([_^]\\)\\("
  3035. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  3036. "\\|"
  3037. "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
  3038. "\\|"
  3039. "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
  3040. "The regular expression matching a sub- or superscript.")
  3041. (defvar org-match-substring-with-braces-regexp
  3042. (concat
  3043. "\\([^\\]\\)\\([_^]\\)\\("
  3044. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  3045. "\\)")
  3046. "The regular expression matching a sub- or superscript, forcing braces.")
  3047. (defconst org-export-html-special-string-regexps
  3048. '(("\\\\-" . "&shy;")
  3049. ("---\\([^-]\\)" . "&mdash;\\1")
  3050. ("--\\([^-]\\)" . "&ndash;\\1")
  3051. ("\\.\\.\\." . "&hellip;"))
  3052. "Regular expressions for special string conversion.")
  3053. (defun org-export-html-convert-special-strings (string)
  3054. "Convert special characters in STRING to HTML."
  3055. (let ((all org-export-html-special-string-regexps)
  3056. e a re rpl start)
  3057. (while (setq a (pop all))
  3058. (setq re (car a) rpl (cdr a) start 0)
  3059. (while (string-match re string start)
  3060. (if (get-text-property (match-beginning 0) 'org-protected string)
  3061. (setq start (match-end 0))
  3062. (setq string (replace-match rpl t nil string)))))
  3063. string))
  3064. (defun org-export-html-convert-sub-super (string)
  3065. "Convert sub- and superscripts in STRING to HTML."
  3066. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  3067. (while (string-match org-match-substring-regexp string s)
  3068. (cond
  3069. ((and requireb (match-end 8)) (setq s (match-end 2)))
  3070. ((get-text-property (match-beginning 2) 'org-protected string)
  3071. (setq s (match-end 2)))
  3072. (t
  3073. (setq s (match-end 1)
  3074. key (if (string= (match-string 2 string) "_") "sub" "sup")
  3075. c (or (match-string 8 string)
  3076. (match-string 6 string)
  3077. (match-string 5 string))
  3078. string (replace-match
  3079. (concat (match-string 1 string)
  3080. "<" key ">" c "</" key ">")
  3081. t t string)))))
  3082. (while (string-match "\\\\\\([_^]\\)" string)
  3083. (setq string (replace-match (match-string 1 string) t t string)))
  3084. string))
  3085. (defun org-export-html-convert-emphasize (string)
  3086. "Apply emphasis."
  3087. (let ((s 0) rpl)
  3088. (while (string-match org-emph-re string s)
  3089. (if (not (equal
  3090. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  3091. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  3092. (setq s (match-beginning 0)
  3093. rpl
  3094. (concat
  3095. (match-string 1 string)
  3096. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  3097. (match-string 4 string)
  3098. (nth 3 (assoc (match-string 3 string)
  3099. org-emphasis-alist))
  3100. (match-string 5 string))
  3101. string (replace-match rpl t t string)
  3102. s (+ s (- (length rpl) 2)))
  3103. (setq s (1+ s))))
  3104. string))
  3105. (defvar org-par-open nil)
  3106. (defun org-open-par ()
  3107. "Insert <p>, but first close previous paragraph if any."
  3108. (org-close-par-maybe)
  3109. (insert "\n<p>")
  3110. (setq org-par-open t))
  3111. (defun org-close-par-maybe ()
  3112. "Close paragraph if there is one open."
  3113. (when org-par-open
  3114. (insert "</p>")
  3115. (setq org-par-open nil)))
  3116. (defun org-close-li ()
  3117. "Close <li> if necessary."
  3118. (org-close-par-maybe)
  3119. (insert "</li>\n"))
  3120. (defvar body-only) ; dynamically scoped into this.
  3121. (defun org-html-level-start (level title umax with-toc head-count)
  3122. "Insert a new level in HTML export.
  3123. When TITLE is nil, just close all open levels."
  3124. (org-close-par-maybe)
  3125. (let ((target (and title (org-get-text-property-any 0 'target title)))
  3126. (l org-level-max)
  3127. snumber)
  3128. (while (>= l level)
  3129. (if (aref org-levels-open (1- l))
  3130. (progn
  3131. (org-html-level-close l umax)
  3132. (aset org-levels-open (1- l) nil)))
  3133. (setq l (1- l)))
  3134. (when title
  3135. ;; If title is nil, this means this function is called to close
  3136. ;; all levels, so the rest is done only if title is given
  3137. (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  3138. (setq title (replace-match
  3139. (if org-export-with-tags
  3140. (save-match-data
  3141. (concat
  3142. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  3143. (mapconcat 'identity (org-split-string
  3144. (match-string 1 title) ":")
  3145. "&nbsp;")
  3146. "</span>"))
  3147. "")
  3148. t t title)))
  3149. (if (> level umax)
  3150. (progn
  3151. (if (aref org-levels-open (1- level))
  3152. (progn
  3153. (org-close-li)
  3154. (if target
  3155. (insert (format "<li id=\"%s\">" target) title "<br/>\n")
  3156. (insert "<li>" title "<br/>\n")))
  3157. (aset org-levels-open (1- level) t)
  3158. (org-close-par-maybe)
  3159. (if target
  3160. (insert (format "<ul>\n<li id=\"%s\">" target)
  3161. title "<br/>\n")
  3162. (insert "<ul>\n<li>" title "<br/>\n"))))
  3163. (aset org-levels-open (1- level) t)
  3164. (setq snumber (org-section-number level))
  3165. (if (and org-export-with-section-numbers (not body-only))
  3166. (setq title (concat snumber " " title)))
  3167. (setq level (+ level org-export-html-toplevel-hlevel -1))
  3168. (unless (= head-count 1) (insert "\n</div>\n"))
  3169. (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s</h%d>\n<div id=\"text-%s\">\n"
  3170. snumber level level snumber title level snumber))
  3171. (org-open-par)))))
  3172. (defun org-get-text-property-any (pos prop &optional object)
  3173. (or (get-text-property pos prop object)
  3174. (and (setq pos (next-single-property-change pos prop object))
  3175. (get-text-property pos prop object))))
  3176. (defun org-html-level-close (level max-outline-level)
  3177. "Terminate one level in HTML export."
  3178. (if (<= level max-outline-level)
  3179. (insert "</div>\n")
  3180. (org-close-li)
  3181. (insert "</ul>\n")))
  3182. ;;; iCalendar export
  3183. ;;;###autoload
  3184. (defun org-export-icalendar-this-file ()
  3185. "Export current file as an iCalendar file.
  3186. The iCalendar file will be located in the same directory as the Org-mode
  3187. file, but with extension `.ics'."
  3188. (interactive)
  3189. (org-export-icalendar nil buffer-file-name))
  3190. ;;;###autoload
  3191. (defun org-export-icalendar-all-agenda-files ()
  3192. "Export all files in `org-agenda-files' to iCalendar .ics files.
  3193. Each iCalendar file will be located in the same directory as the Org-mode
  3194. file, but with extension `.ics'."
  3195. (interactive)
  3196. (apply 'org-export-icalendar nil (org-agenda-files t)))
  3197. ;;;###autoload
  3198. (defun org-export-icalendar-combine-agenda-files ()
  3199. "Export all files in `org-agenda-files' to a single combined iCalendar file.
  3200. The file is stored under the name `org-combined-agenda-icalendar-file'."
  3201. (interactive)
  3202. (apply 'org-export-icalendar t (org-agenda-files t)))
  3203. (defun org-export-icalendar (combine &rest files)
  3204. "Create iCalendar files for all elements of FILES.
  3205. If COMBINE is non-nil, combine all calendar entries into a single large
  3206. file and store it under the name `org-combined-agenda-icalendar-file'."
  3207. (save-excursion
  3208. (org-prepare-agenda-buffers files)
  3209. (let* ((dir (org-export-directory
  3210. :ical (list :publishing-directory
  3211. org-export-publishing-directory)))
  3212. file ical-file ical-buffer category started org-agenda-new-buffers)
  3213. (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
  3214. (when combine
  3215. (setq ical-file
  3216. (if (file-name-absolute-p org-combined-agenda-icalendar-file)
  3217. org-combined-agenda-icalendar-file
  3218. (expand-file-name org-combined-agenda-icalendar-file dir))
  3219. ical-buffer (org-get-agenda-file-buffer ical-file))
  3220. (set-buffer ical-buffer) (erase-buffer))
  3221. (while (setq file (pop files))
  3222. (catch 'nextfile
  3223. (org-check-agenda-file file)
  3224. (set-buffer (org-get-agenda-file-buffer file))
  3225. (unless combine
  3226. (setq ical-file (concat (file-name-as-directory dir)
  3227. (file-name-sans-extension
  3228. (file-name-nondirectory buffer-file-name))
  3229. ".ics"))
  3230. (setq ical-buffer (org-get-agenda-file-buffer ical-file))
  3231. (with-current-buffer ical-buffer (erase-buffer)))
  3232. (setq category (or org-category
  3233. (file-name-sans-extension
  3234. (file-name-nondirectory buffer-file-name))))
  3235. (if (symbolp category) (setq category (symbol-name category)))
  3236. (let ((standard-output ical-buffer))
  3237. (if combine
  3238. (and (not started) (setq started t)
  3239. (org-start-icalendar-file org-icalendar-combined-name))
  3240. (org-start-icalendar-file category))
  3241. (org-print-icalendar-entries combine)
  3242. (when (or (and combine (not files)) (not combine))
  3243. (org-finish-icalendar-file)
  3244. (set-buffer ical-buffer)
  3245. (save-buffer)
  3246. (run-hooks 'org-after-save-iCalendar-file-hook)
  3247. (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
  3248. ))))
  3249. (org-release-buffers org-agenda-new-buffers))))
  3250. (defvar org-after-save-iCalendar-file-hook nil
  3251. "Hook run after an iCalendar file has been saved.
  3252. The iCalendar buffer is still current when this hook is run.
  3253. A good way to use this is to tell a desktop calenndar application to re-read
  3254. the iCalendar file.")
  3255. (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
  3256. (defun org-print-icalendar-entries (&optional combine)
  3257. "Print iCalendar entries for the current Org-mode file to `standard-output'.
  3258. When COMBINE is non nil, add the category to each line."
  3259. (require 'org-agenda)
  3260. (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
  3261. (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
  3262. (dts (org-ical-ts-to-string
  3263. (format-time-string (cdr org-time-stamp-formats) (current-time))
  3264. "DTSTART"))
  3265. hd ts ts2 state status (inc t) pos b sexp rrule
  3266. scheduledp deadlinep tmp pri category entry location summary desc
  3267. (sexp-buffer (get-buffer-create "*ical-tmp*")))
  3268. (org-refresh-category-properties)
  3269. (save-excursion
  3270. (goto-char (point-min))
  3271. (while (re-search-forward re1 nil t)
  3272. (catch :skip
  3273. (org-agenda-skip)
  3274. (when (boundp 'org-icalendar-verify-function)
  3275. (unless (funcall org-icalendar-verify-function)
  3276. (outline-next-heading)
  3277. (backward-char 1)
  3278. (throw :skip nil)))
  3279. (setq pos (match-beginning 0)
  3280. ts (match-string 0)
  3281. inc t
  3282. hd (condition-case nil
  3283. (org-icalendar-cleanup-string
  3284. (org-get-heading))
  3285. (error (throw :skip nil)))
  3286. summary (org-icalendar-cleanup-string
  3287. (org-entry-get nil "SUMMARY"))
  3288. desc (org-icalendar-cleanup-string
  3289. (or (org-entry-get nil "DESCRIPTION")
  3290. (and org-icalendar-include-body (org-get-entry)))
  3291. t org-icalendar-include-body)
  3292. location (org-icalendar-cleanup-string
  3293. (org-entry-get nil "LOCATION"))
  3294. category (org-get-category))
  3295. (if (looking-at re2)
  3296. (progn
  3297. (goto-char (match-end 0))
  3298. (setq ts2 (match-string 1) inc nil))
  3299. (setq tmp (buffer-substring (max (point-min)
  3300. (- pos org-ds-keyword-length))
  3301. pos)
  3302. ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
  3303. (progn
  3304. (setq inc nil)
  3305. (replace-match "\\1" t nil ts))
  3306. ts)
  3307. deadlinep (string-match org-deadline-regexp tmp)
  3308. scheduledp (string-match org-scheduled-regexp tmp)
  3309. ;; donep (org-entry-is-done-p)
  3310. ))
  3311. (if (or (string-match org-tr-regexp hd)
  3312. (string-match org-ts-regexp hd))
  3313. (setq hd (replace-match "" t t hd)))
  3314. (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
  3315. (setq rrule
  3316. (concat "\nRRULE:FREQ="
  3317. (cdr (assoc
  3318. (match-string 2 ts)
  3319. '(("d" . "DAILY")("w" . "WEEKLY")
  3320. ("m" . "MONTHLY")("y" . "YEARLY"))))
  3321. ";INTERVAL=" (match-string 1 ts)))
  3322. (setq rrule ""))
  3323. (setq summary (or summary hd))
  3324. (if (string-match org-bracket-link-regexp summary)
  3325. (setq summary
  3326. (replace-match (if (match-end 3)
  3327. (match-string 3 summary)
  3328. (match-string 1 summary))
  3329. t t summary)))
  3330. (if deadlinep (setq summary (concat "DL: " summary)))
  3331. (if scheduledp (setq summary (concat "S: " summary)))
  3332. (if (string-match "\\`<%%" ts)
  3333. (with-current-buffer sexp-buffer
  3334. (insert (substring ts 1 -1) " " summary "\n"))
  3335. (princ (format "BEGIN:VEVENT
  3336. %s
  3337. %s%s
  3338. SUMMARY:%s%s%s
  3339. CATEGORIES:%s
  3340. END:VEVENT\n"
  3341. (org-ical-ts-to-string ts "DTSTART")
  3342. (org-ical-ts-to-string ts2 "DTEND" inc)
  3343. rrule summary
  3344. (if (and desc (string-match "\\S-" desc))
  3345. (concat "\nDESCRIPTION: " desc) "")
  3346. (if (and location (string-match "\\S-" location))
  3347. (concat "\nLOCATION: " location) "")
  3348. category)))))
  3349. (when (and org-icalendar-include-sexps
  3350. (condition-case nil (require 'icalendar) (error nil))
  3351. (fboundp 'icalendar-export-region))
  3352. ;; Get all the literal sexps
  3353. (goto-char (point-min))
  3354. (while (re-search-forward "^&?%%(" nil t)
  3355. (catch :skip
  3356. (org-agenda-skip)
  3357. (setq b (match-beginning 0))
  3358. (goto-char (1- (match-end 0)))
  3359. (forward-sexp 1)
  3360. (end-of-line 1)
  3361. (setq sexp (buffer-substring b (point)))
  3362. (with-current-buffer sexp-buffer
  3363. (insert sexp "\n"))
  3364. (princ (org-diary-to-ical-string sexp-buffer)))))
  3365. (when org-icalendar-include-todo
  3366. (goto-char (point-min))
  3367. (while (re-search-forward org-todo-line-regexp nil t)
  3368. (catch :skip
  3369. (org-agenda-skip)
  3370. (when (boundp 'org-icalendar-verify-function)
  3371. (unless (funcall org-icalendar-verify-function)
  3372. (outline-next-heading)
  3373. (backward-char 1)
  3374. (throw :skip nil)))
  3375. (setq state (match-string 2))
  3376. (setq status (if (member state org-done-keywords)
  3377. "COMPLETED" "NEEDS-ACTION"))
  3378. (when (and state
  3379. (or (not (member state org-done-keywords))
  3380. (eq org-icalendar-include-todo 'all))
  3381. (not (member org-archive-tag (org-get-tags-at)))
  3382. )
  3383. (setq hd (match-string 3)
  3384. summary (org-icalendar-cleanup-string
  3385. (org-entry-get nil "SUMMARY"))
  3386. desc (org-icalendar-cleanup-string
  3387. (or (org-entry-get nil "DESCRIPTION")
  3388. (and org-icalendar-include-body (org-get-entry)))
  3389. t org-icalendar-include-body)
  3390. location (org-icalendar-cleanup-string
  3391. (org-entry-get nil "LOCATION")))
  3392. (if (string-match org-bracket-link-regexp hd)
  3393. (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
  3394. (match-string 1 hd))
  3395. t t hd)))
  3396. (if (string-match org-priority-regexp hd)
  3397. (setq pri (string-to-char (match-string 2 hd))
  3398. hd (concat (substring hd 0 (match-beginning 1))
  3399. (substring hd (match-end 1))))
  3400. (setq pri org-default-priority))
  3401. (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
  3402. (- org-lowest-priority org-highest-priority))))))
  3403. (princ (format "BEGIN:VTODO
  3404. %s
  3405. SUMMARY:%s%s%s
  3406. CATEGORIES:%s
  3407. SEQUENCE:1
  3408. PRIORITY:%d
  3409. STATUS:%s
  3410. END:VTODO\n"
  3411. dts
  3412. (or summary hd)
  3413. (if (and location (string-match "\\S-" location))
  3414. (concat "\nLOCATION: " location) "")
  3415. (if (and desc (string-match "\\S-" desc))
  3416. (concat "\nDESCRIPTION: " desc) "")
  3417. category pri status)))))))))
  3418. (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
  3419. "Take out stuff and quote what needs to be quoted.
  3420. When IS-BODY is non-nil, assume that this is the body of an item, clean up
  3421. whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
  3422. characters."
  3423. (if (not s)
  3424. nil
  3425. (when is-body
  3426. (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
  3427. (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
  3428. (while (string-match re s) (setq s (replace-match "" t t s)))
  3429. (while (string-match re2 s) (setq s (replace-match "" t t s)))))
  3430. (let ((start 0))
  3431. (while (string-match "\\([,;]\\)" s start)
  3432. (setq start (+ (match-beginning 0) 2)
  3433. s (replace-match "\\\\\\1" nil nil s))))
  3434. (when is-body
  3435. (while (string-match "[ \t]*\n[ \t]*" s)
  3436. (setq s (replace-match "\\n" t t s))))
  3437. (setq s (org-trim s))
  3438. (if is-body
  3439. (if maxlength
  3440. (if (and (numberp maxlength)
  3441. (> (length s) maxlength))
  3442. (setq s (substring s 0 maxlength)))))
  3443. s))
  3444. (defun org-get-entry ()
  3445. "Clean-up description string."
  3446. (save-excursion
  3447. (org-back-to-heading t)
  3448. (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
  3449. (defun org-start-icalendar-file (name)
  3450. "Start an iCalendar file by inserting the header."
  3451. (let ((user user-full-name)
  3452. (name (or name "unknown"))
  3453. (timezone (cadr (current-time-zone))))
  3454. (princ
  3455. (format "BEGIN:VCALENDAR
  3456. VERSION:2.0
  3457. X-WR-CALNAME:%s
  3458. PRODID:-//%s//Emacs with Org-mode//EN
  3459. X-WR-TIMEZONE:%s
  3460. CALSCALE:GREGORIAN\n" name user timezone))))
  3461. (defun org-finish-icalendar-file ()
  3462. "Finish an iCalendar file by inserting the END statement."
  3463. (princ "END:VCALENDAR\n"))
  3464. (defun org-ical-ts-to-string (s keyword &optional inc)
  3465. "Take a time string S and convert it to iCalendar format.
  3466. KEYWORD is added in front, to make a complete line like DTSTART....
  3467. When INC is non-nil, increase the hour by two (if time string contains
  3468. a time), or the day by one (if it does not contain a time)."
  3469. (let ((t1 (org-parse-time-string s 'nodefault))
  3470. t2 fmt have-time time)
  3471. (if (and (car t1) (nth 1 t1) (nth 2 t1))
  3472. (setq t2 t1 have-time t)
  3473. (setq t2 (org-parse-time-string s)))
  3474. (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
  3475. (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
  3476. (when inc
  3477. (if have-time
  3478. (if org-agenda-default-appointment-duration
  3479. (setq mi (+ org-agenda-default-appointment-duration mi))
  3480. (setq h (+ 2 h)))
  3481. (setq d (1+ d))))
  3482. (setq time (encode-time s mi h d m y)))
  3483. (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
  3484. (concat keyword (format-time-string fmt time))))
  3485. ;;; XOXO export
  3486. (defun org-export-as-xoxo-insert-into (buffer &rest output)
  3487. (with-current-buffer buffer
  3488. (apply 'insert output)))
  3489. (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
  3490. ;;;###autoload
  3491. (defun org-export-as-xoxo (&optional buffer)
  3492. "Export the org buffer as XOXO.
  3493. The XOXO buffer is named *xoxo-<source buffer name>*"
  3494. (interactive (list (current-buffer)))
  3495. ;; A quickie abstraction
  3496. ;; Output everything as XOXO
  3497. (with-current-buffer (get-buffer buffer)
  3498. (let* ((pos (point))
  3499. (opt-plist (org-combine-plists (org-default-export-plist)
  3500. (org-infile-export-plist)))
  3501. (filename (concat (file-name-as-directory
  3502. (org-export-directory :xoxo opt-plist))
  3503. (file-name-sans-extension
  3504. (file-name-nondirectory buffer-file-name))
  3505. ".html"))
  3506. (out (find-file-noselect filename))
  3507. (last-level 1)
  3508. (hanging-li nil))
  3509. (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
  3510. ;; Check the output buffer is empty.
  3511. (with-current-buffer out (erase-buffer))
  3512. ;; Kick off the output
  3513. (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
  3514. (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
  3515. (let* ((hd (match-string-no-properties 1))
  3516. (level (length hd))
  3517. (text (concat
  3518. (match-string-no-properties 2)
  3519. (save-excursion
  3520. (goto-char (match-end 0))
  3521. (let ((str ""))
  3522. (catch 'loop
  3523. (while 't
  3524. (forward-line)
  3525. (if (looking-at "^[ \t]\\(.*\\)")
  3526. (setq str (concat str (match-string-no-properties 1)))
  3527. (throw 'loop str)))))))))
  3528. ;; Handle level rendering
  3529. (cond
  3530. ((> level last-level)
  3531. (org-export-as-xoxo-insert-into out "\n<ol>\n"))
  3532. ((< level last-level)
  3533. (dotimes (- (- last-level level) 1)
  3534. (if hanging-li
  3535. (org-export-as-xoxo-insert-into out "</li>\n"))
  3536. (org-export-as-xoxo-insert-into out "</ol>\n"))
  3537. (when hanging-li
  3538. (org-export-as-xoxo-insert-into out "</li>\n")
  3539. (setq hanging-li nil)))
  3540. ((equal level last-level)
  3541. (if hanging-li
  3542. (org-export-as-xoxo-insert-into out "</li>\n")))
  3543. )
  3544. (setq last-level level)
  3545. ;; And output the new li
  3546. (setq hanging-li 't)
  3547. (if (equal ?+ (elt text 0))
  3548. (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
  3549. (org-export-as-xoxo-insert-into out "<li>" text))))
  3550. ;; Finally finish off the ol
  3551. (dotimes (- last-level 1)
  3552. (if hanging-li
  3553. (org-export-as-xoxo-insert-into out "</li>\n"))
  3554. (org-export-as-xoxo-insert-into out "</ol>\n"))
  3555. (goto-char pos)
  3556. ;; Finish the buffer off and clean it up.
  3557. (switch-to-buffer-other-window out)
  3558. (indent-region (point-min) (point-max) nil)
  3559. (save-buffer)
  3560. (goto-char (point-min))
  3561. )))
  3562. (provide 'org-exp)
  3563. ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
  3564. ;;; org-exp.el ends here