org-exp.el 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721
  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-5
  7. ;;
  8. ;; This file is part of GNU Emacs.
  9. ;;
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 3, or (at your option)
  13. ;; any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Commentary:
  25. (require 'org)
  26. (require 'org-agenda)
  27. (eval-and-compile
  28. (require 'cl))
  29. (declare-function org-export-latex-preprocess "org-export-latex" ())
  30. (declare-function org-agenda-skip "org-agenda" ())
  31. (declare-function org-infojs-options-inbuffer-template "org-infojs" ())
  32. (defgroup org-export nil
  33. "Options for exporting org-listings."
  34. :tag "Org Export"
  35. :group 'org)
  36. (defgroup org-export-general nil
  37. "General options for exporting Org-mode files."
  38. :tag "Org Export General"
  39. :group 'org-export)
  40. ;; FIXME
  41. (defvar org-export-publishing-directory nil)
  42. (defcustom org-export-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 { }
  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-export-preprocess-string (string &rest parameters)
  990. "Cleanup STRING so that that the true exported has a more consistent source.
  991. This function takes STRING, which should be a buffer-string of an org-file
  992. to export. It then creates a temporary buffer where it does its job.
  993. The result is then again returned as a string, and the exporter works
  994. on this string to produce the exported version."
  995. (interactive)
  996. (let* ((re-radio (and org-target-link-regexp
  997. (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))
  998. (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
  999. (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
  1000. (re-archive (concat ":" org-archive-tag ":"))
  1001. (re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>"))
  1002. (re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
  1003. (htmlp (plist-get parameters :for-html))
  1004. (asciip (plist-get parameters :for-ascii))
  1005. (latexp (plist-get parameters :for-LaTeX))
  1006. (commentsp (plist-get parameters :comments))
  1007. (archived-trees (plist-get parameters :archived-trees))
  1008. (inhibit-read-only t)
  1009. (drawers org-drawers)
  1010. (exp-drawers (plist-get parameters :drawers))
  1011. (outline-regexp "\\*+ ")
  1012. target-alist tmp target level
  1013. a b xx
  1014. rtn p)
  1015. (with-current-buffer (get-buffer-create " org-mode-tmp")
  1016. (erase-buffer)
  1017. (insert string)
  1018. ;; Remove license-to-kill stuff
  1019. ;; The caller markes some stuff fo killing, stuff that has been
  1020. ;; used to create the page title, for example.
  1021. (while (setq p (text-property-any (point-min) (point-max)
  1022. :org-license-to-kill t))
  1023. (delete-region p (next-single-property-change p :org-license-to-kill)))
  1024. (let ((org-inhibit-startup t)) (org-mode))
  1025. (untabify (point-min) (point-max))
  1026. ;; Get rid of drawers
  1027. (unless (eq t exp-drawers)
  1028. (goto-char (point-min))
  1029. (let ((re (concat "^[ \t]*:\\("
  1030. (mapconcat
  1031. 'identity
  1032. (org-delete-all exp-drawers
  1033. (copy-sequence drawers))
  1034. "\\|")
  1035. "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
  1036. (while (re-search-forward re nil t)
  1037. (replace-match ""))))
  1038. ;; Get the correct stuff before the first headline
  1039. (when (plist-get parameters :skip-before-1st-heading)
  1040. (goto-char (point-min))
  1041. (when (re-search-forward "^\\*+[ \t]" nil t)
  1042. (delete-region (point-min) (match-beginning 0))
  1043. (goto-char (point-min))
  1044. (insert "\n")))
  1045. (when (plist-get parameters :add-text)
  1046. (goto-char (point-min))
  1047. (insert (plist-get parameters :add-text) "\n"))
  1048. ;; Get rid of archived trees
  1049. (when (not (eq archived-trees t))
  1050. (goto-char (point-min))
  1051. (while (re-search-forward re-archive nil t)
  1052. (if (not (org-on-heading-p t))
  1053. (org-end-of-subtree t)
  1054. (beginning-of-line 1)
  1055. (setq a (if archived-trees
  1056. (1+ (point-at-eol)) (point))
  1057. b (org-end-of-subtree t))
  1058. (if (> b a) (delete-region a b)))))
  1059. ;; Find all headings and compute the targets for them
  1060. (goto-char (point-min))
  1061. (org-init-section-numbers)
  1062. (while (re-search-forward org-outline-regexp nil t)
  1063. (setq level (org-reduced-level
  1064. (save-excursion (goto-char (point-at-bol))
  1065. (org-outline-level))))
  1066. (setq target (org-solidify-link-text
  1067. (format "sec-%s" (org-section-number level))))
  1068. (push (cons target target) target-alist)
  1069. (add-text-properties
  1070. (point-at-bol) (point-at-eol)
  1071. (list 'target target)))
  1072. ;; Find targets in comments and move them out of comments,
  1073. ;; but mark them as targets that should be invisible
  1074. (goto-char (point-min))
  1075. (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
  1076. ;; Check if the line before or after is a headline with a target
  1077. (if (setq target (or (get-text-property (point-at-bol 0) 'target)
  1078. (get-text-property (point-at-bol 2) 'target)))
  1079. (progn
  1080. ;; use the existing target in a neighboring line
  1081. (setq tmp (match-string 2))
  1082. (replace-match "")
  1083. (and (looking-at "\n") (delete-char 1))
  1084. (push (cons (org-solidify-link-text tmp) target)
  1085. target-alist))
  1086. ;; Make an invisible target
  1087. (replace-match "\\1(INVISIBLE)")))
  1088. ;; Protect backend specific stuff, throw away the others.
  1089. (let ((formatters
  1090. `((,htmlp "HTML" "BEGIN_HTML" "END_HTML")
  1091. (,asciip "ASCII" "BEGIN_ASCII" "END_ASCII")
  1092. (,latexp "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
  1093. fmt)
  1094. (goto-char (point-min))
  1095. (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
  1096. (goto-char (match-end 0))
  1097. (while (not (looking-at "#\\+END_EXAMPLE"))
  1098. (insert ": ")
  1099. (beginning-of-line 2)))
  1100. (goto-char (point-min))
  1101. (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
  1102. (add-text-properties (match-beginning 0) (match-end 0)
  1103. '(org-protected t)))
  1104. (while formatters
  1105. (setq fmt (pop formatters))
  1106. (when (car fmt)
  1107. (goto-char (point-min))
  1108. (while (re-search-forward (concat "^#\\+" (cadr fmt)
  1109. ":[ \t]*\\(.*\\)") nil t)
  1110. (replace-match "\\1" t)
  1111. (add-text-properties
  1112. (point-at-bol) (min (1+ (point-at-eol)) (point-max))
  1113. '(org-protected t))))
  1114. (goto-char (point-min))
  1115. (while (re-search-forward
  1116. (concat "^#\\+"
  1117. (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
  1118. (cadddr fmt) "\\>.*\n?") nil t)
  1119. (if (car fmt)
  1120. (add-text-properties (match-beginning 1) (1+ (match-end 1))
  1121. '(org-protected t))
  1122. (delete-region (match-beginning 0) (match-end 0))))))
  1123. ;; Protect quoted subtrees
  1124. (goto-char (point-min))
  1125. (while (re-search-forward re-quote nil t)
  1126. (goto-char (match-beginning 0))
  1127. (end-of-line 1)
  1128. (add-text-properties (point) (org-end-of-subtree t)
  1129. '(org-protected t)))
  1130. ;; Protect verbatim elements
  1131. (goto-char (point-min))
  1132. (while (re-search-forward org-verbatim-re nil t)
  1133. (add-text-properties (match-beginning 4) (match-end 4)
  1134. '(org-protected t))
  1135. (goto-char (1+ (match-end 4))))
  1136. ;; Remove subtrees that are commented
  1137. (goto-char (point-min))
  1138. (while (re-search-forward re-commented nil t)
  1139. (goto-char (match-beginning 0))
  1140. (delete-region (point) (org-end-of-subtree t)))
  1141. ;; Remove special table lines
  1142. (when org-export-table-remove-special-lines
  1143. (goto-char (point-min))
  1144. (while (re-search-forward "^[ \t]*|" nil t)
  1145. (beginning-of-line 1)
  1146. (if (or (looking-at "[ \t]*| *[!_^] *|")
  1147. (and (looking-at ".*?| *<[0-9]+> *|")
  1148. (not (looking-at ".*?| *[^ <|]"))))
  1149. (delete-region (max (point-min) (1- (point-at-bol)))
  1150. (point-at-eol))
  1151. (end-of-line 1))))
  1152. ;; Specific LaTeX stuff
  1153. (when latexp
  1154. (require 'org-export-latex nil)
  1155. (org-export-latex-preprocess))
  1156. (when asciip
  1157. (org-export-ascii-clean-string))
  1158. ;; Specific HTML stuff
  1159. (when htmlp
  1160. ;; Convert LaTeX fragments to images
  1161. (when (plist-get parameters :LaTeX-fragments)
  1162. (org-format-latex
  1163. (concat "ltxpng/" (file-name-sans-extension
  1164. (file-name-nondirectory
  1165. org-current-export-file)))
  1166. org-current-export-dir nil "Creating LaTeX image %s"))
  1167. (message "Exporting..."))
  1168. ;; Remove or replace comments
  1169. (goto-char (point-min))
  1170. (while (re-search-forward "^#\\(.*\n?\\)" nil t)
  1171. (if commentsp
  1172. (progn (add-text-properties
  1173. (match-beginning 0) (match-end 0) '(org-protected t))
  1174. (replace-match (format commentsp (match-string 1)) t t))
  1175. (replace-match "")))
  1176. ;; Find matches for radio targets and turn them into internal links
  1177. (goto-char (point-min))
  1178. (when re-radio
  1179. (while (re-search-forward re-radio nil t)
  1180. (org-if-unprotected
  1181. (replace-match "\\1[[\\2]]"))))
  1182. ;; Find all links that contain a newline and put them into a single line
  1183. (goto-char (point-min))
  1184. (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
  1185. (org-if-unprotected
  1186. (replace-match "\\1 \\3")
  1187. (goto-char (match-beginning 0))))
  1188. ;; Find all internal links. If they have a fuzzy match (i.e. not
  1189. ;; a *dedicated* target match, let the link point to the
  1190. ;; correspinding section.
  1191. (goto-char (point-min))
  1192. (while (re-search-forward org-bracket-link-regexp nil t)
  1193. (org-if-unprotected
  1194. (let* ((md (match-data))
  1195. (desc (match-end 2))
  1196. (link (org-link-unescape (match-string 1)))
  1197. (slink (org-solidify-link-text link))
  1198. found props pos
  1199. (target
  1200. (or (cdr (assoc slink target-alist))
  1201. (save-excursion
  1202. (unless (string-match org-link-types-re link)
  1203. (setq found (condition-case nil (org-link-search link)
  1204. (error nil)))
  1205. (when (and found
  1206. (or (org-on-heading-p)
  1207. (not (eq found 'dedicated))))
  1208. (or (get-text-property (point) 'target)
  1209. (get-text-property
  1210. (max (point-min)
  1211. (1- (previous-single-property-change
  1212. (point) 'target)))
  1213. 'target))))))))
  1214. (when target
  1215. (set-match-data md)
  1216. (goto-char (match-beginning 1))
  1217. (setq props (text-properties-at (point)))
  1218. (delete-region (match-beginning 1) (match-end 1))
  1219. (setq pos (point))
  1220. (insert target)
  1221. (unless desc (insert "][" link))
  1222. (add-text-properties pos (point) props)))))
  1223. ;; Normalize links: Convert angle and plain links into bracket links
  1224. ;; Expand link abbreviations
  1225. (goto-char (point-min))
  1226. (while (re-search-forward re-plain-link nil t)
  1227. (goto-char (1- (match-end 0)))
  1228. (org-if-unprotected
  1229. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1230. ":" (match-string 3) "]]")))
  1231. ;; added 'org-link face to links
  1232. (put-text-property 0 (length s) 'face 'org-link s)
  1233. (replace-match s t t))))
  1234. (goto-char (point-min))
  1235. (while (re-search-forward re-angle-link nil t)
  1236. (goto-char (1- (match-end 0)))
  1237. (org-if-unprotected
  1238. (let* ((s (concat (match-string 1) "[[" (match-string 2)
  1239. ":" (match-string 3) "]]")))
  1240. (put-text-property 0 (length s) 'face 'org-link s)
  1241. (replace-match s t t))))
  1242. (goto-char (point-min))
  1243. (while (re-search-forward org-bracket-link-regexp nil t)
  1244. (org-if-unprotected
  1245. (let* ((s (concat "[[" (setq xx (save-match-data
  1246. (org-link-expand-abbrev (match-string 1))))
  1247. "]"
  1248. (if (match-end 3)
  1249. (match-string 2)
  1250. (concat "[" xx "]"))
  1251. "]")))
  1252. (put-text-property 0 (length s) 'face 'org-link s)
  1253. (replace-match s t t))))
  1254. ;; Find multiline emphasis and put them into single line
  1255. (when (plist-get parameters :emph-multiline)
  1256. (goto-char (point-min))
  1257. (while (re-search-forward org-emph-re nil t)
  1258. (if (not (= (char-after (match-beginning 3))
  1259. (char-after (match-beginning 4))))
  1260. (org-if-unprotected
  1261. (subst-char-in-region (match-beginning 0) (match-end 0)
  1262. ?\n ?\ t)
  1263. (goto-char (1- (match-end 0))))
  1264. (goto-char (1+ (match-beginning 0))))))
  1265. (setq rtn (buffer-string)))
  1266. (kill-buffer " org-mode-tmp")
  1267. rtn))
  1268. (defun org-export-grab-title-from-buffer ()
  1269. "Get a title for the current document, from looking at the buffer."
  1270. (let ((inhibit-read-only t))
  1271. (save-excursion
  1272. (goto-char (point-min))
  1273. (let ((end (save-excursion (outline-next-heading) (point))))
  1274. (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
  1275. ;; Mark the line so that it will not be exported as normal text.
  1276. (org-unmodified
  1277. (add-text-properties (match-beginning 0) (match-end 0)
  1278. (list :org-license-to-kill t)))
  1279. ;; Return the title string
  1280. (org-trim (match-string 0)))))))
  1281. (defun org-export-get-title-from-subtree ()
  1282. "Return subtree title and exclude it from export."
  1283. (let (title (m (mark)))
  1284. (save-excursion
  1285. (goto-char (region-beginning))
  1286. (when (and (org-at-heading-p)
  1287. (>= (org-end-of-subtree t t) (region-end)))
  1288. ;; This is a subtree, we take the title from the first heading
  1289. (goto-char (region-beginning))
  1290. (looking-at org-todo-line-regexp)
  1291. (setq title (match-string 3))
  1292. (org-unmodified
  1293. (add-text-properties (point) (1+ (point-at-eol))
  1294. (list :org-license-to-kill t)))))
  1295. title))
  1296. (defun org-solidify-link-text (s &optional alist)
  1297. "Take link text and make a safe target out of it."
  1298. (save-match-data
  1299. (let* ((rtn
  1300. (mapconcat
  1301. 'identity
  1302. (org-split-string s "[ \t\r\n]+") "=="))
  1303. (a (assoc rtn alist)))
  1304. (or (cdr a) rtn))))
  1305. (defun org-get-min-level (lines)
  1306. "Get the minimum level in LINES."
  1307. (let ((re "^\\(\\*+\\) ") l min)
  1308. (catch 'exit
  1309. (while (setq l (pop lines))
  1310. (if (string-match re l)
  1311. (throw 'exit (org-tr-level (length (match-string 1 l))))))
  1312. 1)))
  1313. ;; Variable holding the vector with section numbers
  1314. (defvar org-section-numbers (make-vector org-level-max 0))
  1315. (defun org-init-section-numbers ()
  1316. "Initialize the vector for the section numbers."
  1317. (let* ((level -1)
  1318. (numbers (nreverse (org-split-string "" "\\.")))
  1319. (depth (1- (length org-section-numbers)))
  1320. (i depth) number-string)
  1321. (while (>= i 0)
  1322. (if (> i level)
  1323. (aset org-section-numbers i 0)
  1324. (setq number-string (or (car numbers) "0"))
  1325. (if (string-match "\\`[A-Z]\\'" number-string)
  1326. (aset org-section-numbers i
  1327. (- (string-to-char number-string) ?A -1))
  1328. (aset org-section-numbers i (string-to-number number-string)))
  1329. (pop numbers))
  1330. (setq i (1- i)))))
  1331. (defun org-section-number (&optional level)
  1332. "Return a string with the current section number.
  1333. When LEVEL is non-nil, increase section numbers on that level."
  1334. (let* ((depth (1- (length org-section-numbers))) idx n (string ""))
  1335. (when level
  1336. (when (> level -1)
  1337. (aset org-section-numbers
  1338. level (1+ (aref org-section-numbers level))))
  1339. (setq idx (1+ level))
  1340. (while (<= idx depth)
  1341. (if (not (= idx 1))
  1342. (aset org-section-numbers idx 0))
  1343. (setq idx (1+ idx))))
  1344. (setq idx 0)
  1345. (while (<= idx depth)
  1346. (setq n (aref org-section-numbers idx))
  1347. (setq string (concat string (if (not (string= string "")) "." "")
  1348. (int-to-string n)))
  1349. (setq idx (1+ idx)))
  1350. (save-match-data
  1351. (if (string-match "\\`\\([@0]\\.\\)+" string)
  1352. (setq string (replace-match "" t nil string)))
  1353. (if (string-match "\\(\\.0\\)+\\'" string)
  1354. (setq string (replace-match "" t nil string))))
  1355. string))
  1356. ;;; ASCII export
  1357. (defvar org-last-level nil) ; dynamically scoped variable
  1358. (defvar org-min-level nil) ; dynamically scoped variable
  1359. (defvar org-levels-open nil) ; dynamically scoped parameter
  1360. (defvar org-ascii-current-indentation nil) ; For communication
  1361. ;;;###autoload
  1362. (defun org-export-as-ascii (arg)
  1363. "Export the outline as a pretty ASCII file.
  1364. If there is an active region, export only the region.
  1365. The prefix ARG specifies how many levels of the outline should become
  1366. underlined headlines. The default is 3."
  1367. (interactive "P")
  1368. (setq-default org-todo-line-regexp org-todo-line-regexp)
  1369. (let* ((opt-plist (org-combine-plists (org-default-export-plist)
  1370. (org-infile-export-plist)))
  1371. (region-p (org-region-active-p))
  1372. (subtree-p
  1373. (when region-p
  1374. (save-excursion
  1375. (goto-char (region-beginning))
  1376. (and (org-at-heading-p)
  1377. (>= (org-end-of-subtree t t) (region-end))))))
  1378. (custom-times org-display-custom-times)
  1379. (org-ascii-current-indentation '(0 . 0))
  1380. (level 0) line txt
  1381. (umax nil)
  1382. (umax-toc nil)
  1383. (case-fold-search nil)
  1384. (filename (concat (file-name-as-directory
  1385. (org-export-directory :ascii opt-plist))
  1386. (file-name-sans-extension
  1387. (or (and subtree-p
  1388. (org-entry-get (region-beginning)
  1389. "EXPORT_FILE_NAME" t))
  1390. (file-name-nondirectory buffer-file-name)))
  1391. ".txt"))
  1392. (filename (if (equal (file-truename filename)
  1393. (file-truename buffer-file-name))
  1394. (concat filename ".txt")
  1395. filename))
  1396. (buffer (find-file-noselect filename))
  1397. (org-levels-open (make-vector org-level-max nil))
  1398. (odd org-odd-levels-only)
  1399. (date (plist-get opt-plist :date))
  1400. (author (plist-get opt-plist :author))
  1401. (title (or (and subtree-p (org-export-get-title-from-subtree))
  1402. (plist-get opt-plist :title)
  1403. (and (not
  1404. (plist-get opt-plist :skip-before-1st-heading))
  1405. (org-export-grab-title-from-buffer))
  1406. (file-name-sans-extension
  1407. (file-name-nondirectory buffer-file-name))))
  1408. (email (plist-get opt-plist :email))
  1409. (language (plist-get opt-plist :language))
  1410. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  1411. ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
  1412. (todo nil)
  1413. (lang-words nil)
  1414. (region
  1415. (buffer-substring
  1416. (if (org-region-active-p) (region-beginning) (point-min))
  1417. (if (org-region-active-p) (region-end) (point-max))))
  1418. (lines (org-split-string
  1419. (org-export-preprocess-string
  1420. region
  1421. :for-ascii t
  1422. :skip-before-1st-heading
  1423. (plist-get opt-plist :skip-before-1st-heading)
  1424. :drawers (plist-get opt-plist :drawers)
  1425. :verbatim-multiline t
  1426. :archived-trees
  1427. (plist-get opt-plist :archived-trees)
  1428. :add-text (plist-get opt-plist :text))
  1429. "\n"))
  1430. thetoc have-headings first-heading-pos
  1431. table-open table-buffer)
  1432. (let ((inhibit-read-only t))
  1433. (org-unmodified
  1434. (remove-text-properties (point-min) (point-max)
  1435. '(:org-license-to-kill t))))
  1436. (setq org-min-level (org-get-min-level lines))
  1437. (setq org-last-level org-min-level)
  1438. (org-init-section-numbers)
  1439. (find-file-noselect filename)
  1440. (setq lang-words (or (assoc language org-export-language-setup)
  1441. (assoc "en" org-export-language-setup)))
  1442. (switch-to-buffer-other-window buffer)
  1443. (erase-buffer)
  1444. (fundamental-mode)
  1445. ;; create local variables for all options, to make sure all called
  1446. ;; functions get the correct information
  1447. (mapc (lambda (x)
  1448. (set (make-local-variable (cdr x))
  1449. (plist-get opt-plist (car x))))
  1450. org-export-plist-vars)
  1451. (org-set-local 'org-odd-levels-only odd)
  1452. (setq umax (if arg (prefix-numeric-value arg)
  1453. org-export-headline-levels))
  1454. (setq umax-toc (if (integerp org-export-with-toc)
  1455. (min org-export-with-toc umax)
  1456. umax))
  1457. ;; File header
  1458. (if title (org-insert-centered title ?=))
  1459. (insert "\n")
  1460. (if (and (or author email)
  1461. org-export-author-info)
  1462. (insert (concat (nth 1 lang-words) ": " (or author "")
  1463. (if email (concat " <" email ">") "")
  1464. "\n")))
  1465. (cond
  1466. ((and date (string-match "%" date))
  1467. (setq date (format-time-string date)))
  1468. (date)
  1469. (t (setq date (format-time-string "%Y/%m/%d %X"))))
  1470. (if (and date org-export-time-stamp-file)
  1471. (insert (concat (nth 2 lang-words) ": " date"\n")))
  1472. (insert "\n\n")
  1473. (if org-export-with-toc
  1474. (progn
  1475. (push (concat (nth 3 lang-words) "\n") thetoc)
  1476. (push (concat (make-string (length (nth 3 lang-words)) ?=) "\n") thetoc)
  1477. (mapc '(lambda (line)
  1478. (if (string-match org-todo-line-regexp
  1479. line)
  1480. ;; This is a headline
  1481. (progn
  1482. (setq have-headings t)
  1483. (setq level (- (match-end 1) (match-beginning 1))
  1484. level (org-tr-level level)
  1485. txt (match-string 3 line)
  1486. todo
  1487. (or (and org-export-mark-todo-in-toc
  1488. (match-beginning 2)
  1489. (not (member (match-string 2 line)
  1490. org-done-keywords)))
  1491. ; TODO, not DONE
  1492. (and org-export-mark-todo-in-toc
  1493. (= level umax-toc)
  1494. (org-search-todo-below
  1495. line lines level))))
  1496. (setq txt (org-html-expand-for-ascii txt))
  1497. (while (string-match org-bracket-link-regexp txt)
  1498. (setq txt
  1499. (replace-match
  1500. (match-string (if (match-end 2) 3 1) txt)
  1501. t t txt)))
  1502. (if (and (memq org-export-with-tags '(not-in-toc nil))
  1503. (string-match
  1504. (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
  1505. txt))
  1506. (setq txt (replace-match "" t t txt)))
  1507. (if (string-match quote-re0 txt)
  1508. (setq txt (replace-match "" t t txt)))
  1509. (if org-export-with-section-numbers
  1510. (setq txt (concat (org-section-number level)
  1511. " " txt)))
  1512. (if (<= level umax-toc)
  1513. (progn
  1514. (push
  1515. (concat
  1516. (make-string
  1517. (* (max 0 (- level org-min-level)) 4) ?\ )
  1518. (format (if todo "%s (*)\n" "%s\n") txt))
  1519. thetoc)
  1520. (setq org-last-level level))
  1521. ))))
  1522. lines)
  1523. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  1524. (org-init-section-numbers)
  1525. (while (setq line (pop lines))
  1526. ;; Remove the quoted HTML tags.
  1527. (setq line (org-html-expand-for-ascii line))
  1528. ;; Remove targets
  1529. (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line)
  1530. (setq line (replace-match "" t t line)))
  1531. ;; Replace internal links
  1532. (while (string-match org-bracket-link-regexp line)
  1533. (setq line (replace-match
  1534. (if (match-end 3) "[\\3]" "[\\1]")
  1535. t nil line)))
  1536. (when custom-times
  1537. (setq line (org-translate-time line)))
  1538. (cond
  1539. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  1540. ;; a Headline
  1541. (setq first-heading-pos (or first-heading-pos (point)))
  1542. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  1543. txt (match-string 2 line))
  1544. (org-ascii-level-start level txt umax lines))
  1545. ((and org-export-with-tables
  1546. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  1547. (if (not table-open)
  1548. ;; New table starts
  1549. (setq table-open t table-buffer nil))
  1550. ;; Accumulate lines
  1551. (setq table-buffer (cons line table-buffer))
  1552. (when (or (not lines)
  1553. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  1554. (car lines))))
  1555. (setq table-open nil
  1556. table-buffer (nreverse table-buffer))
  1557. (insert (mapconcat
  1558. (lambda (x)
  1559. (org-fix-indentation x org-ascii-current-indentation))
  1560. (org-format-table-ascii table-buffer)
  1561. "\n") "\n")))
  1562. (t
  1563. (setq line (org-fix-indentation line org-ascii-current-indentation))
  1564. (if (and org-export-with-fixed-width
  1565. (string-match "^\\([ \t]*\\)\\(:\\)" line))
  1566. (setq line (replace-match "\\1" nil nil line)))
  1567. (insert line "\n"))))
  1568. (normal-mode)
  1569. ;; insert the table of contents
  1570. (when thetoc
  1571. (goto-char (point-min))
  1572. (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
  1573. (progn
  1574. (goto-char (match-beginning 0))
  1575. (replace-match ""))
  1576. (goto-char first-heading-pos))
  1577. (mapc 'insert thetoc)
  1578. (or (looking-at "[ \t]*\n[ \t]*\n")
  1579. (insert "\n\n")))
  1580. ;; Convert whitespace place holders
  1581. (goto-char (point-min))
  1582. (let (beg end)
  1583. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  1584. (setq end (next-single-property-change beg 'org-whitespace))
  1585. (goto-char beg)
  1586. (delete-region beg end)
  1587. (insert (make-string (- end beg) ?\ ))))
  1588. (save-buffer)
  1589. ;; remove display and invisible chars
  1590. (let (beg end)
  1591. (goto-char (point-min))
  1592. (while (setq beg (next-single-property-change (point) 'display))
  1593. (setq end (next-single-property-change beg 'display))
  1594. (delete-region beg end)
  1595. (goto-char beg)
  1596. (insert "=>"))
  1597. (goto-char (point-min))
  1598. (while (setq beg (next-single-property-change (point) 'org-cwidth))
  1599. (setq end (next-single-property-change beg 'org-cwidth))
  1600. (delete-region beg end)
  1601. (goto-char beg)))
  1602. (goto-char (point-min))))
  1603. (defun org-export-ascii-clean-string ()
  1604. "Do extra work for ASCII export"
  1605. (goto-char (point-min))
  1606. (while (re-search-forward org-verbatim-re nil t)
  1607. (goto-char (match-end 2))
  1608. (backward-delete-char 1) (insert "'")
  1609. (goto-char (match-beginning 2))
  1610. (delete-char 1) (insert "`")
  1611. (goto-char (match-end 2))))
  1612. (defun org-search-todo-below (line lines level)
  1613. "Search the subtree below LINE for any TODO entries."
  1614. (let ((rest (cdr (memq line lines)))
  1615. (re org-todo-line-regexp)
  1616. line lv todo)
  1617. (catch 'exit
  1618. (while (setq line (pop rest))
  1619. (if (string-match re line)
  1620. (progn
  1621. (setq lv (- (match-end 1) (match-beginning 1))
  1622. todo (and (match-beginning 2)
  1623. (not (member (match-string 2 line)
  1624. org-done-keywords))))
  1625. ; TODO, not DONE
  1626. (if (<= lv level) (throw 'exit nil))
  1627. (if todo (throw 'exit t))))))))
  1628. (defun org-html-expand-for-ascii (line)
  1629. "Handle quoted HTML for ASCII export."
  1630. (if org-export-html-expand
  1631. (while (string-match "@<[^<>\n]*>" line)
  1632. ;; We just remove the tags for now.
  1633. (setq line (replace-match "" nil nil line))))
  1634. line)
  1635. (defun org-insert-centered (s &optional underline)
  1636. "Insert the string S centered and underline it with character UNDERLINE."
  1637. (let ((ind (max (/ (- 80 (string-width s)) 2) 0)))
  1638. (insert (make-string ind ?\ ) s "\n")
  1639. (if underline
  1640. (insert (make-string ind ?\ )
  1641. (make-string (string-width s) underline)
  1642. "\n"))))
  1643. (defun org-ascii-level-start (level title umax &optional lines)
  1644. "Insert a new level in ASCII export."
  1645. (let (char (n (- level umax 1)) (ind 0))
  1646. (if (> level umax)
  1647. (progn
  1648. (insert (make-string (* 2 n) ?\ )
  1649. (char-to-string (nth (% n (length org-export-ascii-bullets))
  1650. org-export-ascii-bullets))
  1651. " " title "\n")
  1652. ;; find the indentation of the next non-empty line
  1653. (catch 'stop
  1654. (while lines
  1655. (if (string-match "^\\* " (car lines)) (throw 'stop nil))
  1656. (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
  1657. (throw 'stop (setq ind (org-get-indentation (car lines)))))
  1658. (pop lines)))
  1659. (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
  1660. (if (or (not (equal (char-before) ?\n))
  1661. (not (equal (char-before (1- (point))) ?\n)))
  1662. (insert "\n"))
  1663. (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
  1664. (unless org-export-with-tags
  1665. (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  1666. (setq title (replace-match "" t t title))))
  1667. (if org-export-with-section-numbers
  1668. (setq title (concat (org-section-number level) " " title)))
  1669. (insert title "\n" (make-string (string-width title) char) "\n")
  1670. (setq org-ascii-current-indentation '(0 . 0)))))
  1671. ;;;###autoload
  1672. (defun org-export-visible (type arg)
  1673. "Create a copy of the visible part of the current buffer, and export it.
  1674. The copy is created in a temporary buffer and removed after use.
  1675. TYPE is the final key (as a string) that also select the export command in
  1676. the `C-c C-e' export dispatcher.
  1677. As a special case, if the you type SPC at the prompt, the temporary
  1678. org-mode file will not be removed but presented to you so that you can
  1679. continue to use it. The prefix arg ARG is passed through to the exporting
  1680. command."
  1681. (interactive
  1682. (list (progn
  1683. (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
  1684. (read-char-exclusive))
  1685. current-prefix-arg))
  1686. (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
  1687. (error "Invalid export key"))
  1688. (let* ((binding (cdr (assoc type
  1689. '((?a . org-export-as-ascii)
  1690. (?\C-a . org-export-as-ascii)
  1691. (?b . org-export-as-html-and-open)
  1692. (?\C-b . org-export-as-html-and-open)
  1693. (?h . org-export-as-html)
  1694. (?H . org-export-as-html-to-buffer)
  1695. (?R . org-export-region-as-html)
  1696. (?x . org-export-as-xoxo)))))
  1697. (keepp (equal type ?\ ))
  1698. (file buffer-file-name)
  1699. (buffer (get-buffer-create "*Org Export Visible*"))
  1700. s e)
  1701. ;; Need to hack the drawers here.
  1702. (save-excursion
  1703. (goto-char (point-min))
  1704. (while (re-search-forward org-drawer-regexp nil t)
  1705. (goto-char (match-beginning 1))
  1706. (or (org-invisible-p) (org-flag-drawer nil))))
  1707. (with-current-buffer buffer (erase-buffer))
  1708. (save-excursion
  1709. (setq s (goto-char (point-min)))
  1710. (while (not (= (point) (point-max)))
  1711. (goto-char (org-find-invisible))
  1712. (append-to-buffer buffer s (point))
  1713. (setq s (goto-char (org-find-visible))))
  1714. (org-cycle-hide-drawers 'all)
  1715. (goto-char (point-min))
  1716. (unless keepp
  1717. ;; Copy all comment lines to the end, to make sure #+ settings are
  1718. ;; still available for the second export step. Kind of a hack, but
  1719. ;; does do the trick.
  1720. (if (looking-at "#[^\r\n]*")
  1721. (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
  1722. (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
  1723. (append-to-buffer buffer (1+ (match-beginning 0))
  1724. (min (point-max) (1+ (match-end 0))))))
  1725. (set-buffer buffer)
  1726. (let ((buffer-file-name file)
  1727. (org-inhibit-startup t))
  1728. (org-mode)
  1729. (show-all)
  1730. (unless keepp (funcall binding arg))))
  1731. (if (not keepp)
  1732. (kill-buffer buffer)
  1733. (switch-to-buffer-other-window buffer)
  1734. (goto-char (point-min)))))
  1735. (defun org-find-visible ()
  1736. (let ((s (point)))
  1737. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  1738. (get-char-property s 'invisible)))
  1739. s))
  1740. (defun org-find-invisible ()
  1741. (let ((s (point)))
  1742. (while (and (not (= (point-max) (setq s (next-overlay-change s))))
  1743. (not (get-char-property s 'invisible))))
  1744. s))
  1745. ;;; HTML export
  1746. (defvar org-archive-location) ;; gets loades with the org-archive require.
  1747. (defun org-get-current-options ()
  1748. "Return a string with current options as keyword options.
  1749. Does include HTML export options as well as TODO and CATEGORY stuff."
  1750. (require 'org-archive)
  1751. (format
  1752. "#+TITLE: %s
  1753. #+AUTHOR: %s
  1754. #+EMAIL: %s
  1755. #+DATE: %s
  1756. #+LANGUAGE: %s
  1757. #+TEXT: Some descriptive text to be emitted. Several lines OK.
  1758. #+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
  1759. %s
  1760. #+LINK_UP: %s
  1761. #+LINK_HOME: %s
  1762. #+CATEGORY: %s
  1763. #+SEQ_TODO: %s
  1764. #+TYP_TODO: %s
  1765. #+PRIORITIES: %c %c %c
  1766. #+DRAWERS: %s
  1767. #+STARTUP: %s %s %s %s %s
  1768. #+TAGS: %s
  1769. #+ARCHIVE: %s
  1770. #+LINK: %s
  1771. "
  1772. (buffer-name) (user-full-name) user-mail-address
  1773. (format-time-string (car org-time-stamp-formats))
  1774. org-export-default-language
  1775. org-export-headline-levels
  1776. org-export-with-section-numbers
  1777. org-export-with-toc
  1778. org-export-preserve-breaks
  1779. org-export-html-expand
  1780. org-export-with-fixed-width
  1781. org-export-with-tables
  1782. org-export-with-sub-superscripts
  1783. org-export-with-special-strings
  1784. org-export-with-footnotes
  1785. org-export-with-emphasize
  1786. org-export-with-TeX-macros
  1787. org-export-with-LaTeX-fragments
  1788. org-export-skip-text-before-1st-heading
  1789. org-export-with-drawers
  1790. org-export-with-tags
  1791. (if (featurep 'org-infojs) (org-infojs-options-inbuffer-template) "")
  1792. org-export-html-link-up
  1793. org-export-html-link-home
  1794. (file-name-nondirectory buffer-file-name)
  1795. "TODO FEEDBACK VERIFY DONE"
  1796. "Me Jason Marie DONE"
  1797. org-highest-priority org-lowest-priority org-default-priority
  1798. (mapconcat 'identity org-drawers " ")
  1799. (cdr (assoc org-startup-folded
  1800. '((nil . "showall") (t . "overview") (content . "content"))))
  1801. (if org-odd-levels-only "odd" "oddeven")
  1802. (if org-hide-leading-stars "hidestars" "showstars")
  1803. (if org-startup-align-all-tables "align" "noalign")
  1804. (cond ((eq org-log-done t) "logdone")
  1805. ((equal org-log-done 'note) "lognotedone")
  1806. ((not org-log-done) "nologdone"))
  1807. (or (mapconcat (lambda (x)
  1808. (cond
  1809. ((equal '(:startgroup) x) "{")
  1810. ((equal '(:endgroup) x) "}")
  1811. ((cdr x) (format "%s(%c)" (car x) (cdr x)))
  1812. (t (car x))))
  1813. (or org-tag-alist (org-get-buffer-tags)) " ") "")
  1814. org-archive-location
  1815. "org file:~/org/%s.org"
  1816. ))
  1817. ;;;###autoload
  1818. (defun org-insert-export-options-template ()
  1819. "Insert into the buffer a template with information for exporting."
  1820. (interactive)
  1821. (if (not (bolp)) (newline))
  1822. (let ((s (org-get-current-options)))
  1823. (and (string-match "#\\+CATEGORY" s)
  1824. (setq s (substring s 0 (match-beginning 0))))
  1825. (insert s)))
  1826. ;;;###autoload
  1827. (defun org-export-as-html-and-open (arg)
  1828. "Export the outline as HTML and immediately open it with a browser.
  1829. If there is an active region, export only the region.
  1830. The prefix ARG specifies how many levels of the outline should become
  1831. headlines. The default is 3. Lower levels will become bulleted lists."
  1832. (interactive "P")
  1833. (org-export-as-html arg 'hidden)
  1834. (org-open-file buffer-file-name))
  1835. ;;;###autoload
  1836. (defun org-export-as-html-batch ()
  1837. "Call `org-export-as-html', may be used in batch processing as
  1838. emacs --batch
  1839. --load=$HOME/lib/emacs/org.el
  1840. --eval \"(setq org-export-headline-levels 2)\"
  1841. --visit=MyFile --funcall org-export-as-html-batch"
  1842. (org-export-as-html org-export-headline-levels 'hidden))
  1843. ;;;###autoload
  1844. (defun org-export-as-html-to-buffer (arg)
  1845. "Call `org-exort-as-html` with output to a temporary buffer.
  1846. No file is created. The prefix ARG is passed through to `org-export-as-html'."
  1847. (interactive "P")
  1848. (org-export-as-html arg nil nil "*Org HTML Export*")
  1849. (switch-to-buffer-other-window "*Org HTML Export*"))
  1850. ;;;###autoload
  1851. (defun org-replace-region-by-html (beg end)
  1852. "Assume the current region has org-mode syntax, and convert it to HTML.
  1853. This can be used in any buffer. For example, you could write an
  1854. itemized list in org-mode syntax in an HTML buffer and then use this
  1855. command to convert it."
  1856. (interactive "r")
  1857. (let (reg html buf pop-up-frames)
  1858. (save-window-excursion
  1859. (if (org-mode-p)
  1860. (setq html (org-export-region-as-html
  1861. beg end t 'string))
  1862. (setq reg (buffer-substring beg end)
  1863. buf (get-buffer-create "*Org tmp*"))
  1864. (with-current-buffer buf
  1865. (erase-buffer)
  1866. (insert reg)
  1867. (org-mode)
  1868. (setq html (org-export-region-as-html
  1869. (point-min) (point-max) t 'string)))
  1870. (kill-buffer buf)))
  1871. (delete-region beg end)
  1872. (insert html)))
  1873. ;;;###autoload
  1874. (defun org-export-region-as-html (beg end &optional body-only buffer)
  1875. "Convert region from BEG to END in org-mode buffer to HTML.
  1876. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  1877. contents, and only produce the region of converted text, useful for
  1878. cut-and-paste operations.
  1879. If BUFFER is a buffer or a string, use/create that buffer as a target
  1880. of the converted HTML. If BUFFER is the symbol `string', return the
  1881. produced HTML as a string and leave not buffer behind. For example,
  1882. a Lisp program could call this function in the following way:
  1883. (setq html (org-export-region-as-html beg end t 'string))
  1884. When called interactively, the output buffer is selected, and shown
  1885. in a window. A non-interactive call will only retunr the buffer."
  1886. (interactive "r\nP")
  1887. (when (interactive-p)
  1888. (setq buffer "*Org HTML Export*"))
  1889. (let ((transient-mark-mode t) (zmacs-regions t)
  1890. rtn)
  1891. (goto-char end)
  1892. (set-mark (point)) ;; to activate the region
  1893. (goto-char beg)
  1894. (setq rtn (org-export-as-html
  1895. nil nil nil
  1896. buffer body-only))
  1897. (if (fboundp 'deactivate-mark) (deactivate-mark))
  1898. (if (and (interactive-p) (bufferp rtn))
  1899. (switch-to-buffer-other-window rtn)
  1900. rtn)))
  1901. (defvar html-table-tag nil) ; dynamically scoped into this.
  1902. ;;;###autoload
  1903. (defun org-export-as-html (arg &optional hidden ext-plist
  1904. to-buffer body-only pub-dir)
  1905. "Export the outline as a pretty HTML file.
  1906. If there is an active region, export only the region. The prefix
  1907. ARG specifies how many levels of the outline should become
  1908. headlines. The default is 3. Lower levels will become bulleted
  1909. lists. When HIDDEN is non-nil, don't display the HTML buffer.
  1910. EXT-PLIST is a property list with external parameters overriding
  1911. org-mode's default settings, but still inferior to file-local
  1912. settings. When TO-BUFFER is non-nil, create a buffer with that
  1913. name and export to that buffer. If TO-BUFFER is the symbol
  1914. `string', don't leave any buffer behind but just return the
  1915. resulting HTML as a string. When BODY-ONLY is set, don't produce
  1916. the file header and footer, simply return the content of
  1917. <body>...</body>, without even the body tags themselves. When
  1918. PUB-DIR is set, use this as the publishing directory."
  1919. (interactive "P")
  1920. ;; Make sure we have a file name when we need it.
  1921. (when (and (not (or to-buffer body-only))
  1922. (not buffer-file-name))
  1923. (if (buffer-base-buffer)
  1924. (org-set-local 'buffer-file-name
  1925. (with-current-buffer (buffer-base-buffer)
  1926. buffer-file-name))
  1927. (error "Need a file name to be able to export.")))
  1928. (message "Exporting...")
  1929. (setq-default org-todo-line-regexp org-todo-line-regexp)
  1930. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  1931. (setq-default org-done-keywords org-done-keywords)
  1932. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  1933. (let* ((opt-plist
  1934. (org-export-process-option-filters
  1935. (org-combine-plists (org-default-export-plist)
  1936. ext-plist
  1937. (org-infile-export-plist))))
  1938. (style (plist-get opt-plist :style))
  1939. (html-extension (plist-get opt-plist :html-extension))
  1940. (link-validate (plist-get opt-plist :link-validation-function))
  1941. valid thetoc have-headings first-heading-pos
  1942. (odd org-odd-levels-only)
  1943. (region-p (org-region-active-p))
  1944. (subtree-p
  1945. (when region-p
  1946. (save-excursion
  1947. (goto-char (region-beginning))
  1948. (and (org-at-heading-p)
  1949. (>= (org-end-of-subtree t t) (region-end))))))
  1950. ;; The following two are dynamically scoped into other
  1951. ;; routines below.
  1952. (org-current-export-dir
  1953. (or pub-dir (org-export-directory :html opt-plist)))
  1954. (org-current-export-file buffer-file-name)
  1955. (level 0) (line "") (origline "") txt todo
  1956. (umax nil)
  1957. (umax-toc nil)
  1958. (filename (if to-buffer nil
  1959. (expand-file-name
  1960. (concat
  1961. (file-name-sans-extension
  1962. (or (and subtree-p
  1963. (org-entry-get (region-beginning)
  1964. "EXPORT_FILE_NAME" t))
  1965. (file-name-nondirectory buffer-file-name)))
  1966. "." html-extension)
  1967. (file-name-as-directory
  1968. (or pub-dir (org-export-directory :html opt-plist))))))
  1969. (current-dir (if buffer-file-name
  1970. (file-name-directory buffer-file-name)
  1971. default-directory))
  1972. (buffer (if to-buffer
  1973. (cond
  1974. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  1975. (t (get-buffer-create to-buffer)))
  1976. (find-file-noselect filename)))
  1977. (org-levels-open (make-vector org-level-max nil))
  1978. (date (plist-get opt-plist :date))
  1979. (author (plist-get opt-plist :author))
  1980. (title (or (and subtree-p (org-export-get-title-from-subtree))
  1981. (plist-get opt-plist :title)
  1982. (and (not
  1983. (plist-get opt-plist :skip-before-1st-heading))
  1984. (org-export-grab-title-from-buffer))
  1985. (and buffer-file-name
  1986. (file-name-sans-extension
  1987. (file-name-nondirectory buffer-file-name)))
  1988. "UNTITLED"))
  1989. (html-table-tag (plist-get opt-plist :html-table-tag))
  1990. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  1991. (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
  1992. (inquote nil)
  1993. (infixed nil)
  1994. (in-local-list nil)
  1995. (local-list-num nil)
  1996. (local-list-indent nil)
  1997. (llt org-plain-list-ordered-item-terminator)
  1998. (email (plist-get opt-plist :email))
  1999. (language (plist-get opt-plist :language))
  2000. (lang-words nil)
  2001. (head-count 0) cnt
  2002. (start 0)
  2003. (coding-system (and (boundp 'buffer-file-coding-system)
  2004. buffer-file-coding-system))
  2005. (coding-system-for-write (or org-export-html-coding-system
  2006. coding-system))
  2007. (save-buffer-coding-system (or org-export-html-coding-system
  2008. coding-system))
  2009. (charset (and coding-system-for-write
  2010. (fboundp 'coding-system-get)
  2011. (coding-system-get coding-system-for-write
  2012. 'mime-charset)))
  2013. (region
  2014. (buffer-substring
  2015. (if region-p (region-beginning) (point-min))
  2016. (if region-p (region-end) (point-max))))
  2017. (lines
  2018. (org-split-string
  2019. (org-export-preprocess-string
  2020. region
  2021. :emph-multiline t
  2022. :for-html t
  2023. :skip-before-1st-heading
  2024. (plist-get opt-plist :skip-before-1st-heading)
  2025. :drawers (plist-get opt-plist :drawers)
  2026. :archived-trees
  2027. (plist-get opt-plist :archived-trees)
  2028. :add-text
  2029. (plist-get opt-plist :text)
  2030. :LaTeX-fragments
  2031. (plist-get opt-plist :LaTeX-fragments))
  2032. "[\r\n]"))
  2033. table-open type
  2034. table-buffer table-orig-buffer
  2035. ind start-is-num starter didclose
  2036. rpl path desc descp desc1 desc2 link
  2037. snumber fnc
  2038. )
  2039. (let ((inhibit-read-only t))
  2040. (org-unmodified
  2041. (remove-text-properties (point-min) (point-max)
  2042. '(:org-license-to-kill t))))
  2043. (message "Exporting...")
  2044. (setq org-min-level (org-get-min-level lines))
  2045. (setq org-last-level org-min-level)
  2046. (org-init-section-numbers)
  2047. (cond
  2048. ((and date (string-match "%" date))
  2049. (setq date (format-time-string date)))
  2050. (date)
  2051. (t (setq date (format-time-string "%Y/%m/%d %X"))))
  2052. ;; Get the language-dependent settings
  2053. (setq lang-words (or (assoc language org-export-language-setup)
  2054. (assoc "en" org-export-language-setup)))
  2055. ;; Switch to the output buffer
  2056. (set-buffer buffer)
  2057. (let ((inhibit-read-only t)) (erase-buffer))
  2058. (fundamental-mode)
  2059. (and (fboundp 'set-buffer-file-coding-system)
  2060. (set-buffer-file-coding-system coding-system-for-write))
  2061. (let ((case-fold-search nil)
  2062. (org-odd-levels-only odd))
  2063. ;; create local variables for all options, to make sure all called
  2064. ;; functions get the correct information
  2065. (mapc (lambda (x)
  2066. (set (make-local-variable (cdr x))
  2067. (plist-get opt-plist (car x))))
  2068. org-export-plist-vars)
  2069. (setq umax (if arg (prefix-numeric-value arg)
  2070. org-export-headline-levels))
  2071. (setq umax-toc (if (integerp org-export-with-toc)
  2072. (min org-export-with-toc umax)
  2073. umax))
  2074. (unless body-only
  2075. ;; File header
  2076. (insert (format
  2077. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  2078. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  2079. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  2080. lang=\"%s\" xml:lang=\"%s\">
  2081. <head>
  2082. <title>%s</title>
  2083. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  2084. <meta name=\"generator\" content=\"Org-mode\"/>
  2085. <meta name=\"generated\" content=\"%s\"/>
  2086. <meta name=\"author\" content=\"%s\"/>
  2087. %s
  2088. </head><body>
  2089. "
  2090. language language (org-html-expand title)
  2091. (or charset "iso-8859-1") date author style))
  2092. (insert (or (plist-get opt-plist :preamble) ""))
  2093. (when (plist-get opt-plist :auto-preamble)
  2094. (if title (insert (format org-export-html-title-format
  2095. (org-html-expand title))))))
  2096. (if (and org-export-with-toc (not body-only))
  2097. (progn
  2098. (push (format "<h%d>%s</h%d>\n"
  2099. org-export-html-toplevel-hlevel
  2100. (nth 3 lang-words)
  2101. org-export-html-toplevel-hlevel)
  2102. thetoc)
  2103. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  2104. (push "<ul>\n<li>" thetoc)
  2105. (setq lines
  2106. (mapcar '(lambda (line)
  2107. (if (string-match org-todo-line-regexp line)
  2108. ;; This is a headline
  2109. (progn
  2110. (setq have-headings t)
  2111. (setq level (- (match-end 1) (match-beginning 1))
  2112. level (org-tr-level level)
  2113. txt (save-match-data
  2114. (org-html-expand
  2115. (org-export-cleanup-toc-line
  2116. (match-string 3 line))))
  2117. todo
  2118. (or (and org-export-mark-todo-in-toc
  2119. (match-beginning 2)
  2120. (not (member (match-string 2 line)
  2121. org-done-keywords)))
  2122. ; TODO, not DONE
  2123. (and org-export-mark-todo-in-toc
  2124. (= level umax-toc)
  2125. (org-search-todo-below
  2126. line lines level))))
  2127. (if (string-match
  2128. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  2129. (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
  2130. (if (string-match quote-re0 txt)
  2131. (setq txt (replace-match "" t t txt)))
  2132. (setq snumber (org-section-number level))
  2133. (if org-export-with-section-numbers
  2134. (setq txt (concat snumber " " txt)))
  2135. (if (<= level (max umax umax-toc))
  2136. (setq head-count (+ head-count 1)))
  2137. (if (<= level umax-toc)
  2138. (progn
  2139. (if (> level org-last-level)
  2140. (progn
  2141. (setq cnt (- level org-last-level))
  2142. (while (>= (setq cnt (1- cnt)) 0)
  2143. (push "\n<ul>\n<li>" thetoc))
  2144. (push "\n" thetoc)))
  2145. (if (< level org-last-level)
  2146. (progn
  2147. (setq cnt (- org-last-level level))
  2148. (while (>= (setq cnt (1- cnt)) 0)
  2149. (push "</li>\n</ul>" thetoc))
  2150. (push "\n" thetoc)))
  2151. ;; Check for targets
  2152. (while (string-match org-any-target-regexp line)
  2153. (setq line (replace-match
  2154. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  2155. t t line)))
  2156. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  2157. (setq txt (replace-match "" t t txt)))
  2158. (push
  2159. (format
  2160. (if todo
  2161. "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
  2162. "</li>\n<li><a href=\"#sec-%s\">%s</a>")
  2163. snumber txt) thetoc)
  2164. (setq org-last-level level))
  2165. )))
  2166. line)
  2167. lines))
  2168. (while (> org-last-level (1- org-min-level))
  2169. (setq org-last-level (1- org-last-level))
  2170. (push "</li>\n</ul>\n" thetoc))
  2171. (push "</div>\n" thetoc)
  2172. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  2173. (setq head-count 0)
  2174. (org-init-section-numbers)
  2175. (while (setq line (pop lines) origline line)
  2176. (catch 'nextline
  2177. ;; end of quote section?
  2178. (when (and inquote (string-match "^\\*+ " line))
  2179. (insert "</pre>\n")
  2180. (setq inquote nil))
  2181. ;; inside a quote section?
  2182. (when inquote
  2183. (insert (org-html-protect line) "\n")
  2184. (throw 'nextline nil))
  2185. ;; verbatim lines
  2186. (when (and org-export-with-fixed-width
  2187. (string-match "^[ \t]*:\\(.*\\)" line))
  2188. (when (not infixed)
  2189. (setq infixed t)
  2190. (insert "<pre>\n"))
  2191. (insert (org-html-protect (match-string 1 line)) "\n")
  2192. (when (and lines
  2193. (not (string-match "^[ \t]*\\(:.*\\)"
  2194. (car lines))))
  2195. (setq infixed nil)
  2196. (insert "</pre>\n"))
  2197. (throw 'nextline nil))
  2198. ;; Protected HTML
  2199. (when (get-text-property 0 'org-protected line)
  2200. (let (par)
  2201. (when (re-search-backward
  2202. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  2203. (setq par (match-string 1))
  2204. (replace-match "\\2\n"))
  2205. (insert line "\n")
  2206. (while (and lines
  2207. (or (= (length (car lines)) 0)
  2208. (get-text-property 0 'org-protected (car lines))))
  2209. (insert (pop lines) "\n"))
  2210. (and par (insert "<p>\n")))
  2211. (throw 'nextline nil))
  2212. ;; Horizontal line
  2213. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
  2214. (insert "\n<hr/>\n")
  2215. (throw 'nextline nil))
  2216. ;; make targets to anchors
  2217. (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
  2218. (cond
  2219. ((match-end 2)
  2220. (setq line (replace-match
  2221. (concat "@<a name=\""
  2222. (org-solidify-link-text (match-string 1 line))
  2223. "\">\\nbsp@</a>")
  2224. t t line)))
  2225. ((and org-export-with-toc (equal (string-to-char line) ?*))
  2226. (setq line (replace-match
  2227. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  2228. ; (concat "@<i>" (match-string 1 line) "@</i> ")
  2229. t t line)))
  2230. (t
  2231. (setq line (replace-match
  2232. (concat "@<a name=\""
  2233. (org-solidify-link-text (match-string 1 line))
  2234. "\" class=\"target\">" (match-string 1 line) "@</a> ")
  2235. t t line)))))
  2236. (setq line (org-html-handle-time-stamps line))
  2237. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  2238. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  2239. ;; Also handle sub_superscripts and checkboxes
  2240. (or (string-match org-table-hline-regexp line)
  2241. (setq line (org-html-expand line)))
  2242. ;; Format the links
  2243. (setq start 0)
  2244. (while (string-match org-bracket-link-analytic-regexp line start)
  2245. (setq start (match-beginning 0))
  2246. (setq type (if (match-end 2) (match-string 2 line) "internal"))
  2247. (setq path (match-string 3 line))
  2248. (setq desc1 (if (match-end 5) (match-string 5 line))
  2249. desc2 (if (match-end 2) (concat type ":" path) path)
  2250. descp (and desc1 (not (equal desc1 desc2)))
  2251. desc (or desc1 desc2))
  2252. ;; Make an image out of the description if that is so wanted
  2253. (when (and descp (org-file-image-p desc))
  2254. (save-match-data
  2255. (if (string-match "^file:" desc)
  2256. (setq desc (substring desc (match-end 0)))))
  2257. (setq desc (concat "<img src=\"" desc "\"/>")))
  2258. ;; FIXME: do we need to unescape here somewhere?
  2259. (cond
  2260. ((equal type "internal")
  2261. (setq rpl
  2262. (concat
  2263. "<a href=\"#"
  2264. (org-solidify-link-text
  2265. (save-match-data (org-link-unescape path)) nil)
  2266. "\">" desc "</a>")))
  2267. ((member type '("http" "https"))
  2268. ;; standard URL, just check if we need to inline an image
  2269. (if (and (or (eq t org-export-html-inline-images)
  2270. (and org-export-html-inline-images (not descp)))
  2271. (org-file-image-p path))
  2272. (setq rpl (concat "<img src=\"" type ":" path "\"/>"))
  2273. (setq link (concat type ":" path))
  2274. (setq rpl (concat "<a href=\"" link "\">" desc "</a>"))))
  2275. ((member type '("ftp" "mailto" "news"))
  2276. ;; standard URL
  2277. (setq link (concat type ":" path))
  2278. (setq rpl (concat "<a href=\"" link "\">" desc "</a>")))
  2279. ((string= type "file")
  2280. ;; FILE link
  2281. (let* ((filename path)
  2282. (abs-p (file-name-absolute-p filename))
  2283. thefile file-is-image-p search)
  2284. (save-match-data
  2285. (if (string-match "::\\(.*\\)" filename)
  2286. (setq search (match-string 1 filename)
  2287. filename (replace-match "" t nil filename)))
  2288. (setq valid
  2289. (if (functionp link-validate)
  2290. (funcall link-validate filename current-dir)
  2291. t))
  2292. (setq file-is-image-p (org-file-image-p filename))
  2293. (setq thefile (if abs-p (expand-file-name filename) filename))
  2294. (when (and org-export-html-link-org-files-as-html
  2295. (string-match "\\.org$" thefile))
  2296. (setq thefile (concat (substring thefile 0
  2297. (match-beginning 0))
  2298. "." html-extension))
  2299. (if (and search
  2300. ;; make sure this is can be used as target search
  2301. (not (string-match "^[0-9]*$" search))
  2302. (not (string-match "^\\*" search))
  2303. (not (string-match "^/.*/$" search)))
  2304. (setq thefile (concat thefile "#"
  2305. (org-solidify-link-text
  2306. (org-link-unescape search)))))
  2307. (when (string-match "^file:" desc)
  2308. (setq desc (replace-match "" t t desc))
  2309. (if (string-match "\\.org$" desc)
  2310. (setq desc (replace-match "" t t desc))))))
  2311. (setq rpl (if (and file-is-image-p
  2312. (or (eq t org-export-html-inline-images)
  2313. (and org-export-html-inline-images
  2314. (not descp))))
  2315. (concat "<img src=\"" thefile "\"/>")
  2316. (concat "<a href=\"" thefile "\">" desc "</a>")))
  2317. (if (not valid) (setq rpl desc))))
  2318. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  2319. (setq rpl
  2320. (save-match-data
  2321. (funcall fnc (org-link-unescape path) desc1 'html))))
  2322. (t
  2323. ;; just publish the path, as default
  2324. (setq rpl (concat "<i>&lt;" type ":"
  2325. (save-match-data (org-link-unescape path))
  2326. "&gt;</i>"))))
  2327. (setq line (replace-match rpl t t line)
  2328. start (+ start (length rpl))))
  2329. ;; TODO items
  2330. (if (and (string-match org-todo-line-regexp line)
  2331. (match-beginning 2))
  2332. (setq line
  2333. (concat (substring line 0 (match-beginning 2))
  2334. "<span class=\""
  2335. (if (member (match-string 2 line)
  2336. org-done-keywords)
  2337. "done" "todo")
  2338. "\">" (match-string 2 line)
  2339. "</span>" (substring line (match-end 2)))))
  2340. ;; Does this contain a reference to a footnote?
  2341. (when org-export-with-footnotes
  2342. (setq start 0)
  2343. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
  2344. (if (get-text-property (match-beginning 2) 'org-protected line)
  2345. (setq start (match-end 2))
  2346. (let ((n (match-string 2 line)))
  2347. (setq line
  2348. (replace-match
  2349. (format
  2350. "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
  2351. (match-string 1 line) n n n)
  2352. t t line))))))
  2353. (cond
  2354. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  2355. ;; This is a headline
  2356. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
  2357. txt (match-string 2 line))
  2358. (if (string-match quote-re0 txt)
  2359. (setq txt (replace-match "" t t txt)))
  2360. (if (<= level (max umax umax-toc))
  2361. (setq head-count (+ head-count 1)))
  2362. (when in-local-list
  2363. ;; Close any local lists before inserting a new header line
  2364. (while local-list-num
  2365. (org-close-li)
  2366. (insert (if (car local-list-num) "</ol>\n" "</ul>"))
  2367. (pop local-list-num))
  2368. (setq local-list-indent nil
  2369. in-local-list nil))
  2370. (setq first-heading-pos (or first-heading-pos (point)))
  2371. (org-html-level-start level txt umax
  2372. (and org-export-with-toc (<= level umax))
  2373. head-count)
  2374. ;; QUOTES
  2375. (when (string-match quote-re line)
  2376. (insert "<pre>")
  2377. (setq inquote t)))
  2378. ((and org-export-with-tables
  2379. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  2380. (if (not table-open)
  2381. ;; New table starts
  2382. (setq table-open t table-buffer nil table-orig-buffer nil))
  2383. ;; Accumulate lines
  2384. (setq table-buffer (cons line table-buffer)
  2385. table-orig-buffer (cons origline table-orig-buffer))
  2386. (when (or (not lines)
  2387. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  2388. (car lines))))
  2389. (setq table-open nil
  2390. table-buffer (nreverse table-buffer)
  2391. table-orig-buffer (nreverse table-orig-buffer))
  2392. (org-close-par-maybe)
  2393. (insert (org-format-table-html table-buffer table-orig-buffer))))
  2394. (t
  2395. ;; Normal lines
  2396. (when (string-match
  2397. (cond
  2398. ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2399. ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2400. ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  2401. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
  2402. line)
  2403. (setq ind (org-get-string-indentation line)
  2404. start-is-num (match-beginning 4)
  2405. starter (if (match-beginning 2)
  2406. (substring (match-string 2 line) 0 -1))
  2407. line (substring line (match-beginning 5)))
  2408. (unless (string-match "[^ \t]" line)
  2409. ;; empty line. Pretend indentation is large.
  2410. (setq ind (if org-empty-line-terminates-plain-lists
  2411. 0
  2412. (1+ (or (car local-list-indent) 1)))))
  2413. (setq didclose nil)
  2414. (while (and in-local-list
  2415. (or (and (= ind (car local-list-indent))
  2416. (not starter))
  2417. (< ind (car local-list-indent))))
  2418. (setq didclose t)
  2419. (org-close-li)
  2420. (insert (if (car local-list-num) "</ol>\n" "</ul>"))
  2421. (pop local-list-num) (pop local-list-indent)
  2422. (setq in-local-list local-list-indent))
  2423. (cond
  2424. ((and starter
  2425. (or (not in-local-list)
  2426. (> ind (car local-list-indent))))
  2427. ;; Start new (level of) list
  2428. (org-close-par-maybe)
  2429. (insert (if start-is-num "<ol>\n<li>\n" "<ul>\n<li>\n"))
  2430. (push start-is-num local-list-num)
  2431. (push ind local-list-indent)
  2432. (setq in-local-list t))
  2433. (starter
  2434. ;; continue current list
  2435. (org-close-li)
  2436. (insert "<li>\n"))
  2437. (didclose
  2438. ;; we did close a list, normal text follows: need <p>
  2439. (org-open-par)))
  2440. (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
  2441. (setq line
  2442. (replace-match
  2443. (if (equal (match-string 1 line) "X")
  2444. "<b>[X]</b>"
  2445. "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
  2446. t t line))))
  2447. ;; Empty lines start a new paragraph. If hand-formatted lists
  2448. ;; are not fully interpreted, lines starting with "-", "+", "*"
  2449. ;; also start a new paragraph.
  2450. (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
  2451. ;; Is this the start of a footnote?
  2452. (when org-export-with-footnotes
  2453. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
  2454. (org-close-par-maybe)
  2455. (let ((n (match-string 1 line)))
  2456. (setq line (replace-match
  2457. (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
  2458. ;; Check if the line break needs to be conserved
  2459. (cond
  2460. ((string-match "\\\\\\\\[ \t]*$" line)
  2461. (setq line (replace-match "<br/>" t t line)))
  2462. (org-export-preserve-breaks
  2463. (setq line (concat line "<br/>"))))
  2464. (insert line "\n")))))
  2465. ;; Properly close all local lists and other lists
  2466. (when inquote (insert "</pre>\n"))
  2467. (when in-local-list
  2468. ;; Close any local lists before inserting a new header line
  2469. (while local-list-num
  2470. (org-close-li)
  2471. (insert (if (car local-list-num) "</ol>\n" "</ul>\n"))
  2472. (pop local-list-num))
  2473. (setq local-list-indent nil
  2474. in-local-list nil))
  2475. (org-html-level-start 1 nil umax
  2476. (and org-export-with-toc (<= level umax))
  2477. head-count)
  2478. ;; the </div> to lose the last text-... div.
  2479. (insert "</div>\n")
  2480. (unless body-only
  2481. (when (plist-get opt-plist :auto-postamble)
  2482. (insert "<div id=\"postamble\">")
  2483. (when (and org-export-author-info author)
  2484. (insert "<p class=\"author\"> "
  2485. (nth 1 lang-words) ": " author "\n")
  2486. (when email
  2487. (if (listp (split-string email ",+ *"))
  2488. (mapc (lambda(e)
  2489. (insert "<a href=\"mailto:" e "\">&lt;"
  2490. e "&gt;</a>\n"))
  2491. (split-string email ",+ *"))
  2492. (insert "<a href=\"mailto:" email "\">&lt;"
  2493. email "&gt;</a>\n")))
  2494. (insert "</p>\n"))
  2495. (when (and date org-export-time-stamp-file)
  2496. (insert "<p class=\"date\"> "
  2497. (nth 2 lang-words) ": "
  2498. date "</p>\n"))
  2499. (insert "</div>"))
  2500. (if org-export-html-with-timestamp
  2501. (insert org-export-html-html-helper-timestamp))
  2502. (insert (or (plist-get opt-plist :postamble) ""))
  2503. (insert "</body>\n</html>\n"))
  2504. (normal-mode)
  2505. (if (eq major-mode default-major-mode) (html-mode))
  2506. ;; insert the table of contents
  2507. (goto-char (point-min))
  2508. (when thetoc
  2509. (if (or (re-search-forward
  2510. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  2511. (re-search-forward
  2512. "\\[TABLE-OF-CONTENTS\\]" nil t))
  2513. (progn
  2514. (goto-char (match-beginning 0))
  2515. (replace-match ""))
  2516. (goto-char first-heading-pos)
  2517. (when (looking-at "\\s-*</p>")
  2518. (goto-char (match-end 0))
  2519. (insert "\n")))
  2520. (insert "<div id=\"table-of-contents\">\n")
  2521. (mapc 'insert thetoc)
  2522. (insert "</div>\n"))
  2523. ;; remove empty paragraphs and lists
  2524. (goto-char (point-min))
  2525. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  2526. (replace-match ""))
  2527. (goto-char (point-min))
  2528. (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
  2529. (replace-match ""))
  2530. (goto-char (point-min))
  2531. (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
  2532. (replace-match ""))
  2533. ;; Convert whitespace place holders
  2534. (goto-char (point-min))
  2535. (let (beg end n)
  2536. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  2537. (setq n (get-text-property beg 'org-whitespace)
  2538. end (next-single-property-change beg 'org-whitespace))
  2539. (goto-char beg)
  2540. (delete-region beg end)
  2541. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  2542. (make-string n ?x)))))
  2543. (or to-buffer (save-buffer))
  2544. (goto-char (point-min))
  2545. (message "Exporting... done")
  2546. (if (eq to-buffer 'string)
  2547. (prog1 (buffer-substring (point-min) (point-max))
  2548. (kill-buffer (current-buffer)))
  2549. (current-buffer)))))
  2550. (defvar org-table-colgroup-info nil)
  2551. (defun org-format-table-ascii (lines)
  2552. "Format a table for ascii export."
  2553. (if (stringp lines)
  2554. (setq lines (org-split-string lines "\n")))
  2555. (if (not (string-match "^[ \t]*|" (car lines)))
  2556. ;; Table made by table.el - test for spanning
  2557. lines
  2558. ;; A normal org table
  2559. ;; Get rid of hlines at beginning and end
  2560. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2561. (setq lines (nreverse lines))
  2562. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2563. (setq lines (nreverse lines))
  2564. (when org-export-table-remove-special-lines
  2565. ;; Check if the table has a marking column. If yes remove the
  2566. ;; column and the special lines
  2567. (setq lines (org-table-clean-before-export lines)))
  2568. ;; Get rid of the vertical lines except for grouping
  2569. (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
  2570. rtn line vl1 start)
  2571. (while (setq line (pop lines))
  2572. (if (string-match org-table-hline-regexp line)
  2573. (and (string-match "|\\(.*\\)|" line)
  2574. (setq line (replace-match " \\1" t nil line)))
  2575. (setq start 0 vl1 vl)
  2576. (while (string-match "|" line start)
  2577. (setq start (match-end 0))
  2578. (or (pop vl1) (setq line (replace-match " " t t line)))))
  2579. (push line rtn))
  2580. (nreverse rtn))))
  2581. (defun org-colgroup-info-to-vline-list (info)
  2582. (let (vl new last)
  2583. (while info
  2584. (setq last new new (pop info))
  2585. (if (or (memq last '(:end :startend))
  2586. (memq new '(:start :startend)))
  2587. (push t vl)
  2588. (push nil vl)))
  2589. (setq vl (nreverse vl))
  2590. (and vl (setcar vl nil))
  2591. vl))
  2592. (defvar org-table-number-regexp) ; defined in org-table.el
  2593. (defun org-format-table-html (lines olines)
  2594. "Find out which HTML converter to use and return the HTML code."
  2595. (if (stringp lines)
  2596. (setq lines (org-split-string lines "\n")))
  2597. (if (string-match "^[ \t]*|" (car lines))
  2598. ;; A normal org table
  2599. (org-format-org-table-html lines)
  2600. ;; Table made by table.el - test for spanning
  2601. (let* ((hlines (delq nil (mapcar
  2602. (lambda (x)
  2603. (if (string-match "^[ \t]*\\+-" x) x
  2604. nil))
  2605. lines)))
  2606. (first (car hlines))
  2607. (ll (and (string-match "\\S-+" first)
  2608. (match-string 0 first)))
  2609. (re (concat "^[ \t]*" (regexp-quote ll)))
  2610. (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
  2611. hlines))))
  2612. (if (and (not spanning)
  2613. (not org-export-prefer-native-exporter-for-tables))
  2614. ;; We can use my own converter with HTML conversions
  2615. (org-format-table-table-html lines)
  2616. ;; Need to use the code generator in table.el, with the original text.
  2617. (org-format-table-table-html-using-table-generate-source olines)))))
  2618. (defvar org-table-number-fraction) ; defined in org-table.el
  2619. (defun org-format-org-table-html (lines &optional splice)
  2620. "Format a table into HTML."
  2621. (require 'org-table)
  2622. ;; Get rid of hlines at beginning and end
  2623. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2624. (setq lines (nreverse lines))
  2625. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  2626. (setq lines (nreverse lines))
  2627. (when org-export-table-remove-special-lines
  2628. ;; Check if the table has a marking column. If yes remove the
  2629. ;; column and the special lines
  2630. (setq lines (org-table-clean-before-export lines)))
  2631. (let ((head (and org-export-highlight-first-table-line
  2632. (delq nil (mapcar
  2633. (lambda (x) (string-match "^[ \t]*|-" x))
  2634. (cdr lines)))))
  2635. (nlines 0) fnum i
  2636. tbopen line fields html gr colgropen)
  2637. (if splice (setq head nil))
  2638. (unless splice (push (if head "<thead>" "<tbody>") html))
  2639. (setq tbopen t)
  2640. (while (setq line (pop lines))
  2641. (catch 'next-line
  2642. (if (string-match "^[ \t]*|-" line)
  2643. (progn
  2644. (unless splice
  2645. (push (if head "</thead>" "</tbody>") html)
  2646. (if lines (push "<tbody>" html) (setq tbopen nil)))
  2647. (setq head nil) ;; head ends here, first time around
  2648. ;; ignore this line
  2649. (throw 'next-line t)))
  2650. ;; Break the line into fields
  2651. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  2652. (unless fnum (setq fnum (make-vector (length fields) 0)))
  2653. (setq nlines (1+ nlines) i -1)
  2654. (push (concat "<tr>"
  2655. (mapconcat
  2656. (lambda (x)
  2657. (setq i (1+ i))
  2658. (if (and (< i nlines)
  2659. (string-match org-table-number-regexp x))
  2660. (incf (aref fnum i)))
  2661. (if head
  2662. (concat (car org-export-table-header-tags) x
  2663. (cdr org-export-table-header-tags))
  2664. (concat (car org-export-table-data-tags) x
  2665. (cdr org-export-table-data-tags))))
  2666. fields "")
  2667. "</tr>")
  2668. html)))
  2669. (unless splice (if tbopen (push "</tbody>" html)))
  2670. (unless splice (push "</table>\n" html))
  2671. (setq html (nreverse html))
  2672. (unless splice
  2673. ;; Put in col tags with the alignment (unfortuntely often ignored...)
  2674. (push (mapconcat
  2675. (lambda (x)
  2676. (setq gr (pop org-table-colgroup-info))
  2677. (format "%s<col align=\"%s\"></col>%s"
  2678. (if (memq gr '(:start :startend))
  2679. (prog1
  2680. (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
  2681. (setq colgropen t))
  2682. "")
  2683. (if (> (/ (float x) nlines) org-table-number-fraction)
  2684. "right" "left")
  2685. (if (memq gr '(:end :startend))
  2686. (progn (setq colgropen nil) "</colgroup>")
  2687. "")))
  2688. fnum "")
  2689. html)
  2690. (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
  2691. (push html-table-tag html))
  2692. (concat (mapconcat 'identity html "\n") "\n")))
  2693. (defun org-table-clean-before-export (lines)
  2694. "Check if the table has a marking column.
  2695. If yes remove the column and the special lines."
  2696. (setq org-table-colgroup-info nil)
  2697. (if (memq nil
  2698. (mapcar
  2699. (lambda (x) (or (string-match "^[ \t]*|-" x)
  2700. (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x)))
  2701. lines))
  2702. (progn
  2703. (setq org-table-clean-did-remove-column nil)
  2704. (delq nil
  2705. (mapcar
  2706. (lambda (x)
  2707. (cond
  2708. ((string-match "^[ \t]*| */ *|" x)
  2709. (setq org-table-colgroup-info
  2710. (mapcar (lambda (x)
  2711. (cond ((member x '("<" "&lt;")) :start)
  2712. ((member x '(">" "&gt;")) :end)
  2713. ((member x '("<>" "&lt;&gt;")) :startend)
  2714. (t nil)))
  2715. (org-split-string x "[ \t]*|[ \t]*")))
  2716. nil)
  2717. (t x)))
  2718. lines)))
  2719. (setq org-table-clean-did-remove-column t)
  2720. (delq nil
  2721. (mapcar
  2722. (lambda (x)
  2723. (cond
  2724. ((string-match "^[ \t]*| */ *|" x)
  2725. (setq org-table-colgroup-info
  2726. (mapcar (lambda (x)
  2727. (cond ((member x '("<" "&lt;")) :start)
  2728. ((member x '(">" "&gt;")) :end)
  2729. ((member x '("<>" "&lt;&gt;")) :startend)
  2730. (t nil)))
  2731. (cdr (org-split-string x "[ \t]*|[ \t]*"))))
  2732. nil)
  2733. ((string-match "^[ \t]*| *[!_^/] *|" x)
  2734. nil) ; ignore this line
  2735. ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
  2736. (string-match "^\\([ \t]*\\)|[^|]*|" x))
  2737. ;; remove the first column
  2738. (replace-match "\\1|" t nil x))))
  2739. lines))))
  2740. (defun org-format-table-table-html (lines)
  2741. "Format a table generated by table.el into HTML.
  2742. This conversion does *not* use `table-generate-source' from table.el.
  2743. This has the advantage that Org-mode's HTML conversions can be used.
  2744. But it has the disadvantage, that no cell- or row-spanning is allowed."
  2745. (let (line field-buffer
  2746. (head org-export-highlight-first-table-line)
  2747. fields html empty)
  2748. (setq html (concat html-table-tag "\n"))
  2749. (while (setq line (pop lines))
  2750. (setq empty "&nbsp;")
  2751. (catch 'next-line
  2752. (if (string-match "^[ \t]*\\+-" line)
  2753. (progn
  2754. (if field-buffer
  2755. (progn
  2756. (setq
  2757. html
  2758. (concat
  2759. html
  2760. "<tr>"
  2761. (mapconcat
  2762. (lambda (x)
  2763. (if (equal x "") (setq x empty))
  2764. (if head
  2765. (concat (car org-export-table-header-tags) x
  2766. (cdr org-export-table-header-tags))
  2767. (concat (car org-export-table-data-tags) x
  2768. (cdr org-export-table-data-tags))))
  2769. field-buffer "\n")
  2770. "</tr>\n"))
  2771. (setq head nil)
  2772. (setq field-buffer nil)))
  2773. ;; Ignore this line
  2774. (throw 'next-line t)))
  2775. ;; Break the line into fields and store the fields
  2776. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  2777. (if field-buffer
  2778. (setq field-buffer (mapcar
  2779. (lambda (x)
  2780. (concat x "<br/>" (pop fields)))
  2781. field-buffer))
  2782. (setq field-buffer fields))))
  2783. (setq html (concat html "</table>\n"))
  2784. html))
  2785. (defun org-format-table-table-html-using-table-generate-source (lines)
  2786. "Format a table into html, using `table-generate-source' from table.el.
  2787. This has the advantage that cell- or row-spanning is allowed.
  2788. But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
  2789. (require 'table)
  2790. (with-current-buffer (get-buffer-create " org-tmp1 ")
  2791. (erase-buffer)
  2792. (insert (mapconcat 'identity lines "\n"))
  2793. (goto-char (point-min))
  2794. (if (not (re-search-forward "|[^+]" nil t))
  2795. (error "Error processing table"))
  2796. (table-recognize-table)
  2797. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  2798. (table-generate-source 'html " org-tmp2 ")
  2799. (set-buffer " org-tmp2 ")
  2800. (buffer-substring (point-min) (point-max))))
  2801. (defun org-html-handle-time-stamps (s)
  2802. "Format time stamps in string S, or remove them."
  2803. (catch 'exit
  2804. (let (r b)
  2805. (while (string-match org-maybe-keyword-time-regexp s)
  2806. (if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
  2807. ;; never export CLOCK
  2808. (throw 'exit ""))
  2809. (or b (setq b (substring s 0 (match-beginning 0))))
  2810. (if (not org-export-with-timestamps)
  2811. (setq r (concat r (substring s 0 (match-beginning 0)))
  2812. s (substring s (match-end 0)))
  2813. (setq r (concat
  2814. r (substring s 0 (match-beginning 0))
  2815. (if (match-end 1)
  2816. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  2817. (match-string 1 s)))
  2818. (format " @<span class=\"timestamp\">%s@</span>"
  2819. (substring
  2820. (org-translate-time (match-string 3 s)) 1 -1)))
  2821. s (substring s (match-end 0)))))
  2822. ;; Line break if line started and ended with time stamp stuff
  2823. (if (not r)
  2824. s
  2825. (setq r (concat r s))
  2826. (unless (string-match "\\S-" (concat b s))
  2827. (setq r (concat r "@<br/>")))
  2828. r))))
  2829. (defun org-html-protect (s)
  2830. ;; convert & to &amp;, < to &lt; and > to &gt;
  2831. (let ((start 0))
  2832. (while (string-match "&" s start)
  2833. (setq s (replace-match "&amp;" t t s)
  2834. start (1+ (match-beginning 0))))
  2835. (while (string-match "<" s)
  2836. (setq s (replace-match "&lt;" t t s)))
  2837. (while (string-match ">" s)
  2838. (setq s (replace-match "&gt;" t t s))))
  2839. s)
  2840. (defun org-export-cleanup-toc-line (s)
  2841. "Remove tags and time staps from lines going into the toc."
  2842. (when (memq org-export-with-tags '(not-in-toc nil))
  2843. (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
  2844. (setq s (replace-match "" t t s))))
  2845. (when org-export-remove-timestamps-from-toc
  2846. (while (string-match org-maybe-keyword-time-regexp s)
  2847. (setq s (replace-match "" t t s))))
  2848. (while (string-match org-bracket-link-regexp s)
  2849. (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
  2850. t t s)))
  2851. s)
  2852. (defun org-html-expand (string)
  2853. "Prepare STRING for HTML export. Applies all active conversions.
  2854. If there are links in the string, don't modify these."
  2855. (let* ((re (concat org-bracket-link-regexp "\\|"
  2856. (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
  2857. m s l res)
  2858. (while (setq m (string-match re string))
  2859. (setq s (substring string 0 m)
  2860. l (match-string 0 string)
  2861. string (substring string (match-end 0)))
  2862. (push (org-html-do-expand s) res)
  2863. (push l res))
  2864. (push (org-html-do-expand string) res)
  2865. (apply 'concat (nreverse res))))
  2866. (defun org-html-do-expand (s)
  2867. "Apply all active conversions to translate special ASCII to HTML."
  2868. (setq s (org-html-protect s))
  2869. (if org-export-html-expand
  2870. (let ((start 0))
  2871. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  2872. (setq s (replace-match "<\\1>" t nil s)))))
  2873. (if org-export-with-emphasize
  2874. (setq s (org-export-html-convert-emphasize s)))
  2875. (if org-export-with-special-strings
  2876. (setq s (org-export-html-convert-special-strings s)))
  2877. (if org-export-with-sub-superscripts
  2878. (setq s (org-export-html-convert-sub-super s)))
  2879. (if org-export-with-TeX-macros
  2880. (let ((start 0) wd ass)
  2881. (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
  2882. (if (get-text-property (match-beginning 0) 'org-protected s)
  2883. (setq start (match-end 0))
  2884. (setq wd (match-string 1 s))
  2885. (if (setq ass (assoc wd org-html-entities))
  2886. (setq s (replace-match (or (cdr ass)
  2887. (concat "&" (car ass) ";"))
  2888. t t s))
  2889. (setq start (+ start (length wd))))))))
  2890. s)
  2891. (defun org-create-multibrace-regexp (left right n)
  2892. "Create a regular expression which will match a balanced sexp.
  2893. Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
  2894. as single character strings.
  2895. The regexp returned will match the entire expression including the
  2896. delimiters. It will also define a single group which contains the
  2897. match except for the outermost delimiters. The maximum depth of
  2898. stacked delimiters is N. Escaping delimiters is not possible."
  2899. (let* ((nothing (concat "[^" "\\" left "\\" right "]*?"))
  2900. (or "\\|")
  2901. (re nothing)
  2902. (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
  2903. (while (> n 1)
  2904. (setq n (1- n)
  2905. re (concat re or next)
  2906. next (concat "\\(?:" nothing left next right "\\)+" nothing)))
  2907. (concat left "\\(" re "\\)" right)))
  2908. (defvar org-match-substring-regexp
  2909. (concat
  2910. "\\([^\\]\\)\\([_^]\\)\\("
  2911. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  2912. "\\|"
  2913. "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
  2914. "\\|"
  2915. "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
  2916. "The regular expression matching a sub- or superscript.")
  2917. (defvar org-match-substring-with-braces-regexp
  2918. (concat
  2919. "\\([^\\]\\)\\([_^]\\)\\("
  2920. "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
  2921. "\\)")
  2922. "The regular expression matching a sub- or superscript, forcing braces.")
  2923. (defconst org-export-html-special-string-regexps
  2924. '(("\\\\-" . "&shy;")
  2925. ("---\\([^-]\\)" . "&mdash;\\1")
  2926. ("--\\([^-]\\)" . "&ndash;\\1")
  2927. ("\\.\\.\\." . "&hellip;"))
  2928. "Regular expressions for special string conversion.")
  2929. (defun org-export-html-convert-special-strings (string)
  2930. "Convert special characters in STRING to HTML."
  2931. (let ((all org-export-html-special-string-regexps)
  2932. e a re rpl start)
  2933. (while (setq a (pop all))
  2934. (setq re (car a) rpl (cdr a) start 0)
  2935. (while (string-match re string start)
  2936. (if (get-text-property (match-beginning 0) 'org-protected string)
  2937. (setq start (match-end 0))
  2938. (setq string (replace-match rpl t nil string)))))
  2939. string))
  2940. (defun org-export-html-convert-sub-super (string)
  2941. "Convert sub- and superscripts in STRING to HTML."
  2942. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  2943. (while (string-match org-match-substring-regexp string s)
  2944. (cond
  2945. ((and requireb (match-end 8)) (setq s (match-end 2)))
  2946. ((get-text-property (match-beginning 2) 'org-protected string)
  2947. (setq s (match-end 2)))
  2948. (t
  2949. (setq s (match-end 1)
  2950. key (if (string= (match-string 2 string) "_") "sub" "sup")
  2951. c (or (match-string 8 string)
  2952. (match-string 6 string)
  2953. (match-string 5 string))
  2954. string (replace-match
  2955. (concat (match-string 1 string)
  2956. "<" key ">" c "</" key ">")
  2957. t t string)))))
  2958. (while (string-match "\\\\\\([_^]\\)" string)
  2959. (setq string (replace-match (match-string 1 string) t t string)))
  2960. string))
  2961. (defun org-export-html-convert-emphasize (string)
  2962. "Apply emphasis."
  2963. (let ((s 0) rpl)
  2964. (while (string-match org-emph-re string s)
  2965. (if (not (equal
  2966. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  2967. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  2968. (setq s (match-beginning 0)
  2969. rpl
  2970. (concat
  2971. (match-string 1 string)
  2972. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  2973. (match-string 4 string)
  2974. (nth 3 (assoc (match-string 3 string)
  2975. org-emphasis-alist))
  2976. (match-string 5 string))
  2977. string (replace-match rpl t t string)
  2978. s (+ s (- (length rpl) 2)))
  2979. (setq s (1+ s))))
  2980. string))
  2981. (defvar org-par-open nil)
  2982. (defun org-open-par ()
  2983. "Insert <p>, but first close previous paragraph if any."
  2984. (org-close-par-maybe)
  2985. (insert "\n<p>")
  2986. (setq org-par-open t))
  2987. (defun org-close-par-maybe ()
  2988. "Close paragraph if there is one open."
  2989. (when org-par-open
  2990. (insert "</p>")
  2991. (setq org-par-open nil)))
  2992. (defun org-close-li ()
  2993. "Close <li> if necessary."
  2994. (org-close-par-maybe)
  2995. (insert "</li>\n"))
  2996. (defvar body-only) ; dynamically scoped into this.
  2997. (defun org-html-level-start (level title umax with-toc head-count)
  2998. "Insert a new level in HTML export.
  2999. When TITLE is nil, just close all open levels."
  3000. (org-close-par-maybe)
  3001. (let ((target (and title (org-get-text-property-any 0 'target title)))
  3002. (l org-level-max)
  3003. snumber)
  3004. (while (>= l level)
  3005. (if (aref org-levels-open (1- l))
  3006. (progn
  3007. (org-html-level-close l umax)
  3008. (aset org-levels-open (1- l) nil)))
  3009. (setq l (1- l)))
  3010. (when title
  3011. ;; If title is nil, this means this function is called to close
  3012. ;; all levels, so the rest is done only if title is given
  3013. (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  3014. (setq title (replace-match
  3015. (if org-export-with-tags
  3016. (save-match-data
  3017. (concat
  3018. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  3019. (mapconcat 'identity (org-split-string
  3020. (match-string 1 title) ":")
  3021. "&nbsp;")
  3022. "</span>"))
  3023. "")
  3024. t t title)))
  3025. (if (> level umax)
  3026. (progn
  3027. (if (aref org-levels-open (1- level))
  3028. (progn
  3029. (org-close-li)
  3030. (if target
  3031. (insert (format "<li id=\"%s\">" target) title "<br/>\n")
  3032. (insert "<li>" title "<br/>\n")))
  3033. (aset org-levels-open (1- level) t)
  3034. (org-close-par-maybe)
  3035. (if target
  3036. (insert (format "<ul>\n<li id=\"%s\">" target)
  3037. title "<br/>\n")
  3038. (insert "<ul>\n<li>" title "<br/>\n"))))
  3039. (aset org-levels-open (1- level) t)
  3040. (setq snumber (org-section-number level))
  3041. (if (and org-export-with-section-numbers (not body-only))
  3042. (setq title (concat snumber " " title)))
  3043. (setq level (+ level org-export-html-toplevel-hlevel -1))
  3044. (unless (= head-count 1) (insert "\n</div>\n"))
  3045. (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"
  3046. snumber level level snumber title level snumber))
  3047. (org-open-par)))))
  3048. (defun org-get-text-property-any (pos prop &optional object)
  3049. (or (get-text-property pos prop object)
  3050. (and (setq pos (next-single-property-change pos prop object))
  3051. (get-text-property pos prop object))))
  3052. (defun org-html-level-close (level max-outline-level)
  3053. "Terminate one level in HTML export."
  3054. (if (<= level max-outline-level)
  3055. (insert "</div>\n")
  3056. (org-close-li)
  3057. (insert "</ul>\n")))
  3058. ;;; iCalendar export
  3059. ;;;###autoload
  3060. (defun org-export-icalendar-this-file ()
  3061. "Export current file as an iCalendar file.
  3062. The iCalendar file will be located in the same directory as the Org-mode
  3063. file, but with extension `.ics'."
  3064. (interactive)
  3065. (org-export-icalendar nil buffer-file-name))
  3066. ;;;###autoload
  3067. (defun org-export-icalendar-all-agenda-files ()
  3068. "Export all files in `org-agenda-files' to iCalendar .ics files.
  3069. Each iCalendar file will be located in the same directory as the Org-mode
  3070. file, but with extension `.ics'."
  3071. (interactive)
  3072. (apply 'org-export-icalendar nil (org-agenda-files t)))
  3073. ;;;###autoload
  3074. (defun org-export-icalendar-combine-agenda-files ()
  3075. "Export all files in `org-agenda-files' to a single combined iCalendar file.
  3076. The file is stored under the name `org-combined-agenda-icalendar-file'."
  3077. (interactive)
  3078. (apply 'org-export-icalendar t (org-agenda-files t)))
  3079. (defun org-export-icalendar (combine &rest files)
  3080. "Create iCalendar files for all elements of FILES.
  3081. If COMBINE is non-nil, combine all calendar entries into a single large
  3082. file and store it under the name `org-combined-agenda-icalendar-file'."
  3083. (save-excursion
  3084. (org-prepare-agenda-buffers files)
  3085. (let* ((dir (org-export-directory
  3086. :ical (list :publishing-directory
  3087. org-export-publishing-directory)))
  3088. file ical-file ical-buffer category started org-agenda-new-buffers)
  3089. (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
  3090. (when combine
  3091. (setq ical-file
  3092. (if (file-name-absolute-p org-combined-agenda-icalendar-file)
  3093. org-combined-agenda-icalendar-file
  3094. (expand-file-name org-combined-agenda-icalendar-file dir))
  3095. ical-buffer (org-get-agenda-file-buffer ical-file))
  3096. (set-buffer ical-buffer) (erase-buffer))
  3097. (while (setq file (pop files))
  3098. (catch 'nextfile
  3099. (org-check-agenda-file file)
  3100. (set-buffer (org-get-agenda-file-buffer file))
  3101. (unless combine
  3102. (setq ical-file (concat (file-name-as-directory dir)
  3103. (file-name-sans-extension
  3104. (file-name-nondirectory buffer-file-name))
  3105. ".ics"))
  3106. (setq ical-buffer (org-get-agenda-file-buffer ical-file))
  3107. (with-current-buffer ical-buffer (erase-buffer)))
  3108. (setq category (or org-category
  3109. (file-name-sans-extension
  3110. (file-name-nondirectory buffer-file-name))))
  3111. (if (symbolp category) (setq category (symbol-name category)))
  3112. (let ((standard-output ical-buffer))
  3113. (if combine
  3114. (and (not started) (setq started t)
  3115. (org-start-icalendar-file org-icalendar-combined-name))
  3116. (org-start-icalendar-file category))
  3117. (org-print-icalendar-entries combine)
  3118. (when (or (and combine (not files)) (not combine))
  3119. (org-finish-icalendar-file)
  3120. (set-buffer ical-buffer)
  3121. (save-buffer)
  3122. (run-hooks 'org-after-save-iCalendar-file-hook)))))
  3123. (org-release-buffers org-agenda-new-buffers))))
  3124. (defvar org-after-save-iCalendar-file-hook nil
  3125. "Hook run after an iCalendar file has been saved.
  3126. The iCalendar buffer is still current when this hook is run.
  3127. A good way to use this is to tell a desktop calenndar application to re-read
  3128. the iCalendar file.")
  3129. (defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
  3130. (defun org-print-icalendar-entries (&optional combine)
  3131. "Print iCalendar entries for the current Org-mode file to `standard-output'.
  3132. When COMBINE is non nil, add the category to each line."
  3133. (require 'org-agenda)
  3134. (let ((re1 (concat org-ts-regexp "\\|<%%([^>\n]+>"))
  3135. (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
  3136. (dts (org-ical-ts-to-string
  3137. (format-time-string (cdr org-time-stamp-formats) (current-time))
  3138. "DTSTART"))
  3139. hd ts ts2 state status (inc t) pos b sexp rrule
  3140. scheduledp deadlinep tmp pri category entry location summary desc
  3141. (sexp-buffer (get-buffer-create "*ical-tmp*")))
  3142. (org-refresh-category-properties)
  3143. (save-excursion
  3144. (goto-char (point-min))
  3145. (while (re-search-forward re1 nil t)
  3146. (catch :skip
  3147. (org-agenda-skip)
  3148. (when (boundp 'org-icalendar-verify-function)
  3149. (unless (funcall org-icalendar-verify-function)
  3150. (outline-next-heading)
  3151. (backward-char 1)
  3152. (throw :skip nil)))
  3153. (setq pos (match-beginning 0)
  3154. ts (match-string 0)
  3155. inc t
  3156. hd (condition-case nil (org-get-heading)
  3157. (error (throw :skip nil)))
  3158. summary (org-icalendar-cleanup-string
  3159. (org-entry-get nil "SUMMARY"))
  3160. desc (org-icalendar-cleanup-string
  3161. (or (org-entry-get nil "DESCRIPTION")
  3162. (and org-icalendar-include-body (org-get-entry)))
  3163. t org-icalendar-include-body)
  3164. location (org-icalendar-cleanup-string
  3165. (org-entry-get nil "LOCATION"))
  3166. category (org-get-category))
  3167. (if (looking-at re2)
  3168. (progn
  3169. (goto-char (match-end 0))
  3170. (setq ts2 (match-string 1) inc nil))
  3171. (setq tmp (buffer-substring (max (point-min)
  3172. (- pos org-ds-keyword-length))
  3173. pos)
  3174. ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
  3175. (progn
  3176. (setq inc nil)
  3177. (replace-match "\\1" t nil ts))
  3178. ts)
  3179. deadlinep (string-match org-deadline-regexp tmp)
  3180. scheduledp (string-match org-scheduled-regexp tmp)
  3181. ;; donep (org-entry-is-done-p)
  3182. ))
  3183. (if (or (string-match org-tr-regexp hd)
  3184. (string-match org-ts-regexp hd))
  3185. (setq hd (replace-match "" t t hd)))
  3186. (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts)
  3187. (setq rrule
  3188. (concat "\nRRULE:FREQ="
  3189. (cdr (assoc
  3190. (match-string 2 ts)
  3191. '(("d" . "DAILY")("w" . "WEEKLY")
  3192. ("m" . "MONTHLY")("y" . "YEARLY"))))
  3193. ";INTERVAL=" (match-string 1 ts)))
  3194. (setq rrule ""))
  3195. (setq summary (or summary hd))
  3196. (if (string-match org-bracket-link-regexp summary)
  3197. (setq summary
  3198. (replace-match (if (match-end 3)
  3199. (match-string 3 summary)
  3200. (match-string 1 summary))
  3201. t t summary)))
  3202. (if deadlinep (setq summary (concat "DL: " summary)))
  3203. (if scheduledp (setq summary (concat "S: " summary)))
  3204. (if (string-match "\\`<%%" ts)
  3205. (with-current-buffer sexp-buffer
  3206. (insert (substring ts 1 -1) " " summary "\n"))
  3207. (princ (format "BEGIN:VEVENT
  3208. %s
  3209. %s%s
  3210. SUMMARY:%s%s%s
  3211. CATEGORIES:%s
  3212. END:VEVENT\n"
  3213. (org-ical-ts-to-string ts "DTSTART")
  3214. (org-ical-ts-to-string ts2 "DTEND" inc)
  3215. rrule summary
  3216. (if (and desc (string-match "\\S-" desc))
  3217. (concat "\nDESCRIPTION: " desc) "")
  3218. (if (and location (string-match "\\S-" location))
  3219. (concat "\nLOCATION: " location) "")
  3220. category)))))
  3221. (when (and org-icalendar-include-sexps
  3222. (condition-case nil (require 'icalendar) (error nil))
  3223. (fboundp 'icalendar-export-region))
  3224. ;; Get all the literal sexps
  3225. (goto-char (point-min))
  3226. (while (re-search-forward "^&?%%(" nil t)
  3227. (catch :skip
  3228. (org-agenda-skip)
  3229. (setq b (match-beginning 0))
  3230. (goto-char (1- (match-end 0)))
  3231. (forward-sexp 1)
  3232. (end-of-line 1)
  3233. (setq sexp (buffer-substring b (point)))
  3234. (with-current-buffer sexp-buffer
  3235. (insert sexp "\n"))
  3236. (princ (org-diary-to-ical-string sexp-buffer)))))
  3237. (when org-icalendar-include-todo
  3238. (goto-char (point-min))
  3239. (while (re-search-forward org-todo-line-regexp nil t)
  3240. (catch :skip
  3241. (org-agenda-skip)
  3242. (when (boundp 'org-icalendar-verify-function)
  3243. (unless (funcall org-icalendar-verify-function)
  3244. (outline-next-heading)
  3245. (backward-char 1)
  3246. (throw :skip nil)))
  3247. (setq state (match-string 2))
  3248. (setq status (if (member state org-done-keywords)
  3249. "COMPLETED" "NEEDS-ACTION"))
  3250. (when (and state
  3251. (or (not (member state org-done-keywords))
  3252. (eq org-icalendar-include-todo 'all))
  3253. (not (member org-archive-tag (org-get-tags-at)))
  3254. )
  3255. (setq hd (match-string 3)
  3256. summary (org-icalendar-cleanup-string
  3257. (org-entry-get nil "SUMMARY"))
  3258. desc (org-icalendar-cleanup-string
  3259. (or (org-entry-get nil "DESCRIPTION")
  3260. (and org-icalendar-include-body (org-get-entry)))
  3261. t org-icalendar-include-body)
  3262. location (org-icalendar-cleanup-string
  3263. (org-entry-get nil "LOCATION")))
  3264. (if (string-match org-bracket-link-regexp hd)
  3265. (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
  3266. (match-string 1 hd))
  3267. t t hd)))
  3268. (if (string-match org-priority-regexp hd)
  3269. (setq pri (string-to-char (match-string 2 hd))
  3270. hd (concat (substring hd 0 (match-beginning 1))
  3271. (substring hd (match-end 1))))
  3272. (setq pri org-default-priority))
  3273. (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
  3274. (- org-lowest-priority org-highest-priority))))))
  3275. (princ (format "BEGIN:VTODO
  3276. %s
  3277. SUMMARY:%s%s%s
  3278. CATEGORIES:%s
  3279. SEQUENCE:1
  3280. PRIORITY:%d
  3281. STATUS:%s
  3282. END:VTODO\n"
  3283. dts
  3284. (or summary hd)
  3285. (if (and location (string-match "\\S-" location))
  3286. (concat "\nLOCATION: " location) "")
  3287. (if (and desc (string-match "\\S-" desc))
  3288. (concat "\nDESCRIPTION: " desc) "")
  3289. category pri status)))))))))
  3290. (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
  3291. "Take out stuff and quote what needs to be quoted.
  3292. When IS-BODY is non-nil, assume that this is the body of an item, clean up
  3293. whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
  3294. characters."
  3295. (if (not s)
  3296. nil
  3297. (when is-body
  3298. (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
  3299. (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
  3300. (while (string-match re s) (setq s (replace-match "" t t s)))
  3301. (while (string-match re2 s) (setq s (replace-match "" t t s)))))
  3302. (let ((start 0))
  3303. (while (string-match "\\([,;\\]\\)" s start)
  3304. (setq start (+ (match-beginning 0) 2)
  3305. s (replace-match "\\\\\\1" nil nil s))))
  3306. (when is-body
  3307. (while (string-match "[ \t]*\n[ \t]*" s)
  3308. (setq s (replace-match "\\n" t t s))))
  3309. (setq s (org-trim s))
  3310. (if is-body
  3311. (if maxlength
  3312. (if (and (numberp maxlength)
  3313. (> (length s) maxlength))
  3314. (setq s (substring s 0 maxlength)))))
  3315. s))
  3316. (defun org-get-entry ()
  3317. "Clean-up description string."
  3318. (save-excursion
  3319. (org-back-to-heading t)
  3320. (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
  3321. (defun org-start-icalendar-file (name)
  3322. "Start an iCalendar file by inserting the header."
  3323. (let ((user user-full-name)
  3324. (name (or name "unknown"))
  3325. (timezone (cadr (current-time-zone))))
  3326. (princ
  3327. (format "BEGIN:VCALENDAR
  3328. VERSION:2.0
  3329. X-WR-CALNAME:%s
  3330. PRODID:-//%s//Emacs with Org-mode//EN
  3331. X-WR-TIMEZONE:%s
  3332. CALSCALE:GREGORIAN\n" name user timezone))))
  3333. (defun org-finish-icalendar-file ()
  3334. "Finish an iCalendar file by inserting the END statement."
  3335. (princ "END:VCALENDAR\n"))
  3336. (defun org-ical-ts-to-string (s keyword &optional inc)
  3337. "Take a time string S and convert it to iCalendar format.
  3338. KEYWORD is added in front, to make a complete line like DTSTART....
  3339. When INC is non-nil, increase the hour by two (if time string contains
  3340. a time), or the day by one (if it does not contain a time)."
  3341. (let ((t1 (org-parse-time-string s 'nodefault))
  3342. t2 fmt have-time time)
  3343. (if (and (car t1) (nth 1 t1) (nth 2 t1))
  3344. (setq t2 t1 have-time t)
  3345. (setq t2 (org-parse-time-string s)))
  3346. (let ((s (car t2)) (mi (nth 1 t2)) (h (nth 2 t2))
  3347. (d (nth 3 t2)) (m (nth 4 t2)) (y (nth 5 t2)))
  3348. (when inc
  3349. (if have-time
  3350. (if org-agenda-default-appointment-duration
  3351. (setq mi (+ org-agenda-default-appointment-duration mi))
  3352. (setq h (+ 2 h)))
  3353. (setq d (1+ d))))
  3354. (setq time (encode-time s mi h d m y)))
  3355. (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
  3356. (concat keyword (format-time-string fmt time))))
  3357. ;;; XOXO export
  3358. (defun org-export-as-xoxo-insert-into (buffer &rest output)
  3359. (with-current-buffer buffer
  3360. (apply 'insert output)))
  3361. (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
  3362. ;;;###autoload
  3363. (defun org-export-as-xoxo (&optional buffer)
  3364. "Export the org buffer as XOXO.
  3365. The XOXO buffer is named *xoxo-<source buffer name>*"
  3366. (interactive (list (current-buffer)))
  3367. ;; A quickie abstraction
  3368. ;; Output everything as XOXO
  3369. (with-current-buffer (get-buffer buffer)
  3370. (let* ((pos (point))
  3371. (opt-plist (org-combine-plists (org-default-export-plist)
  3372. (org-infile-export-plist)))
  3373. (filename (concat (file-name-as-directory
  3374. (org-export-directory :xoxo opt-plist))
  3375. (file-name-sans-extension
  3376. (file-name-nondirectory buffer-file-name))
  3377. ".html"))
  3378. (out (find-file-noselect filename))
  3379. (last-level 1)
  3380. (hanging-li nil))
  3381. (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
  3382. ;; Check the output buffer is empty.
  3383. (with-current-buffer out (erase-buffer))
  3384. ;; Kick off the output
  3385. (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
  3386. (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
  3387. (let* ((hd (match-string-no-properties 1))
  3388. (level (length hd))
  3389. (text (concat
  3390. (match-string-no-properties 2)
  3391. (save-excursion
  3392. (goto-char (match-end 0))
  3393. (let ((str ""))
  3394. (catch 'loop
  3395. (while 't
  3396. (forward-line)
  3397. (if (looking-at "^[ \t]\\(.*\\)")
  3398. (setq str (concat str (match-string-no-properties 1)))
  3399. (throw 'loop str)))))))))
  3400. ;; Handle level rendering
  3401. (cond
  3402. ((> level last-level)
  3403. (org-export-as-xoxo-insert-into out "\n<ol>\n"))
  3404. ((< level last-level)
  3405. (dotimes (- (- last-level level) 1)
  3406. (if hanging-li
  3407. (org-export-as-xoxo-insert-into out "</li>\n"))
  3408. (org-export-as-xoxo-insert-into out "</ol>\n"))
  3409. (when hanging-li
  3410. (org-export-as-xoxo-insert-into out "</li>\n")
  3411. (setq hanging-li nil)))
  3412. ((equal level last-level)
  3413. (if hanging-li
  3414. (org-export-as-xoxo-insert-into out "</li>\n")))
  3415. )
  3416. (setq last-level level)
  3417. ;; And output the new li
  3418. (setq hanging-li 't)
  3419. (if (equal ?+ (elt text 0))
  3420. (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
  3421. (org-export-as-xoxo-insert-into out "<li>" text))))
  3422. ;; Finally finish off the ol
  3423. (dotimes (- last-level 1)
  3424. (if hanging-li
  3425. (org-export-as-xoxo-insert-into out "</li>\n"))
  3426. (org-export-as-xoxo-insert-into out "</ol>\n"))
  3427. (goto-char pos)
  3428. ;; Finish the buffer off and clean it up.
  3429. (switch-to-buffer-other-window out)
  3430. (indent-region (point-min) (point-max) nil)
  3431. (save-buffer)
  3432. (goto-char (point-min))
  3433. )))
  3434. (provide 'org-exp)
  3435. ;;; org-exp.el ends here
  3436. (defun org-export-process-option-filters (plist)
  3437. (let ((functions org-export-options-filters) f)
  3438. (while (setq f (pop functions))
  3439. (setq plist (funcall f plist))))
  3440. plist)