org-exp.el 151 KB

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