org-exp.el 174 KB

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