org-exp.el 149 KB

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