org-e-odt.el 147 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231
  1. ;;; org-e-odt.el --- OpenDocument Text exporter for Org-mode
  2. ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
  3. ;; Author: Jambunathan K <kjambunathan at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;; Code:
  19. (eval-when-compile
  20. (require 'cl))
  21. (require 'org-export)
  22. ;;; Define Back-End
  23. (defvar org-e-odt-translate-alist
  24. '((babel-call . org-e-odt-babel-call)
  25. (bold . org-e-odt-bold)
  26. (center-block . org-e-odt-center-block)
  27. (clock . org-e-odt-clock)
  28. (code . org-e-odt-code)
  29. (comment . org-e-odt-comment)
  30. (comment-block . org-e-odt-comment-block)
  31. (drawer . org-e-odt-drawer)
  32. (dynamic-block . org-e-odt-dynamic-block)
  33. (entity . org-e-odt-entity)
  34. (example-block . org-e-odt-example-block)
  35. (export-block . org-e-odt-export-block)
  36. (export-snippet . org-e-odt-export-snippet)
  37. (fixed-width . org-e-odt-fixed-width)
  38. (footnote-definition . org-e-odt-footnote-definition)
  39. (footnote-reference . org-e-odt-footnote-reference)
  40. (headline . org-e-odt-headline)
  41. (horizontal-rule . org-e-odt-horizontal-rule)
  42. (inline-babel-call . org-e-odt-inline-babel-call)
  43. (inline-src-block . org-e-odt-inline-src-block)
  44. (inlinetask . org-e-odt-inlinetask)
  45. (italic . org-e-odt-italic)
  46. (item . org-e-odt-item)
  47. (keyword . org-e-odt-keyword)
  48. (latex-environment . org-e-odt-latex-environment)
  49. (latex-fragment . org-e-odt-latex-fragment)
  50. (line-break . org-e-odt-line-break)
  51. (link . org-e-odt-link)
  52. (macro . org-e-odt-macro)
  53. (paragraph . org-e-odt-paragraph)
  54. (plain-list . org-e-odt-plain-list)
  55. (plain-text . org-e-odt-plain-text)
  56. (planning . org-e-odt-planning)
  57. (property-drawer . org-e-odt-property-drawer)
  58. (quote-block . org-e-odt-quote-block)
  59. (quote-section . org-e-odt-quote-section)
  60. (radio-target . org-e-odt-radio-target)
  61. (section . org-e-odt-section)
  62. (special-block . org-e-odt-special-block)
  63. (src-block . org-e-odt-src-block)
  64. (statistics-cookie . org-e-odt-statistics-cookie)
  65. (strike-through . org-e-odt-strike-through)
  66. (subscript . org-e-odt-subscript)
  67. (superscript . org-e-odt-superscript)
  68. (table . org-e-odt-table)
  69. (table-cell . org-e-odt-table-cell)
  70. (table-row . org-e-odt-table-row)
  71. (target . org-e-odt-target)
  72. (template . org-e-odt-template)
  73. (timestamp . org-e-odt-timestamp)
  74. (underline . org-e-odt-underline)
  75. (verbatim . org-e-odt-verbatim)
  76. (verse-block . org-e-odt-verse-block))
  77. "Alist between element or object types and translators.")
  78. (defconst org-e-odt-options-alist
  79. '(
  80. ;; (:agenda-style nil nil org-agenda-export-html-style)
  81. ;; ;; (:expand-quoted-html nil "@" org-e-odt-expand)
  82. ;; ;; (:timestamp nil nil org-e-odt-with-timestamp)
  83. (:odt-styles-file "ODT_STYLES_FILE" nil nil t)
  84. (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments))
  85. "Alist between ODT export properties and ways to set them.
  86. See `org-export-options-alist' for more information on the
  87. structure of the values.")
  88. ;; FIXMES
  89. ;; org-e-odt-preprocess-latex-fragments
  90. ;; org-export-as-e-odt-and-open
  91. ;; org-export-as-e-odt-batch
  92. ;; org-export-as-e-odt
  93. (defun org-e-odt-get-style-name-for-entity (category &optional entity)
  94. (let ((entity (or entity 'default)))
  95. (or
  96. (cdr (assoc entity (cdr (assoc category
  97. org-e-odt-org-styles-alist))))
  98. (cdr (assoc entity (cdr (assoc category
  99. org-e-odt-default-org-styles-alist))))
  100. (error "Cannot determine style name for entity %s of type %s"
  101. entity category))))
  102. ;; Following variable is let bound when `org-do-lparse' is in
  103. ;; progress. See org-html.el.
  104. (defun org-e-odt-format-preamble (info)
  105. (let* ((title (org-export-data (plist-get info :title) info))
  106. (author (and (plist-get info :with-author)
  107. (let ((auth (plist-get info :author)))
  108. (and auth (org-export-data auth info)))))
  109. (date (plist-get info :date))
  110. (iso-date (org-e-odt-format-date date))
  111. (date (org-e-odt-format-date date "%d %b %Y"))
  112. (email (plist-get info :email))
  113. ;; switch on or off above vars based on user settings
  114. (author (and (plist-get info :with-author) (or author email)))
  115. ;; (date (and (plist-get info :time-stamp-file) date))
  116. (email (and (plist-get info :with-email) email)))
  117. (concat
  118. ;; title
  119. (when title
  120. (concat
  121. (org-e-odt-format-stylized-paragraph
  122. 'title (format "\n<text:title>%s</text:title>" title))
  123. ;; separator
  124. "\n<text:p text:style-name=\"OrgTitle\"/>"))
  125. (cond
  126. ((and author (not email))
  127. ;; author only
  128. (concat
  129. (org-e-odt-format-stylized-paragraph
  130. 'subtitle
  131. (format "<text:initial-creator>%s</text:initial-creator>" author))
  132. ;; separator
  133. "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
  134. ((and author email)
  135. ;; author and email
  136. (concat
  137. (org-e-odt-format-stylized-paragraph
  138. 'subtitle
  139. (org-e-odt-format-link
  140. (format "<text:initial-creator>%s</text:initial-creator>" author)
  141. (concat "mailto:" email)))
  142. ;; separator
  143. "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
  144. ;; date
  145. (when date
  146. (concat
  147. (org-e-odt-format-stylized-paragraph
  148. 'subtitle
  149. (org-e-odt-format-tags
  150. '("<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">"
  151. . "</text:date>")
  152. date "N75" iso-date))
  153. ;; separator
  154. "<text:p text:style-name=\"OrgSubtitle\"/>")))))
  155. (defun org-e-odt-begin-section (style &optional name)
  156. (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
  157. (format "<text:section text:style-name=\"%s\" text:name=\"%s\">"
  158. style (or name default-name))))
  159. (defun org-e-odt-end-section ()
  160. "</text:section>")
  161. (defun org-e-odt-begin-paragraph (&optional style)
  162. (format "<text:p%s>" (org-e-odt-get-extra-attrs-for-paragraph-style style)))
  163. (defun org-e-odt-end-paragraph ()
  164. "</text:p>")
  165. (defun org-e-odt-get-extra-attrs-for-paragraph-style (style)
  166. (let (style-name)
  167. (setq style-name
  168. (cond
  169. ((stringp style) style)
  170. ((symbolp style) (org-e-odt-get-style-name-for-entity
  171. 'paragraph style))))
  172. (unless style-name
  173. (error "Don't know how to handle paragraph style %s" style))
  174. (format " text:style-name=\"%s\"" style-name)))
  175. (defun org-e-odt-format-stylized-paragraph (style text)
  176. (format "\n<text:p%s>%s</text:p>"
  177. (org-e-odt-get-extra-attrs-for-paragraph-style style)
  178. text))
  179. (defun org-e-odt-format-author (&optional author )
  180. (when (setq author (or author (plist-get org-lparse-opt-plist :author)))
  181. (format "<dc:creator>%s</dc:creator>" author)))
  182. (defun org-e-odt-format-date (&optional org-ts fmt)
  183. (save-match-data
  184. (let* ((time
  185. (and (stringp org-ts)
  186. (string-match org-ts-regexp0 org-ts)
  187. (apply 'encode-time
  188. (org-fix-decoded-time
  189. (org-parse-time-string (match-string 0 org-ts) t)))))
  190. date)
  191. (cond
  192. (fmt (format-time-string fmt time))
  193. (t (setq date (format-time-string "%Y-%m-%dT%H:%M:%S%z" time))
  194. (format "%s:%s" (substring date 0 -2) (substring date -2)))))))
  195. (defun org-e-odt-begin-annotation (&optional author date)
  196. (concat
  197. "<office:annotation>\n"
  198. (and author (org-e-odt-format-author author))
  199. (org-e-odt-format-tags
  200. '("<dc:date>" . "</dc:date>")
  201. (org-e-odt-format-date
  202. (or date (plist-get org-lparse-opt-plist :date))))
  203. (org-e-odt-begin-paragraph)))
  204. (defun org-e-odt-end-annotation ()
  205. "</office:annotation>")
  206. (defun org-e-odt-begin-plain-list (ltype &optional continue-numbering)
  207. (let* ((style-name (org-e-odt-get-style-name-for-entity 'list ltype))
  208. (extra (concat
  209. (if continue-numbering
  210. " text:continue-numbering=\"true\""
  211. " text:continue-numbering=\"false\"")
  212. (when style-name
  213. (format " text:style-name=\"%s\"" style-name)))))
  214. (case ltype
  215. ((ordered unordered descriptive)
  216. (concat
  217. ;; (org-e-odt-end-paragraph)
  218. (format "<text:list%s>" extra)))
  219. (t (error "Unknown list type: %s" ltype)))))
  220. (defun org-e-odt-end-plain-list (ltype)
  221. (if ltype "</text:list>"
  222. (error "Unknown list type: %s" ltype)))
  223. (defun org-e-odt-begin-list-item (ltype &optional arg headline)
  224. (case ltype
  225. (ordered
  226. (assert (not headline) t)
  227. (let* ((counter arg) (extra ""))
  228. ;; "<text:list-header>"
  229. "<text:list-item>"))
  230. (unordered
  231. (let* ((id arg) (extra ""))
  232. (concat
  233. ;; "<text:list-header>"
  234. "<text:list-item>"
  235. (if headline (org-e-odt-format-target headline id)
  236. (org-e-odt-format-bookmark "" id)))))
  237. (descriptive
  238. (assert (not headline) t)
  239. (let ((term (or arg "(no term)")))
  240. (concat
  241. (org-e-odt-format-tags
  242. '("<text:list-item>" . "</text:list-item>")
  243. (org-e-odt-format-stylized-paragraph 'definition-term term))
  244. (org-e-odt-begin-list-item 'unordered)
  245. (org-e-odt-begin-plain-list 'descriptive)
  246. (org-e-odt-begin-list-item 'unordered))))
  247. (t (error "Unknown list type"))))
  248. (defun org-e-odt-end-list-item (ltype)
  249. (case ltype
  250. ((ordered unordered)
  251. ;; "</text:list-header>"
  252. "</text:list-item>")
  253. (descriptive
  254. (concat
  255. (org-e-odt-end-list-item 'unordered)
  256. (org-e-odt-end-plain-list 'descriptive)
  257. (org-e-odt-end-list-item 'unordered)
  258. ))
  259. (t (error "Unknown list type"))))
  260. (defun org-e-odt-write-automatic-styles ()
  261. "Write automatic styles to \"content.xml\"."
  262. (with-current-buffer
  263. (find-file-noselect (expand-file-name "content.xml") t)
  264. ;; position the cursor
  265. (goto-char (point-min))
  266. (re-search-forward " </office:automatic-styles>" nil t)
  267. (goto-char (match-beginning 0))
  268. ;; write automatic table styles
  269. (loop for (style-name props) in
  270. (plist-get org-e-odt-automatic-styles 'Table) do
  271. (when (setq props (or (plist-get props :rel-width) 96))
  272. (insert (format org-e-odt-table-style-format style-name props))))))
  273. (defun org-e-odt-update-display-level (&optional level)
  274. (with-current-buffer
  275. (find-file-noselect (expand-file-name "content.xml") t)
  276. ;; position the cursor.
  277. (goto-char (point-min))
  278. ;; remove existing sequence decls.
  279. (when (re-search-forward "<text:sequence-decls" nil t)
  280. (delete-region (match-beginning 0)
  281. (re-search-forward "</text:sequence-decls>" nil nil)))
  282. ;; insert new ones.
  283. (insert "
  284. <text:sequence-decls>")
  285. (loop for x in org-e-odt-category-map-alist
  286. do (insert (format "
  287. <text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
  288. level (nth 1 x))))
  289. (insert "
  290. </text:sequence-decls>")))
  291. (defun org-e-odt-add-automatic-style (object-type &optional object-props)
  292. "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
  293. OBJECT-PROPS is (typically) a plist created by passing
  294. \"#+ATTR_ODT: \" option of the object in question to
  295. `org-e-odt-parse-block-attributes'.
  296. Use `org-e-odt-object-counters' to generate an automatic
  297. OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
  298. new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
  299. . STYLE-NAME)."
  300. (assert (stringp object-type))
  301. (let* ((object (intern object-type))
  302. (seqvar object)
  303. (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar) 0)))
  304. (object-name (format "%s%d" object-type seqno)) style-name)
  305. (setq org-e-odt-object-counters
  306. (plist-put org-e-odt-object-counters seqvar seqno))
  307. (when object-props
  308. (setq style-name (format "Org%s" object-name))
  309. (setq org-e-odt-automatic-styles
  310. (plist-put org-e-odt-automatic-styles object
  311. (append (list (list style-name object-props))
  312. (plist-get org-e-odt-automatic-styles object)))))
  313. (cons object-name style-name)))
  314. (defun org-e-odt-begin-toc (lang-specific-heading max-level)
  315. (concat
  316. (format "
  317. <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
  318. <text:table-of-content-source text:outline-level=\"%d\">
  319. <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
  320. " max-level lang-specific-heading)
  321. (let ((entry-templates ""))
  322. (loop for level from 1 upto 10
  323. do (setq entry-templates
  324. (concat entry-templates
  325. (format
  326. "
  327. <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
  328. <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
  329. <text:index-entry-chapter/>
  330. <text:index-entry-text/>
  331. <text:index-entry-link-end/>
  332. </text:table-of-content-entry-template>
  333. " level level))))
  334. entry-templates)
  335. (format "
  336. </text:table-of-content-source>
  337. <text:index-body>
  338. <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
  339. <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
  340. </text:index-title>
  341. " lang-specific-heading)))
  342. (defun org-e-odt-end-toc ()
  343. (format "
  344. </text:index-body>
  345. </text:table-of-content>
  346. "))
  347. (defun org-e-odt-format-toc-entry (snumber todo headline tags href)
  348. ;; FIXME
  349. (setq headline (concat
  350. (and org-export-with-section-numbers
  351. (concat snumber ". "))
  352. headline
  353. (and tags
  354. (concat
  355. (org-e-odt-format-spaces 3)
  356. (org-e-odt-format-fontify tags "tag")))))
  357. (when todo
  358. (setq headline (org-e-odt-format-fontify headline "todo")))
  359. (let ((org-e-odt-suppress-xref t))
  360. (org-e-odt-format-link headline (concat "#" href))))
  361. (defun org-e-odt-format-toc-item (toc-entry level org-last-level)
  362. (let ((style (format "Contents_20_%d" level)))
  363. (concat "\n" (org-e-odt-format-stylized-paragraph style toc-entry) "\n")))
  364. ;; Following variable is let bound during 'ORG-LINK callback. See
  365. ;; org-html.el
  366. (defun org-e-odt-format-link (desc href &optional attr)
  367. (cond
  368. ((and (= (string-to-char href) ?#) (not org-e-odt-suppress-xref))
  369. (setq href (substring href 1))
  370. (let ((xref-format "text"))
  371. (when (numberp desc)
  372. (setq desc (format "%d" desc) xref-format "number"))
  373. (when (listp desc)
  374. (setq desc (mapconcat 'identity desc ".") xref-format "chapter"))
  375. (setq href (concat org-e-odt-bookmark-prefix href))
  376. (org-e-odt-format-tags-simple
  377. '("<text:bookmark-ref text:reference-format=\"%s\" text:ref-name=\"%s\">" .
  378. "</text:bookmark-ref>")
  379. desc xref-format href)))
  380. (org-lparse-link-description-is-image
  381. (org-e-odt-format-tags
  382. '("<draw:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" . "</draw:a>")
  383. desc href (or attr "")))
  384. (t
  385. (org-e-odt-format-tags-simple
  386. '("<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" . "</text:a>")
  387. desc href (or attr "")))))
  388. (defun org-e-odt-format-spaces (n)
  389. (cond
  390. ((= n 1) " ")
  391. ((> n 1) (concat
  392. " " (org-e-odt-format-tags "<text:s text:c=\"%d\"/>" "" (1- n))))
  393. (t "")))
  394. (defun org-e-odt-format-tabs (&optional n)
  395. (let ((tab "<text:tab/>")
  396. (n (or n 1)))
  397. (insert tab)))
  398. (defun org-e-odt-format-line-break ()
  399. (org-e-odt-format-tags "<text:line-break/>" ""))
  400. (defun org-e-odt-format-horizontal-line ()
  401. (org-e-odt-format-stylized-paragraph 'horizontal-line ""))
  402. (defun org-e-odt-encode-plain-text (text &optional no-whitespace-filling)
  403. (mapc
  404. (lambda (pair)
  405. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
  406. '(("&" . "&amp;") ("<" . "&lt;") (">" . "&gt;")))
  407. (if no-whitespace-filling text
  408. (org-e-odt-fill-tabs-and-spaces text)))
  409. (defun org-e-odt-format-line (line)
  410. (case org-lparse-dyn-current-environment
  411. (fixedwidth (concat
  412. (org-e-odt-format-stylized-paragraph
  413. 'fixedwidth (org-e-odt-encode-plain-text line)) "\n"))
  414. (t (concat line "\n"))))
  415. (defun org-e-odt-format-comment (fmt &rest args)
  416. (let ((comment (apply 'format fmt args)))
  417. (format "\n<!-- %s -->\n" comment)))
  418. (defun org-e-odt-format-org-entity (wd)
  419. (org-entity-get-representation wd 'utf8))
  420. (defun org-e-odt-fill-tabs-and-spaces (line)
  421. (replace-regexp-in-string
  422. "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
  423. (cond
  424. ((string= s "\t") (org-e-odt-format-tabs))
  425. (t (org-e-odt-format-spaces (length s))))) line))
  426. (defun org-e-odt-hfy-face-to-css (fn)
  427. "Create custom style for face FN.
  428. When FN is the default face, use it's foreground and background
  429. properties to create \"OrgSrcBlock\" paragraph style. Otherwise
  430. use it's color attribute to create a character style whose name
  431. is obtained from FN. Currently all attributes of FN other than
  432. color are ignored.
  433. The style name for a face FN is derived using the following
  434. operations on the face name in that order - de-dash, CamelCase
  435. and prefix with \"OrgSrc\". For example,
  436. `font-lock-function-name-face' is associated with
  437. \"OrgSrcFontLockFunctionNameFace\"."
  438. (let* ((css-list (hfy-face-to-style fn))
  439. (style-name ((lambda (fn)
  440. (concat "OrgSrc"
  441. (mapconcat
  442. 'capitalize (split-string
  443. (hfy-face-or-def-to-name fn) "-")
  444. ""))) fn))
  445. (color-val (cdr (assoc "color" css-list)))
  446. (background-color-val (cdr (assoc "background" css-list)))
  447. (style (and org-e-odt-create-custom-styles-for-srcblocks
  448. (cond
  449. ((eq fn 'default)
  450. (format org-src-block-paragraph-format
  451. background-color-val color-val))
  452. (t
  453. (format
  454. "
  455. <style:style style:name=\"%s\" style:family=\"text\">
  456. <style:text-properties fo:color=\"%s\"/>
  457. </style:style>" style-name color-val))))))
  458. (cons style-name style)))
  459. (defun org-e-odt-insert-custom-styles-for-srcblocks (styles)
  460. "Save STYLES used for colorizing of source blocks.
  461. Update styles.xml with styles that were collected as part of
  462. `org-e-odt-hfy-face-to-css' callbacks."
  463. (when styles
  464. (with-current-buffer
  465. (find-file-noselect (expand-file-name "styles.xml") t)
  466. (goto-char (point-min))
  467. (when (re-search-forward "</office:styles>" nil t)
  468. (goto-char (match-beginning 0))
  469. (insert "\n<!-- Org Htmlfontify Styles -->\n" styles "\n")))))
  470. (defun org-e-odt-remap-stylenames (style-name)
  471. (or
  472. (cdr (assoc style-name '(("timestamp-wrapper" . "OrgTimestampWrapper")
  473. ("timestamp" . "OrgTimestamp")
  474. ("timestamp-kwd" . "OrgTimestampKeyword")
  475. ("tag" . "OrgTag")
  476. ("todo" . "OrgTodo")
  477. ("done" . "OrgDone")
  478. ("target" . "OrgTarget"))))
  479. style-name))
  480. (defun org-e-odt-format-fontify (text style &optional id)
  481. (let* ((style-name
  482. (cond
  483. ((stringp style)
  484. (org-e-odt-remap-stylenames style))
  485. ((symbolp style)
  486. (org-e-odt-get-style-name-for-entity 'character style))
  487. ((listp style)
  488. (assert (< 1 (length style)))
  489. (let ((parent-style (pop style)))
  490. (mapconcat (lambda (s)
  491. ;; (assert (stringp s) t)
  492. (org-e-odt-remap-stylenames s)) style "")
  493. (org-e-odt-remap-stylenames parent-style)))
  494. (t (error "Don't how to handle style %s" style)))))
  495. (org-e-odt-format-tags-simple
  496. '("<text:span text:style-name=\"%s\">" . "</text:span>")
  497. text style-name)))
  498. (defun org-e-odt-relocate-relative-path (path dir)
  499. (if (file-name-absolute-p path) path
  500. (file-relative-name (expand-file-name path dir)
  501. (expand-file-name "eyecandy" dir))))
  502. (defun org-e-odt-format-formula (element info)
  503. (let* ((src (cond
  504. ((eq (org-element-type element) 'link) ; FIXME
  505. (let* ((type (org-element-property :type element))
  506. (raw-path (org-element-property :path element)))
  507. (cond
  508. ((file-name-absolute-p raw-path)
  509. (expand-file-name raw-path))
  510. (t raw-path))))
  511. ((member (org-element-type element)
  512. '(latex-fragment latex-environment))
  513. (let* ((latex-frag (org-remove-indentation
  514. (org-element-property
  515. :value element)))
  516. (formula-link (org-e-odt-format-latex
  517. latex-frag 'mathml)))
  518. (and formula-link
  519. (string-match "file:\\([^]]*\\)" formula-link)
  520. (match-string 1 formula-link))))
  521. (t (error "what is this?"))))
  522. (caption-from
  523. (case (org-element-type element)
  524. (link (org-export-get-parent-paragraph element info))
  525. (t element)))
  526. (captions (org-e-odt-format-label caption-from info 'definition))
  527. (caption (car captions))
  528. (href
  529. (org-e-odt-format-tags
  530. "<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
  531. (file-name-directory (org-e-odt-copy-formula-file src))))
  532. (embed-as (if caption 'paragraph 'character))
  533. width height)
  534. (cond
  535. ((eq embed-as 'character)
  536. (org-e-odt-format-entity "InlineFormula" href width height))
  537. (t
  538. (let ((table-info nil)
  539. (table-info
  540. '(:alignment ["c" "c"]
  541. :column-groups [nil nil]
  542. :row-groups (0)
  543. :special-column-p nil :width [8 1]))
  544. (org-lparse-table-ncols 2)) ; FIXME
  545. (org-e-odt-list-table ; FIXME
  546. (list
  547. (list
  548. (org-e-odt-format-entity
  549. "CaptionedDisplayFormula" href width height captions)
  550. (let* ((org-e-odt-category-map-alist
  551. '(("__Table__" "Table" "value")
  552. ("__Figure__" "Illustration" "value")
  553. ("__MathFormula__" "Text" "math-label")
  554. ("__DvipngImage__" "Equation" "value")
  555. ("__Listing__" "Listing" "value"))))
  556. (car (org-e-odt-format-label caption-from info 'definition)))))
  557. '(table (:attr_odt (":style \"OrgEquation\""))) info))))))
  558. (defun org-e-odt-copy-formula-file (path)
  559. "Returns the internal name of the file"
  560. (let* ((src-file (expand-file-name
  561. path (file-name-directory org-current-export-file)))
  562. (target-dir (format "Formula-%04d/"
  563. (incf org-e-odt-embedded-formulas-count)))
  564. (target-file (concat target-dir "content.xml")))
  565. (message "Embedding %s as %s ..."
  566. (substring-no-properties path) target-file)
  567. (make-directory target-dir)
  568. (org-e-odt-create-manifest-file-entry
  569. "application/vnd.oasis.opendocument.formula" target-dir "1.2")
  570. (case (org-e-odt-is-formula-link-p src-file)
  571. (mathml
  572. (copy-file src-file target-file 'overwrite))
  573. (odf
  574. (org-e-odt-zip-extract-one src-file "content.xml" target-dir))
  575. (t
  576. (error "%s is not a formula file" src-file)))
  577. (org-e-odt-create-manifest-file-entry "text/xml" target-file)
  578. target-file))
  579. (defun org-e-odt-is-formula-link-p (file)
  580. (let ((case-fold-search nil))
  581. (cond
  582. ((string-match "\\.\\(mathml\\|mml\\)\\'" file)
  583. 'mathml)
  584. ((string-match "\\.odf\\'" file)
  585. 'odf))))
  586. (defun org-e-odt-format-org-link (opt-plist type-1 path fragment desc attr
  587. descp)
  588. "Make a OpenDocument link.
  589. OPT-PLIST is an options list.
  590. TYPE-1 is the device-type of the link (THIS://foo.html).
  591. PATH is the path of the link (http://THIS#location).
  592. FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
  593. DESC is the link description, if any.
  594. ATTR is a string of other attributes of the a element."
  595. (declare (special org-lparse-par-open))
  596. (save-match-data
  597. (let* ((may-inline-p
  598. (and (member type-1 '("http" "https" "file"))
  599. (org-lparse-should-inline-p path descp)
  600. (not fragment)))
  601. (type (if (equal type-1 "id") "file" type-1))
  602. (filename path)
  603. (thefile path))
  604. (cond
  605. ;; check for inlined images
  606. ((and (member type '("file"))
  607. (not fragment)
  608. (org-file-image-p
  609. filename org-e-odt-inline-image-extensions)
  610. (not descp))
  611. (org-e-odt-format-inline-image thefile))
  612. ;; check for embedded formulas
  613. ((and (member type '("file"))
  614. (not fragment)
  615. (org-e-odt-is-formula-link-p filename)
  616. (or (not descp)))
  617. (org-e-odt-format-formula thefile))
  618. ((string= type "coderef")
  619. (let* ((ref fragment)
  620. (lineno-or-ref (cdr (assoc ref org-export-code-refs)))
  621. (desc (and descp desc))
  622. (org-e-odt-suppress-xref nil)
  623. (href (org-xml-format-href (concat "#coderef-" ref))))
  624. (cond
  625. ((and (numberp lineno-or-ref) (not desc))
  626. (org-e-odt-format-link lineno-or-ref href))
  627. ((and (numberp lineno-or-ref) desc
  628. (string-match (regexp-quote (concat "(" ref ")")) desc))
  629. (format (replace-match "%s" t t desc)
  630. (org-e-odt-format-link lineno-or-ref href)))
  631. (t
  632. (setq desc (format
  633. (if (and desc (string-match
  634. (regexp-quote (concat "(" ref ")"))
  635. desc))
  636. (replace-match "%s" t t desc)
  637. (or desc "%s"))
  638. lineno-or-ref))
  639. (org-e-odt-format-link (org-xml-format-desc desc) href)))))
  640. (t
  641. (when (string= type "file")
  642. (setq thefile
  643. (cond
  644. ((file-name-absolute-p path)
  645. (concat "file://" (expand-file-name path)))
  646. (t (org-e-odt-relocate-relative-path
  647. thefile org-current-export-file)))))
  648. (when (and (member type '("" "http" "https" "file")) fragment)
  649. (setq thefile (concat thefile "#" fragment)))
  650. (setq thefile (org-xml-format-href thefile))
  651. (when (not (member type '("" "file")))
  652. (setq thefile (concat type ":" thefile)))
  653. (let ((org-e-odt-suppress-xref nil))
  654. (org-e-odt-format-link
  655. (org-xml-format-desc desc) thefile attr)))))))
  656. (defun org-e-odt-format-anchor (text name &optional class)
  657. (org-e-odt-format-target text name))
  658. (defun org-e-odt-format-bookmark (text id)
  659. (if id
  660. (org-e-odt-format-tags "<text:bookmark text:name=\"%s\"/>" text id)
  661. text))
  662. (defun org-e-odt-format-target (text id)
  663. (let ((name (concat org-e-odt-bookmark-prefix id)))
  664. (concat
  665. (and id (org-e-odt-format-tags
  666. "<text:bookmark-start text:name=\"%s\"/>" "" name))
  667. (org-e-odt-format-bookmark text id)
  668. (and id (org-e-odt-format-tags
  669. "<text:bookmark-end text:name=\"%s\"/>" "" name)))))
  670. (defun org-e-odt-format-footnote (n def)
  671. (setq n (format "%d" n))
  672. (let ((id (concat "fn" n))
  673. (note-class "footnote")
  674. (par-style "Footnote"))
  675. (org-e-odt-format-tags-simple
  676. '("<text:note text:id=\"%s\" text:note-class=\"%s\">" . "</text:note>")
  677. (concat
  678. (org-e-odt-format-tags-simple
  679. '("<text:note-citation>" . "</text:note-citation>") n)
  680. (org-e-odt-format-tags-simple
  681. '("<text:note-body>" . "</text:note-body>") def))
  682. id note-class)))
  683. (defun org-e-odt-format-footnote-reference (n def refcnt)
  684. (if (= refcnt 1)
  685. (org-e-odt-format-footnote n def)
  686. (org-e-odt-format-footnote-ref n)))
  687. (defun org-e-odt-format-footnote-ref (n)
  688. (setq n (format "%d" n))
  689. (let ((note-class "footnote")
  690. (ref-format "text")
  691. (ref-name (concat "fn" n)))
  692. (org-e-odt-format-tags-simple
  693. '("<text:span text:style-name=\"%s\">" . "</text:span>")
  694. (org-e-odt-format-tags-simple
  695. '("<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">" . "</text:note-ref>")
  696. n note-class ref-format ref-name)
  697. "OrgSuperscript")))
  698. (defun org-e-odt-element-attributes (element info)
  699. (let* ((raw-attr (org-element-property :attr_odt element))
  700. (raw-attr (and raw-attr
  701. (org-trim (mapconcat #'identity raw-attr " ")))))
  702. (unless (and raw-attr (string-match "\\`(.*)\\'" raw-attr))
  703. (setq raw-attr (format "(%s)" raw-attr)))
  704. (ignore-errors (read raw-attr))))
  705. (defun org-e-odt-format-object-description (title description)
  706. (concat (and title (org-e-odt-format-tags
  707. '("<svg:title>" . "</svg:title>")
  708. (org-e-odt-encode-plain-text title t)))
  709. (and description (org-e-odt-format-tags
  710. '("<svg:desc>" . "</svg:desc>")
  711. (org-e-odt-encode-plain-text description t)))))
  712. (defun org-e-odt-format-frame (text width height style &optional
  713. extra anchor-type)
  714. (let ((frame-attrs
  715. (concat
  716. (if width (format " svg:width=\"%0.2fcm\"" width) "")
  717. (if height (format " svg:height=\"%0.2fcm\"" height) "")
  718. extra
  719. (format " text:anchor-type=\"%s\"" (or anchor-type "paragraph")))))
  720. (org-e-odt-format-tags
  721. '("<draw:frame draw:style-name=\"%s\"%s>" . "</draw:frame>")
  722. (concat text (org-e-odt-format-object-description
  723. (get-text-property 0 :title text)
  724. (get-text-property 0 :description text)))
  725. style frame-attrs)))
  726. (defun org-e-odt-format-textbox (text width height style &optional
  727. extra anchor-type)
  728. (org-e-odt-format-frame
  729. (org-e-odt-format-tags
  730. '("<draw:text-box %s>" . "</draw:text-box>")
  731. text (concat (format " fo:min-height=\"%0.2fcm\"" (or height .2))
  732. (unless width
  733. (format " fo:min-width=\"%0.2fcm\"" (or width .2)))))
  734. width nil style extra anchor-type))
  735. (defun org-e-odt-merge-frame-params(default-frame-params user-frame-params)
  736. (if (not user-frame-params) default-frame-params
  737. (assert (= (length default-frame-params) 3))
  738. (assert (= (length user-frame-params) 3))
  739. (loop for user-frame-param in user-frame-params
  740. for default-frame-param in default-frame-params
  741. collect (or user-frame-param default-frame-param))))
  742. (defun org-e-odt-copy-image-file (path)
  743. "Returns the internal name of the file"
  744. (let* ((image-type (file-name-extension path))
  745. (media-type (format "image/%s" image-type))
  746. (src-file (expand-file-name
  747. path (file-name-directory org-current-export-file)))
  748. (target-dir "Images/")
  749. (target-file
  750. (format "%s%04d.%s" target-dir
  751. (incf org-e-odt-embedded-images-count) image-type)))
  752. (message "Embedding %s as %s ..."
  753. (substring-no-properties path) target-file)
  754. (when (= 1 org-e-odt-embedded-images-count)
  755. (make-directory target-dir)
  756. (org-e-odt-create-manifest-file-entry "" target-dir))
  757. (copy-file src-file target-file 'overwrite)
  758. (org-e-odt-create-manifest-file-entry media-type target-file)
  759. target-file))
  760. (defun org-e-odt-do-image-size (probe-method file &optional dpi anchor-type)
  761. (setq dpi (or dpi org-e-odt-pixels-per-inch))
  762. (setq anchor-type (or anchor-type "paragraph"))
  763. (flet ((size-in-cms (size-in-pixels)
  764. (flet ((pixels-to-cms (pixels)
  765. (let* ((cms-per-inch 2.54)
  766. (inches (/ pixels dpi)))
  767. (* cms-per-inch inches))))
  768. (and size-in-pixels
  769. (cons (pixels-to-cms (car size-in-pixels))
  770. (pixels-to-cms (cdr size-in-pixels)))))))
  771. (case probe-method
  772. (emacs
  773. (size-in-cms (ignore-errors ; Emacs could be in batch mode
  774. (clear-image-cache)
  775. (image-size (create-image file) 'pixels))))
  776. (imagemagick
  777. (size-in-cms
  778. (let ((dim (shell-command-to-string
  779. (format "identify -format \"%%w:%%h\" \"%s\"" file))))
  780. (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim)
  781. (cons (string-to-number (match-string 1 dim))
  782. (string-to-number (match-string 2 dim)))))))
  783. (t
  784. (cdr (assoc-string anchor-type
  785. org-e-odt-default-image-sizes-alist))))))
  786. (defun org-e-odt-image-size-from-file (file &optional user-width
  787. user-height scale dpi embed-as)
  788. (unless (file-name-absolute-p file)
  789. (setq file (expand-file-name
  790. file (file-name-directory org-current-export-file))))
  791. (let* (size width height)
  792. (unless (and user-height user-width)
  793. (loop for probe-method in org-e-odt-image-size-probe-method
  794. until size
  795. do (setq size (org-e-odt-do-image-size
  796. probe-method file dpi embed-as)))
  797. (or size (error "Cannot determine Image size. Aborting ..."))
  798. (setq width (car size) height (cdr size)))
  799. (cond
  800. (scale
  801. (setq width (* width scale) height (* height scale)))
  802. ((and user-height user-width)
  803. (setq width user-width height user-height))
  804. (user-height
  805. (setq width (* user-height (/ width height)) height user-height))
  806. (user-width
  807. (setq height (* user-width (/ height width)) width user-width))
  808. (t (ignore)))
  809. ;; ensure that an embedded image fits comfortably within a page
  810. (let ((max-width (car org-e-odt-max-image-size))
  811. (max-height (cdr org-e-odt-max-image-size)))
  812. (when (or (> width max-width) (> height max-height))
  813. (let* ((scale1 (/ max-width width))
  814. (scale2 (/ max-height height))
  815. (scale (min scale1 scale2)))
  816. (setq width (* scale width) height (* scale height)))))
  817. (cons width height)))
  818. (defun org-e-odt-format-label (element info op)
  819. (let* ((caption-from
  820. (case (org-element-type element)
  821. (link (org-export-get-parent-paragraph element info))
  822. (t element)))
  823. ;; get label and caption.
  824. (label (org-element-property :name caption-from))
  825. (caption (org-element-property :caption caption-from))
  826. (short-caption (cdr caption))
  827. ;; transcode captions.
  828. (caption (and (car caption) (org-export-data (car caption) info)))
  829. (short-caption (and short-caption
  830. (org-export-data short-caption info))))
  831. (when (or label caption)
  832. (let* ((default-category
  833. (cond
  834. ((eq (org-element-type element) 'table)
  835. "__Table__")
  836. ((org-e-odt-standalone-image-p element info)
  837. "__Figure__")
  838. ((member (org-element-type element)
  839. '(latex-environment latex-fragment))
  840. (let ((processing-type (plist-get info :LaTeX-fragments)))
  841. (cond
  842. ((eq processing-type 'dvipng) "__DvipngImage__")
  843. ((eq processing-type 'mathjax) "__MathFormula__")
  844. ((eq processing-type 't) "__MathFormula__")
  845. (t (error "Handle LaTeX:verbatim")))))
  846. ((eq (org-element-type element) 'src-block)
  847. "__Listing__")
  848. (t (error "Handle enumeration of %S" element))))
  849. (predicate
  850. (cond
  851. ((member (org-element-type element)
  852. '(table latex-environment src-block))
  853. nil)
  854. ((org-e-odt-standalone-image-p element info)
  855. 'org-e-odt-standalone-image-p)
  856. (t (error "Handle enumeration of %S" element))))
  857. (seqno (org-e-odt-enumerate-element
  858. element info predicate)) ; FIXME
  859. ;; handle label props.
  860. (label-props (assoc default-category org-e-odt-category-map-alist))
  861. ;; identify opendocument counter
  862. (counter (nth 1 label-props))
  863. ;; identify label style
  864. (label-style (nth 2 label-props))
  865. ;; grok language setting
  866. (en-strings (assoc-default "en" org-e-odt-category-strings))
  867. (lang (plist-get info :language)) ; FIXME
  868. (lang-strings (assoc-default lang org-e-odt-category-strings))
  869. ;; retrieve localized category sting
  870. (pos (- (length org-e-odt-category-map-alist)
  871. (length (memq label-props org-e-odt-category-map-alist))))
  872. (category (or (nth pos lang-strings) (nth pos en-strings))))
  873. (case op
  874. (definition
  875. ;; assign an internal label, if user has not provided one
  876. (setq label (or label (format "%s-%s" default-category seqno)))
  877. (setq label (org-solidify-link-text label))
  878. (cons
  879. (format-spec
  880. (cadr (assoc-string label-style org-e-odt-label-styles t))
  881. `((?e . ,category)
  882. (?n . ,(org-e-odt-format-tags-simple
  883. '("<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">" . "</text:sequence>")
  884. seqno label counter counter))
  885. (?c . ,(or caption ""))))
  886. short-caption))
  887. (reference
  888. (assert label)
  889. (setq label (org-solidify-link-text label))
  890. (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t)))
  891. (fmt1 (car fmt))
  892. (fmt2 (cadr fmt)))
  893. (org-e-odt-format-tags-simple
  894. '("<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">"
  895. . "</text:sequence-ref>")
  896. (format-spec fmt2 `((?e . ,category)
  897. (?n . ,seqno))) fmt1 label)))
  898. (t (error "Unknow %S on label" op)))))))
  899. (defun org-e-odt-format-tags-1 (tag text prefix suffix &rest args)
  900. (cond
  901. ((consp tag)
  902. (concat prefix (apply 'format (car tag) args) text suffix
  903. (format (cdr tag))))
  904. ((stringp tag) ; singleton tag
  905. (concat prefix (apply 'format tag args) text))))
  906. (defun org-e-odt-format-tags (tag text &rest args)
  907. (apply 'org-e-odt-format-tags-1 tag text "\n" "\n" args))
  908. (defun org-e-odt-format-tags-simple (tag text &rest args)
  909. (apply 'org-e-odt-format-tags-1 tag text nil nil args))
  910. (defun org-e-odt-init-outfile ()
  911. (unless (executable-find "zip")
  912. ;; Not at all OSes ship with zip by default
  913. (error "Executable \"zip\" needed for creating OpenDocument files"))
  914. (let* ((outdir (make-temp-file
  915. (format org-e-odt-tmpdir-prefix 'odt) t)) ; FIXME
  916. (content-file (expand-file-name "content.xml" outdir)))
  917. ;; reset variables
  918. (setq org-e-odt-manifest-file-entries nil
  919. org-e-odt-embedded-images-count 0
  920. org-e-odt-embedded-formulas-count 0
  921. org-e-odt-section-count 0
  922. org-e-odt-automatic-styles nil
  923. org-e-odt-object-counters nil)
  924. ;; let `htmlfontify' know that we are interested in collecting
  925. ;; styles - FIXME
  926. (setq hfy-user-sheet-assoc nil)
  927. ;; init conten.xml
  928. (require 'nxml-mode) ; FIXME
  929. (with-current-buffer
  930. (let ((nxml-auto-insert-xml-declaration-flag nil))
  931. (find-file-noselect content-file t))
  932. (current-buffer))))
  933. (defun org-e-odt-save-as-outfile (target opt-plist)
  934. ;; write automatic styles
  935. (org-e-odt-write-automatic-styles)
  936. ;; update display levels
  937. (org-e-odt-update-display-level org-e-odt-display-outline-level)
  938. ;; create mimetype file
  939. (let ((mimetype (org-e-odt-write-mimetype-file ;; org-lparse-backend FIXME
  940. 'odt)))
  941. (org-e-odt-create-manifest-file-entry mimetype "/" "1.2"))
  942. ;; create a manifest entry for content.xml
  943. (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
  944. ;; write out the manifest entries before zipping
  945. (org-e-odt-write-manifest-file)
  946. (let ((xml-files '("mimetype" "META-INF/manifest.xml" "content.xml"
  947. "meta.xml"))
  948. (zipdir default-directory))
  949. (when (or t (equal org-lparse-backend 'odt)) ; FIXME
  950. (push "styles.xml" xml-files))
  951. (message "Switching to directory %s" (expand-file-name zipdir))
  952. ;; save all xml files
  953. (mapc (lambda (file)
  954. (with-current-buffer
  955. (find-file-noselect (expand-file-name file) t)
  956. ;; prettify output if needed
  957. (when org-e-odt-prettify-xml
  958. (indent-region (point-min) (point-max)))
  959. (save-buffer 0)))
  960. xml-files)
  961. (let* ((target-name (file-name-nondirectory target))
  962. (target-dir (file-name-directory target))
  963. (cmds `(("zip" "-mX0" ,target-name "mimetype")
  964. ("zip" "-rmTq" ,target-name "."))))
  965. (when (file-exists-p target)
  966. ;; FIXME: If the file is locked this throws a cryptic error
  967. (delete-file target))
  968. (let ((coding-system-for-write 'no-conversion) exitcode err-string)
  969. (message "Creating odt file...")
  970. (mapc
  971. (lambda (cmd)
  972. (message "Running %s" (mapconcat 'identity cmd " "))
  973. (setq err-string
  974. (with-output-to-string
  975. (setq exitcode
  976. (apply 'call-process (car cmd)
  977. nil standard-output nil (cdr cmd)))))
  978. (or (zerop exitcode)
  979. (ignore (message "%s" err-string))
  980. (error "Unable to create odt file (%S)" exitcode)))
  981. cmds))
  982. ;; move the file from outdir to target-dir
  983. (rename-file target-name target-dir)
  984. ;; kill all xml buffers
  985. (mapc (lambda (file)
  986. (kill-buffer
  987. (find-file-noselect (expand-file-name file zipdir) t)))
  988. xml-files)
  989. (delete-directory zipdir)))
  990. (message "Created %s" target)
  991. (set-buffer (find-file-noselect target t)))
  992. (defun org-e-odt-create-manifest-file-entry (&rest args)
  993. (push args org-e-odt-manifest-file-entries))
  994. (defun org-e-odt-write-manifest-file ()
  995. (make-directory "META-INF")
  996. (let ((manifest-file (expand-file-name "META-INF/manifest.xml")))
  997. (with-current-buffer
  998. (let ((nxml-auto-insert-xml-declaration-flag nil))
  999. (find-file-noselect manifest-file t))
  1000. (insert
  1001. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
  1002. <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
  1003. (mapc
  1004. (lambda (file-entry)
  1005. (let* ((version (nth 2 file-entry))
  1006. (extra (if version
  1007. (format " manifest:version=\"%s\"" version)
  1008. "")))
  1009. (insert
  1010. (format org-e-odt-manifest-file-entry-tag
  1011. (nth 0 file-entry) (nth 1 file-entry) extra))))
  1012. org-e-odt-manifest-file-entries)
  1013. (insert "\n</manifest:manifest>"))))
  1014. (defun org-e-odt-update-meta-file (info) ; FIXME opt-plist
  1015. (let ((title (org-export-data (plist-get info :title) info))
  1016. (author (or (let ((auth (plist-get info :author)))
  1017. (and auth (org-export-data auth info))) ""))
  1018. (date (org-e-odt-format-date (plist-get info :date)))
  1019. (email (plist-get info :email))
  1020. (keywords (plist-get info :keywords))
  1021. (description (plist-get info :description)))
  1022. (write-region
  1023. (concat
  1024. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
  1025. <office:document-meta
  1026. xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
  1027. xmlns:xlink=\"http://www.w3.org/1999/xlink\"
  1028. xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
  1029. xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
  1030. xmlns:ooo=\"http://openoffice.org/2004/office\"
  1031. office:version=\"1.2\">
  1032. <office:meta>\n"
  1033. (org-e-odt-format-author author) "\n"
  1034. (format "<meta:initial-creator>%s</meta:initial-creator>\n" author)
  1035. (format "<dc:date>%s</dc:date>\n" date)
  1036. (format "<meta:creation-date>%s</meta:creation-date>\n" date)
  1037. (format "<meta:generator>%s</meta:generator>\n"
  1038. (concat (and org-export-creator-info org-export-creator-string)))
  1039. (format "<meta:keyword>%s</meta:keyword>\n" keywords)
  1040. (format "<dc:subject>%s</dc:subject>\n" description)
  1041. (format "<dc:title>%s</dc:title>\n" title)
  1042. "\n"
  1043. " </office:meta>\n" "</office:document-meta>")
  1044. nil (expand-file-name "meta.xml")))
  1045. ;; create a manifest entry for meta.xml
  1046. (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
  1047. (defun org-e-odt-update-styles-file (info)
  1048. ;; write styles file
  1049. (let ((styles-file (plist-get info :odt-styles-file)))
  1050. (org-e-odt-copy-styles-file (and styles-file
  1051. (read (org-trim styles-file))))
  1052. ;; FIXME: Who is opening an empty styles.xml before this point?
  1053. (with-current-buffer
  1054. (find-file-noselect (expand-file-name "styles.xml") t)
  1055. (revert-buffer t t)))
  1056. ;; Write custom styles for source blocks
  1057. (org-e-odt-insert-custom-styles-for-srcblocks
  1058. (mapconcat
  1059. (lambda (style)
  1060. (format " %s\n" (cddr style)))
  1061. hfy-user-sheet-assoc "")))
  1062. (defun org-e-odt-write-mimetype-file (format)
  1063. ;; create mimetype file
  1064. (let ((mimetype
  1065. (case format
  1066. (odt "application/vnd.oasis.opendocument.text")
  1067. (odf "application/vnd.oasis.opendocument.formula")
  1068. (t (error "Unknown OpenDocument backend %S" org-lparse-backend)))))
  1069. (write-region mimetype nil (expand-file-name "mimetype"))
  1070. mimetype))
  1071. (defun org-e-odt-do-preprocess-latex-fragments ()
  1072. "Convert LaTeX fragments to images."
  1073. (let* ((latex-frag-opt (plist-get org-lparse-opt-plist :LaTeX-fragments))
  1074. (latex-frag-opt ; massage the options
  1075. (or (and (member latex-frag-opt '(mathjax t))
  1076. (not (and (fboundp 'org-format-latex-mathml-available-p)
  1077. (org-format-latex-mathml-available-p)))
  1078. (prog1 org-lparse-latex-fragment-fallback
  1079. (org-lparse-warn
  1080. (concat
  1081. "LaTeX to MathML converter not available. "
  1082. (format "Using %S instead."
  1083. org-lparse-latex-fragment-fallback)))))
  1084. latex-frag-opt))
  1085. cache-dir display-msg)
  1086. (cond
  1087. ((eq latex-frag-opt 'dvipng)
  1088. (setq cache-dir "ltxpng/")
  1089. (setq display-msg "Creating LaTeX image %s"))
  1090. ((member latex-frag-opt '(mathjax t))
  1091. (setq latex-frag-opt 'mathml)
  1092. (setq cache-dir "ltxmathml/")
  1093. (setq display-msg "Creating MathML formula %s")))
  1094. (when (and org-current-export-file)
  1095. (org-format-latex
  1096. (concat cache-dir (file-name-sans-extension
  1097. (file-name-nondirectory org-current-export-file)))
  1098. org-current-export-dir nil display-msg
  1099. nil nil latex-frag-opt))))
  1100. (eval-after-load 'org-odt
  1101. '(ad-deactivate 'org-format-latex-as-mathml))
  1102. ; FIXME
  1103. ;; (defadvice org-format-latex-as-mathml ; FIXME
  1104. ;; (after org-e-odt-protect-latex-fragment activate)
  1105. ;; "Encode LaTeX fragment as XML.
  1106. ;; Do this when translation to MathML fails."
  1107. ;; (when (or (not (> (length ad-return-value) 0))
  1108. ;; (get-text-property 0 'org-protected ad-return-value))
  1109. ;; (setq ad-return-value
  1110. ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
  1111. ;; 'org-protected t))))
  1112. (defun org-e-odt-zip-extract-one (archive member &optional target)
  1113. (require 'arc-mode)
  1114. (let* ((target (or target default-directory))
  1115. (archive (expand-file-name archive))
  1116. (archive-zip-extract
  1117. (list "unzip" "-qq" "-o" "-d" target))
  1118. exit-code command-output)
  1119. (setq command-output
  1120. (with-temp-buffer
  1121. (setq exit-code (archive-zip-extract archive member))
  1122. (buffer-string)))
  1123. (unless (zerop exit-code)
  1124. (message command-output)
  1125. (error "Extraction failed"))))
  1126. (defun org-e-odt-zip-extract (archive members &optional target)
  1127. (when (atom members) (setq members (list members)))
  1128. (mapc (lambda (member)
  1129. (org-e-odt-zip-extract-one archive member target))
  1130. members))
  1131. (defun org-e-odt-copy-styles-file (&optional styles-file)
  1132. ;; Non-availability of styles.xml is not a critical error. For now
  1133. ;; throw an error purely for aesthetic reasons.
  1134. (setq styles-file (or styles-file
  1135. org-e-odt-styles-file
  1136. (expand-file-name "OrgOdtStyles.xml"
  1137. org-e-odt-styles-dir)
  1138. (error "org-e-odt: Missing styles file?")))
  1139. (cond
  1140. ((listp styles-file)
  1141. (let ((archive (nth 0 styles-file))
  1142. (members (nth 1 styles-file)))
  1143. (org-e-odt-zip-extract archive members)
  1144. (mapc
  1145. (lambda (member)
  1146. (when (org-file-image-p member)
  1147. (let* ((image-type (file-name-extension member))
  1148. (media-type (format "image/%s" image-type)))
  1149. (org-e-odt-create-manifest-file-entry media-type member))))
  1150. members)))
  1151. ((and (stringp styles-file) (file-exists-p styles-file))
  1152. (let ((styles-file-type (file-name-extension styles-file)))
  1153. (cond
  1154. ((string= styles-file-type "xml")
  1155. (copy-file styles-file (expand-file-name "styles.xml") t))
  1156. ((member styles-file-type '("odt" "ott"))
  1157. (org-e-odt-zip-extract styles-file "styles.xml")))))
  1158. (t
  1159. (error (format "Invalid specification of styles.xml file: %S"
  1160. org-e-odt-styles-file))))
  1161. ;; create a manifest entry for styles.xml
  1162. (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml"))
  1163. (defun org-e-odt-configure-outline-numbering ()
  1164. "Outline numbering is retained only upto LEVEL.
  1165. To disable outline numbering pass a LEVEL of 0."
  1166. (goto-char (point-min))
  1167. (let ((regex
  1168. "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
  1169. (replacement
  1170. "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
  1171. (while (re-search-forward regex nil t)
  1172. (unless (let ((sec-num (plist-get info :section-numbers))
  1173. (level (string-to-number (match-string 2))))
  1174. (if (wholenump sec-num) (<= level sec-num) sec-num))
  1175. (replace-match replacement t nil))))
  1176. (save-buffer 0))
  1177. ;;;###autoload
  1178. (defun org-export-as-odf (latex-frag &optional odf-file)
  1179. "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
  1180. Use `org-create-math-formula' to convert LATEX-FRAG first to
  1181. MathML. When invoked as an interactive command, use
  1182. `org-latex-regexps' to infer LATEX-FRAG from currently active
  1183. region. If no LaTeX fragments are found, prompt for it. Push
  1184. MathML source to kill ring, if `org-export-copy-to-kill-ring' is
  1185. non-nil."
  1186. (interactive
  1187. `(,(let (frag)
  1188. (setq frag (and (setq frag (and (region-active-p)
  1189. (buffer-substring (region-beginning)
  1190. (region-end))))
  1191. (loop for e in org-latex-regexps
  1192. thereis (when (string-match (nth 1 e) frag)
  1193. (match-string (nth 2 e) frag)))))
  1194. (read-string "LaTeX Fragment: " frag nil frag))
  1195. ,(let ((odf-filename (expand-file-name
  1196. (concat
  1197. (file-name-sans-extension
  1198. (or (file-name-nondirectory buffer-file-name)))
  1199. "." "odf")
  1200. (file-name-directory buffer-file-name))))
  1201. (read-file-name "ODF filename: " nil odf-filename nil
  1202. (file-name-nondirectory odf-filename)))))
  1203. (let* ((org-lparse-backend 'odf)
  1204. org-lparse-opt-plist
  1205. (filename (or odf-file
  1206. (expand-file-name
  1207. (concat
  1208. (file-name-sans-extension
  1209. (or (file-name-nondirectory buffer-file-name)))
  1210. "." "odf")
  1211. (file-name-directory buffer-file-name))))
  1212. (buffer (find-file-noselect (org-e-odt-init-outfile filename)))
  1213. (coding-system-for-write 'utf-8)
  1214. (save-buffer-coding-system 'utf-8))
  1215. (set-buffer buffer)
  1216. (set-buffer-file-coding-system coding-system-for-write)
  1217. (let ((mathml (org-create-math-formula latex-frag)))
  1218. (unless mathml (error "No Math formula created"))
  1219. (insert mathml)
  1220. (or (org-export-push-to-kill-ring
  1221. (upcase (symbol-name org-lparse-backend)))
  1222. (message "Exporting... done")))
  1223. (org-e-odt-save-as-outfile filename nil ; FIXME
  1224. )))
  1225. ;;;###autoload
  1226. (defun org-export-as-odf-and-open ()
  1227. "Export LaTeX fragment as OpenDocument formula and immediately open it.
  1228. Use `org-export-as-odf' to read LaTeX fragment and OpenDocument
  1229. formula file."
  1230. (interactive)
  1231. (org-lparse-and-open
  1232. nil nil nil (call-interactively 'org-export-as-odf)))
  1233. ;;; Driver Starts here
  1234. ;;; Dependencies
  1235. (require 'format-spec)
  1236. (eval-when-compile (require 'cl) (require 'table))
  1237. ;;; Hooks
  1238. ;;; Function Declarations
  1239. (declare-function org-id-find-id-file "org-id" (id))
  1240. (declare-function hfy-face-to-style "htmlfontify" (fn))
  1241. (declare-function hfy-face-or-def-to-name "htmlfontify" (fn))
  1242. (declare-function archive-zip-extract "arc-mode.el" (archive name))
  1243. (declare-function org-create-math-formula "org" (latex-frag &optional mathml-file))
  1244. ;;; Internal Variables
  1245. ;;;; ODT Internal Variables
  1246. (defconst org-e-odt-lib-dir
  1247. (file-name-directory load-file-name)
  1248. "Location of ODT exporter.
  1249. Use this to infer values of `org-e-odt-styles-dir' and
  1250. `org-e-odt-schema-dir'.")
  1251. (defvar org-e-odt-data-dir
  1252. (expand-file-name "../../etc/" org-e-odt-lib-dir)
  1253. "Data directory for ODT exporter.
  1254. Use this to infer values of `org-e-odt-styles-dir' and
  1255. `org-e-odt-schema-dir'.")
  1256. (defconst org-e-odt-special-string-regexps
  1257. '(("\\\\-" . "&#x00ad;\\1") ; shy
  1258. ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
  1259. ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
  1260. ("\\.\\.\\." . "&#x2026;")) ; hellip
  1261. "Regular expressions for special string conversion.")
  1262. (defconst org-e-odt-schema-dir-list
  1263. (list
  1264. (and org-e-odt-data-dir
  1265. (expand-file-name "./schema/" org-e-odt-data-dir)) ; bail out
  1266. (eval-when-compile
  1267. (and (boundp 'org-e-odt-data-dir) org-e-odt-data-dir ; see make install
  1268. (expand-file-name "./schema/" org-e-odt-data-dir))))
  1269. "List of directories to search for OpenDocument schema files.
  1270. Use this list to set the default value of
  1271. `org-e-odt-schema-dir'. The entries in this list are
  1272. populated heuristically based on the values of `org-e-odt-lib-dir'
  1273. and `org-e-odt-data-dir'.")
  1274. (defconst org-e-odt-styles-dir-list
  1275. (list
  1276. (and org-e-odt-data-dir
  1277. (expand-file-name "./styles/" org-e-odt-data-dir)) ; bail out
  1278. (eval-when-compile
  1279. (and (boundp 'org-e-odt-data-dir) org-e-odt-data-dir ; see make install
  1280. (expand-file-name "./styles/" org-e-odt-data-dir)))
  1281. (expand-file-name "../../etc/styles/" org-e-odt-lib-dir) ; git
  1282. (expand-file-name "./etc/styles/" org-e-odt-lib-dir) ; elpa
  1283. (expand-file-name "./org/" data-directory) ; system
  1284. )
  1285. "List of directories to search for OpenDocument styles files.
  1286. See `org-e-odt-styles-dir'. The entries in this list are populated
  1287. heuristically based on the values of `org-e-odt-lib-dir' and
  1288. `org-e-odt-data-dir'.")
  1289. (defconst org-e-odt-styles-dir
  1290. (let* ((styles-dir
  1291. (catch 'styles-dir
  1292. (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
  1293. (mapc (lambda (styles-dir)
  1294. (when styles-dir
  1295. (message "Debug (org-e-odt): Trying %s..." styles-dir)
  1296. (when (and (file-readable-p
  1297. (expand-file-name
  1298. "OrgOdtContentTemplate.xml" styles-dir))
  1299. (file-readable-p
  1300. (expand-file-name
  1301. "OrgOdtStyles.xml" styles-dir)))
  1302. (message "Debug (org-e-odt): Using styles under %s"
  1303. styles-dir)
  1304. (throw 'styles-dir styles-dir))))
  1305. org-e-odt-styles-dir-list)
  1306. nil)))
  1307. (unless styles-dir
  1308. (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
  1309. styles-dir)
  1310. "Directory that holds auxiliary XML files used by the ODT exporter.
  1311. This directory contains the following XML files -
  1312. \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
  1313. XML files are used as the default values of
  1314. `org-e-odt-styles-file' and
  1315. `org-e-odt-content-template-file'.
  1316. The default value of this variable varies depending on the
  1317. version of org in use and is initialized from
  1318. `org-e-odt-styles-dir-list'. Note that the user could be using org
  1319. from one of: org's own private git repository, GNU ELPA tar or
  1320. standard Emacs.")
  1321. (defconst org-e-odt-tmpdir-prefix "%s-")
  1322. (defconst org-e-odt-bookmark-prefix "OrgXref.")
  1323. (defconst org-e-odt-manifest-file-entry-tag
  1324. "
  1325. <manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
  1326. (defvar org-lparse-dyn-first-heading-pos) ; let bound during org-do-lparse
  1327. (defvar org-e-odt-suppress-xref nil)
  1328. (defvar org-e-odt-file-extensions
  1329. '(("odt" . "OpenDocument Text")
  1330. ("ott" . "OpenDocument Text Template")
  1331. ("odm" . "OpenDocument Master Document")
  1332. ("ods" . "OpenDocument Spreadsheet")
  1333. ("ots" . "OpenDocument Spreadsheet Template")
  1334. ("odg" . "OpenDocument Drawing (Graphics)")
  1335. ("otg" . "OpenDocument Drawing Template")
  1336. ("odp" . "OpenDocument Presentation")
  1337. ("otp" . "OpenDocument Presentation Template")
  1338. ("odi" . "OpenDocument Image")
  1339. ("odf" . "OpenDocument Formula")
  1340. ("odc" . "OpenDocument Chart")))
  1341. (defconst org-e-odt-default-org-styles-alist
  1342. '((paragraph . ((default . "Text_20_body")
  1343. (fixedwidth . "OrgFixedWidthBlock")
  1344. (verse . "OrgVerse")
  1345. (quote . "Quotations")
  1346. (blockquote . "Quotations")
  1347. (center . "OrgCenter")
  1348. (left . "OrgLeft")
  1349. (right . "OrgRight")
  1350. (title . "OrgTitle")
  1351. (subtitle . "OrgSubtitle")
  1352. (footnote . "Footnote")
  1353. (src . "OrgSrcBlock")
  1354. (illustration . "Illustration")
  1355. (table . "Table")
  1356. (listing . "Listing")
  1357. (definition-term . "Text_20_body_20_bold")
  1358. (horizontal-line . "Horizontal_20_Line")))
  1359. (character . ((bold . "Bold")
  1360. (italic . "Emphasis")
  1361. (code . "OrgCode")
  1362. (verbatim . "OrgCode")
  1363. (strike . "Strikethrough")
  1364. (underline . "Underline")
  1365. (subscript . "OrgSubscript")
  1366. (superscript . "OrgSuperscript")))
  1367. (list . ((ordered . "OrgNumberedList")
  1368. (unordered . "OrgBulletedList")
  1369. (descriptive . "OrgDescriptionList"))))
  1370. "Default styles for various entities.")
  1371. (defvar org-e-odt-org-styles-alist org-e-odt-default-org-styles-alist)
  1372. (defvar org-lparse-opt-plist) ; bound during org-do-lparse
  1373. (defvar org-lparse-table-ncols)
  1374. (defvar org-e-odt-table-style-format
  1375. "
  1376. <style:style style:name=\"%s\" style:family=\"table\">
  1377. <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
  1378. </style:style>
  1379. "
  1380. "Template for auto-generated Table styles.")
  1381. (defvar org-e-odt-automatic-styles '()
  1382. "Registry of automatic styles for various OBJECT-TYPEs.
  1383. The variable has the following form:
  1384. \(\(OBJECT-TYPE-A
  1385. \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
  1386. \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
  1387. \(OBJECT-TYPE-B
  1388. \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
  1389. \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
  1390. ...\).
  1391. OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
  1392. OBJECT-PROPS is (typically) a plist created by passing
  1393. \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
  1394. Use `org-e-odt-add-automatic-style' to add update this variable.'")
  1395. (defvar org-e-odt-object-counters nil
  1396. "Running counters for various OBJECT-TYPEs.
  1397. Use this to generate automatic names and style-names. See
  1398. `org-e-odt-add-automatic-style'.")
  1399. (defvar org-lparse-link-description-is-image nil)
  1400. (defvar org-src-block-paragraph-format
  1401. "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
  1402. <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
  1403. <style:background-image/>
  1404. </style:paragraph-properties>
  1405. <style:text-properties fo:color=\"%s\"/>
  1406. </style:style>"
  1407. "Custom paragraph style for colorized source and example blocks.
  1408. This style is much the same as that of \"OrgFixedWidthBlock\"
  1409. except that the foreground and background colors are set
  1410. according to the default face identified by the `htmlfontify'.")
  1411. (defvar hfy-optimisations)
  1412. (defvar org-e-odt-embedded-formulas-count 0)
  1413. (defvar org-e-odt-entity-frame-styles
  1414. '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil "as-char"))
  1415. ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil "paragraph"))
  1416. ("PageImage" "__Figure__" ("OrgPageImage" nil "page"))
  1417. ("CaptionedAs-CharImage" "__Figure__"
  1418. ("OrgCaptionedImage"
  1419. " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
  1420. ("OrgInlineImage" nil "as-char"))
  1421. ("CaptionedParagraphImage" "__Figure__"
  1422. ("OrgCaptionedImage"
  1423. " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
  1424. ("OrgImageCaptionFrame" nil "paragraph"))
  1425. ("CaptionedPageImage" "__Figure__"
  1426. ("OrgCaptionedImage"
  1427. " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
  1428. ("OrgPageImageCaptionFrame" nil "page"))
  1429. ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil "as-char"))
  1430. ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil "as-char"))
  1431. ("CaptionedDisplayFormula" "__MathFormula__"
  1432. ("OrgCaptionedFormula" nil "paragraph")
  1433. ("OrgFormulaCaptionFrame" nil "as-char"))))
  1434. (defvar org-e-odt-embedded-images-count 0)
  1435. (defvar org-e-odt-image-size-probe-method
  1436. (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
  1437. '(emacs fixed))
  1438. "Ordered list of methods for determining image sizes.")
  1439. (defvar org-e-odt-default-image-sizes-alist
  1440. '(("as-char" . (5 . 0.4))
  1441. ("paragraph" . (5 . 5)))
  1442. "Hardcoded image dimensions one for each of the anchor
  1443. methods.")
  1444. ;; A4 page size is 21.0 by 29.7 cms
  1445. ;; The default page settings has 2cm margin on each of the sides. So
  1446. ;; the effective text area is 17.0 by 25.7 cm
  1447. (defvar org-e-odt-max-image-size '(17.0 . 20.0)
  1448. "Limiting dimensions for an embedded image.")
  1449. (defvar org-e-odt-label-styles
  1450. '(("math-formula" "%c" "text" "(%n)")
  1451. ("math-label" "(%n)" "text" "(%n)")
  1452. ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
  1453. ("value" "%e %n: %c" "value" "%n"))
  1454. "Specify how labels are applied and referenced.
  1455. This is an alist where each element is of the
  1456. form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
  1457. LABEL-REF-FMT).
  1458. LABEL-ATTACH-FMT controls how labels and captions are attached to
  1459. an entity. It may contain following specifiers - %e, %n and %c.
  1460. %e is replaced with the CATEGORY-NAME. %n is replaced with
  1461. \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
  1462. with CAPTION. See `org-e-odt-format-label-definition'.
  1463. LABEL-REF-MODE and LABEL-REF-FMT controls how label references
  1464. are generated. The following XML is generated for a label
  1465. reference - \"<text:sequence-ref
  1466. text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
  1467. </text:sequence-ref>\". LABEL-REF-FMT may contain following
  1468. specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
  1469. %n is replaced with SEQNO. See
  1470. `org-e-odt-format-label-reference'.")
  1471. (defcustom org-e-odt-category-strings
  1472. '(("en" "Table" "Figure" "Equation" "Equation" "Listing"))
  1473. "Specify category strings for various captionable entities.
  1474. Captionable entity can be one of a Table, an Embedded Image, a
  1475. LaTeX fragment (generated with dvipng) or a Math Formula.
  1476. For example, when `org-export-default-language' is \"en\", an
  1477. embedded image will be captioned as \"Figure 1: Orgmode Logo\".
  1478. If you want the images to be captioned instead as \"Illustration
  1479. 1: Orgmode Logo\", then modify the entry for \"en\" as shown
  1480. below.
  1481. \(setq org-e-odt-category-strings
  1482. '\(\(\"en\" \"Table\" \"Illustration\"
  1483. \"Equation\" \"Equation\"\)\)\)"
  1484. :group 'org-export-e-odt
  1485. :version "24.1"
  1486. :type '(repeat (list (string :tag "Language tag")
  1487. (choice :tag "Table"
  1488. (const :tag "Use Default" nil)
  1489. (string :tag "Category string"))
  1490. (choice :tag "Figure"
  1491. (const :tag "Use Default" nil)
  1492. (string :tag "Category string"))
  1493. (choice :tag "Math Formula"
  1494. (const :tag "Use Default" nil)
  1495. (string :tag "Category string"))
  1496. (choice :tag "Dvipng Image"
  1497. (const :tag "Use Default" nil)
  1498. (string :tag "Category string"))
  1499. (choice :tag "Listing"
  1500. (const :tag "Use Default" nil)
  1501. (string :tag "Category string")))))
  1502. (defvar org-e-odt-category-map-alist
  1503. '(("__Table__" "Table" "value")
  1504. ("__Figure__" "Illustration" "value")
  1505. ("__MathFormula__" "Text" "math-formula")
  1506. ("__DvipngImage__" "Equation" "value")
  1507. ("__Listing__" "Listing" "value")
  1508. ;; ("__Table__" "Table" "category-and-value")
  1509. ;; ("__Figure__" "Figure" "category-and-value")
  1510. ;; ("__DvipngImage__" "Equation" "category-and-value")
  1511. )
  1512. "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
  1513. This is a list where each entry is of the form \\(CATEGORY-HANDLE
  1514. OD-VARIABLE LABEL-STYLE\\). CATEGORY_HANDLE identifies the
  1515. captionable entity in question. OD-VARIABLE is the OpenDocument
  1516. sequence counter associated with the entity. These counters are
  1517. declared within
  1518. \"<text:sequence-decls>...</text:sequence-decls>\" block of
  1519. `org-e-odt-content-template-file'. LABEL-STYLE is a key
  1520. into `org-e-odt-label-styles' and specifies how a given entity
  1521. should be captioned and referenced.
  1522. The position of a CATEGORY-HANDLE in this list is used as an
  1523. index in to per-language entry for
  1524. `org-e-odt-category-strings' to retrieve a CATEGORY-NAME.
  1525. This CATEGORY-NAME is then used for qualifying the user-specified
  1526. captions on export.")
  1527. (defvar org-e-odt-manifest-file-entries nil)
  1528. (defvar hfy-user-sheet-assoc) ; bound during org-do-lparse
  1529. (defvar org-lparse-latex-fragment-fallback) ; set by org-do-lparse
  1530. ;;;; HTML Internal Variables
  1531. (defvar html-table-tag nil) ; dynamically scoped into this.
  1532. ;; FIXME: it already exists in org-e-odt.el
  1533. (defconst org-e-odt-cvt-link-fn
  1534. nil
  1535. "Function to convert link URLs to exportable URLs.
  1536. Takes two arguments, TYPE and PATH.
  1537. Returns exportable url as (TYPE PATH), or nil to signal that it
  1538. didn't handle this case.
  1539. Intended to be locally bound around a call to `org-export-as-html'." )
  1540. (defvar org-e-odt-headline-formatter
  1541. (lambda (level snumber todo todo-type priority
  1542. title tags target extra-targets extra-class)
  1543. (concat snumber " " title)))
  1544. ;;; User Configuration Variables
  1545. (defgroup org-export-e-odt nil
  1546. "Options for exporting Org mode files to ODT."
  1547. :tag "Org Export ODT"
  1548. :group 'org-export)
  1549. (defcustom org-e-odt-schema-dir
  1550. (let* ((schema-dir
  1551. (catch 'schema-dir
  1552. (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
  1553. (mapc
  1554. (lambda (schema-dir)
  1555. (when schema-dir
  1556. (message "Debug (org-e-odt): Trying %s..." schema-dir)
  1557. (when (and (file-readable-p
  1558. (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
  1559. schema-dir))
  1560. (file-readable-p
  1561. (expand-file-name "od-schema-v1.2-cs01.rnc"
  1562. schema-dir))
  1563. (file-readable-p
  1564. (expand-file-name "schemas.xml" schema-dir)))
  1565. (message "Debug (org-e-odt): Using schema files under %s"
  1566. schema-dir)
  1567. (throw 'schema-dir schema-dir))))
  1568. org-e-odt-schema-dir-list)
  1569. (message "Debug (org-e-odt): No OpenDocument schema files installed")
  1570. nil)))
  1571. schema-dir)
  1572. "Directory that contains OpenDocument schema files.
  1573. This directory contains:
  1574. 1. rnc files for OpenDocument schema
  1575. 2. a \"schemas.xml\" file that specifies locating rules needed
  1576. for auto validation of OpenDocument XML files.
  1577. Use the customize interface to set this variable. This ensures
  1578. that `rng-schema-locating-files' is updated and auto-validation
  1579. of OpenDocument XML takes place based on the value
  1580. `rng-nxml-auto-validate-flag'.
  1581. The default value of this variable varies depending on the
  1582. version of org in use and is initialized from
  1583. `org-e-odt-schema-dir-list'. The OASIS schema files are available
  1584. only in the org's private git repository. It is *not* bundled
  1585. with GNU ELPA tar or standard Emacs distribution."
  1586. :type '(choice
  1587. (const :tag "Not set" nil)
  1588. (directory :tag "Schema directory"))
  1589. :group 'org-export-e-odt
  1590. :version "24.1"
  1591. :set
  1592. (lambda (var value)
  1593. "Set `org-e-odt-schema-dir'.
  1594. Also add it to `rng-schema-locating-files'."
  1595. (let ((schema-dir value))
  1596. (set var
  1597. (if (and
  1598. (file-readable-p
  1599. (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir))
  1600. (file-readable-p
  1601. (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir))
  1602. (file-readable-p
  1603. (expand-file-name "schemas.xml" schema-dir)))
  1604. schema-dir
  1605. (when value
  1606. (message "Error (org-e-odt): %s has no OpenDocument schema files"
  1607. value))
  1608. nil)))
  1609. (when org-e-odt-schema-dir
  1610. (eval-after-load 'rng-loc
  1611. '(add-to-list 'rng-schema-locating-files
  1612. (expand-file-name "schemas.xml"
  1613. org-e-odt-schema-dir))))))
  1614. (defcustom org-e-odt-content-template-file nil
  1615. "Template file for \"content.xml\".
  1616. The exporter embeds the exported content just before
  1617. \"</office:text>\" element.
  1618. If unspecified, the file named \"OrgOdtContentTemplate.xml\"
  1619. under `org-e-odt-styles-dir' is used."
  1620. :type 'file
  1621. :group 'org-export-e-odt
  1622. :version "24.1")
  1623. (defcustom org-e-odt-styles-file nil
  1624. "Default styles file for use with ODT export.
  1625. Valid values are one of:
  1626. 1. nil
  1627. 2. path to a styles.xml file
  1628. 3. path to a *.odt or a *.ott file
  1629. 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
  1630. ...))
  1631. In case of option 1, an in-built styles.xml is used. See
  1632. `org-e-odt-styles-dir' for more information.
  1633. In case of option 3, the specified file is unzipped and the
  1634. styles.xml embedded therein is used.
  1635. In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
  1636. and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
  1637. generated odt file. Use relative path for specifying the
  1638. FILE-MEMBERS. styles.xml must be specified as one of the
  1639. FILE-MEMBERS.
  1640. Use options 1, 2 or 3 only if styles.xml alone suffices for
  1641. achieving the desired formatting. Use option 4, if the styles.xml
  1642. references additional files like header and footer images for
  1643. achieving the desired formatting.
  1644. Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
  1645. a per-file basis. For example,
  1646. #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
  1647. #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
  1648. :group 'org-export-e-odt
  1649. :version "24.1"
  1650. :type
  1651. '(choice
  1652. (const :tag "Factory settings" nil)
  1653. (file :must-match t :tag "styles.xml")
  1654. (file :must-match t :tag "ODT or OTT file")
  1655. (list :tag "ODT or OTT file + Members"
  1656. (file :must-match t :tag "ODF Text or Text Template file")
  1657. (cons :tag "Members"
  1658. (file :tag " Member" "styles.xml")
  1659. (repeat (file :tag "Member"))))))
  1660. (defcustom org-e-odt-inline-image-extensions
  1661. '("png" "jpeg" "jpg" "gif")
  1662. "Extensions of image files that can be inlined into HTML."
  1663. :type '(repeat (string :tag "Extension"))
  1664. :group 'org-export-e-odt
  1665. :version "24.1")
  1666. (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
  1667. "Scaling factor for converting images pixels to inches.
  1668. Use this for sizing of embedded images. See Info node `(org)
  1669. Images in ODT export' for more information."
  1670. :type 'float
  1671. :group 'org-export-e-odt
  1672. :version "24.1")
  1673. (defcustom org-e-odt-create-custom-styles-for-srcblocks t
  1674. "Whether custom styles for colorized source blocks be automatically created.
  1675. When this option is turned on, the exporter creates custom styles
  1676. for source blocks based on the advice of `htmlfontify'. Creation
  1677. of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
  1678. When this option is turned off exporter does not create such
  1679. styles.
  1680. Use the latter option if you do not want the custom styles to be
  1681. based on your current display settings. It is necessary that the
  1682. styles.xml already contains needed styles for colorizing to work.
  1683. This variable is effective only if
  1684. `org-e-odt-fontify-srcblocks' is turned on."
  1685. :group 'org-export-e-odt
  1686. :version "24.1"
  1687. :type 'boolean)
  1688. (defcustom org-e-odt-preferred-output-format nil
  1689. "Automatically post-process to this format after exporting to \"odt\".
  1690. Interactive commands `org-export-as-e-odt' and
  1691. `org-export-as-e-odt-and-open' export first to \"odt\" format and
  1692. then use `org-e-odt-convert-process' to convert the
  1693. resulting document to this format. During customization of this
  1694. variable, the list of valid values are populated based on
  1695. `org-e-odt-convert-capabilities'."
  1696. :group 'org-export-e-odt
  1697. :version "24.1"
  1698. :type '(choice :convert-widget
  1699. (lambda (w)
  1700. (apply 'widget-convert (widget-type w)
  1701. (eval (car (widget-get w :args)))))
  1702. `((const :tag "None" nil)
  1703. ,@(mapcar (lambda (c)
  1704. `(const :tag ,c ,c))
  1705. (org-e-odt-reachable-formats "odt")))))
  1706. (defcustom org-e-odt-table-styles
  1707. '(("OrgEquation" "OrgEquation"
  1708. ((use-first-column-styles . t)
  1709. (use-last-column-styles . t))))
  1710. "Specify how Table Styles should be derived from a Table Template.
  1711. This is a list where each element is of the
  1712. form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
  1713. TABLE-STYLE-NAME is the style associated with the table through
  1714. \"#+ATTR_ODT: :style TABLE-STYLE-NAME\" line.
  1715. TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
  1716. TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
  1717. below) that is included in
  1718. `org-e-odt-content-template-file'.
  1719. TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
  1720. \"TableCell\"
  1721. PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
  1722. \"TableParagraph\"
  1723. TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
  1724. \"FirstRow\" | \"LastRow\" |
  1725. \"EvenRow\" | \"OddRow\" |
  1726. \"EvenColumn\" | \"OddColumn\" | \"\"
  1727. where \"+\" above denotes string concatenation.
  1728. TABLE-CELL-OPTIONS is an alist where each element is of the
  1729. form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
  1730. TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
  1731. `use-last-row-styles' |
  1732. `use-first-column-styles' |
  1733. `use-last-column-styles' |
  1734. `use-banding-rows-styles' |
  1735. `use-banding-columns-styles' |
  1736. `use-first-row-styles'
  1737. ON-OR-OFF := `t' | `nil'
  1738. For example, with the following configuration
  1739. \(setq org-e-odt-table-styles
  1740. '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
  1741. \(\(use-first-row-styles . t\)
  1742. \(use-first-column-styles . t\)\)\)
  1743. \(\"TableWithHeaderColumns\" \"Custom\"
  1744. \(\(use-first-column-styles . t\)\)\)\)\)
  1745. 1. A table associated with \"TableWithHeaderRowsAndColumns\"
  1746. style will use the following table-cell styles -
  1747. \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
  1748. \"CustomTableCell\" and the following paragraph styles
  1749. \"CustomFirstRowTableParagraph\",
  1750. \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
  1751. as appropriate.
  1752. 2. A table associated with \"TableWithHeaderColumns\" style will
  1753. use the following table-cell styles -
  1754. \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
  1755. following paragraph styles
  1756. \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
  1757. as appropriate..
  1758. Note that TABLE-TEMPLATE-NAME corresponds to the
  1759. \"<table:table-template>\" elements contained within
  1760. \"<office:styles>\". The entries (TABLE-STYLE-NAME
  1761. TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
  1762. \"table:template-name\" and \"table:use-first-row-styles\" etc
  1763. attributes of \"<table:table>\" element. Refer ODF-1.2
  1764. specification for more information. Also consult the
  1765. implementation filed under `org-e-odt-get-table-cell-styles'.
  1766. The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
  1767. formatting of numbered display equations. Do not delete this
  1768. style from the list."
  1769. :group 'org-export-e-odt
  1770. :version "24.1"
  1771. :type '(choice
  1772. (const :tag "None" nil)
  1773. (repeat :tag "Table Styles"
  1774. (list :tag "Table Style Specification"
  1775. (string :tag "Table Style Name")
  1776. (string :tag "Table Template Name")
  1777. (alist :options (use-first-row-styles
  1778. use-last-row-styles
  1779. use-first-column-styles
  1780. use-last-column-styles
  1781. use-banding-rows-styles
  1782. use-banding-columns-styles)
  1783. :key-type symbol
  1784. :value-type (const :tag "True" t))))))
  1785. (defcustom org-e-odt-fontify-srcblocks t
  1786. "Specify whether or not source blocks need to be fontified.
  1787. Turn this option on if you want to colorize the source code
  1788. blocks in the exported file. For colorization to work, you need
  1789. to make available an enhanced version of `htmlfontify' library."
  1790. :type 'boolean
  1791. :group 'org-export-e-odt
  1792. :version "24.1")
  1793. (defcustom org-e-odt-prettify-xml nil
  1794. "Specify whether or not the xml output should be prettified.
  1795. When this option is turned on, `indent-region' is run on all
  1796. component xml buffers before they are saved. Turn this off for
  1797. regular use. Turn this on if you need to examine the xml
  1798. visually."
  1799. :group 'org-export-e-odt
  1800. :version "24.1"
  1801. :type 'boolean)
  1802. (defcustom org-e-odt-convert-processes
  1803. '(("LibreOffice"
  1804. "soffice --headless --convert-to %f%x --outdir %d %i")
  1805. ("unoconv"
  1806. "unoconv -f %f -o %d %i"))
  1807. "Specify a list of document converters and their usage.
  1808. The converters in this list are offered as choices while
  1809. customizing `org-e-odt-convert-process'.
  1810. This variable is a list where each element is of the
  1811. form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
  1812. of the converter. CONVERTER-CMD is the shell command for the
  1813. converter and can contain format specifiers. These format
  1814. specifiers are interpreted as below:
  1815. %i input file name in full
  1816. %I input file name as a URL
  1817. %f format of the output file
  1818. %o output file name in full
  1819. %O output file name as a URL
  1820. %d output dir in full
  1821. %D output dir as a URL.
  1822. %x extra options as set in `org-e-odt-convert-capabilities'."
  1823. :group 'org-export-e-odt
  1824. :version "24.1"
  1825. :type
  1826. '(choice
  1827. (const :tag "None" nil)
  1828. (alist :tag "Converters"
  1829. :key-type (string :tag "Converter Name")
  1830. :value-type (group (string :tag "Command line")))))
  1831. (defcustom org-e-odt-convert-process "LibreOffice"
  1832. "Use this converter to convert from \"odt\" format to other formats.
  1833. During customization, the list of converter names are populated
  1834. from `org-e-odt-convert-processes'."
  1835. :group 'org-export-e-odt
  1836. :version "24.1"
  1837. :type '(choice :convert-widget
  1838. (lambda (w)
  1839. (apply 'widget-convert (widget-type w)
  1840. (eval (car (widget-get w :args)))))
  1841. `((const :tag "None" nil)
  1842. ,@(mapcar (lambda (c)
  1843. `(const :tag ,(car c) ,(car c)))
  1844. org-e-odt-convert-processes))))
  1845. (defcustom org-e-odt-convert-capabilities
  1846. '(("Text"
  1847. ("odt" "ott" "doc" "rtf" "docx")
  1848. (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
  1849. ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
  1850. ("Web"
  1851. ("html")
  1852. (("pdf" "pdf") ("odt" "odt") ("html" "html")))
  1853. ("Spreadsheet"
  1854. ("ods" "ots" "xls" "csv" "xlsx")
  1855. (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
  1856. ("xls" "xls") ("xlsx" "xlsx")))
  1857. ("Presentation"
  1858. ("odp" "otp" "ppt" "pptx")
  1859. (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
  1860. ("pptx" "pptx") ("odg" "odg"))))
  1861. "Specify input and output formats of `org-e-odt-convert-process'.
  1862. More correctly, specify the set of input and output formats that
  1863. the user is actually interested in.
  1864. This variable is an alist where each element is of the
  1865. form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
  1866. INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
  1867. alist where each element is of the form (OUTPUT-FMT
  1868. OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
  1869. The variable is interpreted as follows:
  1870. `org-e-odt-convert-process' can take any document that is in
  1871. INPUT-FMT-LIST and produce any document that is in the
  1872. OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
  1873. OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
  1874. serves dual purposes:
  1875. - It is used for populating completion candidates during
  1876. `org-e-odt-convert' commands.
  1877. - It is used as the value of \"%f\" specifier in
  1878. `org-e-odt-convert-process'.
  1879. EXTRA-OPTIONS is used as the value of \"%x\" specifier in
  1880. `org-e-odt-convert-process'.
  1881. DOCUMENT-CLASS is used to group a set of file formats in
  1882. INPUT-FMT-LIST in to a single class.
  1883. Note that this variable inherently captures how LibreOffice based
  1884. converters work. LibreOffice maps documents of various formats
  1885. to classes like Text, Web, Spreadsheet, Presentation etc and
  1886. allow document of a given class (irrespective of it's source
  1887. format) to be converted to any of the export formats associated
  1888. with that class.
  1889. See default setting of this variable for an typical
  1890. configuration."
  1891. :group 'org-export-e-odt
  1892. :version "24.1"
  1893. :type
  1894. '(choice
  1895. (const :tag "None" nil)
  1896. (alist :tag "Capabilities"
  1897. :key-type (string :tag "Document Class")
  1898. :value-type
  1899. (group (repeat :tag "Input formats" (string :tag "Input format"))
  1900. (alist :tag "Output formats"
  1901. :key-type (string :tag "Output format")
  1902. :value-type
  1903. (group (string :tag "Output file extension")
  1904. (choice
  1905. (const :tag "None" nil)
  1906. (string :tag "Extra options"))))))))
  1907. ;;;; Debugging
  1908. ;;;; Document
  1909. ;;;; Document Header (Styles)
  1910. ;;;; Document Header (Scripts)
  1911. ;;;; Document Header (Mathjax)
  1912. ;;;; Preamble
  1913. ;;;; Postamble
  1914. ;;;; Emphasis
  1915. ;;;; Todos
  1916. ;;;; Tags
  1917. ;;;; Timestamps
  1918. ;;;; Statistics Cookie
  1919. ;;;; Subscript
  1920. ;;;; Superscript
  1921. ;;;; Inline images
  1922. ;;;; Block
  1923. ;;;; Comment
  1924. ;;;; Comment Block
  1925. ;;;; Drawer
  1926. ;;;; Dynamic Block
  1927. ;;;; Emphasis
  1928. ;;;; Entity
  1929. ;;;; Example Block
  1930. ;;;; Export Snippet
  1931. ;;;; Export Block
  1932. ;;;; Fixed Width
  1933. ;;;; Footnotes
  1934. ;;;; Headline
  1935. ;;;; Horizontal Rule
  1936. ;;;; Inline Babel Call
  1937. ;;;; Inline Src Block
  1938. ;;;; Inlinetask
  1939. ;;;; Item
  1940. ;;;; Keyword
  1941. ;;;; Latex Environment
  1942. ;;;; Latex Fragment
  1943. ;;;; Line Break
  1944. ;;;; Link
  1945. ;;;; Babel Call
  1946. ;;;; Macro
  1947. ;;;; Paragraph
  1948. ;;;; Plain List
  1949. ;;;; Plain Text
  1950. ;;;; Property Drawer
  1951. ;;;; Quote Block
  1952. ;;;; Quote Section
  1953. ;;;; Section
  1954. ;;;; Radio Target
  1955. ;;;; Special Block
  1956. ;;;; Src Block
  1957. ;;;; Table
  1958. ;;;; Target
  1959. ;;;; Timestamp
  1960. ;;;; Verbatim
  1961. ;;;; Verse Block
  1962. ;;;; Headline
  1963. ;;;; Links
  1964. ;;;; Drawers
  1965. ;;;; Inlinetasks
  1966. ;;;; Publishing
  1967. ;;;; Compilation
  1968. ;;; User Configurable Variables (MAYBE)
  1969. ;;;; Preamble
  1970. ;;;; Headline
  1971. ;;;; Emphasis
  1972. (defcustom org-e-odt-format-headline-function nil
  1973. "Function to format headline text.
  1974. This function will be called with 5 arguments:
  1975. TODO the todo keyword \(string or nil\).
  1976. TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
  1977. PRIORITY the priority of the headline \(integer or nil\)
  1978. TEXT the main headline text \(string\).
  1979. TAGS the tags string, separated with colons \(string or nil\).
  1980. The function result will be used in the section format string.
  1981. As an example, one could set the variable to the following, in
  1982. order to reproduce the default set-up:
  1983. \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
  1984. \"Default format function for an headline.\"
  1985. \(concat \(when todo
  1986. \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
  1987. \(when priority
  1988. \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  1989. text
  1990. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
  1991. :group 'org-export-e-odt
  1992. :type 'function)
  1993. ;;;; Footnotes
  1994. ;;;; Timestamps
  1995. (defcustom org-e-odt-active-timestamp-format "\\textit{%s}"
  1996. "A printf format string to be applied to active timestamps."
  1997. :group 'org-export-e-odt
  1998. :type 'string)
  1999. (defcustom org-e-odt-inactive-timestamp-format "\\textit{%s}"
  2000. "A printf format string to be applied to inactive timestamps."
  2001. :group 'org-export-e-odt
  2002. :type 'string)
  2003. (defcustom org-e-odt-diary-timestamp-format "\\textit{%s}"
  2004. "A printf format string to be applied to diary timestamps."
  2005. :group 'org-export-e-odt
  2006. :type 'string)
  2007. ;;;; Links
  2008. (defcustom org-e-odt-inline-image-rules
  2009. '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
  2010. "Rules characterizing image files that can be inlined into HTML.
  2011. A rule consists in an association whose key is the type of link
  2012. to consider, and value is a regexp that will be matched against
  2013. link's path.
  2014. Note that, by default, the image extension *actually* allowed
  2015. depend on the way the HTML file is processed. When used with
  2016. pdflatex, pdf, jpg and png images are OK. When processing
  2017. through dvi to Postscript, only ps and eps are allowed. The
  2018. default we use here encompasses both."
  2019. :group 'org-export-e-odt
  2020. :type '(alist :key-type (string :tag "Type")
  2021. :value-type (regexp :tag "Path")))
  2022. ;;;; Tables
  2023. (defcustom org-e-odt-table-caption-above t
  2024. "When non-nil, place caption string at the beginning of the table.
  2025. Otherwise, place it near the end."
  2026. :group 'org-export-e-odt
  2027. :type 'boolean)
  2028. ;;;; Drawers
  2029. (defcustom org-e-odt-format-drawer-function nil
  2030. "Function called to format a drawer in HTML code.
  2031. The function must accept two parameters:
  2032. NAME the drawer name, like \"LOGBOOK\"
  2033. CONTENTS the contents of the drawer.
  2034. The function should return the string to be exported.
  2035. For example, the variable could be set to the following function
  2036. in order to mimic default behaviour:
  2037. \(defun org-e-odt-format-drawer-default \(name contents\)
  2038. \"Format a drawer element for HTML export.\"
  2039. contents\)"
  2040. :group 'org-export-e-odt
  2041. :type 'function)
  2042. ;;;; Inlinetasks
  2043. (defcustom org-e-odt-format-inlinetask-function nil
  2044. "Function called to format an inlinetask in HTML code.
  2045. The function must accept six parameters:
  2046. TODO the todo keyword, as a string
  2047. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  2048. PRIORITY the inlinetask priority, as a string
  2049. NAME the inlinetask name, as a string.
  2050. TAGS the inlinetask tags, as a string.
  2051. CONTENTS the contents of the inlinetask, as a string.
  2052. The function should return the string to be exported.
  2053. For example, the variable could be set to the following function
  2054. in order to mimic default behaviour:
  2055. \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
  2056. \"Format an inline task element for HTML export.\"
  2057. \(let \(\(full-title
  2058. \(concat
  2059. \(when todo
  2060. \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
  2061. \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  2062. title
  2063. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
  2064. \(format \(concat \"\\\\begin{center}\\n\"
  2065. \"\\\\fbox{\\n\"
  2066. \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
  2067. \"%s\\n\\n\"
  2068. \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
  2069. \"%s\"
  2070. \"\\\\end{minipage}}\"
  2071. \"\\\\end{center}\"\)
  2072. full-title contents\)\)"
  2073. :group 'org-export-e-odt
  2074. :type 'function)
  2075. ;; Src blocks
  2076. ;;;; Plain text
  2077. (defcustom org-e-odt-quotes
  2078. '(("fr"
  2079. ("\\(\\s-\\|[[(]\\|^\\)\"" . "« ")
  2080. ("\\(\\S-\\)\"" . "» ")
  2081. ("\\(\\s-\\|(\\|^\\)'" . "'"))
  2082. ("en"
  2083. ("\\(\\s-\\|[[(]\\|^\\)\"" . "“")
  2084. ("\\(\\S-\\)\"" . "”")
  2085. ("\\(\\s-\\|(\\|^\\)'" . "‘")
  2086. ("\\(\\S-\\)'" . "’")))
  2087. "Alist for quotes to use when converting english double-quotes.
  2088. The CAR of each item in this alist is the language code.
  2089. The CDR of each item in this alist is a list of three CONS:
  2090. - the first CONS defines the opening quote;
  2091. - the second CONS defines the closing quote;
  2092. - the last CONS defines single quotes.
  2093. For each item in a CONS, the first string is a regexp
  2094. for allowed characters before/after the quote, the second
  2095. string defines the replacement string for this quote."
  2096. :group 'org-export-e-odt
  2097. :type '(list
  2098. (cons :tag "Opening quote"
  2099. (string :tag "Regexp for char before")
  2100. (string :tag "Replacement quote "))
  2101. (cons :tag "Closing quote"
  2102. (string :tag "Regexp for char after ")
  2103. (string :tag "Replacement quote "))
  2104. (cons :tag "Single quote"
  2105. (string :tag "Regexp for char before")
  2106. (string :tag "Replacement quote "))))
  2107. ;;;; Compilation
  2108. ;;; Internal Functions (HTML)
  2109. ;;;; Bibliography
  2110. ;;;; Table
  2111. (defun org-e-odt-make-string (n string)
  2112. (let (out) (dotimes (i n out) (setq out (concat string out)))))
  2113. (defun org-e-odt-toc-text (toc-entries)
  2114. (let* ((prev-level (1- (nth 1 (car toc-entries))))
  2115. (start-level prev-level))
  2116. (mapconcat
  2117. (lambda (entry)
  2118. (let ((headline (nth 0 entry))
  2119. (level (nth 1 entry)))
  2120. (prog1 (org-e-odt-format-toc-item headline level prev-level)
  2121. (setq prev-level level))))
  2122. toc-entries "")))
  2123. (defun* org-e-odt-format-toc-headline
  2124. (todo todo-type priority text tags
  2125. &key level section-number headline-label &allow-other-keys)
  2126. ;; FIXME
  2127. (setq text (concat
  2128. (and org-export-with-section-numbers
  2129. (concat section-number ". "))
  2130. text
  2131. (and tags
  2132. (concat
  2133. (org-e-odt-format-spaces 3)
  2134. (org-e-odt-format-fontify tags "tag")))))
  2135. (when todo
  2136. (setq text (org-e-odt-format-fontify text "todo")))
  2137. (let ((org-e-odt-suppress-xref t))
  2138. (org-e-odt-format-link text (concat "#" headline-label))))
  2139. (defun org-e-odt-toc (depth info)
  2140. (assert (wholenump depth))
  2141. (let* ((headlines (org-export-collect-headlines info depth))
  2142. (toc-entries
  2143. (loop for headline in headlines collect
  2144. (list (org-e-odt-format-headline--wrap
  2145. headline info 'org-e-odt-format-toc-headline)
  2146. (org-export-get-relative-level headline info)))))
  2147. (when toc-entries
  2148. (let* ((lang-specific-heading "Table of Contents")) ; FIXME
  2149. (concat
  2150. (org-e-odt-begin-toc lang-specific-heading depth)
  2151. (org-e-odt-toc-text toc-entries)
  2152. (org-e-odt-end-toc))))))
  2153. ;; (defun org-e-odt-format-line (line)
  2154. ;; (case org-lparse-dyn-current-environment
  2155. ;; ((quote fixedwidth) (concat (org-e-odt-encode-plain-text line) "\n"))
  2156. ;; (t (concat line "\n"))))
  2157. (defun org-e-odt-fix-class-name (kwd) ; audit callers of this function
  2158. "Turn todo keyword into a valid class name.
  2159. Replaces invalid characters with \"_\"."
  2160. (save-match-data
  2161. (while (string-match "[^a-zA-Z0-9_]" kwd)
  2162. (setq kwd (replace-match "_" t t kwd))))
  2163. kwd)
  2164. (defun org-e-odt-format-internal-link (text href &optional extra)
  2165. (org-e-odt-format-link text (concat "#" href) extra))
  2166. (defun org-e-odt-format-extra-targets (extra-targets)
  2167. (if (not extra-targets) ""
  2168. (mapconcat (lambda (x)
  2169. (when x
  2170. (setq x (org-solidify-link-text
  2171. (if (org-uuidgen-p x) (concat "ID-" x) x)))
  2172. (org-e-odt-format-anchor "" x))) extra-targets "")))
  2173. (defun org-e-odt-format-org-tags (tags)
  2174. (if (not tags) ""
  2175. (org-e-odt-format-fontify
  2176. (mapconcat
  2177. (lambda (x)
  2178. (org-e-odt-format-fontify
  2179. x (concat "" ;; org-e-odt-tag-class-prefix
  2180. (org-e-odt-fix-class-name x))))
  2181. tags
  2182. (org-e-odt-format-spaces 1)) "tag")))
  2183. ;;; Internal Functions (Ngz)
  2184. (defun org-e-odt--caption/label-string (caption label info)
  2185. "Return caption and label HTML string for floats.
  2186. CAPTION is a cons cell of secondary strings, the car being the
  2187. standard caption and the cdr its short form. LABEL is a string
  2188. representing the label. INFO is a plist holding contextual
  2189. information.
  2190. If there's no caption nor label, return the empty string.
  2191. For non-floats, see `org-e-odt--wrap-label'."
  2192. (setq label nil) ;; FIXME
  2193. (let ((label-str (if label (format "\\label{%s}" label) "")))
  2194. (cond
  2195. ((and (not caption) (not label)) "")
  2196. ((not caption) (format "\\label{%s}\n" label))
  2197. ;; Option caption format with short name.
  2198. ((cdr caption)
  2199. (format "\\caption[%s]{%s%s}\n"
  2200. (org-export-data (cdr caption) info)
  2201. label-str
  2202. (org-export-data (car caption) info)))
  2203. ;; Standard caption format.
  2204. ;; (t (format "\\caption{%s%s}\n"
  2205. ;; label-str
  2206. ;; (org-export-data (car caption) info)))
  2207. (t (org-export-data (car caption) info)))))
  2208. (defun org-e-odt--find-verb-separator (s)
  2209. "Return a character not used in string S.
  2210. This is used to choose a separator for constructs like \\verb."
  2211. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  2212. (loop for c across ll
  2213. when (not (string-match (regexp-quote (char-to-string c)) s))
  2214. return (char-to-string c))))
  2215. (defun org-e-odt--quotation-marks (text info)
  2216. "Export quotation marks depending on language conventions.
  2217. TEXT is a string containing quotation marks to be replaced. INFO
  2218. is a plist used as a communication channel."
  2219. (mapc (lambda(l)
  2220. (let ((start 0))
  2221. (while (setq start (string-match (car l) text start))
  2222. (let ((new-quote (concat (match-string 1 text) (cdr l))))
  2223. (setq text (replace-match new-quote t t text))))))
  2224. (cdr (or (assoc (plist-get info :language) org-e-odt-quotes)
  2225. ;; Falls back on English.
  2226. (assoc "en" org-e-odt-quotes))))
  2227. text)
  2228. (defun org-e-odt--wrap-label (element output)
  2229. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  2230. This function shouldn't be used for floats. See
  2231. `org-e-odt--caption/label-string'."
  2232. ;; (let ((label (org-element-property :name element)))
  2233. ;; (if (or (not output) (not label) (string= output "") (string= label ""))
  2234. ;; output
  2235. ;; (concat (format "\\label{%s}\n" label) output)))
  2236. output)
  2237. ;;; Transcode Helpers
  2238. (defun* org-e-odt-format-headline
  2239. (todo todo-type priority text tags
  2240. &key level section-number headline-label &allow-other-keys)
  2241. (concat (org-e-odt-todo todo) (and todo " ") text
  2242. (and tags (org-e-odt-format-spaces 3))
  2243. (and tags (org-e-odt-format-org-tags tags))))
  2244. ;;;; Src Code
  2245. (defun org-e-odt-htmlfontify-string (line)
  2246. (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
  2247. (hfy-html-quote-map '(("\"" "&quot;")
  2248. ("<" "&lt;")
  2249. ("&" "&amp;")
  2250. (">" "&gt;")
  2251. (" " "<text:s/>")
  2252. (" " "<text:tab/>")))
  2253. (hfy-face-to-css 'org-e-odt-hfy-face-to-css)
  2254. (hfy-optimisations-1 (copy-seq hfy-optimisations))
  2255. (hfy-optimisations (add-to-list 'hfy-optimisations-1
  2256. 'body-text-only))
  2257. (hfy-begin-span-handler
  2258. (lambda (style text-block text-id text-begins-block-p)
  2259. (insert (format "<text:span text:style-name=\"%s\">" style))))
  2260. (hfy-end-span-handler (lambda nil (insert "</text:span>"))))
  2261. (htmlfontify-string line)))
  2262. (defun org-e-odt-do-format-code
  2263. (code &optional lang refs retain-labels num-start)
  2264. (let* ((lang (or (assoc-default lang org-src-lang-modes) lang))
  2265. (lang-mode (and lang (intern (format "%s-mode" lang))))
  2266. (code-lines (org-split-string code "\n"))
  2267. (code-length (length code-lines))
  2268. (use-htmlfontify-p (and (functionp lang-mode)
  2269. org-e-odt-fontify-srcblocks
  2270. (require 'htmlfontify nil t)
  2271. (fboundp 'htmlfontify-string)))
  2272. (code (if (not use-htmlfontify-p) code
  2273. (with-temp-buffer
  2274. (insert code)
  2275. (funcall lang-mode)
  2276. (font-lock-fontify-buffer)
  2277. (buffer-string))))
  2278. (fontifier (if use-htmlfontify-p 'org-e-odt-htmlfontify-string
  2279. 'org-e-odt-encode-plain-text))
  2280. (par-style (if use-htmlfontify-p "OrgSrcBlock"
  2281. "OrgFixedWidthBlock"))
  2282. (i 0))
  2283. (assert (= code-length (length (org-split-string code "\n"))))
  2284. (setq code
  2285. (org-export-format-code
  2286. code
  2287. (lambda (loc line-num ref)
  2288. (setq par-style
  2289. (concat par-style (and (= (incf i) code-length) "LastLine")))
  2290. (setq loc (concat loc (and ref retain-labels (format " (%s)" ref))))
  2291. (setq loc (funcall fontifier loc))
  2292. (when ref
  2293. (setq loc (org-e-odt-format-target loc (concat "coderef-" ref))))
  2294. (setq loc (org-e-odt-format-stylized-paragraph par-style loc))
  2295. (if (not line-num) loc
  2296. (org-e-odt-format-tags
  2297. '("<text:list-item>" . "</text:list-item>") loc)))
  2298. num-start refs))
  2299. (cond
  2300. ((not num-start) code)
  2301. ((equal num-start 0)
  2302. (org-e-odt-format-tags
  2303. '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
  2304. . "</text:list>") code " text:continue-numbering=\"false\""))
  2305. (t (org-e-odt-format-tags
  2306. '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
  2307. . "</text:list>") code " text:continue-numbering=\"true\"")))))
  2308. (defun org-e-odt-format-code (element info)
  2309. (let* ((lang (org-element-property :language element))
  2310. ;; Extract code and references.
  2311. (code-info (org-export-unravel-code element))
  2312. (code (car code-info))
  2313. (refs (cdr code-info))
  2314. ;; Does the src block contain labels?
  2315. (retain-labels (org-element-property :retain-labels element))
  2316. ;; Does it have line numbers?
  2317. (num-start (case (org-element-property :number-lines element)
  2318. (continued (org-export-get-loc element info))
  2319. (new 0))))
  2320. (org-e-odt-do-format-code code lang refs retain-labels num-start)))
  2321. ;;; Template
  2322. (defun org-e-odt-template (contents info)
  2323. "Return complete document string after HTML conversion.
  2324. CONTENTS is the transcoded contents string. RAW-DATA is the
  2325. original parsed data. INFO is a plist holding export options."
  2326. ;; write meta file
  2327. (org-e-odt-update-meta-file info)
  2328. (with-temp-buffer
  2329. (insert-file-contents
  2330. (or org-e-odt-content-template-file
  2331. (expand-file-name "OrgOdtContentTemplate.xml"
  2332. org-e-odt-styles-dir)))
  2333. (goto-char (point-min))
  2334. (re-search-forward "</office:text>" nil nil)
  2335. (goto-char (match-beginning 0))
  2336. ;; Title
  2337. (insert (org-e-odt-format-preamble info))
  2338. ;; Table of Contents
  2339. (let ((depth (plist-get info :with-toc)))
  2340. (when (wholenump depth) (insert (org-e-odt-toc depth info))))
  2341. ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
  2342. (org-e-odt-update-styles-file info)
  2343. ;; Update styles.xml - take care of outline numbering
  2344. (with-current-buffer
  2345. (find-file-noselect (expand-file-name "styles.xml") t)
  2346. ;; Don't make automatic backup of styles.xml file. This setting
  2347. ;; prevents the backed-up styles.xml file from being zipped in to
  2348. ;; odt file. This is more of a hackish fix. Better alternative
  2349. ;; would be to fix the zip command so that the output odt file
  2350. ;; includes only the needed files and excludes any auto-generated
  2351. ;; extra files like backups and auto-saves etc etc. Note that
  2352. ;; currently the zip command zips up the entire temp directory so
  2353. ;; that any auto-generated files created under the hood ends up in
  2354. ;; the resulting odt file.
  2355. (set (make-local-variable 'backup-inhibited) t)
  2356. (org-e-odt-configure-outline-numbering))
  2357. ;; Contents
  2358. (insert contents)
  2359. (buffer-substring-no-properties (point-min) (point-max))))
  2360. ;;; Transcode Functions
  2361. ;;;; Bold
  2362. (defun org-e-odt-bold (bold contents info)
  2363. "Transcode BOLD from Org to ODT.
  2364. CONTENTS is the text with bold markup. INFO is a plist holding
  2365. contextual information."
  2366. (org-e-odt-format-fontify contents 'bold))
  2367. ;;;; Center Block
  2368. (defun org-e-odt-center-block (center-block contents info)
  2369. "Transcode a CENTER-BLOCK element from Org to ODT.
  2370. CONTENTS holds the contents of the center block. INFO is a plist
  2371. holding contextual information."
  2372. (org-e-odt--wrap-label center-block contents))
  2373. ;;;; Clock
  2374. (defun org-e-odt-clock (clock contents info)
  2375. "Transcode a CLOCK element from Org to ODT.
  2376. CONTENTS is nil. INFO is a plist used as a communication
  2377. channel."
  2378. (org-e-odt-format-fontify
  2379. (concat (org-e-odt-format-fontify org-clock-string "timestamp-kwd")
  2380. (org-e-odt-format-fontify
  2381. (concat (org-translate-time (org-element-property :value clock))
  2382. (let ((time (org-element-property :time clock)))
  2383. (and time (format " (%s)" time))))
  2384. "timestamp"))
  2385. "timestamp-wrapper"))
  2386. ;;;; Code
  2387. (defun org-e-odt-code (code contents info)
  2388. "Transcode a CODE object from Org to ODT.
  2389. CONTENTS is nil. INFO is a plist used as a communication
  2390. channel."
  2391. (org-e-odt-format-fontify (org-element-property :value code) 'code))
  2392. ;;;; Comment
  2393. ;; Comments are ignored.
  2394. ;;;; Comment Block
  2395. ;; Comment Blocks are ignored.
  2396. ;;;; Drawer
  2397. (defun org-e-odt-drawer (drawer contents info)
  2398. "Transcode a DRAWER element from Org to ODT.
  2399. CONTENTS holds the contents of the block. INFO is a plist
  2400. holding contextual information."
  2401. (let* ((name (org-element-property :drawer-name drawer))
  2402. (output (if (functionp org-e-odt-format-drawer-function)
  2403. (funcall org-e-odt-format-drawer-function
  2404. name contents)
  2405. ;; If there's no user defined function: simply
  2406. ;; display contents of the drawer.
  2407. contents)))
  2408. (org-e-odt--wrap-label drawer output)))
  2409. ;;;; Dynamic Block
  2410. (defun org-e-odt-dynamic-block (dynamic-block contents info)
  2411. "Transcode a DYNAMIC-BLOCK element from Org to ODT.
  2412. CONTENTS holds the contents of the block. INFO is a plist
  2413. holding contextual information. See `org-export-data'."
  2414. (org-e-odt--wrap-label dynamic-block contents))
  2415. ;;;; Entity
  2416. (defun org-e-odt-entity (entity contents info)
  2417. "Transcode an ENTITY object from Org to ODT.
  2418. CONTENTS are the definition itself. INFO is a plist holding
  2419. contextual information."
  2420. ;; (let ((ent (org-element-property :latex entity)))
  2421. ;; (if (org-element-property :latex-math-p entity)
  2422. ;; (format "$%s$" ent)
  2423. ;; ent))
  2424. (org-element-property :utf-8 entity))
  2425. ;;;; Example Block
  2426. (defun org-e-odt-example-block (example-block contents info)
  2427. "Transcode a EXAMPLE-BLOCK element from Org to ODT.
  2428. CONTENTS is nil. INFO is a plist holding contextual information."
  2429. (org-e-odt--wrap-label
  2430. example-block (org-e-odt-format-code example-block info)))
  2431. ;;;; Export Snippet
  2432. (defun org-e-odt-export-snippet (export-snippet contents info)
  2433. "Transcode a EXPORT-SNIPPET object from Org to ODT.
  2434. CONTENTS is nil. INFO is a plist holding contextual information."
  2435. (when (eq (org-export-snippet-backend export-snippet) 'e-odt)
  2436. (org-element-property :value export-snippet)))
  2437. ;;;; Export Block
  2438. (defun org-e-odt-export-block (export-block contents info)
  2439. "Transcode a EXPORT-BLOCK element from Org to ODT.
  2440. CONTENTS is nil. INFO is a plist holding contextual information."
  2441. (when (string= (org-element-property :type export-block) "ODT")
  2442. (org-remove-indentation (org-element-property :value export-block))))
  2443. ;;;; Fixed Width
  2444. (defun org-e-odt-fixed-width (fixed-width contents info)
  2445. "Transcode a FIXED-WIDTH element from Org to ODT.
  2446. CONTENTS is nil. INFO is a plist holding contextual information."
  2447. (org-e-odt--wrap-label
  2448. fixed-width (org-e-odt-do-format-code
  2449. (org-element-property :value fixed-width))))
  2450. ;;;; Footnote Definition
  2451. ;; Footnote Definitions are ignored.
  2452. ;;;; Footnote Reference
  2453. (defun org-e-odt-footnote-def (raw info) ; FIXME
  2454. (if (equal (org-element-type raw) 'org-data)
  2455. (org-trim (org-export-data raw info)) ; fix paragraph style
  2456. (org-e-odt-format-stylized-paragraph
  2457. 'footnote (org-trim (org-export-data raw info)))))
  2458. (defvar org-e-odt-footnote-separator
  2459. (org-e-odt-format-fontify "," 'superscript))
  2460. (defun org-e-odt-footnote-reference (footnote-reference contents info)
  2461. "Transcode a FOOTNOTE-REFERENCE element from Org to ODT.
  2462. CONTENTS is nil. INFO is a plist holding contextual information."
  2463. (concat
  2464. ;; Insert separator between two footnotes in a row.
  2465. (let ((prev (org-export-get-previous-element footnote-reference info)))
  2466. (when (eq (org-element-type prev) 'footnote-reference)
  2467. org-e-odt-footnote-separator))
  2468. (cond
  2469. ((not (org-export-footnote-first-reference-p footnote-reference info))
  2470. (let* ((n (org-export-get-footnote-number footnote-reference info)))
  2471. (org-e-odt-format-footnote-reference n "IGNORED" 100)))
  2472. ;; Inline definitions are secondary strings.
  2473. ((eq (org-element-property :type footnote-reference) 'inline)
  2474. (let* ((raw (org-export-get-footnote-definition footnote-reference info))
  2475. (n (org-export-get-footnote-number footnote-reference info))
  2476. (def (org-e-odt-footnote-def raw info)))
  2477. (org-e-odt-format-footnote-reference n def 1)))
  2478. ;; Non-inline footnotes definitions are full Org data.
  2479. (t
  2480. (let* ((raw (org-export-get-footnote-definition footnote-reference info))
  2481. (n (org-export-get-footnote-number footnote-reference info))
  2482. (def (org-e-odt-footnote-def raw info)))
  2483. (org-e-odt-format-footnote-reference n def 1))))))
  2484. ;;;; Headline
  2485. (defun org-e-odt-todo (todo)
  2486. (when todo
  2487. (org-e-odt-format-fontify
  2488. (concat
  2489. "" ; org-e-odt-todo-kwd-class-prefix
  2490. (org-e-odt-fix-class-name todo))
  2491. (list (if (member todo org-done-keywords) "done" "todo")
  2492. todo))))
  2493. (defun org-e-odt-format-headline--wrap (headline info
  2494. &optional format-function
  2495. &rest extra-keys)
  2496. "Transcode an HEADLINE element from Org to ODT.
  2497. CONTENTS holds the contents of the headline. INFO is a plist
  2498. holding contextual information."
  2499. (let* ((level (+ (org-export-get-relative-level headline info)))
  2500. (headline-number (org-export-get-headline-number headline info))
  2501. (section-number (and (org-export-numbered-headline-p headline info)
  2502. (mapconcat 'number-to-string
  2503. headline-number ".")))
  2504. (todo (and (plist-get info :with-todo-keywords)
  2505. (let ((todo (org-element-property :todo-keyword headline)))
  2506. (and todo (org-export-data todo info)))))
  2507. (todo-type (and todo (org-element-property :todo-type headline)))
  2508. (priority (and (plist-get info :with-priority)
  2509. (org-element-property :priority headline)))
  2510. (text (org-export-data (org-element-property :title headline) info))
  2511. (tags (and (plist-get info :with-tags)
  2512. (org-export-get-tags headline info)))
  2513. (headline-label (concat "sec-" (mapconcat 'number-to-string
  2514. headline-number "-")))
  2515. (format-function (cond
  2516. ((functionp format-function) format-function)
  2517. ((functionp org-e-odt-format-headline-function)
  2518. (function*
  2519. (lambda (todo todo-type priority text tags
  2520. &allow-other-keys)
  2521. (funcall org-e-odt-format-headline-function
  2522. todo todo-type priority text tags))))
  2523. (t 'org-e-odt-format-headline))))
  2524. (apply format-function
  2525. todo todo-type priority text tags
  2526. :headline-label headline-label :level level
  2527. :section-number section-number extra-keys)))
  2528. (defun org-e-odt-headline (headline contents info)
  2529. "Transcode an HEADLINE element from Org to ODT.
  2530. CONTENTS holds the contents of the headline. INFO is a plist
  2531. holding contextual information."
  2532. (let* ((numberedp (org-export-numbered-headline-p headline info))
  2533. ;; Get level relative to current parsed data.
  2534. (level (org-export-get-relative-level headline info))
  2535. (text (org-export-data (org-element-property :title headline) info))
  2536. ;; Create the headline text.
  2537. (full-text (org-e-odt-format-headline--wrap headline info)))
  2538. (cond
  2539. ;; Case 1: This is a footnote section: ignore it.
  2540. ((org-element-property :footnote-section-p headline) nil)
  2541. ;; Case 2. This is a deep sub-tree: export it as a list item.
  2542. ;; Also export as items headlines for which no section
  2543. ;; format has been found.
  2544. ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
  2545. ;; Build the real contents of the sub-tree.
  2546. (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
  2547. (itemized-body (org-e-odt-format-list-item
  2548. contents type nil nil full-text)))
  2549. (concat
  2550. (and (org-export-first-sibling-p headline info)
  2551. (org-e-odt-begin-plain-list type))
  2552. itemized-body
  2553. (and (org-export-last-sibling-p headline info)
  2554. (org-e-odt-end-plain-list type)))))
  2555. ;; Case 3. Standard headline. Export it as a section.
  2556. (t
  2557. (let* ((extra-ids (list (org-element-property :custom-id headline)
  2558. (org-element-property :id headline)))
  2559. (extra-ids nil) ; FIXME
  2560. (id (concat "sec-" (mapconcat 'number-to-string
  2561. (org-export-get-headline-number
  2562. headline info) "-"))))
  2563. (concat
  2564. (org-e-odt-format-tags
  2565. '("<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">" .
  2566. "</text:h>")
  2567. (concat (org-e-odt-format-extra-targets extra-ids)
  2568. (if (not id) full-text (org-e-odt-format-target full-text id) ))
  2569. level level)
  2570. contents))))))
  2571. ;;;; Horizontal Rule
  2572. (defun org-e-odt-horizontal-rule (horizontal-rule contents info)
  2573. "Transcode an HORIZONTAL-RULE object from Org to ODT.
  2574. CONTENTS is nil. INFO is a plist holding contextual information."
  2575. (let ((attr (mapconcat #'identity
  2576. (org-element-property :attr_odt horizontal-rule)
  2577. " ")))
  2578. (org-e-odt--wrap-label horizontal-rule
  2579. (org-e-odt-format-horizontal-line))))
  2580. ;;;; Inline Babel Call
  2581. ;; Inline Babel Calls are ignored.
  2582. ;;;; Inline Src Block
  2583. (defun org-e-odt-inline-src-block (inline-src-block contents info)
  2584. "Transcode an INLINE-SRC-BLOCK element from Org to ODT.
  2585. CONTENTS holds the contents of the item. INFO is a plist holding
  2586. contextual information."
  2587. (let* ((org-lang (org-element-property :language inline-src-block))
  2588. (code (org-element-property :value inline-src-block))
  2589. (separator (org-e-odt--find-verb-separator code)))
  2590. (error "FIXME")))
  2591. ;;;; Inlinetask
  2592. (defun org-e-odt-format-section (text class &optional id)
  2593. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  2594. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  2595. (defun org-e-odt-inlinetask (inlinetask contents info)
  2596. "Transcode an INLINETASK element from Org to ODT.
  2597. CONTENTS holds the contents of the block. INFO is a plist
  2598. holding contextual information."
  2599. (cond
  2600. ;; If `org-e-odt-format-inlinetask-function' is provided, call it
  2601. ;; with appropriate arguments.
  2602. ((functionp org-e-odt-format-inlinetask-function)
  2603. (let ((format-function
  2604. (function*
  2605. (lambda (todo todo-type priority text tags
  2606. &key contents &allow-other-keys)
  2607. (funcall org-e-odt-format-inlinetask-function
  2608. todo todo-type priority text tags contents)))))
  2609. (org-e-odt-format-headline--wrap
  2610. inlinetask info format-function :contents contents)))
  2611. ;; Otherwise, use a default template.
  2612. (t (org-e-odt--wrap-label
  2613. inlinetask
  2614. (org-e-odt-format-stylized-paragraph
  2615. nil (org-e-odt-format-textbox
  2616. (concat (org-e-odt-format-stylized-paragraph
  2617. "OrgInlineTaskHeading" (org-e-odt-format-headline--wrap
  2618. inlinetask info))
  2619. contents)
  2620. nil nil "OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
  2621. ;;;; Italic
  2622. (defun org-e-odt-italic (italic contents info)
  2623. "Transcode ITALIC from Org to ODT.
  2624. CONTENTS is the text with italic markup. INFO is a plist holding
  2625. contextual information."
  2626. (org-e-odt-format-fontify contents 'italic))
  2627. ;;;; Item
  2628. (defun org-e-odt-format-list-item (contents type checkbox
  2629. &optional term-counter-id
  2630. headline)
  2631. (when checkbox
  2632. (setq checkbox
  2633. (org-e-odt-format-fontify (case checkbox
  2634. (on "[X]")
  2635. (off "[&nbsp;]")
  2636. (trans "[-]")) 'code)))
  2637. (concat
  2638. (org-e-odt-begin-list-item type term-counter-id headline)
  2639. ;; FIXME checkbox (and checkbox " ")
  2640. contents
  2641. (org-e-odt-end-list-item type)))
  2642. (defun org-e-odt-item (item contents info)
  2643. "Transcode an ITEM element from Org to ODT.
  2644. CONTENTS holds the contents of the item. INFO is a plist holding
  2645. contextual information."
  2646. (let* ((plain-list (org-export-get-parent item info))
  2647. (type (org-element-property :type plain-list))
  2648. (counter (org-element-property :counter item))
  2649. (checkbox (org-element-property :checkbox item))
  2650. (tag (let ((tag (org-element-property :tag item)))
  2651. (and tag (org-export-data tag info)))))
  2652. (org-e-odt-format-list-item
  2653. contents type checkbox (or tag counter))))
  2654. ;;;; Keyword
  2655. (defun org-e-odt-keyword (keyword contents info)
  2656. "Transcode a KEYWORD element from Org to ODT.
  2657. CONTENTS is nil. INFO is a plist holding contextual information."
  2658. (let ((key (org-element-property :key keyword))
  2659. (value (org-element-property :value keyword)))
  2660. (cond
  2661. ((string= key "LATEX") value)
  2662. ((string= key "INDEX") (format "\\index{%s}" value))
  2663. ((string= key "TARGET") nil ; FIXME
  2664. ;; (format "\\label{%s}" (org-export-solidify-link-text value))
  2665. )
  2666. ((string= key "toc")
  2667. (let ((value (downcase value)))
  2668. (cond
  2669. ((string-match "\\<headlines\\>" value)
  2670. (let ((depth (or (and (string-match "[0-9]+" value)
  2671. (string-to-number (match-string 0 value)))
  2672. (plist-get info :with-toc))))
  2673. (when (wholenump depth) (org-e-odt-toc depth info))))
  2674. ((string= "tables" value) "FIXME")
  2675. ((string= "figures" value) "FIXME")
  2676. ((string= "listings" value)
  2677. (cond
  2678. ;; At the moment, src blocks with a caption are wrapped
  2679. ;; into a figure environment.
  2680. (t "FIXME")))))))))
  2681. ;;;; Latex Environment
  2682. (defun org-e-odt-format-latex (latex-frag processing-type)
  2683. (let* ((prefix (case processing-type
  2684. (dvipng "ltxpng/")
  2685. (mathml "ltxmathml/")))
  2686. (cache-relpath
  2687. (concat prefix (file-name-sans-extension
  2688. (file-name-nondirectory (buffer-file-name)))))
  2689. (cache-dir (file-name-directory (buffer-file-name )))
  2690. (display-msg (case processing-type
  2691. (dvipng "Creating LaTeX Image...")
  2692. (mathml "Creating MathML snippet..."))))
  2693. (with-temp-buffer
  2694. (insert latex-frag)
  2695. (org-format-latex cache-relpath cache-dir nil display-msg
  2696. nil nil processing-type)
  2697. (buffer-string))))
  2698. (defun org-e-odt-latex-environment (latex-environment contents info)
  2699. "Transcode a LATEX-ENVIRONMENT element from Org to ODT.
  2700. CONTENTS is nil. INFO is a plist holding contextual information."
  2701. (org-e-odt--wrap-label
  2702. latex-environment
  2703. (let* ((latex-frag
  2704. (org-remove-indentation
  2705. (org-element-property :value latex-environment)))
  2706. (processing-type (plist-get info :LaTeX-fragments))
  2707. (caption (org-element-property :caption latex-environment))
  2708. (short-caption (and (cdr caption)
  2709. (org-export-data (cdr caption) info)))
  2710. (caption (and (car caption) (org-export-data (car caption) info)))
  2711. (label (org-element-property :name latex-environment))
  2712. (attr nil) ; FIXME
  2713. (label (org-element-property :name latex-environment)))
  2714. (cond
  2715. ((member processing-type '(t mathjax))
  2716. (org-e-odt-format-formula latex-environment info))
  2717. ((equal processing-type 'dvipng)
  2718. (org-e-odt-format-stylized-paragraph
  2719. nil (org-e-odt-link--inline-image latex-environment info)))
  2720. (t latex-frag)))))
  2721. ;;;; Latex Fragment
  2722. ;; (when latex-frag ; FIXME
  2723. ;; (setq href (org-propertize href :title "LaTeX Fragment"
  2724. ;; :description latex-frag)))
  2725. ;; handle verbatim
  2726. ;; provide descriptions
  2727. (defun org-e-odt-latex-fragment (latex-fragment contents info)
  2728. "Transcode a LATEX-FRAGMENT object from Org to ODT.
  2729. CONTENTS is nil. INFO is a plist holding contextual information."
  2730. (let* ((latex-frag (org-element-property :value latex-fragment))
  2731. (processing-type (plist-get info :LaTeX-fragments)))
  2732. (cond
  2733. ((member processing-type '(t mathjax))
  2734. (org-e-odt-format-formula latex-fragment info))
  2735. ((equal processing-type 'dvipng)
  2736. (org-e-odt-link--inline-image latex-fragment info))
  2737. (t latex-frag))))
  2738. ;;;; Line Break
  2739. (defun org-e-odt-line-break (line-break contents info)
  2740. "Transcode a LINE-BREAK object from Org to ODT.
  2741. CONTENTS is nil. INFO is a plist holding contextual information."
  2742. "<text:line-break/>\n")
  2743. ;;;; Link
  2744. (defun org-e-odt-link--inline-image (element info)
  2745. "Return HTML code for an inline image.
  2746. LINK is the link pointing to the inline image. INFO is a plist
  2747. used as a communication channel."
  2748. (let* ((src (cond
  2749. ((eq (org-element-type element) 'link)
  2750. (let* ((type (org-element-property :type element))
  2751. (raw-path (org-element-property :path element)))
  2752. (cond ((member type '("http" "https"))
  2753. (concat type ":" raw-path))
  2754. ((file-name-absolute-p raw-path)
  2755. (expand-file-name raw-path))
  2756. (t raw-path))))
  2757. ((member (org-element-type element)
  2758. '(latex-fragment latex-environment))
  2759. (let* ((latex-frag (org-remove-indentation
  2760. (org-element-property
  2761. :value element)))
  2762. (formula-link (org-e-odt-format-latex
  2763. latex-frag 'dvipng)))
  2764. (and formula-link
  2765. (string-match "file:\\([^]]*\\)" formula-link)
  2766. (match-string 1 formula-link))))
  2767. (t (error "what is this?"))))
  2768. (href (org-e-odt-format-tags
  2769. "<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
  2770. (org-e-odt-copy-image-file src)))
  2771. ;; extract attributes from #+ATTR_ODT line.
  2772. (attr-from (case (org-element-type element)
  2773. (link (org-export-get-parent-paragraph element info))
  2774. (t element)))
  2775. ;; convert attributes to a plist.
  2776. (attr-plist (org-e-odt-element-attributes attr-from info))
  2777. ;; handle `:anchor', `:style' and `:attributes' properties.
  2778. (user-frame-anchor
  2779. (car (assoc-string (plist-get attr-plist :anchor)
  2780. '(("as-char") ("paragraph") ("page")) t)))
  2781. (user-frame-style
  2782. (and user-frame-anchor (plist-get attr-plist :style)))
  2783. (user-frame-attrs
  2784. (and user-frame-anchor (plist-get attr-plist :attributes)))
  2785. (user-frame-params
  2786. (list user-frame-style user-frame-attrs user-frame-anchor))
  2787. ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
  2788. ;; extrac
  2789. ;; handle `:width', `:height' and `:scale' properties.
  2790. (size (org-e-odt-image-size-from-file
  2791. src (plist-get attr-plist :width)
  2792. (plist-get attr-plist :height)
  2793. (plist-get attr-plist :scale) nil ;; embed-as
  2794. "paragraph" ; FIXME
  2795. ))
  2796. (width (car size)) (height (cdr size))
  2797. (embed-as
  2798. (case (org-element-type element)
  2799. ((org-e-odt-standalone-image-p element info) "paragraph")
  2800. (latex-fragment "as-char")
  2801. (latex-environment "paragraph")
  2802. (t "paragraph")))
  2803. (captions (org-e-odt-format-label element info 'definition))
  2804. (caption (car captions)) (short-caption (cdr captions))
  2805. (entity (concat (and caption "Captioned") embed-as "Image")))
  2806. (org-e-odt-format-entity entity href width height
  2807. captions user-frame-params )))
  2808. (defun org-e-odt-format-entity (entity href width height &optional
  2809. captions user-frame-params)
  2810. (let* ((caption (car captions)) (short-caption (cdr captions))
  2811. (entity-style (assoc-string entity org-e-odt-entity-frame-styles t))
  2812. default-frame-params frame-params)
  2813. (cond
  2814. ((not caption)
  2815. (setq default-frame-params (nth 2 entity-style))
  2816. (setq frame-params (org-e-odt-merge-frame-params
  2817. default-frame-params user-frame-params))
  2818. (apply 'org-e-odt-format-frame href width height frame-params))
  2819. (t
  2820. (setq default-frame-params (nth 3 entity-style))
  2821. (setq frame-params (org-e-odt-merge-frame-params
  2822. default-frame-params user-frame-params))
  2823. (apply 'org-e-odt-format-textbox
  2824. (org-e-odt-format-stylized-paragraph
  2825. 'illustration
  2826. (concat
  2827. (apply 'org-e-odt-format-frame href width height
  2828. (let ((entity-style-1 (copy-sequence
  2829. (nth 2 entity-style))))
  2830. (setcar (cdr entity-style-1)
  2831. (concat
  2832. (cadr entity-style-1)
  2833. (and short-caption
  2834. (format " draw:name=\"%s\" "
  2835. short-caption))))
  2836. entity-style-1))
  2837. caption))
  2838. width height frame-params)))))
  2839. (defvar org-e-odt-standalone-image-predicate
  2840. (function (lambda (paragraph)
  2841. (or (org-element-property :caption paragraph)
  2842. (org-element-property :name paragraph)))))
  2843. (defun org-e-odt-standalone-image-p (element info &optional predicate)
  2844. "Test if ELEMENT is a standalone image for the purpose ODT export.
  2845. INFO is a plist holding contextual information.
  2846. Return non-nil, if ELEMENT is of type paragraph and it's sole
  2847. content, save for whitespaces, is a link that qualifies as an
  2848. inline image.
  2849. Return non-nil, if ELEMENT is of type link and it's containing
  2850. paragraph has no other content save for leading and trailing
  2851. whitespaces.
  2852. Return nil, otherwise.
  2853. Bind `org-e-odt-standalone-image-predicate' to constrain
  2854. paragraph further. For example, to check for only captioned
  2855. standalone images, do the following.
  2856. \(setq org-e-odt-standalone-image-predicate
  2857. \(lambda \(paragraph\)
  2858. \(org-element-property :caption paragraph\)\)\)
  2859. "
  2860. (let ((paragraph (case (org-element-type element)
  2861. (paragraph element)
  2862. (link (and (org-export-inline-image-p
  2863. element org-e-odt-inline-image-rules)
  2864. (org-export-get-parent element info)))
  2865. (t nil))))
  2866. (when paragraph
  2867. (assert (eq (org-element-type paragraph) 'paragraph))
  2868. (when (or (not (and (boundp 'org-e-odt-standalone-image-predicate)
  2869. (functionp org-e-odt-standalone-image-predicate)))
  2870. (funcall org-e-odt-standalone-image-predicate paragraph))
  2871. (let ((contents (org-element-contents paragraph)))
  2872. (loop for x in contents
  2873. with inline-image-count = 0
  2874. always (cond
  2875. ((eq (org-element-type x) 'plain-text)
  2876. (not (org-string-nw-p x)))
  2877. ((eq (org-element-type x) 'link)
  2878. (when (org-export-inline-image-p
  2879. x org-e-odt-inline-image-rules)
  2880. (= (incf inline-image-count) 1)))
  2881. (t nil))))))))
  2882. (defun org-e-odt-link (link desc info)
  2883. "Transcode a LINK object from Org to ODT.
  2884. DESC is the description part of the link, or the empty string.
  2885. INFO is a plist holding contextual information. See
  2886. `org-export-data'."
  2887. (let* ((type (org-element-property :type link))
  2888. (raw-path (org-element-property :path link))
  2889. ;; Ensure DESC really exists, or set it to nil.
  2890. (desc (and (not (string= desc "")) desc))
  2891. (imagep (org-export-inline-image-p
  2892. link org-e-odt-inline-image-rules))
  2893. (path (cond
  2894. ((member type '("http" "https" "ftp" "mailto"))
  2895. (concat type ":" raw-path))
  2896. ((string= type "file")
  2897. (when (string-match "\\(.+\\)::.+" raw-path)
  2898. (setq raw-path (match-string 1 raw-path)))
  2899. (if (file-name-absolute-p raw-path)
  2900. (concat "file://" (expand-file-name raw-path))
  2901. (concat "file://" raw-path)))
  2902. (t raw-path)))
  2903. protocol)
  2904. (cond
  2905. ;; Image file.
  2906. ((and (not desc) (org-export-inline-image-p
  2907. link org-e-odt-inline-image-rules))
  2908. (org-e-odt-link--inline-image link info))
  2909. ;; Radio target: Transcode target's contents and use them as
  2910. ;; link's description.
  2911. ((string= type "radio")
  2912. (let ((destination (org-export-resolve-radio-link link info)))
  2913. (when destination
  2914. (org-e-odt-format-internal-link
  2915. (org-export-data (org-element-contents destination) info)
  2916. (org-export-solidify-link-text path)))))
  2917. ;; Links pointing to an headline: Find destination and build
  2918. ;; appropriate referencing command.
  2919. ((member type '("custom-id" "fuzzy" "id"))
  2920. (let ((destination (if (string= type "fuzzy")
  2921. (org-export-resolve-fuzzy-link link info)
  2922. (org-export-resolve-id-link link info))))
  2923. (case (org-element-type destination)
  2924. ;; Fuzzy link points nowhere.
  2925. ('nil
  2926. (org-e-odt-format-fontify
  2927. (or desc (org-export-data
  2928. (org-element-property :raw-link link) info))
  2929. 'italic))
  2930. ;; Fuzzy link points to an invisible target.
  2931. (keyword nil)
  2932. ;; LINK points to an headline. If headlines are numbered
  2933. ;; and the link has no description, display headline's
  2934. ;; number. Otherwise, display description or headline's
  2935. ;; title.
  2936. (headline
  2937. (let* ((headline-no (org-export-get-headline-number destination info))
  2938. (label (format "sec-%s" (mapconcat 'number-to-string
  2939. headline-no "-")))
  2940. (section-no (mapconcat 'number-to-string headline-no ".")))
  2941. (setq desc
  2942. (cond
  2943. (desc desc)
  2944. ((plist-get info :section-numbers) section-no)
  2945. (t (org-export-data
  2946. (org-element-property :title destination) info))))
  2947. (org-e-odt-format-internal-link desc label)))
  2948. ;; Fuzzy link points to a target. Do as above.
  2949. (otherwise
  2950. ;; (unless desc
  2951. ;; (setq number (cond
  2952. ;; ((org-e-odt-standalone-image-p destination info)
  2953. ;; (org-export-get-ordinal
  2954. ;; (assoc 'link (org-element-contents destination))
  2955. ;; info 'link 'org-e-odt-standalone-image-p))
  2956. ;; (t (org-export-get-ordinal destination info))))
  2957. ;; (setq desc (when number
  2958. ;; (if (atom number) (number-to-string number)
  2959. ;; (mapconcat 'number-to-string number ".")))))
  2960. (let ((label-reference
  2961. (org-e-odt-format-label destination info 'reference)))
  2962. (assert label-reference)
  2963. label-reference)))))
  2964. ;; Coderef: replace link with the reference name or the
  2965. ;; equivalent line number.
  2966. ((string= type "coderef")
  2967. (let* ((fmt (org-export-get-coderef-format path desc))
  2968. (res (org-export-resolve-coderef path info))
  2969. (org-e-odt-suppress-xref nil)
  2970. (href (concat "#coderef-" path)))
  2971. (format fmt (org-e-odt-format-link res href))))
  2972. ;; Link type is handled by a special function.
  2973. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2974. (funcall protocol (org-link-unescape path) desc 'odt))
  2975. ;; External link with a description part.
  2976. ((and path desc) (org-e-odt-format-link desc path))
  2977. ;; External link without a description part.
  2978. (path (org-e-odt-format-link path path))
  2979. ;; No path, only description. Try to do something useful.
  2980. (t (org-e-odt-format-fontify desc 'italic)))))
  2981. ;;;; Babel Call
  2982. ;; Babel Calls are ignored.
  2983. ;;;; Macro
  2984. (defun org-e-odt-macro (macro contents info)
  2985. "Transcode a MACRO element from Org to ODT.
  2986. CONTENTS is nil. INFO is a plist holding contextual information."
  2987. ;; Use available tools.
  2988. (org-export-expand-macro macro info))
  2989. ;;;; Paragraph
  2990. (defun org-e-odt-paragraph (paragraph contents info)
  2991. "Transcode a PARAGRAPH element from Org to ODT.
  2992. CONTENTS is the contents of the paragraph, as a string. INFO is
  2993. the plist used as a communication channel."
  2994. (let* ((style nil) ; FIXME
  2995. (class (cdr (assoc style '((footnote . "footnote")
  2996. (verse . nil)))))
  2997. (extra (if class (format " class=\"%s\"" class) ""))
  2998. (parent (org-export-get-parent paragraph info))
  2999. (parent-type (org-element-type parent))
  3000. (style (case parent-type
  3001. (quote-block 'quote)
  3002. (center-block 'center)
  3003. (footnote-definition 'footnote)
  3004. (t nil))))
  3005. (org-e-odt-format-stylized-paragraph style contents)))
  3006. ;;;; Plain List
  3007. (defun org-e-odt-plain-list (plain-list contents info)
  3008. "Transcode a PLAIN-LIST element from Org to ODT.
  3009. CONTENTS is the contents of the list. INFO is a plist holding
  3010. contextual information."
  3011. (let* (arg1 ;; FIXME
  3012. (type (org-element-property :type plain-list))
  3013. (attr (mapconcat #'identity
  3014. (org-element-property :attr_odt plain-list)
  3015. " ")))
  3016. (org-e-odt--wrap-label
  3017. plain-list (format "%s\n%s%s"
  3018. (org-e-odt-begin-plain-list type)
  3019. contents (org-e-odt-end-plain-list type)))))
  3020. ;;;; Plain Text
  3021. (defun org-e-odt-plain-text (text info)
  3022. "Transcode a TEXT string from Org to ODT.
  3023. TEXT is the string to transcode. INFO is a plist holding
  3024. contextual information."
  3025. ;; Protect &, < and >.
  3026. (setq text (org-e-odt-encode-plain-text text t))
  3027. ;; Handle quotation marks
  3028. (setq text (org-e-odt--quotation-marks text info))
  3029. ;; Convert special strings.
  3030. (when (plist-get info :with-special-strings)
  3031. (mapc
  3032. (lambda (pair)
  3033. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t nil)))
  3034. org-e-odt-special-string-regexps))
  3035. ;; Handle break preservation if required.
  3036. (when (plist-get info :preserve-breaks)
  3037. (setq text (replace-regexp-in-string
  3038. "\\(\\\\\\\\\\)?[ \t]*\n" "<text:line-break/>\n" text t)))
  3039. ;; Return value.
  3040. text)
  3041. ;;;; Planning
  3042. (defun org-e-odt-planning (planning contents info)
  3043. "Transcode a PLANNING element from Org to ODT.
  3044. CONTENTS is nil. INFO is a plist used as a communication
  3045. channel."
  3046. (org-e-odt-format-fontify
  3047. (concat
  3048. (let ((closed (org-element-property :closed planning)))
  3049. (when closed
  3050. (concat (org-e-odt-format-fontify org-closed-string "timestamp-kwd")
  3051. (org-e-odt-format-fontify (org-translate-time closed)
  3052. "timestamp"))))
  3053. (let ((deadline (org-element-property :deadline planning)))
  3054. (when deadline
  3055. (concat (org-e-odt-format-fontify org-deadline-string "timestamp-kwd")
  3056. (org-e-odt-format-fontify (org-translate-time deadline)
  3057. "timestamp"))))
  3058. (let ((scheduled (org-element-property :scheduled planning)))
  3059. (when scheduled
  3060. (concat (org-e-odt-format-fontify org-scheduled-string "timestamp-kwd")
  3061. (org-e-odt-format-fontify (org-translate-time scheduled)
  3062. "timestamp")))))
  3063. "timestamp-wrapper"))
  3064. ;;;; Property Drawer
  3065. (defun org-e-odt-property-drawer (property-drawer contents info)
  3066. "Transcode a PROPERTY-DRAWER element from Org to ODT.
  3067. CONTENTS is nil. INFO is a plist holding contextual
  3068. information."
  3069. ;; The property drawer isn't exported but we want separating blank
  3070. ;; lines nonetheless.
  3071. "")
  3072. ;;;; Quote Block
  3073. (defun org-e-odt-quote-block (quote-block contents info)
  3074. "Transcode a QUOTE-BLOCK element from Org to ODT.
  3075. CONTENTS holds the contents of the block. INFO is a plist
  3076. holding contextual information."
  3077. (org-e-odt--wrap-label quote-block contents))
  3078. ;;;; Quote Section
  3079. (defun org-e-odt-quote-section (quote-section contents info)
  3080. "Transcode a QUOTE-SECTION element from Org to ODT.
  3081. CONTENTS is nil. INFO is a plist holding contextual information."
  3082. (let ((value (org-remove-indentation
  3083. (org-element-property :value quote-section))))
  3084. (when value (org-e-odt-do-format-code value))))
  3085. ;;;; Section
  3086. (defun org-e-odt-section (section contents info) ; FIXME
  3087. "Transcode a SECTION element from Org to ODT.
  3088. CONTENTS holds the contents of the section. INFO is a plist
  3089. holding contextual information."
  3090. contents)
  3091. ;;;; Radio Target
  3092. (defun org-e-odt-radio-target (radio-target text info)
  3093. "Transcode a RADIO-TARGET object from Org to ODT.
  3094. TEXT is the text of the target. INFO is a plist holding
  3095. contextual information."
  3096. (org-e-odt-format-anchor
  3097. text (org-export-solidify-link-text
  3098. (org-element-property :value radio-target))))
  3099. ;;;; Special Block
  3100. (defun org-e-odt-special-block (special-block contents info)
  3101. "Transcode a SPECIAL-BLOCK element from Org to ODT.
  3102. CONTENTS holds the contents of the block. INFO is a plist
  3103. holding contextual information."
  3104. (let ((type (downcase (org-element-property :type special-block))))
  3105. (org-e-odt--wrap-label
  3106. special-block
  3107. (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
  3108. ;;;; Src Block
  3109. (defun org-e-odt-src-block (src-block contents info)
  3110. "Transcode a SRC-BLOCK element from Org to ODT.
  3111. CONTENTS holds the contents of the item. INFO is a plist holding
  3112. contextual information."
  3113. (let* ((lang (org-element-property :language src-block))
  3114. (caption (org-element-property :caption src-block))
  3115. (short-caption (and (cdr caption)
  3116. (org-export-data (cdr caption) info)))
  3117. (caption (and (car caption) (org-export-data (car caption) info)))
  3118. (label (org-element-property :name src-block)))
  3119. ;; FIXME: Handle caption
  3120. ;; caption-str (when caption)
  3121. ;; (main (org-export-data (car caption) info))
  3122. ;; (secondary (org-export-data (cdr caption) info))
  3123. ;; (caption-str (org-e-odt--caption/label-string caption label info))
  3124. (let* ((captions (org-e-odt-format-label src-block info 'definition))
  3125. (caption (car captions)) (short-caption (cdr captions)))
  3126. (concat
  3127. (and caption (org-e-odt-format-stylized-paragraph 'listing caption))
  3128. (org-e-odt-format-code src-block info)))))
  3129. ;;;; Statistics Cookie
  3130. (defun org-e-odt-statistics-cookie (statistics-cookie contents info)
  3131. "Transcode a STATISTICS-COOKIE object from Org to ODT.
  3132. CONTENTS is nil. INFO is a plist holding contextual information."
  3133. (let ((cookie-value (org-element-property :value statistics-cookie)))
  3134. (org-e-odt-format-fontify cookie-value 'code)))
  3135. ;;;; Strike-Through
  3136. (defun org-e-odt-strike-through (strike-through contents info)
  3137. "Transcode STRIKE-THROUGH from Org to ODT.
  3138. CONTENTS is the text with strike-through markup. INFO is a plist
  3139. holding contextual information."
  3140. (org-e-odt-format-fontify contents 'strike))
  3141. ;;;; Subscript
  3142. (defun org-e-odt-subscript (subscript contents info)
  3143. "Transcode a SUBSCRIPT object from Org to ODT.
  3144. CONTENTS is the contents of the object. INFO is a plist holding
  3145. contextual information."
  3146. ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
  3147. (org-e-odt-format-fontify contents 'subscript))
  3148. ;;;; Superscript
  3149. (defun org-e-odt-superscript (superscript contents info)
  3150. "Transcode a SUPERSCRIPT object from Org to ODT.
  3151. CONTENTS is the contents of the object. INFO is a plist holding
  3152. contextual information."
  3153. ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
  3154. (org-e-odt-format-fontify contents 'superscript))
  3155. ;;;; Table Cell
  3156. (defun org-e-odt-table-style-spec (element info)
  3157. (let* ((table (org-export-get-parent-table element info))
  3158. (table-attributes (org-e-odt-element-attributes table info))
  3159. (table-style (plist-get table-attributes :style)))
  3160. (assoc table-style org-e-odt-table-styles)))
  3161. (defun org-e-odt-get-table-cell-styles (table-cell info)
  3162. "Retrieve styles applicable to a table cell.
  3163. R and C are (zero-based) row and column numbers of the table
  3164. cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
  3165. applicable to the current table. It is `nil' if the table is not
  3166. associated with any style attributes.
  3167. Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
  3168. When STYLE-SPEC is nil, style the table cell the conventional way
  3169. - choose cell borders based on row and column groupings and
  3170. choose paragraph alignment based on `org-col-cookies' text
  3171. property. See also
  3172. `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
  3173. When STYLE-SPEC is non-nil, ignore the above cookie and return
  3174. styles congruent with the ODF-1.2 specification."
  3175. (let* ((table-cell-address (org-export-table-cell-address table-cell info))
  3176. (r (car table-cell-address)) (c (cdr table-cell-address))
  3177. (style-spec (org-e-odt-table-style-spec table-cell info))
  3178. (table-dimensions (org-export-table-dimensions
  3179. (org-export-get-parent-table table-cell info)
  3180. info)))
  3181. (when style-spec
  3182. ;; LibreOffice - particularly the Writer - honors neither table
  3183. ;; templates nor custom table-cell styles. Inorder to retain
  3184. ;; inter-operability with LibreOffice, only automatic styles are
  3185. ;; used for styling of table-cells. The current implementation is
  3186. ;; congruent with ODF-1.2 specification and hence is
  3187. ;; future-compatible.
  3188. ;; Additional Note: LibreOffice's AutoFormat facility for tables -
  3189. ;; which recognizes as many as 16 different cell types - is much
  3190. ;; richer. Unfortunately it is NOT amenable to easy configuration
  3191. ;; by hand.
  3192. (let* ((template-name (nth 1 style-spec))
  3193. (cell-style-selectors (nth 2 style-spec))
  3194. (cell-type
  3195. (cond
  3196. ((and (cdr (assoc 'use-first-column-styles cell-style-selectors))
  3197. (= c 0)) "FirstColumn")
  3198. ((and (cdr (assoc 'use-last-column-styles cell-style-selectors))
  3199. (= (1+ c) (cdr table-dimensions)))
  3200. "LastColumn")
  3201. ((and (cdr (assoc 'use-first-row-styles cell-style-selectors))
  3202. (= r 0)) "FirstRow")
  3203. ((and (cdr (assoc 'use-last-row-styles cell-style-selectors))
  3204. (= (1+ r) (car table-dimensions)))
  3205. "LastRow")
  3206. ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors))
  3207. (= (% r 2) 1)) "EvenRow")
  3208. ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors))
  3209. (= (% r 2) 0)) "OddRow")
  3210. ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors))
  3211. (= (% c 2) 1)) "EvenColumn")
  3212. ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors))
  3213. (= (% c 2) 0)) "OddColumn")
  3214. (t ""))))
  3215. (concat template-name cell-type)))))
  3216. (defun org-e-odt-table-cell (table-cell contents info)
  3217. "Transcode a TABLE-CELL element from Org to ODT.
  3218. CONTENTS is nil. INFO is a plist used as a communication
  3219. channel."
  3220. (let* ((table-cell-address (org-export-table-cell-address table-cell info))
  3221. (r (car table-cell-address))
  3222. (c (cdr table-cell-address))
  3223. (horiz-span (or (org-export-table-cell-width table-cell info) 0))
  3224. (table-row (org-export-get-parent table-cell info))
  3225. (custom-style-prefix (org-e-odt-get-table-cell-styles
  3226. table-cell info))
  3227. (paragraph-style
  3228. (or
  3229. (and custom-style-prefix
  3230. (format "%sTableParagraph" custom-style-prefix))
  3231. (concat
  3232. (cond
  3233. ((and (= 1 (org-export-table-row-group table-row info))
  3234. (org-export-table-has-header-p
  3235. (org-export-get-parent-table table-row info) info))
  3236. "OrgTableHeading")
  3237. ((let* ((table (org-export-get-parent-table table-cell info))
  3238. (table-attrs (org-e-odt-element-attributes table info))
  3239. (table-header-columns (plist-get table-attrs
  3240. :header-columns)))
  3241. (<= c (cond ((wholenump table-header-columns)
  3242. (- table-header-columns 1))
  3243. (table-header-columns 0)
  3244. (t -1))))
  3245. "OrgTableHeading")
  3246. (t "OrgTableContents"))
  3247. (capitalize (symbol-name (org-export-table-cell-alignment
  3248. table-cell info))))))
  3249. (cell-style-name
  3250. (or
  3251. (and custom-style-prefix (format "%sTableCell"
  3252. custom-style-prefix))
  3253. (concat
  3254. "OrgTblCell"
  3255. (when (or (org-export-table-row-starts-rowgroup-p table-row info)
  3256. (zerop r)) "T")
  3257. (when (org-export-table-row-ends-rowgroup-p table-row info) "B")
  3258. (when (and (org-export-table-cell-starts-colgroup-p table-cell info)
  3259. (not (zerop c)) ) "L"))))
  3260. (cell-attributes
  3261. (concat
  3262. (format " table:style-name=\"%s\"" cell-style-name)
  3263. (and (> horiz-span 0)
  3264. (format " table:number-columns-spanned=\"%d\""
  3265. (1+ horiz-span))))))
  3266. (unless contents (setq contents ""))
  3267. (concat
  3268. (org-e-odt-format-tags
  3269. '("<table:table-cell%s>" . "</table:table-cell>")
  3270. (org-e-odt-format-stylized-paragraph paragraph-style contents)
  3271. cell-attributes)
  3272. (let (s)
  3273. (dotimes (i horiz-span s)
  3274. (setq s (concat s "\n<table:covered-table-cell/>"))))
  3275. "\n")))
  3276. ;;;; Table Row
  3277. (defun org-e-odt-table-row (table-row contents info)
  3278. "Transcode a TABLE-ROW element from Org to ODT.
  3279. CONTENTS is the contents of the row. INFO is a plist used as a
  3280. communication channel."
  3281. ;; Rules are ignored since table separators are deduced from
  3282. ;; borders of the current row.
  3283. (when (eq (org-element-property :type table-row) 'standard)
  3284. (let* ((rowgroup-tags
  3285. (if (and (= 1 (org-export-table-row-group table-row info))
  3286. (org-export-table-has-header-p
  3287. (org-export-get-parent-table table-row info) info))
  3288. ;; If the row belongs to the first rowgroup and the
  3289. ;; table has more than one row groups, then this row
  3290. ;; belongs to the header row group.
  3291. '("\n<table:table-header-rows>" . "\n</table:table-header-rows>")
  3292. ;; Otherwise, it belongs to non-header row group.
  3293. '("\n<table:table-rows>" . "\n</table:table-rows>"))))
  3294. (concat
  3295. ;; Does this row begin a rowgroup?
  3296. (when (org-export-table-row-starts-rowgroup-p table-row info)
  3297. (car rowgroup-tags))
  3298. ;; Actual table row
  3299. (org-e-odt-format-tags
  3300. '("<table:table-row>" . "</table:table-row>") contents)
  3301. ;; Does this row end a rowgroup?
  3302. (when (org-export-table-row-ends-rowgroup-p table-row info)
  3303. (cdr rowgroup-tags))))))
  3304. ;;;; Table
  3305. (defun org-e-odt-table-first-row-data-cells (table info)
  3306. (let ((table-row
  3307. (org-element-map
  3308. table 'table-row
  3309. (lambda (row)
  3310. (unless (eq (org-element-property :type row) 'rule) row))
  3311. info 'first-match))
  3312. (special-column-p (org-export-table-has-special-column-p table)))
  3313. (if (not special-column-p) (org-element-contents table-row)
  3314. (cdr (org-element-contents table-row)))))
  3315. (defun org-e-odt--table (table contents info)
  3316. "Transcode a TABLE element from Org to ODT.
  3317. CONTENTS is the contents of the table. INFO is a plist holding
  3318. contextual information."
  3319. (case (org-element-property :type table)
  3320. ;; Case 1: table.el doesn't support export to OD format. Strip
  3321. ;; such tables from export.
  3322. (table.el
  3323. (prog1 nil
  3324. (message
  3325. (concat
  3326. "(org-e-odt): Found table.el-type table in the source Org file."
  3327. " table.el doesn't support export to ODT format."
  3328. " Stripping the table from export."))))
  3329. ;; Case 2: Native Org tables.
  3330. (otherwise
  3331. (let* ((captions (org-e-odt-format-label table info 'definition))
  3332. (caption (car captions)) (short-caption (cdr captions))
  3333. (attributes (org-e-odt-element-attributes table info))
  3334. (custom-table-style (nth 1 (org-e-odt-table-style-spec table info)))
  3335. (table-column-specs
  3336. (function
  3337. (lambda (table info)
  3338. (let* ((table-style (or custom-table-style "OrgTable"))
  3339. (column-style (format "%sColumn" table-style)))
  3340. (mapconcat
  3341. (lambda (table-cell)
  3342. (let ((width (1+ (or (org-export-table-cell-width
  3343. table-cell info) 0))))
  3344. (org-e-odt-make-string
  3345. width
  3346. (org-e-odt-format-tags
  3347. "<table:table-column table:style-name=\"%s\"/>"
  3348. "" column-style))))
  3349. (org-e-odt-table-first-row-data-cells table info) "\n"))))))
  3350. (concat
  3351. ;; caption.
  3352. (when caption (org-e-odt-format-stylized-paragraph 'table caption))
  3353. ;; begin table.
  3354. (let* ((automatic-name
  3355. (org-e-odt-add-automatic-style "Table" attributes)))
  3356. (format
  3357. "\n<table:table table:name=\"%s\" table:style-name=\"%s\">\n"
  3358. (or short-caption (car automatic-name))
  3359. (or custom-table-style (cdr automatic-name) "OrgTable")))
  3360. ;; column specification.
  3361. (funcall table-column-specs table info)
  3362. ;; actual contents.
  3363. "\n" contents
  3364. ;; end table.
  3365. "</table:table>")))))
  3366. (defun org-e-odt-table (table contents info)
  3367. "Transcode a TABLE element from Org to ODT.
  3368. CONTENTS is the contents of the table. INFO is a plist holding
  3369. contextual information."
  3370. (let* ((transcoded-table (org-e-odt--table table contents info))
  3371. (genealogy (org-export-get-genealogy table info))
  3372. (list-genealogy (and (equal (org-element-type (car genealogy)) 'item)
  3373. (loop for element in genealogy
  3374. when (member (org-element-type element)
  3375. '(item plain-list))
  3376. collect element))))
  3377. (when (and transcoded-table list-genealogy)
  3378. (let ((parent-list (nth 1 list-genealogy)))
  3379. (assert (equal (org-element-type parent-list) 'plain-list))
  3380. (assert
  3381. (not (equal (org-element-property :type parent-list) 'descriptive))
  3382. nil "ODT export doesn't support tables within description list."))
  3383. ;; Within the Org file, the table is appearing within a
  3384. ;; list item. OpenDocument doesn't allow table to appear
  3385. ;; within list items. Temporarily terminate the list, put
  3386. ;; the table in an indented section and then re-continue
  3387. ;; the list.
  3388. ;; Put the Table in an indented section.
  3389. (setq transcoded-table
  3390. (let ((level (/ (length list-genealogy) 2)))
  3391. (concat (org-e-odt-begin-section
  3392. (format "OrgIndentedSection-Level-%d" level))
  3393. transcoded-table (org-e-odt-end-section))))
  3394. (loop for element in list-genealogy
  3395. when (equal (org-element-type element) 'plain-list)
  3396. do (setq transcoded-table
  3397. (concat
  3398. ;; Discontinue this list.
  3399. "\n</text:list-item>"
  3400. "\n</text:list>"
  3401. ;; Embed the table.
  3402. transcoded-table
  3403. ;; Continute the this list.
  3404. (org-e-odt-begin-plain-list
  3405. (org-element-property :type element)
  3406. 'continue-numbering)
  3407. (if (cdr element) "\n<text:list-item>"
  3408. "\n<text:list-header>")))))
  3409. transcoded-table))
  3410. ;;;; Target
  3411. (defun org-e-odt-target (target contents info)
  3412. "Transcode a TARGET object from Org to ODT.
  3413. CONTENTS is nil. INFO is a plist holding contextual
  3414. information."
  3415. (org-e-odt-format-anchor
  3416. "" (org-export-solidify-link-text (org-element-property :value target))))
  3417. ;;;; Timestamp
  3418. (defun org-e-odt-timestamp (timestamp contents info)
  3419. "Transcode a TIMESTAMP object from Org to ODT.
  3420. CONTENTS is nil. INFO is a plist used as a communication
  3421. channel."
  3422. (org-e-odt-format-fontify
  3423. (org-e-odt-format-fontify
  3424. (org-translate-time (org-element-property :value timestamp))
  3425. "timestamp")
  3426. "timestamp-wrapper"))
  3427. ;;;; Underline
  3428. (defun org-e-odt-underline (underline contents info)
  3429. "Transcode UNDERLINE from Org to ODT.
  3430. CONTENTS is the text with underline markup. INFO is a plist
  3431. holding contextual information."
  3432. (org-e-odt-format-fontify contents 'underline))
  3433. ;;;; Verbatim
  3434. (defun org-e-odt-verbatim (verbatim contents info)
  3435. "Transcode a VERBATIM object from Org to ODT.
  3436. CONTENTS is nil. INFO is a plist used as a communication
  3437. channel."
  3438. (org-e-odt-format-fontify (org-element-property :value verbatim) 'verbatim))
  3439. ;;;; Verse Block
  3440. (defun org-e-odt-verse-block (verse-block contents info)
  3441. "Transcode a VERSE-BLOCK element from Org to ODT.
  3442. CONTENTS is verse block contents. INFO is a plist holding
  3443. contextual information."
  3444. ;; Add line breaks to each line of verse.
  3445. (setq contents (replace-regexp-in-string
  3446. "\\(<text:line-break/>\\)?[ \t]*\n"
  3447. "<text:line-break/>" contents))
  3448. ;; Replace tabs and spaces.
  3449. (setq contents (org-e-odt-fill-tabs-and-spaces contents))
  3450. ;; Surround it in a verse environment.
  3451. (org-e-odt--wrap-label
  3452. verse-block (org-e-odt-format-stylized-paragraph 'verse contents)))
  3453. ;;; Filter Functions
  3454. ;;;; Filter Settings
  3455. ;;;; Filters
  3456. ;;; Interactive functions
  3457. ;;;###autoload
  3458. (defun org-e-odt-export-to-odt
  3459. (&optional subtreep visible-only body-only ext-plist pub-dir)
  3460. "Export current buffer to a HTML file.
  3461. If narrowing is active in the current buffer, only export its
  3462. narrowed part.
  3463. If a region is active, export that region.
  3464. When optional argument SUBTREEP is non-nil, export the sub-tree
  3465. at point, extracting information from the headline properties
  3466. first.
  3467. When optional argument VISIBLE-ONLY is non-nil, don't export
  3468. contents of hidden elements.
  3469. When optional argument BODY-ONLY is non-nil, only write code
  3470. between \"\\begin{document}\" and \"\\end{document}\".
  3471. EXT-PLIST, when provided, is a property list with external
  3472. parameters overriding Org default settings, but still inferior to
  3473. file-local settings.
  3474. When optional argument PUB-DIR is set, use it as the publishing
  3475. directory.
  3476. Return output file's name."
  3477. (interactive)
  3478. (setq debug-on-error t) ; FIXME
  3479. (let* ((outbuf (org-e-odt-init-outfile))
  3480. (target (org-export-output-file-name ".odt" subtreep pub-dir))
  3481. (outdir (file-name-directory (buffer-file-name outbuf)))
  3482. (default-directory outdir))
  3483. ;; FIXME: for copying embedded images
  3484. (setq org-current-export-file
  3485. (file-name-directory
  3486. (org-export-output-file-name ".odt" subtreep nil)))
  3487. (org-export-to-buffer
  3488. 'e-odt outbuf
  3489. (memq 'subtree optns) (memq 'visible optns) (memq 'body optns))
  3490. (setq org-lparse-opt-plist nil) ; FIXME
  3491. (org-e-odt-save-as-outfile target ;; info
  3492. nil
  3493. )
  3494. ;; return outfile
  3495. (if (not org-e-odt-preferred-output-format) target
  3496. (or (org-e-odt-convert target org-e-odt-preferred-output-format)
  3497. target))))
  3498. (defun org-e-odt-reachable-p (in-fmt out-fmt)
  3499. "Return non-nil if IN-FMT can be converted to OUT-FMT."
  3500. (catch 'done
  3501. (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt)))
  3502. (dolist (e reachable-formats)
  3503. (let ((out-fmt-spec (assoc out-fmt (cdr e))))
  3504. (when out-fmt-spec
  3505. (throw 'done (cons (car e) out-fmt-spec))))))))
  3506. (defun org-e-odt-do-convert (in-file out-fmt &optional prefix-arg)
  3507. "Workhorse routine for `org-e-odt-convert'."
  3508. (require 'browse-url)
  3509. (let* ((in-file (expand-file-name (or in-file buffer-file-name)))
  3510. (dummy (or (file-readable-p in-file)
  3511. (error "Cannot read %s" in-file)))
  3512. (in-fmt (file-name-extension in-file))
  3513. (out-fmt (or out-fmt (error "Output format unspecified")))
  3514. (how (or (org-e-odt-reachable-p in-fmt out-fmt)
  3515. (error "Cannot convert from %s format to %s format?"
  3516. in-fmt out-fmt)))
  3517. (convert-process (car how))
  3518. (out-file (concat (file-name-sans-extension in-file) "."
  3519. (nth 1 (or (cdr how) out-fmt))))
  3520. (extra-options (or (nth 2 (cdr how)) ""))
  3521. (out-dir (file-name-directory in-file))
  3522. (cmd (format-spec convert-process
  3523. `((?i . ,(shell-quote-argument in-file))
  3524. (?I . ,(browse-url-file-url in-file))
  3525. (?f . ,out-fmt)
  3526. (?o . ,out-file)
  3527. (?O . ,(browse-url-file-url out-file))
  3528. (?d . , (shell-quote-argument out-dir))
  3529. (?D . ,(browse-url-file-url out-dir))
  3530. (?x . ,extra-options)))))
  3531. (when (file-exists-p out-file)
  3532. (delete-file out-file))
  3533. (message "Executing %s" cmd)
  3534. (let ((cmd-output (shell-command-to-string cmd)))
  3535. (message "%s" cmd-output))
  3536. (cond
  3537. ((file-exists-p out-file)
  3538. (message "Exported to %s" out-file)
  3539. (when prefix-arg
  3540. (message "Opening %s..." out-file)
  3541. (org-open-file out-file))
  3542. out-file)
  3543. (t
  3544. (message "Export to %s failed" out-file)
  3545. nil))))
  3546. (defun org-e-odt-do-reachable-formats (in-fmt)
  3547. "Return verbose info about formats to which IN-FMT can be converted.
  3548. Return a list where each element is of the
  3549. form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
  3550. `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
  3551. `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
  3552. (let* ((converter
  3553. (and org-e-odt-convert-process
  3554. (cadr (assoc-string org-e-odt-convert-process
  3555. org-e-odt-convert-processes t))))
  3556. (capabilities
  3557. (and org-e-odt-convert-process
  3558. (cadr (assoc-string org-e-odt-convert-process
  3559. org-e-odt-convert-processes t))
  3560. org-e-odt-convert-capabilities))
  3561. reachable-formats)
  3562. (when converter
  3563. (dolist (c capabilities)
  3564. (when (member in-fmt (nth 1 c))
  3565. (push (cons converter (nth 2 c)) reachable-formats))))
  3566. reachable-formats))
  3567. (defun org-e-odt-reachable-formats (in-fmt)
  3568. "Return list of formats to which IN-FMT can be converted.
  3569. The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
  3570. (let (l)
  3571. (mapc (lambda (e) (add-to-list 'l e))
  3572. (apply 'append (mapcar
  3573. (lambda (e) (mapcar 'car (cdr e)))
  3574. (org-e-odt-do-reachable-formats in-fmt))))
  3575. l))
  3576. (defun org-e-odt-convert-read-params ()
  3577. "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
  3578. This is a helper routine for interactive use."
  3579. (let* ((input (if (featurep 'ido) 'ido-completing-read 'completing-read))
  3580. (in-file (read-file-name "File to be converted: "
  3581. nil buffer-file-name t))
  3582. (in-fmt (file-name-extension in-file))
  3583. (out-fmt-choices (org-e-odt-reachable-formats in-fmt))
  3584. (out-fmt
  3585. (or (and out-fmt-choices
  3586. (funcall input "Output format: "
  3587. out-fmt-choices nil nil nil))
  3588. (error
  3589. "No known converter or no known output formats for %s files"
  3590. in-fmt))))
  3591. (list in-file out-fmt)))
  3592. ;;;###autoload
  3593. (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg)
  3594. "Convert IN-FILE to format OUT-FMT using a command line converter.
  3595. IN-FILE is the file to be converted. If unspecified, it defaults
  3596. to variable `buffer-file-name'. OUT-FMT is the desired output
  3597. format. Use `org-e-odt-convert-process' as the converter.
  3598. If PREFIX-ARG is non-nil then the newly converted file is opened
  3599. using `org-open-file'."
  3600. (interactive
  3601. (append (org-e-odt-convert-read-params) current-prefix-arg))
  3602. (org-e-odt-do-convert in-file out-fmt prefix-arg))
  3603. ;;; FIXMES, TODOS, FOR REVIEW etc
  3604. ;;;; org-solidify-link-text
  3605. ;;;; coding system
  3606. ;;;; org-e-odt-table-caption-above
  3607. ;;;; org-e-odt-with-timestamp
  3608. ;;;; org-e-odt-html-helper-timestamp
  3609. ;;;; (org-export-directory :html opt-plist)
  3610. ;;;; org-e-odt-todo-kwd-class-prefix
  3611. ;;;; org-e-odt-tag-class-prefix
  3612. ;;;; org-e-odt-footnote-separator
  3613. ;;; Library Initializations
  3614. (mapc
  3615. (lambda (desc)
  3616. ;; Let Org open all OpenDocument files using system-registered app
  3617. (add-to-list 'org-file-apps
  3618. (cons (concat "\\." (car desc) "\\'") 'system))
  3619. ;; Let Emacs open all OpenDocument files in archive mode
  3620. (add-to-list 'auto-mode-alist
  3621. (cons (concat "\\." (car desc) "\\'") 'archive-mode)))
  3622. org-e-odt-file-extensions)
  3623. (defvar org-e-odt-display-outline-level 2)
  3624. (defun org-e-odt-enumerate-element (element info &optional predicate n)
  3625. (let* ((numbered-parent-headline-at-<=-n
  3626. (function
  3627. (lambda (element n info)
  3628. (loop for x in (org-export-get-genealogy element info)
  3629. thereis (and (eq (org-element-type x) 'headline)
  3630. (<= (org-export-get-relative-level x info) n)
  3631. (org-export-numbered-headline-p x info)
  3632. x)))))
  3633. (enumerate
  3634. (function
  3635. (lambda (element scope info &optional predicate)
  3636. (let ((counter 0))
  3637. (org-element-map
  3638. (or scope (plist-get info :parse-tree))
  3639. (org-element-type element)
  3640. (lambda (el)
  3641. (and (or (not predicate) (funcall predicate el info))
  3642. (incf counter)
  3643. (equal element el)
  3644. counter))
  3645. info 'first-match)))))
  3646. (scope (funcall numbered-parent-headline-at-<=-n
  3647. element (or n org-e-odt-display-outline-level) info))
  3648. (ordinal (funcall enumerate element scope info predicate))
  3649. (tag
  3650. (concat
  3651. ;; section number
  3652. (and scope
  3653. (mapconcat 'number-to-string
  3654. (org-export-get-headline-number scope info) "."))
  3655. ;; separator
  3656. (and scope ".")
  3657. ;; ordinal
  3658. (number-to-string ordinal))))
  3659. ;; (message "%s:\t%s" (org-element-property :name element) tag)
  3660. tag))
  3661. (provide 'org-e-odt)
  3662. ;;; org-e-odt.el ends here