org-exp.el 140 KB

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