org-exp.el 136 KB

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