org-exp.el 136 KB

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