org-exp.el 137 KB

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