org-exp.el 174 KB

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