org-exp.el 123 KB

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