org-exp.el 134 KB

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