org-e-odt.el 162 KB

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