org-exp.el 128 KB

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