org-exp.el 147 KB

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