org-exp.el 144 KB

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