org-e-odt.el 157 KB

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