org-exp.el 123 KB

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