org-exp.el 124 KB

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