org-exp.el 140 KB

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