org-exp.el 160 KB

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