org-exp.el 162 KB

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