org-exp.el 176 KB

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