org-exp.el 132 KB

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