org-e-odt.el 149 KB

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