org-exp.el 134 KB

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