org-exp.el 160 KB

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