org-exp.el 153 KB

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