org-exp.el 162 KB

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