org-exp.el 140 KB

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