org-e-odt.el 157 KB

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