org-e-odt.el 181 KB

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