org-e-html.el 173 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902
  1. ;;; org-e-html.el --- HTML Back-End For Org Export Engine
  2. ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This library implements a HTML back-end for Org generic exporter.
  17. ;; To test it, run
  18. ;;
  19. ;; M-: (org-export-to-buffer 'e-html "*Test e-HTML*") RET
  20. ;;
  21. ;; in an org-mode buffer then switch to the buffer to see the HTML
  22. ;; export. See contrib/lisp/org-export.el for more details on how
  23. ;; this exporter works.
  24. ;; It introduces three new buffer keywords: "LATEX_CLASS",
  25. ;; "LATEX_CLASS_OPTIONS" and "LATEX_HEADER".
  26. ;;; Code:
  27. ;;; org-xhtml.el
  28. (defvar org-e-html-debug nil)
  29. (defvar org-e-html-pp nil)
  30. (defun org-e-html-debug (fmt &rest args)
  31. (when org-e-html-debug
  32. (with-current-buffer (get-buffer "*debug*")
  33. (insert "\n" (apply 'format fmt args)))))
  34. (defun org-element-debug (header text)
  35. (insert "\n" "===== [" header "] =====")
  36. (insert "\n" (pp-to-string text)))
  37. (defun org-elements-debug (args)
  38. (with-current-buffer "*debug*"
  39. (insert "\n\n\n\n\n-------------------------\n")
  40. (while args
  41. (let* ((header (pop args))
  42. (text (pop args)))
  43. (org-element-debug (format "%s" header) text)))
  44. (insert "\n--------------------------\n")))
  45. (defvar org-elements-debug-depth 0)
  46. (defmacro org-e-html-pp (&rest args)
  47. (if org-e-html-pp
  48. (let ((newargs))
  49. (while args
  50. (let ((e (pop args)))
  51. (setq newargs (append newargs (list e (eval e))))))
  52. ;; (pp-eval-expression 'newargs)
  53. `(org-elements-debug (quote ,newargs)))
  54. (list 'ignore)))
  55. (require 'org-exp)
  56. (require 'format-spec)
  57. (eval-when-compile (require 'cl) (require 'table))
  58. (declare-function org-id-find-id-file "org-id" (id))
  59. (declare-function htmlize-region "ext:htmlize" (beg end))
  60. (declare-function org-pop-to-buffer-same-window
  61. "org-compat" (&optional buffer-or-name norecord label))
  62. (defgroup org-export-e-html nil
  63. "Options specific for HTML export of Org-mode files."
  64. :tag "Org Export HTML"
  65. :group 'org-export)
  66. (defconst org-export-e-html-special-string-regexps
  67. '(("\\\\-" . "&shy;")
  68. ("---\\([^-]\\)" . "&mdash;\\1")
  69. ("--\\([^-]\\)" . "&ndash;\\1")
  70. ("\\.\\.\\." . "&hellip;"))
  71. "Regular expressions for special string conversion.")
  72. (defcustom org-export-e-html-footnotes-section "<div id=\"footnotes\">
  73. <h2 class=\"footnotes\">%s: </h2>
  74. <div id=\"text-footnotes\">
  75. %s
  76. </div>
  77. </div>"
  78. "Format for the footnotes section.
  79. Should contain a two instances of %s. The first will be replaced with the
  80. language-specific word for \"Footnotes\", the second one will be replaced
  81. by the footnotes themselves."
  82. :group 'org-export-e-html
  83. :type 'string)
  84. (defcustom org-export-e-html-footnote-format "<sup>%s</sup>"
  85. "The format for the footnote reference.
  86. %s will be replaced by the footnote reference itself."
  87. :group 'org-export-e-html
  88. :type 'string)
  89. (defcustom org-export-e-html-footnote-separator "<sup>, </sup>"
  90. "Text used to separate footnotes."
  91. :group 'org-export-e-html
  92. :type 'string)
  93. (defcustom org-export-e-html-coding-system nil
  94. "Coding system for HTML export, defaults to `buffer-file-coding-system'."
  95. :group 'org-export-e-html
  96. :type 'coding-system)
  97. (defcustom org-export-e-html-extension "html"
  98. "The extension for exported HTML files."
  99. :group 'org-export-e-html
  100. :type 'string)
  101. (defcustom org-export-e-html-xml-declaration
  102. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  103. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  104. "The extension for exported HTML files.
  105. %s will be replaced with the charset of the exported file.
  106. This may be a string, or an alist with export extensions
  107. and corresponding declarations."
  108. :group 'org-export-e-html
  109. :type '(choice
  110. (string :tag "Single declaration")
  111. (repeat :tag "Dependent on extension"
  112. (cons (string :tag "Extension")
  113. (string :tag "Declaration")))))
  114. (defcustom org-export-e-html-style-include-scripts t
  115. "Non-nil means include the JavaScript snippets in exported HTML files.
  116. The actual script is defined in `org-export-e-html-scripts' and should
  117. not be modified."
  118. :group 'org-export-e-html
  119. :type 'boolean)
  120. (defconst org-export-e-html-scripts
  121. "<script type=\"text/javascript\">
  122. <!--/*--><![CDATA[/*><!--*/
  123. function CodeHighlightOn(elem, id)
  124. {
  125. var target = document.getElementById(id);
  126. if(null != target) {
  127. elem.cacheClassElem = elem.className;
  128. elem.cacheClassTarget = target.className;
  129. target.className = \"code-highlighted\";
  130. elem.className = \"code-highlighted\";
  131. }
  132. }
  133. function CodeHighlightOff(elem, id)
  134. {
  135. var target = document.getElementById(id);
  136. if(elem.cacheClassElem)
  137. elem.className = elem.cacheClassElem;
  138. if(elem.cacheClassTarget)
  139. target.className = elem.cacheClassTarget;
  140. }
  141. /*]]>*///-->
  142. </script>"
  143. "Basic JavaScript that is needed by HTML files produced by Org-mode.")
  144. (defconst org-export-e-html-style-default
  145. "<style type=\"text/css\">
  146. <!--/*--><![CDATA[/*><!--*/
  147. html { font-family: Times, serif; font-size: 12pt; }
  148. .title { text-align: center; }
  149. .todo { color: red; }
  150. .done { color: green; }
  151. .tag { background-color: #add8e6; font-weight:normal }
  152. .target { }
  153. .timestamp { color: #bebebe; }
  154. .timestamp-kwd { color: #5f9ea0; }
  155. .right {margin-left:auto; margin-right:0px; text-align:right;}
  156. .left {margin-left:0px; margin-right:auto; text-align:left;}
  157. .center {margin-left:auto; margin-right:auto; text-align:center;}
  158. p.verse { margin-left: 3% }
  159. pre {
  160. border: 1pt solid #AEBDCC;
  161. background-color: #F3F5F7;
  162. padding: 5pt;
  163. font-family: courier, monospace;
  164. font-size: 90%;
  165. overflow:auto;
  166. }
  167. table { border-collapse: collapse; }
  168. td, th { vertical-align: top; }
  169. th.right { text-align:center; }
  170. th.left { text-align:center; }
  171. th.center { text-align:center; }
  172. td.right { text-align:right; }
  173. td.left { text-align:left; }
  174. td.center { text-align:center; }
  175. dt { font-weight: bold; }
  176. div.figure { padding: 0.5em; }
  177. div.figure p { text-align: center; }
  178. div.inlinetask {
  179. padding:10px;
  180. border:2px solid gray;
  181. margin:10px;
  182. background: #ffffcc;
  183. }
  184. textarea { overflow-x: auto; }
  185. .linenr { font-size:smaller }
  186. .code-highlighted {background-color:#ffff00;}
  187. .org-info-js_info-navigation { border-style:none; }
  188. #org-info-js_console-label { font-size:10px; font-weight:bold;
  189. white-space:nowrap; }
  190. .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
  191. font-weight:bold; }
  192. /*]]>*/-->
  193. </style>"
  194. "The default style specification for exported HTML files.
  195. Please use the variables `org-export-e-html-style' and
  196. `org-export-e-html-style-extra' to add to this style. If you wish to not
  197. have the default style included, customize the variable
  198. `org-export-e-html-style-include-default'.")
  199. (defcustom org-export-e-html-style-include-default t
  200. "Non-nil means include the default style in exported HTML files.
  201. The actual style is defined in `org-export-e-html-style-default' and should
  202. not be modified. Use the variables `org-export-e-html-style' to add
  203. your own style information."
  204. :group 'org-export-e-html
  205. :type 'boolean)
  206. ;;;###autoload
  207. (put 'org-export-e-html-style-include-default 'safe-local-variable 'booleanp)
  208. (defcustom org-export-e-html-style ""
  209. "Org-wide style definitions for exported HTML files.
  210. This variable needs to contain the full HTML structure to provide a style,
  211. including the surrounding HTML tags. If you set the value of this variable,
  212. you should consider to include definitions for the following classes:
  213. title, todo, done, timestamp, timestamp-kwd, tag, target.
  214. For example, a valid value would be:
  215. <style type=\"text/css\">
  216. <![CDATA[
  217. p { font-weight: normal; color: gray; }
  218. h1 { color: black; }
  219. .title { text-align: center; }
  220. .todo, .timestamp-kwd { color: red; }
  221. .done { color: green; }
  222. ]]>
  223. </style>
  224. If you'd like to refer to an external style file, use something like
  225. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  226. As the value of this option simply gets inserted into the HTML <head> header,
  227. you can \"misuse\" it to add arbitrary text to the header.
  228. See also the variable `org-export-e-html-style-extra'."
  229. :group 'org-export-e-html
  230. :type 'string)
  231. ;;;###autoload
  232. (put 'org-export-e-html-style 'safe-local-variable 'stringp)
  233. (defcustom org-export-e-html-style-extra ""
  234. "Additional style information for HTML export.
  235. The value of this variable is inserted into the HTML buffer right after
  236. the value of `org-export-e-html-style'. Use this variable for per-file
  237. settings of style information, and do not forget to surround the style
  238. settings with <style>...</style> tags."
  239. :group 'org-export-e-html
  240. :type 'string)
  241. ;;;###autoload
  242. (put 'org-export-e-html-style-extra 'safe-local-variable 'stringp)
  243. (defcustom org-export-e-html-mathjax-options
  244. '((path "http://orgmode.org/mathjax/MathJax.js")
  245. (scale "100")
  246. (align "center")
  247. (indent "2em")
  248. (mathml nil))
  249. "Options for MathJax setup.
  250. path The path where to find MathJax
  251. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  252. align How to align display math: left, center, or right
  253. indent If align is not center, how far from the left/right side?
  254. mathml Should a MathML player be used if available?
  255. This is faster and reduces bandwidth use, but currently
  256. sometimes has lower spacing quality. Therefore, the default is
  257. nil. When browsers get better, this switch can be flipped.
  258. You can also customize this for each buffer, using something like
  259. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  260. :group 'org-export-e-html
  261. :type '(list :greedy t
  262. (list :tag "path (the path from where to load MathJax.js)"
  263. (const :format " " path) (string))
  264. (list :tag "scale (scaling for the displayed math)"
  265. (const :format " " scale) (string))
  266. (list :tag "align (alignment of displayed equations)"
  267. (const :format " " align) (string))
  268. (list :tag "indent (indentation with left or right alignment)"
  269. (const :format " " indent) (string))
  270. (list :tag "mathml (should MathML display be used is possible)"
  271. (const :format " " mathml) (boolean))))
  272. (defun org-export-e-html-mathjax-config (template options in-buffer)
  273. "Insert the user setup into the matchjax template."
  274. (let (name val (yes " ") (no "// ") x)
  275. (mapc
  276. (lambda (e)
  277. (setq name (car e) val (nth 1 e))
  278. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  279. (setq val (car (read-from-string
  280. (substring in-buffer (match-end 0))))))
  281. (if (not (stringp val)) (setq val (format "%s" val)))
  282. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  283. (setq template (replace-match val t t template))))
  284. options)
  285. (setq val (nth 1 (assq 'mathml options)))
  286. (if (string-match (concat "\\<mathml:") in-buffer)
  287. (setq val (car (read-from-string
  288. (substring in-buffer (match-end 0))))))
  289. ;; Exchange prefixes depending on mathml setting
  290. (if (not val) (setq x yes yes no no x))
  291. ;; Replace cookies to turn on or off the config/jax lines
  292. (if (string-match ":MMLYES:" template)
  293. (setq template (replace-match yes t t template)))
  294. (if (string-match ":MMLNO:" template)
  295. (setq template (replace-match no t t template)))
  296. ;; Return the modified template
  297. template))
  298. (defcustom org-export-e-html-mathjax-template
  299. "<script type=\"text/javascript\" src=\"%PATH\">
  300. <!--/*--><![CDATA[/*><!--*/
  301. MathJax.Hub.Config({
  302. // Only one of the two following lines, depending on user settings
  303. // First allows browser-native MathML display, second forces HTML/CSS
  304. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  305. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  306. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  307. \"TeX/noUndefined.js\"],
  308. tex2jax: {
  309. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  310. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  311. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  312. ignoreClass: \"tex2jax_ignore\",
  313. processEscapes: false,
  314. processEnvironments: true,
  315. preview: \"TeX\"
  316. },
  317. showProcessingMessages: true,
  318. displayAlign: \"%ALIGN\",
  319. displayIndent: \"%INDENT\",
  320. \"HTML-CSS\": {
  321. scale: %SCALE,
  322. availableFonts: [\"STIX\",\"TeX\"],
  323. preferredFont: \"TeX\",
  324. webFont: \"TeX\",
  325. imageFont: \"TeX\",
  326. showMathMenu: true,
  327. },
  328. MMLorHTML: {
  329. prefer: {
  330. MSIE: \"MML\",
  331. Firefox: \"MML\",
  332. Opera: \"HTML\",
  333. other: \"HTML\"
  334. }
  335. }
  336. });
  337. /*]]>*///-->
  338. </script>"
  339. "The MathJax setup for XHTML files."
  340. :group 'org-export-e-html
  341. :type 'string)
  342. (defcustom org-export-e-html-tag-class-prefix ""
  343. "Prefix to class names for TODO keywords.
  344. Each tag gets a class given by the tag itself, with this prefix.
  345. The default prefix is empty because it is nice to just use the keyword
  346. as a class name. But if you get into conflicts with other, existing
  347. CSS classes, then this prefix can be very useful."
  348. :group 'org-export-e-html
  349. :type 'string)
  350. (defcustom org-export-e-html-todo-kwd-class-prefix ""
  351. "Prefix to class names for TODO keywords.
  352. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  353. The default prefix is empty because it is nice to just use the keyword
  354. as a class name. But if you get into conflicts with other, existing
  355. CSS classes, then this prefix can be very useful."
  356. :group 'org-export-e-html
  357. :type 'string)
  358. (defcustom org-export-e-html-preamble t
  359. "Non-nil means insert a preamble in HTML export.
  360. When `t', insert a string as defined by one of the formatting
  361. strings in `org-export-e-html-preamble-format'. When set to a
  362. string, this string overrides `org-export-e-html-preamble-format'.
  363. When set to a function, apply this function and insert the
  364. returned string. The function takes the property list of export
  365. options as its only argument.
  366. Setting :html-preamble in publishing projects will take
  367. precedence over this variable."
  368. :group 'org-export-e-html
  369. :type '(choice (const :tag "No preamble" nil)
  370. (const :tag "Default preamble" t)
  371. (string :tag "Custom formatting string")
  372. (function :tag "Function (must return a string)")))
  373. (defcustom org-export-e-html-preamble-format '(("en" ""))
  374. "The format for the HTML preamble.
  375. %t stands for the title.
  376. %a stands for the author's name.
  377. %e stands for the author's email.
  378. %d stands for the date.
  379. If you need to use a \"%\" character, you need to escape it
  380. like that: \"%%\"."
  381. :group 'org-export-e-html
  382. :type 'string)
  383. (defcustom org-export-e-html-postamble 'auto
  384. "Non-nil means insert a postamble in HTML export.
  385. When `t', insert a string as defined by the formatting string in
  386. `org-export-e-html-postamble-format'. When set to a string, this
  387. string overrides `org-export-e-html-postamble-format'. When set to
  388. 'auto, discard `org-export-e-html-postamble-format' and honor
  389. `org-export-author/email/creator-info' variables. When set to a
  390. function, apply this function and insert the returned string.
  391. The function takes the property list of export options as its
  392. only argument.
  393. Setting :html-postamble in publishing projects will take
  394. precedence over this variable."
  395. :group 'org-export-e-html
  396. :type '(choice (const :tag "No postamble" nil)
  397. (const :tag "Auto preamble" 'auto)
  398. (const :tag "Default formatting string" t)
  399. (string :tag "Custom formatting string")
  400. (function :tag "Function (must return a string)")))
  401. (defcustom org-export-e-html-postamble-format
  402. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  403. <p class=\"date\">Date: %d</p>
  404. <p class=\"creator\">Generated by %c</p>
  405. <p class=\"xhtml-validation\">%v</p>
  406. "))
  407. "The format for the HTML postamble.
  408. %a stands for the author's name.
  409. %e stands for the author's email.
  410. %d stands for the date.
  411. %c will be replaced by information about Org/Emacs versions.
  412. %v will be replaced by `org-export-e-html-validation-link'.
  413. If you need to use a \"%\" character, you need to escape it
  414. like that: \"%%\"."
  415. :group 'org-export-e-html
  416. :type 'string)
  417. (defcustom org-export-e-html-home/up-format
  418. "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  419. <a accesskey=\"h\" href=\"%s\"> UP </a>
  420. |
  421. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  422. </div>"
  423. "Snippet used to insert the HOME and UP links.
  424. This is a format string, the first %s will receive the UP link,
  425. the second the HOME link. If both `org-export-e-html-link-up' and
  426. `org-export-e-html-link-home' are empty, the entire snippet will be
  427. ignored."
  428. :group 'org-export-e-html
  429. :type 'string)
  430. (defcustom org-export-e-html-toplevel-hlevel 2
  431. "The <H> level for level 1 headings in HTML export.
  432. This is also important for the classes that will be wrapped around headlines
  433. and outline structure. If this variable is 1, the top-level headlines will
  434. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  435. and outline-text-1. If this is 2, all of these will get a 2 instead.
  436. The default for this variable is 2, because we use <h1> for formatting the
  437. document title."
  438. :group 'org-export-e-html
  439. :type 'string)
  440. (defcustom org-export-e-html-link-org-files-as-html t
  441. "Non-nil means make file links to `file.org' point to `file.html'.
  442. When org-mode is exporting an org-mode file to HTML, links to
  443. non-html files are directly put into a href tag in HTML.
  444. However, links to other Org-mode files (recognized by the
  445. extension `.org.) should become links to the corresponding html
  446. file, assuming that the linked org-mode file will also be
  447. converted to HTML.
  448. When nil, the links still point to the plain `.org' file."
  449. :group 'org-export-e-html
  450. :type 'boolean)
  451. (defcustom org-export-e-html-inline-images 'maybe
  452. "Non-nil means inline images into exported HTML pages.
  453. This is done using an <img> tag. When nil, an anchor with href is used to
  454. link to the image. If this option is `maybe', then images in links with
  455. an empty description will be inlined, while images with a description will
  456. be linked only."
  457. :group 'org-export-e-html
  458. :type '(choice (const :tag "Never" nil)
  459. (const :tag "Always" t)
  460. (const :tag "When there is no description" maybe)))
  461. (defcustom org-export-e-html-inline-image-extensions
  462. '("png" "jpeg" "jpg" "gif" "svg")
  463. "Extensions of image files that can be inlined into HTML."
  464. :group 'org-export-e-html
  465. :type '(repeat (string :tag "Extension")))
  466. (defcustom org-export-e-html-table-tag
  467. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  468. "The HTML tag that is used to start a table.
  469. This must be a <table> tag, but you may change the options like
  470. borders and spacing."
  471. :group 'org-export-e-html
  472. :type 'string)
  473. (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  474. "The opening tag for table header fields.
  475. This is customizable so that alignment options can be specified.
  476. The first %s will be filled with the scope of the field, either row or col.
  477. The second %s will be replaced by a style entry to align the field.
  478. See also the variable `org-export-e-html-table-use-header-tags-for-first-column'.
  479. See also the variable `org-export-e-html-table-align-individual-fields'."
  480. :group 'org-export-tables
  481. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  482. (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
  483. "The opening tag for table data fields.
  484. This is customizable so that alignment options can be specified.
  485. The first %s will be filled with the scope of the field, either row or col.
  486. The second %s will be replaced by a style entry to align the field.
  487. See also the variable `org-export-e-html-table-align-individual-fields'."
  488. :group 'org-export-tables
  489. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  490. (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
  491. "The opening tag for table data fields.
  492. This is customizable so that alignment options can be specified.
  493. Instead of strings, these can be Lisp forms that will be evaluated
  494. for each row in order to construct the table row tags. During evaluation,
  495. the variable `head' will be true when this is a header line, nil when this
  496. is a body line. And the variable `nline' will contain the line number,
  497. starting from 1 in the first header line. For example
  498. (setq org-export-table-row-tags
  499. (cons '(if head
  500. \"<tr>\"
  501. (if (= (mod nline 2) 1)
  502. \"<tr class=\\\"tr-odd\\\">\"
  503. \"<tr class=\\\"tr-even\\\">\"))
  504. \"</tr>\"))
  505. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  506. :group 'org-export-tables
  507. :type '(cons
  508. (choice :tag "Opening tag"
  509. (string :tag "Specify")
  510. (sexp))
  511. (choice :tag "Closing tag"
  512. (string :tag "Specify")
  513. (sexp))))
  514. (defcustom org-export-e-html-table-align-individual-fields t
  515. "Non-nil means attach style attributes for alignment to each table field.
  516. When nil, alignment will only be specified in the column tags, but this
  517. is ignored by some browsers (like Firefox, Safari). Opera does it right
  518. though."
  519. :group 'org-export-tables
  520. :type 'boolean)
  521. (defcustom org-export-e-html-table-use-header-tags-for-first-column nil
  522. "Non-nil means format column one in tables with header tags.
  523. When nil, also column one will use data tags."
  524. :group 'org-export-tables
  525. :type 'boolean)
  526. (defcustom org-export-e-html-validation-link
  527. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  528. "Link to HTML validation service."
  529. :group 'org-export-e-html
  530. :type 'string)
  531. ;; FIXME Obsolete since Org 7.7
  532. ;; Use the :timestamp option or `org-export-time-stamp-file' instead
  533. (defvar org-export-e-html-with-timestamp nil
  534. "If non-nil, write container for HTML-helper-mode timestamp.")
  535. ;; FIXME Obsolete since Org 7.7
  536. (defvar org-export-e-html-html-helper-timestamp
  537. "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
  538. "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
  539. (defcustom org-export-e-html-protect-char-alist
  540. '(("&" . "&amp;")
  541. ("<" . "&lt;")
  542. (">" . "&gt;"))
  543. "Alist of characters to be converted by `org-e-html-protect'."
  544. :group 'org-export-e-html
  545. :type '(repeat (cons (string :tag "Character")
  546. (string :tag "HTML equivalent"))))
  547. (defgroup org-export-e-htmlize nil
  548. "Options for processing examples with htmlize.el."
  549. :tag "Org Export Htmlize"
  550. :group 'org-export-e-html)
  551. (defcustom org-export-e-htmlize-output-type 'inline-css
  552. "Output type to be used by htmlize when formatting code snippets.
  553. Choices are `css', to export the CSS selectors only, or `inline-css', to
  554. export the CSS attribute values inline in the HTML. We use as default
  555. `inline-css', in order to make the resulting HTML self-containing.
  556. However, this will fail when using Emacs in batch mode for export, because
  557. then no rich font definitions are in place. It will also not be good if
  558. people with different Emacs setup contribute HTML files to a website,
  559. because the fonts will represent the individual setups. In these cases,
  560. it is much better to let Org/Htmlize assign classes only, and to use
  561. a style file to define the look of these classes.
  562. To get a start for your css file, start Emacs session and make sure that
  563. all the faces you are interested in are defined, for example by loading files
  564. in all modes you want. Then, use the command
  565. \\[org-export-e-htmlize-generate-css] to extract class definitions."
  566. :group 'org-export-e-htmlize
  567. :type '(choice (const css) (const inline-css)))
  568. (defcustom org-export-e-htmlize-css-font-prefix "org-"
  569. "The prefix for CSS class names for htmlize font specifications."
  570. :group 'org-export-e-htmlize
  571. :type 'string)
  572. (defcustom org-export-e-htmlized-org-css-url nil
  573. "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
  574. Normally when creating an htmlized version of an Org buffer, htmlize will
  575. create CSS to define the font colors. However, this does not work when
  576. converting in batch mode, and it also can look bad if different people
  577. with different fontification setup work on the same website.
  578. When this variable is non-nil, creating an htmlized version of an Org buffer
  579. using `org-export-as-org' will remove the internal CSS section and replace it
  580. with a link to this URL."
  581. :group 'org-export-e-htmlize
  582. :type '(choice
  583. (const :tag "Keep internal css" nil)
  584. (string :tag "URL or local href")))
  585. ;; FIXME: The following variable is obsolete since Org 7.7 but is
  586. ;; still declared and checked within code for compatibility reasons.
  587. ;; Use the custom variables `org-export-e-html-divs' instead.
  588. (defvar org-export-e-html-content-div "content"
  589. "The name of the container DIV that holds all the page contents.
  590. This variable is obsolete since Org version 7.7.
  591. Please set `org-export-e-html-divs' instead.")
  592. (defcustom org-export-e-html-divs '("preamble" "content" "postamble")
  593. "The name of the main divs for HTML export.
  594. This is a list of three strings, the first one for the preamble
  595. DIV, the second one for the content DIV and the third one for the
  596. postamble DIV."
  597. :group 'org-export-e-html
  598. :type '(list
  599. (string :tag " Div for the preamble:")
  600. (string :tag " Div for the content:")
  601. (string :tag "Div for the postamble:")))
  602. ;;; Hooks
  603. (defvar org-export-e-html-after-blockquotes-hook nil
  604. "Hook run during HTML export, after blockquote, verse, center are done.")
  605. (defvar org-export-e-html-final-hook nil
  606. "Hook run at the end of HTML export, in the new buffer.")
  607. (defun org-export-e-html-preprocess-latex-fragments ()
  608. (when (equal org-lparse-backend 'html)
  609. (org-export-e-html-do-preprocess-latex-fragments)))
  610. (defvar org-lparse-opt-plist) ; bound during org-do-lparse
  611. (defun org-export-e-html-do-preprocess-latex-fragments ()
  612. "Convert HTML fragments to images."
  613. (let* ((latex-frag-opt (plist-get org-lparse-opt-plist :HTML-fragments))
  614. (latex-frag-opt-1 ; massage the options
  615. (cond
  616. ((eq latex-frag-opt 'verbatim) 'verbatim)
  617. ((eq latex-frag-opt 'mathjax ) 'mathjax)
  618. ((eq latex-frag-opt t ) 'mathjax)
  619. ((eq latex-frag-opt 'dvipng ) 'dvipng)
  620. (t nil))))
  621. (when (and org-current-export-file latex-frag-opt)
  622. (org-format-latex
  623. (concat "ltxpng/" (file-name-sans-extension
  624. (file-name-nondirectory
  625. org-current-export-file)))
  626. org-current-export-dir nil "Creating HTML image %s"
  627. nil nil latex-frag-opt-1))))
  628. (defun org-export-e-html-preprocess-label-references ()
  629. (goto-char (point-min))
  630. (let (label l1)
  631. (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
  632. (org-if-unprotected-at (match-beginning 1)
  633. (setq label (match-string 1))
  634. (save-match-data
  635. (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  636. (setq l1 (substring label (match-beginning 1)))
  637. (setq l1 label)))
  638. (replace-match (format "[[#%s][%s]]" label l1) t t)))))
  639. (defun org-export-e-html-preprocess (parameters)
  640. (org-export-e-html-preprocess-label-references))
  641. ;; Process latex fragments as part of
  642. ;; `org-export-preprocess-after-blockquote-hook'. Note that this hook
  643. ;; is the one that is closest and well before the call to
  644. ;; `org-export-attach-captions-and-attributes' in
  645. ;; `org-export-preprocess-stirng'. The above arrangement permits
  646. ;; captions, labels and attributes to be attached to png images
  647. ;; generated out of latex equations.
  648. (add-hook 'org-export-preprocess-after-blockquote-hook
  649. 'org-export-e-html-preprocess-latex-fragments)
  650. (defvar html-table-tag nil) ; dynamically scoped into this.
  651. ;; FIXME: it already exists in org-e-html.el
  652. (defconst org-e-html-cvt-link-fn
  653. nil
  654. "Function to convert link URLs to exportable URLs.
  655. Takes two arguments, TYPE and PATH.
  656. Returns exportable url as (TYPE PATH), or nil to signal that it
  657. didn't handle this case.
  658. Intended to be locally bound around a call to `org-export-as-html'." )
  659. ;; FIXME: it already exists in org-e-html.el
  660. (defun org-e-html-cvt-org-as-html (opt-plist type path)
  661. "Convert an org filename to an equivalent html filename.
  662. If TYPE is not file, just return `nil'.
  663. See variable `org-export-e-html-link-org-files-as-html'"
  664. (save-match-data
  665. (and
  666. org-export-e-html-link-org-files-as-html
  667. (string= type "file")
  668. (string-match "\\.org$" path)
  669. (progn
  670. (list
  671. "file"
  672. (concat
  673. (substring path 0 (match-beginning 0))
  674. "."
  675. (plist-get opt-plist :html-extension)))))))
  676. (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
  677. descp)
  678. "Make an HTML link.
  679. OPT-PLIST is an options list.
  680. TYPE is the device-type of the link (THIS://foo.html).
  681. PATH is the path of the link (http://THIS#location).
  682. FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
  683. DESC is the link description, if any.
  684. ATTR is a string of other attributes of the \"a\" element."
  685. (declare (special org-lparse-par-open))
  686. (save-match-data
  687. (when (string= type-1 "coderef")
  688. (let ((ref fragment))
  689. (setq desc (format (org-export-get-coderef-format ref (and descp desc))
  690. (cdr (assoc ref org-export-code-refs)))
  691. fragment (concat "coderef-" ref)
  692. attr (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  693. fragment fragment))))
  694. (let* ((may-inline-p
  695. (and (member type-1 '("http" "https" "file"))
  696. (org-lparse-should-inline-p path descp)
  697. (not fragment)))
  698. (type (if (equal type-1 "id") "file" type-1))
  699. (filename path)
  700. ;;First pass. Just sanity stuff.
  701. (components-1
  702. (cond
  703. ((string= type "file")
  704. (list
  705. type
  706. ;;Substitute just if original path was absolute.
  707. ;;(Otherwise path must remain relative)
  708. (if (file-name-absolute-p path)
  709. (concat "file://" (expand-file-name path))
  710. path)))
  711. ((string= type "")
  712. (list nil path))
  713. (t (list type path))))
  714. ;;Second pass. Components converted so they can refer
  715. ;;to a remote site.
  716. (components-2
  717. (or
  718. (and org-e-html-cvt-link-fn
  719. (apply org-e-html-cvt-link-fn
  720. opt-plist components-1))
  721. (apply #'org-e-html-cvt-org-as-html
  722. opt-plist components-1)
  723. components-1))
  724. (type (first components-2))
  725. (thefile (second components-2)))
  726. ;;Third pass. Build final link except for leading type
  727. ;;spec.
  728. (cond
  729. ((or
  730. (not type)
  731. (string= type "http")
  732. (string= type "https")
  733. (string= type "file")
  734. (string= type "coderef"))
  735. (if fragment
  736. (setq thefile (concat thefile "#" fragment))))
  737. (t))
  738. ;;Final URL-build, for all types.
  739. (setq thefile
  740. (let
  741. ((str (org-xml-format-href thefile)))
  742. (if (and type (not (or (string= "file" type)
  743. (string= "coderef" type))))
  744. (concat type ":" str)
  745. str)))
  746. (if may-inline-p
  747. (org-e-html-format-image thefile)
  748. (org-lparse-format
  749. 'LINK (org-xml-format-desc desc) thefile attr)))))
  750. (defun org-e-html-format-inline-image (path &optional caption label attr)
  751. ;; FIXME: alt text missing here?
  752. (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
  753. path (file-name-nondirectory path))))
  754. (if (not label) inline-image
  755. (org-e-html-format-section inline-image "figure" label))))
  756. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  757. (defvar org-lparse-link-description-is-image)
  758. (defun org-e-html-format-image (src)
  759. "Create image tag with source and attributes."
  760. (save-match-data
  761. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  762. (attr (org-find-text-property-in-string 'org-attributes src))
  763. (label (org-find-text-property-in-string 'org-label src))
  764. (caption (and caption (org-xml-encode-org-text caption)))
  765. (img-extras (if (string-match "^ltxpng/" src)
  766. (format " alt=\"%s\""
  767. (org-find-text-property-in-string
  768. 'org-latex-src src))
  769. (if (string-match "\\<alt=" (or attr ""))
  770. (concat " " attr )
  771. (concat " " attr " alt=\"" src "\""))))
  772. (img (format "<img src=\"%s\"%s />" src img-extras))
  773. (extra (concat
  774. (and label
  775. (format "id=\"%s\" " (org-solidify-link-text label)))
  776. "class=\"figure\"")))
  777. (if caption
  778. (with-temp-buffer
  779. (with-org-lparse-preserve-paragraph-state
  780. (insert
  781. (org-lparse-format
  782. '("<div %s>" . "\n</div>")
  783. (concat
  784. (org-lparse-format '("\n<p>" . "</p>") img)
  785. (org-lparse-format '("\n<p>" . "</p>") caption))
  786. extra)))
  787. (buffer-string))
  788. img))))
  789. (defun org-export-e-html-get-bibliography ()
  790. "Find bibliography, cut it out and return it."
  791. (catch 'exit
  792. (let (beg end (cnt 1) bib)
  793. (save-excursion
  794. (goto-char (point-min))
  795. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  796. (setq beg (match-beginning 0))
  797. (while (re-search-forward "</?div\\>" nil t)
  798. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  799. (when (= cnt 0)
  800. (and (looking-at ">") (forward-char 1))
  801. (setq bib (buffer-substring beg (point)))
  802. (delete-region beg (point))
  803. (throw 'exit bib))))
  804. nil))))
  805. (defmacro with-org-lparse-backend (backend &rest body)
  806. `(let* ((org-lparse-backend ,backend)
  807. (org-lparse-entity-control-callbacks-alist
  808. (org-lparse-get 'ENTITY-CONTROL))
  809. (org-lparse-entity-format-callbacks-alist
  810. (org-lparse-get 'ENTITY-FORMAT)))
  811. ,@body))
  812. (defun org-e-html-format-table (lines olines)
  813. (let ((org-e-html-format-table-no-css nil))
  814. (org-lparse-format-table lines olines)))
  815. ;; Following variable is defined for native tables i.e., when
  816. ;; `org-lparse-table-is-styled' evals to t.
  817. (defvar org-e-html-format-table-no-css)
  818. (defvar org-table-number-regexp) ; defined in org-table.el
  819. (defun org-format-table-html (lines olines &optional no-css)
  820. "Find out which HTML converter to use and return the HTML code.
  821. NO-CSS is passed to the exporter."
  822. (with-org-lparse-backend
  823. 'html (let* ((org-e-html-format-table-no-css no-css))
  824. (org-lparse-format-table lines olines))))
  825. (defun org-format-org-table-html (lines &optional splice no-css)
  826. (with-org-lparse-backend
  827. 'html (let* ((org-e-html-format-table-no-css no-css))
  828. (org-lparse-format-org-table lines splice))))
  829. (defun org-export-splice-attributes (tag attributes)
  830. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  831. (if (not attributes)
  832. tag
  833. (let (oldatt newatt)
  834. (setq oldatt (org-extract-attributes-from-string tag)
  835. tag (pop oldatt)
  836. newatt (cdr (org-extract-attributes-from-string attributes)))
  837. (while newatt
  838. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  839. (if (string-match ">" tag)
  840. (setq tag
  841. (replace-match (concat (org-attributes-to-string oldatt) ">")
  842. t t tag)))
  843. tag)))
  844. (defun org-format-table-table-html (lines)
  845. (with-org-lparse-backend
  846. 'html (org-lparse-format-table-table lines)))
  847. (defun org-export-splice-style (style extra)
  848. "Splice EXTRA into STYLE, just before \"</style>\"."
  849. (if (and (stringp extra)
  850. (string-match "\\S-" extra)
  851. (string-match "</style>" style))
  852. (concat (substring style 0 (match-beginning 0))
  853. "\n" extra "\n"
  854. (substring style (match-beginning 0)))
  855. style))
  856. (defvar htmlize-buffer-places) ; from htmlize.el
  857. (defun org-export-e-htmlize-region-for-paste (beg end)
  858. "Convert the region to HTML, using htmlize.el.
  859. This is much like `htmlize-region-for-paste', only that it uses
  860. the settings define in the org-... variables."
  861. (let* ((htmlize-output-type org-export-e-htmlize-output-type)
  862. (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
  863. (htmlbuf (htmlize-region beg end)))
  864. (unwind-protect
  865. (with-current-buffer htmlbuf
  866. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  867. (plist-get htmlize-buffer-places 'content-end)))
  868. (kill-buffer htmlbuf))))
  869. ;;;###autoload
  870. (defun org-export-e-htmlize-generate-css ()
  871. "Create the CSS for all font definitions in the current Emacs session.
  872. Use this to create face definitions in your CSS style file that can then
  873. be used by code snippets transformed by htmlize.
  874. This command just produces a buffer that contains class definitions for all
  875. faces used in the current Emacs session. You can copy and paste the ones you
  876. need into your CSS file.
  877. If you then set `org-export-e-htmlize-output-type' to `css', calls to
  878. the function `org-export-e-htmlize-region-for-paste' will produce code
  879. that uses these same face definitions."
  880. (interactive)
  881. (require 'htmlize)
  882. (and (get-buffer "*html*") (kill-buffer "*html*"))
  883. (with-temp-buffer
  884. (let ((fl (face-list))
  885. (htmlize-css-name-prefix "org-")
  886. (htmlize-output-type 'css)
  887. f i)
  888. (while (setq f (pop fl)
  889. i (and f (face-attribute f :inherit)))
  890. (when (and (symbolp f) (or (not i) (not (listp i))))
  891. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  892. (htmlize-region (point-min) (point-max))))
  893. (org-pop-to-buffer-same-window "*html*")
  894. (goto-char (point-min))
  895. (if (re-search-forward "<style" nil t)
  896. (delete-region (point-min) (match-beginning 0)))
  897. (if (re-search-forward "</style>" nil t)
  898. (delete-region (1+ (match-end 0)) (point-max)))
  899. (beginning-of-line 1)
  900. (if (looking-at " +") (replace-match ""))
  901. (goto-char (point-min)))
  902. (defvar body-only) ; dynamically scoped into this.
  903. ;; Following variable is let bound when `org-do-lparse' is in
  904. ;; progress. See org-lparse.el.
  905. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  906. (defvar org-lparse-toc)
  907. (defvar org-lparse-footnote-definitions)
  908. (defvar org-lparse-dyn-first-heading-pos)
  909. (defun org-e-html-end-export ()
  910. ;; insert the table of contents
  911. (when (and org-export-with-toc (not body-only) org-lparse-toc)
  912. (org-e-html-insert-toc org-lparse-toc))
  913. ;; remove empty paragraphs
  914. (goto-char (point-min))
  915. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  916. (replace-match ""))
  917. ;; Convert whitespace place holders
  918. (goto-char (point-min))
  919. (let (beg end n)
  920. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  921. (setq n (get-text-property beg 'org-whitespace)
  922. end (next-single-property-change beg 'org-whitespace))
  923. (goto-char beg)
  924. (delete-region beg end)
  925. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  926. (make-string n ?x)))))
  927. ;; Remove empty lines at the beginning of the file.
  928. (goto-char (point-min))
  929. (when (looking-at "\\s-+\n") (replace-match ""))
  930. ;; Remove display properties
  931. (remove-text-properties (point-min) (point-max) '(display t))
  932. ;; Run the hook
  933. (run-hooks 'org-export-e-html-final-hook))
  934. (defun org-e-html-format-toc-entry (snumber todo headline tags href)
  935. (setq headline (concat
  936. (and org-export-with-section-numbers
  937. (concat snumber " "))
  938. headline
  939. (and tags
  940. (concat
  941. (org-lparse-format 'SPACES 3)
  942. (org-lparse-format 'FONTIFY tags "tag")))))
  943. (when todo
  944. (setq headline (org-lparse-format 'FONTIFY headline "todo")))
  945. (org-lparse-format 'LINK headline (concat "#" href)))
  946. (defun org-e-html-format-toc-item (toc-entry level org-last-level)
  947. (when (> level org-last-level)
  948. (let ((cnt (- level org-last-level)))
  949. (while (>= (setq cnt (1- cnt)) 0)
  950. (org-lparse-begin-list 'unordered)
  951. (org-lparse-begin-list-item 'unordered))))
  952. (when (< level org-last-level)
  953. (let ((cnt (- org-last-level level)))
  954. (while (>= (setq cnt (1- cnt)) 0)
  955. (org-lparse-end-list-item-1)
  956. (org-lparse-end-list 'unordered))))
  957. (org-lparse-end-list-item-1)
  958. (org-lparse-begin-list-item 'unordered)
  959. (insert toc-entry))
  960. (defun org-e-html-begin-toc (lang-specific-heading max-level)
  961. (org-lparse-insert-tag "<div id=\"table-of-contents\">")
  962. (insert
  963. (org-lparse-format 'HEADING lang-specific-heading
  964. (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1)))
  965. (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
  966. (org-lparse-begin-list 'unordered)
  967. (org-lparse-begin-list-item 'unordered))
  968. (defun org-e-html-end-toc ()
  969. (while (> org-last-level (1- org-min-level))
  970. (setq org-last-level (1- org-last-level))
  971. (org-lparse-end-list-item-1)
  972. (org-lparse-end-list 'unordered))
  973. (org-lparse-insert-tag "</div>")
  974. (org-lparse-insert-tag "</div>")
  975. ;; cleanup empty list items in toc
  976. (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
  977. (replace-match "")))
  978. ;;;###autoload
  979. ;; (defun org-export-as-html-and-open (arg)
  980. ;; "Export the outline as HTML and immediately open it with a browser.
  981. ;; If there is an active region, export only the region.
  982. ;; The prefix ARG specifies how many levels of the outline should become
  983. ;; headlines. The default is 3. Lower levels will become bulleted lists."
  984. ;; (interactive "P")
  985. ;; (org-lparse-and-open "html" "html" arg))
  986. ;;;###autoload
  987. ;; (defun org-export-as-html-batch ()
  988. ;; "Call the function `org-lparse-batch'.
  989. ;; This function can be used in batch processing as:
  990. ;; emacs --batch
  991. ;; --load=$HOME/lib/emacs/org.el
  992. ;; --eval \"(setq org-export-headline-levels 2)\"
  993. ;; --visit=MyFile --funcall org-export-as-html-batch"
  994. ;; (org-lparse-batch "html"))
  995. ;;;###autoload
  996. ;; (defun org-export-as-html-to-buffer (arg)
  997. ;; "Call `org-lparse-to-buffer` with output to a temporary buffer.
  998. ;; No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
  999. ;; (interactive "P")
  1000. ;; (org-lparse-to-buffer "html" arg))
  1001. ;;;###autoload
  1002. ;; (defun org-replace-region-by-html (beg end)
  1003. ;; "Assume the current region has org-mode syntax, and convert it to HTML.
  1004. ;; This can be used in any buffer. For example, you could write an
  1005. ;; itemized list in org-mode syntax in an HTML buffer and then use this
  1006. ;; command to convert it."
  1007. ;; (interactive "r")
  1008. ;; (org-replace-region-by "html" beg end))
  1009. ;;;###autoload
  1010. ;; (defun org-export-region-as-html (beg end &optional body-only buffer)
  1011. ;; "Convert region from BEG to END in `org-mode' buffer to HTML.
  1012. ;; If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  1013. ;; contents, and only produce the region of converted text, useful for
  1014. ;; cut-and-paste operations.
  1015. ;; If BUFFER is a buffer or a string, use/create that buffer as a target
  1016. ;; of the converted HTML. If BUFFER is the symbol `string', return the
  1017. ;; produced HTML as a string and leave not buffer behind. For example,
  1018. ;; a Lisp program could call this function in the following way:
  1019. ;; (setq html (org-export-region-as-html beg end t 'string))
  1020. ;; When called interactively, the output buffer is selected, and shown
  1021. ;; in a window. A non-interactive call will only return the buffer."
  1022. ;; (interactive "r\nP")
  1023. ;; (org-lparse-region "html" beg end body-only buffer))
  1024. ;;; org-export-as-html
  1025. ;;;###autoload
  1026. ;; (defun org-export-as-html (arg &optional hidden ext-plist
  1027. ;; to-buffer body-only pub-dir)
  1028. ;; "Export the outline as a pretty HTML file.
  1029. ;; Use `org-lparse' internally to perform the actual export. This
  1030. ;; routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
  1031. ;; of `org-lparse' to \"html\"."
  1032. ;; (interactive "P")
  1033. ;; (org-lparse "html" "html" arg hidden ext-plist to-buffer body-only pub-dir))
  1034. (defvar org-e-html-entity-control-callbacks-alist
  1035. `((EXPORT
  1036. . (org-e-html-begin-export org-e-html-end-export))
  1037. (DOCUMENT-CONTENT
  1038. . (org-e-html-begin-document-content org-e-html-end-document-content))
  1039. (DOCUMENT-BODY
  1040. . (org-e-html-begin-document-body org-e-html-end-document-body))
  1041. (TOC
  1042. . (org-e-html-begin-toc org-e-html-end-toc))
  1043. (ENVIRONMENT
  1044. . (org-e-html-begin-environment org-e-html-end-environment))
  1045. (FOOTNOTE-DEFINITION
  1046. . (org-e-html-begin-footnote-definition org-e-html-end-footnote-definition))
  1047. (TABLE
  1048. . (org-e-html-begin-table org-e-html-end-table))
  1049. (TABLE-ROWGROUP
  1050. . (org-e-html-begin-table-rowgroup org-e-html-end-table-rowgroup))
  1051. (LIST
  1052. . (org-e-html-begin-list org-e-html-end-list))
  1053. (LIST-ITEM
  1054. . (org-e-html-begin-list-item org-e-html-end-list-item))
  1055. (OUTLINE
  1056. . (org-e-html-begin-outline org-e-html-end-outline))
  1057. (OUTLINE-TEXT
  1058. . (org-e-html-begin-outline-text org-e-html-end-outline-text))
  1059. (PARAGRAPH
  1060. . (org-e-html-begin-paragraph org-e-html-end-paragraph)))
  1061. "Alist of control callbacks registered with the exporter.
  1062. Each element is of the form (ENTITY . (BEGIN-ENTITY-FUNCTION
  1063. END-ENTITY-FUNCTION)). ENTITY is one of PARAGRAPH, LIST etc as
  1064. seen above. BEGIN-ENTITY-FUNCTION and END-ENTITY-FUNCTION are
  1065. functions that get called when the exporter needs to begin or end
  1066. an entity in the currently exported file. The signatures of
  1067. these callbacks are specific to the ENTITY being emitted. These
  1068. callbacks always get called with exported file as the current
  1069. buffer and need to insert the appropriate tags into the current
  1070. buffer. For example, `org-e-html-begin-paragraph' inserts <p> and
  1071. `org-e-html-end-paragraph' inserts </p> in to the current buffer.
  1072. These callbacks are invoked via `org-lparse-begin' and
  1073. `org-lparse-end'.")
  1074. (defvar org-e-html-entity-format-callbacks-alist
  1075. `((EXTRA-TARGETS . org-lparse-format-extra-targets)
  1076. (ORG-TAGS . org-lparse-format-org-tags)
  1077. (SECTION-NUMBER . org-lparse-format-section-number)
  1078. (HEADLINE . org-e-html-format-headline)
  1079. (TOC-ENTRY . org-e-html-format-toc-entry)
  1080. (TOC-ITEM . org-e-html-format-toc-item)
  1081. (TAGS . org-e-html-format-tags)
  1082. (SPACES . org-e-html-format-spaces)
  1083. (TABS . org-e-html-format-tabs)
  1084. (LINE-BREAK . org-e-html-format-line-break)
  1085. (FONTIFY . org-e-html-format-fontify)
  1086. (TODO . org-lparse-format-todo)
  1087. (ORG-LINK . org-e-html-format-org-link)
  1088. (LINK . org-e-html-format-link)
  1089. (INLINE-IMAGE . org-e-html-format-inline-image)
  1090. (HEADING . org-e-html-format-heading)
  1091. (ANCHOR . org-e-html-format-anchor)
  1092. (TABLE . org-e-html-format-table)
  1093. (TABLE-ROW . org-e-html-format-table-row)
  1094. (TABLE-CELL . org-e-html-format-table-cell)
  1095. (FOOTNOTES-SECTION . org-e-html-format-footnotes-section)
  1096. (FOOTNOTE-REFERENCE . org-e-html-format-footnote-reference)
  1097. (HORIZONTAL-LINE . org-e-html-format-horizontal-line)
  1098. (LINE . org-e-html-format-line)
  1099. (COMMENT . org-e-html-format-comment)
  1100. (ORG-ENTITY . org-e-html-format-org-entity))
  1101. "Alist of format callbacks registered with the exporter.
  1102. Each element is of the form (ENTITY . ENTITY-FORMAT-FUNCTION).
  1103. ENTITY is one of LINE, HEADING, COMMENT, LINK, TABLE-ROW etc as
  1104. seen above. ENTITY-FORMAT-FUNCTION is a functions that gets
  1105. called when the exporter needs to format a string in `org-mode'
  1106. buffer in a backend specific way. The signatures of the
  1107. formatting callback is specific to the ENTITY being passed in.
  1108. These callbacks always need to encode the incoming entity in
  1109. backend specific way and return the same. These callbacks do not
  1110. make any modifications to the exporter file. For example,
  1111. `org-e-html-format-table-row' encloses incoming entity in <tr>
  1112. </tr> tags and returns it. See also `org-lparse-format'.")
  1113. (defun org-e-html-unload-function ()
  1114. (org-lparse-unregister-backend 'html)
  1115. (remove-hook 'org-export-preprocess-after-blockquote-hook
  1116. 'org-export-e-html-preprocess-latex-fragments)
  1117. nil)
  1118. (defun org-e-html-begin-body (info)
  1119. )
  1120. (defun org-e-html-begin-document-content (info)
  1121. )
  1122. (defun org-e-html-end-document-content ()
  1123. )
  1124. (defun org-e-html-begin-outline (level1 snumber title tags
  1125. target extra-targets extra-class)
  1126. (let* ((class (format "outline-%d" level1))
  1127. (class (if extra-class (concat class " " extra-class) class))
  1128. (id (format "outline-container-%s"
  1129. (org-lparse-suffix-from-snumber snumber)))
  1130. (extra (concat (when id (format " id=\"%s\"" id))
  1131. (when class (format " class=\"%s\"" class)))))
  1132. (org-lparse-insert-tag "<div%s>" extra)
  1133. (insert
  1134. (org-lparse-format 'HEADING
  1135. (org-lparse-format
  1136. 'HEADLINE title extra-targets tags snumber level1)
  1137. level1 target))))
  1138. (defun org-e-html-end-outline ()
  1139. (org-lparse-insert-tag "</div>"))
  1140. ;; (defun org-e-html-format-heading (text level &optional id)
  1141. ;; (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
  1142. ;; (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
  1143. (defun org-e-html-suffix-from-snumber (snumber)
  1144. (let* ((snu (replace-regexp-in-string "\\." "-" snumber))
  1145. (href (cdr (assoc (concat "sec-" snu)
  1146. org-export-preferred-target-alist))))
  1147. (org-solidify-link-text (or href snu))))
  1148. (defun org-e-html-format-outline (contents level1 snumber title
  1149. tags target extra-targets extra-class)
  1150. (let* ((class (format "outline-%d" level1))
  1151. (class (if extra-class (concat class " " extra-class) class))
  1152. (id (and snumber ;; FIXME
  1153. (format "outline-container-%s"
  1154. (org-e-html-suffix-from-snumber snumber))))
  1155. (extra (concat (when id (format " id=\"%s\"" id))
  1156. (when class (format " class=\"%s\"" class)))))
  1157. (concat
  1158. (format "<div%s>\n" extra)
  1159. (org-e-html-format-heading
  1160. (org-e-html-format-headline title extra-targets tags snumber level1)
  1161. level1 target)
  1162. contents
  1163. "</div>")))
  1164. (defun org-e-html-begin-outline-text (level1 snumber extra-class)
  1165. (let* ((class (format "outline-text-%d" level1))
  1166. (class (if extra-class (concat class " " extra-class) class))
  1167. (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
  1168. (extra (concat (when id (format " id=\"%s\"" id))
  1169. (when class (format " class=\"%s\"" class)))))
  1170. (org-lparse-insert-tag "<div%s>" extra)))
  1171. (defun org-e-html-end-outline-text ()
  1172. (org-lparse-insert-tag "</div>"))
  1173. (defun org-e-html-begin-paragraph (&optional style)
  1174. (let* ((class (cdr (assoc style '((footnote . "footnote")
  1175. (verse . nil)))))
  1176. (extra (if class (format " class=\"%s\"" class) "")))
  1177. (org-lparse-insert-tag "<p%s>" extra)))
  1178. (defun org-e-html-end-paragraph ()
  1179. (insert "</p>"))
  1180. (defun org-e-html-format-environment (style beg-end)
  1181. (assert (memq style '(blockquote center verse fixedwidth quote native)) t)
  1182. (case style
  1183. (blockquote
  1184. (case beg-end
  1185. (BEGIN
  1186. (org-lparse-end-paragraph)
  1187. (insert "<blockquote>\n")
  1188. (org-lparse-begin-paragraph))
  1189. (END
  1190. (org-lparse-end-paragraph)
  1191. (insert "\n</blockquote>\n")
  1192. (org-lparse-begin-paragraph))))
  1193. (verse
  1194. (case beg-end
  1195. (BEGIN
  1196. (org-lparse-end-paragraph)
  1197. (insert "\n<p class=\"verse\">\n")
  1198. (setq org-lparse-par-open t))
  1199. (END
  1200. (insert "</p>\n")
  1201. (setq org-lparse-par-open nil)
  1202. (org-lparse-begin-paragraph))))
  1203. (center
  1204. (case beg-end
  1205. (BEGIN
  1206. (org-lparse-end-paragraph)
  1207. (insert "\n<div style=\"text-align: center\">")
  1208. (org-lparse-begin-paragraph))
  1209. (END
  1210. (org-lparse-end-paragraph)
  1211. (insert "\n</div>")
  1212. (org-lparse-begin-paragraph))))
  1213. (fixedwidth
  1214. (case beg-end
  1215. (BEGIN
  1216. (org-lparse-end-paragraph)
  1217. (insert "<pre class=\"example\">\n"))
  1218. (END
  1219. (insert "</pre>\n")
  1220. (org-lparse-begin-paragraph))))
  1221. (quote
  1222. (case beg-end
  1223. (BEGIN
  1224. (org-lparse-end-paragraph)
  1225. (insert "<pre>"))
  1226. (END
  1227. (insert "</pre>\n")
  1228. (org-lparse-begin-paragraph))))
  1229. (native
  1230. (case beg-end
  1231. (BEGIN (org-lparse-end-paragraph))
  1232. (END (org-lparse-begin-paragraph))))
  1233. (t (error "Unknown environment %s" style))))
  1234. (defun org-e-html-begin-environment (style env-options-plist)
  1235. (org-e-html-format-environment style 'BEGIN))
  1236. (defun org-e-html-end-environment (style env-options-plist)
  1237. (org-e-html-format-environment style 'END))
  1238. (defun org-e-html-begin-list (ltype)
  1239. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1240. ltype))
  1241. (case ltype
  1242. (ordered (let* ((arg1 nil)
  1243. (extra (if arg1 (format " start=\"%d\"" arg1) "")))
  1244. (org-lparse-insert-tag "<ol%s>" extra)))
  1245. (unordered (org-lparse-insert-tag "<ul>"))
  1246. (description (org-lparse-insert-tag "<dl>"))
  1247. (t (error "Unknown list type: %s" ltype))))
  1248. (defun org-e-html-end-list (ltype)
  1249. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1250. ltype))
  1251. (org-lparse-insert-tag
  1252. (case ltype
  1253. (ordered "</ol>")
  1254. (unordered "</ul>")
  1255. (description "</dl>")
  1256. (t (error "Unknown list type: %s" ltype)))))
  1257. (defun org-e-html-begin-list-item (ltype &optional arg headline)
  1258. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1259. ltype))
  1260. (case ltype
  1261. (ordered
  1262. (assert (not headline) t)
  1263. (let* ((counter arg)
  1264. (extra (if counter (format " value=\"%s\"" counter) "")))
  1265. (org-lparse-insert-tag "<li%s>" extra)))
  1266. (unordered
  1267. (let* ((id arg)
  1268. (extra (if id (format " id=\"%s\"" id) "")))
  1269. (org-lparse-insert-tag "<li%s>" extra)
  1270. (when headline
  1271. (insert headline (org-lparse-format 'LINE-BREAK) "\n"))))
  1272. (description
  1273. (assert (not headline) t)
  1274. (let* ((desc-tag (or arg "(no term)")))
  1275. (insert
  1276. (org-e-html-format-tags '("<dt>" . "</dt>") desc-tag))
  1277. (org-lparse-insert-tag "<dd>")))
  1278. (t (error "Unknown list type"))))
  1279. (defun org-e-html-end-list-item (ltype)
  1280. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1281. ltype))
  1282. (case ltype
  1283. (ordered (org-lparse-insert-tag "</li>"))
  1284. (unordered (org-lparse-insert-tag "</li>"))
  1285. (description (org-lparse-insert-tag "</dd>"))
  1286. (t (error "Unknown list type"))))
  1287. ;; Following variables are let bound when table emission is in
  1288. ;; progress. See org-lparse.el.
  1289. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  1290. (defvar org-lparse-table-begin-marker)
  1291. (defvar org-lparse-table-ncols)
  1292. (defvar org-lparse-table-rowgrp-open)
  1293. (defvar org-lparse-table-rownum)
  1294. (defvar org-lparse-table-cur-rowgrp-is-hdr)
  1295. (defvar org-lparse-table-is-styled)
  1296. (defvar org-lparse-table-rowgrp-info)
  1297. (defvar org-lparse-table-colalign-vector)
  1298. (defvar org-lparse-table-num-numeric-items-per-column)
  1299. (defun org-e-html-begin-footnote-definition (n)
  1300. (org-lparse-begin-paragraph 'footnote)
  1301. (insert
  1302. (format
  1303. (format org-export-e-html-footnote-format
  1304. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1305. n n n)))
  1306. (defun org-e-html-end-footnote-definition (n)
  1307. (org-lparse-end-paragraph))
  1308. (defun org-e-html-format-footnote-definition (contents n)
  1309. (concat
  1310. (format
  1311. (format org-export-e-html-footnote-format
  1312. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1313. n n n)
  1314. contents))
  1315. ;; (defun org-e-html-format-spaces (n)
  1316. ;; (let ((space (or (and org-lparse-encode-pending "\\nbsp") "&nbsp;")) out)
  1317. ;; (while (> n 0)
  1318. ;; (setq out (concat out space))
  1319. ;; (setq n (1- n))) out))
  1320. (defun org-e-html-format-tabs (&optional n)
  1321. (ignore))
  1322. (defun org-e-html-format-line-break ()
  1323. (org-e-html-format-tags "<br/>" ""))
  1324. (defun org-e-html-format-horizontal-line ()
  1325. (concat "\n" "<hr/>" "\n"))
  1326. (defun org-e-html-format-line (line)
  1327. (case org-lparse-dyn-current-environment
  1328. ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
  1329. (t (concat line "\n"))))
  1330. (defun org-e-html-format-comment (fmt &rest args)
  1331. (let ((comment (apply 'format fmt args)))
  1332. (format "\n<!-- %s -->\n" comment)))
  1333. (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
  1334. "Turn todo keyword into a valid class name.
  1335. Replaces invalid characters with \"_\"."
  1336. (save-match-data
  1337. (while (string-match "[^a-zA-Z0-9_]" kwd)
  1338. (setq kwd (replace-match "_" t t kwd))))
  1339. kwd)
  1340. (defun org-e-html-format-fontify (text style &optional id)
  1341. (let (class extra how)
  1342. (cond
  1343. ((eq style 'underline)
  1344. (setq extra " style=\"text-decoration:underline;\"" ))
  1345. ((setq how (cdr (assoc style
  1346. '((bold . ("<b>" . "</b>"))
  1347. (emphasis . ("<i>" . "</i>"))
  1348. (code . ("<code>" . "</code>"))
  1349. (verbatim . ("<code>" . "</code>"))
  1350. (strike . ("<del>" . "</del>"))
  1351. (subscript . ("<sub>" . "</sub>"))
  1352. (superscript . ("<sup>" . "</sup>")))))))
  1353. ((listp style)
  1354. (setq class (mapconcat 'identity style " ")))
  1355. ((stringp style)
  1356. (setq class style))
  1357. (t (error "Unknown style %S" style)))
  1358. (setq extra (concat (when class (format " class=\"%s\"" class))
  1359. (when id (format " id=\"%s\"" id))
  1360. extra))
  1361. (let ((tags (or how '("<span%s>" . "</span>"))))
  1362. (concat (format (car tags) extra) text (cdr tags)))))
  1363. (defun org-e-html-format-link (text href &optional extra)
  1364. (let ((extra (concat (format " href=\"%s\"" href)
  1365. (and extra (concat " " extra)))))
  1366. (format "<a%s>%s</a>" extra text)))
  1367. (defun org-e-html-format-internal-link (text href &optional extra)
  1368. (org-e-html-format-link text (concat "#" href) extra))
  1369. (defun org-e-html-format-heading (text level &optional id)
  1370. (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
  1371. (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
  1372. ;; (defun org-e-html-format-headline (title extra-targets tags
  1373. ;; &optional snumber level)
  1374. ;; (concat
  1375. ;; (org-lparse-format 'EXTRA-TARGETS extra-targets)
  1376. ;; (concat (org-lparse-format 'SECTION-NUMBER snumber level) " ")
  1377. ;; title
  1378. ;; (and tags (concat (org-lparse-format 'SPACES 3)
  1379. ;; (org-lparse-format 'ORG-TAGS tags)))))
  1380. (defun org-e-html-format-anchor (text name &optional class)
  1381. (let* ((id name)
  1382. (extra (concat
  1383. (when name (format " name=\"%s\"" name))
  1384. (when id (format " id=\"%s\"" id))
  1385. (when class (format " class=\"%s\"" class)))))
  1386. (format "<a%s>%s</a>" extra text)))
  1387. (defun org-e-html-format-extra-targets (extra-targets)
  1388. (if (not extra-targets) ""
  1389. (mapconcat (lambda (x)
  1390. (when x
  1391. (setq x (org-solidify-link-text
  1392. (if (org-uuidgen-p x) (concat "ID-" x) x)))
  1393. (org-e-html-format-anchor "" x))) extra-targets "")))
  1394. (defun org-e-html-format-spaces (n)
  1395. (let (out) (dotimes (i n out) (setq out (concat out "&nbsp;")))))
  1396. (defun org-e-html-format-org-tags (tags)
  1397. (if (not tags) ""
  1398. (org-e-html-format-fontify
  1399. (mapconcat
  1400. (lambda (x)
  1401. (org-e-html-format-fontify
  1402. x (concat org-export-e-html-tag-class-prefix
  1403. (org-e-html-fix-class-name x))))
  1404. (org-split-string tags ":")
  1405. (org-e-html-format-spaces 1)) "tag")))
  1406. (defun org-e-html-format-section-number (&optional snumber level)
  1407. ;; FIXME
  1408. (and org-export-with-section-numbers
  1409. ;; (not org-lparse-body-only)
  1410. snumber level
  1411. (org-e-html-format-fontify snumber (format "section-number-%d" level))))
  1412. (defun org-e-html-format-headline (title extra-targets tags
  1413. &optional snumber level)
  1414. (concat
  1415. (org-e-html-format-extra-targets extra-targets)
  1416. (concat (org-e-html-format-section-number snumber level) " ")
  1417. title
  1418. (and tags (concat (org-e-html-format-spaces 3)
  1419. (org-e-html-format-org-tags tags)))))
  1420. (defun org-e-html-format-footnote-reference (n def refcnt)
  1421. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  1422. (format org-export-e-html-footnote-format
  1423. (format
  1424. "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
  1425. n extra n n))))
  1426. (defun org-e-html-format-footnotes-section (section-name definitions)
  1427. (if (not definitions) ""
  1428. (format org-export-e-html-footnotes-section section-name definitions)))
  1429. (defun org-e-html-format-org-entity (wd)
  1430. (org-entity-get-representation wd 'html))
  1431. (defun org-e-html-format-tags (tag text &rest args)
  1432. (let ((prefix (when org-lparse-encode-pending "@"))
  1433. (suffix (when org-lparse-encode-pending "@")))
  1434. (apply 'org-lparse-format-tags tag text prefix suffix args)))
  1435. (defun org-e-html-get (what &optional opt-plist)
  1436. (case what
  1437. (BACKEND 'html)
  1438. (INIT-METHOD nil)
  1439. (SAVE-METHOD nil)
  1440. (CLEANUP-METHOD nil)
  1441. ;; (OTHER-BACKENDS
  1442. ;; ;; There is a provision to register a per-backend converter and
  1443. ;; ;; output formats. Refer `org-lparse-get-converter' and
  1444. ;; ;; `org-lparse-get-other-backends'.
  1445. ;; ;; The default behaviour is to use `org-lparse-convert-process'
  1446. ;; ;; and `org-lparse-convert-capabilities'.
  1447. ;; )
  1448. ;; (CONVERT-METHOD
  1449. ;; ;; See note above
  1450. ;; )
  1451. (EXPORT-DIR (org-export-directory :html opt-plist))
  1452. (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
  1453. (EXPORT-BUFFER-NAME "*Org HTML Export*")
  1454. (ENTITY-CONTROL org-e-html-entity-control-callbacks-alist)
  1455. (ENTITY-FORMAT org-e-html-entity-format-callbacks-alist)
  1456. (TOPLEVEL-HLEVEL org-export-e-html-toplevel-hlevel)
  1457. (SPECIAL-STRING-REGEXPS org-export-e-html-special-string-regexps)
  1458. (CODING-SYSTEM-FOR-WRITE org-export-e-html-coding-system)
  1459. (CODING-SYSTEM-FOR-SAVE org-export-e-html-coding-system)
  1460. (INLINE-IMAGES org-export-e-html-inline-images)
  1461. (INLINE-IMAGE-EXTENSIONS org-export-e-html-inline-image-extensions)
  1462. (PLAIN-TEXT-MAP org-export-e-html-protect-char-alist)
  1463. (TABLE-FIRST-COLUMN-AS-LABELS
  1464. org-export-e-html-table-use-header-tags-for-first-column)
  1465. (TODO-KWD-CLASS-PREFIX org-export-e-html-todo-kwd-class-prefix)
  1466. (TAG-CLASS-PREFIX org-export-e-html-tag-class-prefix)
  1467. (FOOTNOTE-SEPARATOR org-export-e-html-footnote-separator)
  1468. (t (error "Unknown property: %s" what))))
  1469. (defun org-e-html-get-coding-system-for-write ()
  1470. (or org-export-e-html-coding-system
  1471. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1472. (defun org-e-html-get-coding-system-for-save ()
  1473. (or org-export-e-html-coding-system
  1474. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1475. (defun org-e-html-insert-toc (toc)
  1476. ;; locate where toc needs to be inserted
  1477. (goto-char (point-min))
  1478. (cond
  1479. ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  1480. (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t))
  1481. (goto-char (match-beginning 0))
  1482. (replace-match "")
  1483. (insert toc))
  1484. (org-lparse-dyn-first-heading-pos
  1485. (goto-char org-lparse-dyn-first-heading-pos)
  1486. (when (looking-at "\\s-*</p>")
  1487. (goto-char (match-end 0))
  1488. (insert "\n"))
  1489. (insert toc))
  1490. (t (ignore))))
  1491. (defun org-e-html-format-date (info)
  1492. (let ((date (plist-get info :date)))
  1493. (cond
  1494. ((and date (string-match "%" date))
  1495. (format-time-string date))
  1496. (date date)
  1497. (t (format-time-string "%Y-%m-%d %T %Z")))))
  1498. (defun org-e-html-footnote-section (info)
  1499. (when org-e-html-footnotes-alist
  1500. ;; (setq org-e-html-footnotes-alist
  1501. ;; (sort org-e-html-footnotes-alist
  1502. ;; (lambda (n1 n2) (< (or (nth 1 n1) most-positive-fixnum)
  1503. ;; (or (nth 1 n2) most-positive-fixnum)))))
  1504. ;; (setq org-e-html-footnote-alist (nreverse org-e-html-footnotes-alist))
  1505. (setq org-e-html-footnotes-alist (nreverse org-e-html-footnotes-alist))
  1506. (org-e-html-format-footnotes-section
  1507. (nth 4 (or (assoc (plist-get info :language)
  1508. org-export-language-setup)
  1509. (assoc "en" org-export-language-setup)))
  1510. (format "
  1511. <table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">
  1512. %s
  1513. </table>
  1514. "
  1515. (mapconcat
  1516. (lambda (x)
  1517. (let ((n (car x))
  1518. (def (cdr x)))
  1519. (format "
  1520. <tr>
  1521. <td>%s</td>
  1522. <td>%s</td>
  1523. </tr>
  1524. "
  1525. (format
  1526. (format org-export-e-html-footnote-format
  1527. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1528. n n n) def)))
  1529. org-e-html-footnotes-alist "\n")
  1530. )
  1531. )))
  1532. (defun org-e-html-bibliography ()
  1533. (org-export-e-html-get-bibliography))
  1534. (defun org-e-html-expand (s)
  1535. (with-org-lparse-backend 'html (org-xml-encode-org-text-skip-links s)))
  1536. (defun org-e-html-protect (s)
  1537. (with-org-lparse-backend 'html (org-e-html-encode-plain-text s)))
  1538. (defun org-e-html-do-expand (s)
  1539. (with-org-lparse-backend 'html (org-xml-encode-org-text s)))
  1540. (defun org-export-e-html-format-href (s)
  1541. (org-xml-format-href s))
  1542. (defun org-export-e-html-format-desc (s)
  1543. (org-xml-format-desc s))
  1544. (eval-when-compile (require 'cl))
  1545. ;;; org-e-html.el
  1546. (defvar org-export-latex-default-packages-alist)
  1547. (defvar org-export-latex-packages-alist)
  1548. (declare-function org-element-get-property "org-element" (property element))
  1549. (declare-function org-element-normalize-string "org-element" (s))
  1550. (declare-function org-element-parse-secondary-string
  1551. "org-element" (string restriction &optional buffer))
  1552. (defvar org-element-string-restrictions)
  1553. (declare-function org-export-clean-table "org-export" (table specialp))
  1554. (declare-function org-export-data "org-export" (data backend info))
  1555. (declare-function org-export-directory "org-export" (type plist))
  1556. (declare-function org-export-expand-macro "org-export" (macro info))
  1557. (declare-function org-export-first-sibling-p "org-export" (headline info))
  1558. (declare-function org-export-footnote-first-reference-p "org-export"
  1559. (footnote-reference info))
  1560. (declare-function org-export-get-coderef-format "org-export" (path desc))
  1561. (declare-function org-export-get-footnote-definition "org-export"
  1562. (footnote-reference info))
  1563. (declare-function org-export-get-footnote-number "org-export" (footnote info))
  1564. (declare-function org-export-get-previous-element "org-export" (blob info))
  1565. (declare-function org-export-get-relative-level "org-export" (headline info))
  1566. (declare-function org-export-handle-code
  1567. "org-export" (element info &optional num-fmt ref-fmt delayed))
  1568. (declare-function org-export-included-file "org-export" (keyword backend info))
  1569. (declare-function org-export-inline-image-p "org-export"
  1570. (link &optional extensions))
  1571. (declare-function org-export-last-sibling-p "org-export" (headline info))
  1572. (declare-function org-export-low-level-p "org-export" (headline info))
  1573. (declare-function org-export-output-file-name
  1574. "org-export" (extension &optional subtreep pub-dir))
  1575. (declare-function org-export-resolve-coderef "org-export" (ref info))
  1576. (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
  1577. (declare-function org-export-secondary-string "org-export"
  1578. (secondary backend info))
  1579. (declare-function org-export-solidify-link-text "org-export" (s))
  1580. (declare-function org-export-table-format-info "org-export" (table))
  1581. (declare-function
  1582. org-export-to-buffer "org-export"
  1583. (backend buffer &optional subtreep visible-only body-only ext-plist))
  1584. (declare-function
  1585. org-export-to-file "org-export"
  1586. (backend file &optional subtreep visible-only body-only ext-plist))
  1587. ;;; Internal Variables
  1588. ;; (defconst org-e-html-option-alist
  1589. ;; '((:date "DATE" nil org-e-html-date-format t)
  1590. ;; (:latex-class "LATEX_CLASS" nil org-e-html-default-class t)
  1591. ;; (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
  1592. ;; (:latex-header-extra "LATEX_HEADER" nil nil newline))
  1593. ;; "Alist between HTML export properties and ways to set them.
  1594. ;; See `org-export-option-alist' for more information on the
  1595. ;; structure of the value.")
  1596. (defconst org-e-html-option-alist
  1597. '((:agenda-style nil nil org-agenda-export-html-style)
  1598. (:convert-org-links nil nil org-export-e-html-link-org-files-as-html)
  1599. ;; (:expand-quoted-html nil "@" org-export-e-html-expand) FIXME
  1600. (:inline-images nil nil org-export-e-html-inline-images)
  1601. ;; (:link-home nil nil org-export-e-html-link-home) FIXME
  1602. ;; (:link-up nil nil org-export-e-html-link-up) FIXME
  1603. (:style nil nil org-export-e-html-style)
  1604. (:style-extra nil nil org-export-e-html-style-extra)
  1605. (:style-include-default nil nil org-export-e-html-style-include-default)
  1606. (:style-include-scripts nil nil org-export-e-html-style-include-scripts)
  1607. (:timestamp nil nil org-export-e-html-with-timestamp)
  1608. (:html-extension nil nil org-export-e-html-extension)
  1609. (:html-postamble nil nil org-export-e-html-postamble)
  1610. (:html-preamble nil nil org-export-e-html-preamble)
  1611. (:html-table-tag nil nil org-export-e-html-table-tag)
  1612. (:xml-declaration nil nil org-export-e-html-xml-declaration)
  1613. (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments))
  1614. "Alist between export properties and ways to set them.
  1615. The car of the alist is the property name, and the cdr is a list
  1616. like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
  1617. KEYWORD is a string representing a buffer keyword, or nil.
  1618. OPTION is a string that could be found in an #+OPTIONS: line.
  1619. DEFAULT is the default value for the property.
  1620. BEHAVIOUR determine how Org should handle multiple keywords for
  1621. the same property. It is a symbol among:
  1622. nil Keep old value and discard the new one.
  1623. t Replace old value with the new one.
  1624. `space' Concatenate the values, separating them with a space.
  1625. `newline' Concatenate the values, separating them with
  1626. a newline.
  1627. `split' Split values at white spaces, and cons them to the
  1628. previous list.
  1629. KEYWORD and OPTION have precedence over DEFAULT.
  1630. All these properties should be back-end agnostic. For back-end
  1631. specific properties, define a similar variable named
  1632. `org-BACKEND-option-alist', replacing BACKEND with the name of
  1633. the appropriate back-end. You can also redefine properties
  1634. there, as they have precedence over these.")
  1635. ;;; User Configurable Variables
  1636. (defgroup org-export-e-html nil
  1637. "Options for exporting Org mode files to HTML."
  1638. :tag "Org Export HTML"
  1639. :group 'org-export)
  1640. ;;;; Preamble
  1641. (defcustom org-e-html-default-class "article"
  1642. "The default HTML class."
  1643. :group 'org-export-e-html
  1644. :type '(string :tag "HTML class"))
  1645. (defcustom org-e-html-classes
  1646. '(("article"
  1647. "\\documentclass[11pt]{article}"
  1648. ("\\section{%s}" . "\\section*{%s}")
  1649. ("\\subsection{%s}" . "\\subsection*{%s}")
  1650. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  1651. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  1652. ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
  1653. ("report"
  1654. "\\documentclass[11pt]{report}"
  1655. ("\\part{%s}" . "\\part*{%s}")
  1656. ("\\chapter{%s}" . "\\chapter*{%s}")
  1657. ("\\section{%s}" . "\\section*{%s}")
  1658. ("\\subsection{%s}" . "\\subsection*{%s}")
  1659. ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
  1660. ("book"
  1661. "\\documentclass[11pt]{book}"
  1662. ("\\part{%s}" . "\\part*{%s}")
  1663. ("\\chapter{%s}" . "\\chapter*{%s}")
  1664. ("\\section{%s}" . "\\section*{%s}")
  1665. ("\\subsection{%s}" . "\\subsection*{%s}")
  1666. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
  1667. "Alist of HTML classes and associated header and structure.
  1668. If #+HTML_CLASS is set in the buffer, use its value and the
  1669. associated information. Here is the structure of each cell:
  1670. \(class-name
  1671. header-string
  1672. \(numbered-section . unnumbered-section\)
  1673. ...\)
  1674. The header string
  1675. -----------------
  1676. The HEADER-STRING is the header that will be inserted into the
  1677. HTML file. It should contain the \\documentclass macro, and
  1678. anything else that is needed for this setup. To this header, the
  1679. following commands will be added:
  1680. - Calls to \\usepackage for all packages mentioned in the
  1681. variables `org-export-latex-default-packages-alist' and
  1682. `org-export-latex-packages-alist'. Thus, your header
  1683. definitions should avoid to also request these packages.
  1684. - Lines specified via \"#+HTML_HEADER:\"
  1685. If you need more control about the sequence in which the header
  1686. is built up, or if you want to exclude one of these building
  1687. blocks for a particular class, you can use the following
  1688. macro-like placeholders.
  1689. [DEFAULT-PACKAGES] \\usepackage statements for default packages
  1690. [NO-DEFAULT-PACKAGES] do not include any of the default packages
  1691. [PACKAGES] \\usepackage statements for packages
  1692. [NO-PACKAGES] do not include the packages
  1693. [EXTRA] the stuff from #+HTML_HEADER
  1694. [NO-EXTRA] do not include #+HTML_HEADER stuff
  1695. [BEAMER-HEADER-EXTRA] the beamer extra headers
  1696. So a header like
  1697. \\documentclass{article}
  1698. [NO-DEFAULT-PACKAGES]
  1699. [EXTRA]
  1700. \\providecommand{\\alert}[1]{\\textbf{#1}}
  1701. [PACKAGES]
  1702. will omit the default packages, and will include the
  1703. #+HTML_HEADER lines, then have a call to \\providecommand, and
  1704. then place \\usepackage commands based on the content of
  1705. `org-export-latex-packages-alist'.
  1706. If your header, `org-export-latex-default-packages-alist' or
  1707. `org-export-latex-packages-alist' inserts
  1708. \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be
  1709. replaced with a coding system derived from
  1710. `buffer-file-coding-system'. See also the variable
  1711. `org-e-html-inputenc-alist' for a way to influence this
  1712. mechanism.
  1713. The sectioning structure
  1714. ------------------------
  1715. The sectioning structure of the class is given by the elements
  1716. following the header string. For each sectioning level, a number
  1717. of strings is specified. A %s formatter is mandatory in each
  1718. section string and will be replaced by the title of the section.
  1719. Instead of a cons cell \(numbered . unnumbered\), you can also
  1720. provide a list of 2 or 4 elements,
  1721. \(numbered-open numbered-close\)
  1722. or
  1723. \(numbered-open numbered-close unnumbered-open unnumbered-close\)
  1724. providing opening and closing strings for a HTML environment
  1725. that should represent the document section. The opening clause
  1726. should have a %s to represent the section title.
  1727. Instead of a list of sectioning commands, you can also specify
  1728. a function name. That function will be called with two
  1729. parameters, the \(reduced) level of the headline, and a predicate
  1730. non-nil when the headline should be numbered. It must return
  1731. a format string in which the section title will be added."
  1732. :group 'org-export-e-html
  1733. :type '(repeat
  1734. (list (string :tag "HTML class")
  1735. (string :tag "HTML header")
  1736. (repeat :tag "Levels" :inline t
  1737. (choice
  1738. (cons :tag "Heading"
  1739. (string :tag " numbered")
  1740. (string :tag "unnumbered"))
  1741. (list :tag "Environment"
  1742. (string :tag "Opening (numbered)")
  1743. (string :tag "Closing (numbered)")
  1744. (string :tag "Opening (unnumbered)")
  1745. (string :tag "Closing (unnumbered)"))
  1746. (function :tag "Hook computing sectioning"))))))
  1747. (defcustom org-e-html-inputenc-alist nil
  1748. "Alist of inputenc coding system names, and what should really be used.
  1749. For example, adding an entry
  1750. (\"utf8\" . \"utf8x\")
  1751. will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
  1752. are written as utf8 files."
  1753. :group 'org-export-e-html
  1754. :type '(repeat
  1755. (cons
  1756. (string :tag "Derived from buffer")
  1757. (string :tag "Use this instead"))))
  1758. (defcustom org-e-html-date-format
  1759. "\\today"
  1760. "Format string for \\date{...}."
  1761. :group 'org-export-e-html
  1762. :type 'boolean)
  1763. (defcustom org-e-html-title-command "\\maketitle"
  1764. "The command used to insert the title just after \\begin{document}.
  1765. If this string contains the formatting specification \"%s\" then
  1766. it will be used as a formatting string, passing the title as an
  1767. argument."
  1768. :group 'org-export-e-html
  1769. :type 'string)
  1770. ;;;; Headline
  1771. (defcustom org-e-html-format-headline-function nil
  1772. "Function to format headline text.
  1773. This function will be called with 5 arguments:
  1774. TODO the todo keyword \(string or nil\).
  1775. TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
  1776. PRIORITY the priority of the headline \(integer or nil\)
  1777. TEXT the main headline text \(string\).
  1778. TAGS the tags string, separated with colons \(string or nil\).
  1779. The function result will be used in the section format string.
  1780. As an example, one could set the variable to the following, in
  1781. order to reproduce the default set-up:
  1782. \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
  1783. \"Default format function for an headline.\"
  1784. \(concat \(when todo
  1785. \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
  1786. \(when priority
  1787. \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  1788. text
  1789. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
  1790. :group 'org-export-e-html
  1791. :type 'function)
  1792. ;;;; Emphasis
  1793. (defcustom org-e-html-emphasis-alist
  1794. '(("*" . "\\textbf{%s}")
  1795. ("/" . "\\emph{%s}")
  1796. ("_" . "\\underline{%s}")
  1797. ("+" . "\\st{%s}")
  1798. ("=" . protectedtexttt)
  1799. ("~" . verb))
  1800. "Alist of HTML expressions to convert emphasis fontifiers.
  1801. The key is the character used as a marker for fontification. The
  1802. value is a formatting string to wrap fontified text with.
  1803. Value can also be set to the following symbols: `verb' and
  1804. `protectedtexttt'. For the former, Org will use \"\\verb\" to
  1805. create a format string and select a delimiter character that
  1806. isn't in the string. For the latter, Org will use \"\\texttt\"
  1807. to typeset and try to protect special characters."
  1808. :group 'org-export-e-html
  1809. :type 'alist)
  1810. ;;;; Footnotes
  1811. (defcustom org-e-html-footnote-separator "<sup>, </sup>"
  1812. "Text used to separate footnotes."
  1813. :group 'org-export-e-html
  1814. :type 'string)
  1815. ;;;; Time-stamps
  1816. (defcustom org-e-html-active-timestamp-format "\\textit{%s}"
  1817. "A printf format string to be applied to active time-stamps."
  1818. :group 'org-export-e-html
  1819. :type 'string)
  1820. (defcustom org-e-html-inactive-timestamp-format "\\textit{%s}"
  1821. "A printf format string to be applied to inactive time-stamps."
  1822. :group 'org-export-e-html
  1823. :type 'string)
  1824. (defcustom org-e-html-diary-timestamp-format "\\textit{%s}"
  1825. "A printf format string to be applied to diary time-stamps."
  1826. :group 'org-export-e-html
  1827. :type 'string)
  1828. ;;;; Links
  1829. (defcustom org-e-html-image-default-option "width=.9\\linewidth"
  1830. "Default option for images."
  1831. :group 'org-export-e-html
  1832. :type 'string)
  1833. (defcustom org-e-html-default-figure-position "htb"
  1834. "Default position for latex figures."
  1835. :group 'org-export-e-html
  1836. :type 'string)
  1837. (defcustom org-e-html-inline-image-rules
  1838. '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
  1839. "Rules characterizing image files that can be inlined into HTML.
  1840. A rule consists in an association whose key is the type of link
  1841. to consider, and value is a regexp that will be matched against
  1842. link's path.
  1843. Note that, by default, the image extension *actually* allowed
  1844. depend on the way the HTML file is processed. When used with
  1845. pdflatex, pdf, jpg and png images are OK. When processing
  1846. through dvi to Postscript, only ps and eps are allowed. The
  1847. default we use here encompasses both."
  1848. :group 'org-export-e-html
  1849. :type '(alist :key-type (string :tag "Type")
  1850. :value-type (regexp :tag "Path")))
  1851. ;;;; Tables
  1852. (defcustom org-e-html-default-table-environment "tabular"
  1853. "Default environment used to build tables."
  1854. :group 'org-export-e-html
  1855. :type 'string)
  1856. (defcustom org-e-html-tables-centered t
  1857. "When non-nil, tables are exported in a center environment."
  1858. :group 'org-export-e-html
  1859. :type 'boolean)
  1860. (defcustom org-e-html-tables-verbatim nil
  1861. "When non-nil, tables are exported verbatim."
  1862. :group 'org-export-e-html
  1863. :type 'boolean)
  1864. (defcustom org-e-html-tables-booktabs nil
  1865. "When non-nil, display tables in a formal \"booktabs\" style.
  1866. This option assumes that the \"booktabs\" package is properly
  1867. loaded in the header of the document. This value can be ignored
  1868. locally with \"booktabs=yes\" and \"booktabs=no\" HTML
  1869. attributes."
  1870. :group 'org-export-e-html
  1871. :type 'boolean)
  1872. (defcustom org-e-html-table-caption-above t
  1873. "When non-nil, place caption string at the beginning of the table.
  1874. Otherwise, place it near the end."
  1875. :group 'org-export-e-html
  1876. :type 'boolean)
  1877. ;;;; Drawers
  1878. (defcustom org-e-html-format-drawer-function nil
  1879. "Function called to format a drawer in HTML code.
  1880. The function must accept two parameters:
  1881. NAME the drawer name, like \"LOGBOOK\"
  1882. CONTENTS the contents of the drawer.
  1883. The function should return the string to be exported.
  1884. For example, the variable could be set to the following function
  1885. in order to mimic default behaviour:
  1886. \(defun org-e-html-format-drawer-default \(name contents\)
  1887. \"Format a drawer element for HTML export.\"
  1888. contents\)"
  1889. :group 'org-export-e-html
  1890. :type 'function)
  1891. ;;;; Inlinetasks
  1892. (defcustom org-e-html-format-inlinetask-function nil
  1893. "Function called to format an inlinetask in HTML code.
  1894. The function must accept six parameters:
  1895. TODO the todo keyword, as a string
  1896. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  1897. PRIORITY the inlinetask priority, as a string
  1898. NAME the inlinetask name, as a string.
  1899. TAGS the inlinetask tags, as a string.
  1900. CONTENTS the contents of the inlinetask, as a string.
  1901. The function should return the string to be exported.
  1902. For example, the variable could be set to the following function
  1903. in order to mimic default behaviour:
  1904. \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
  1905. \"Format an inline task element for HTML export.\"
  1906. \(let \(\(full-title
  1907. \(concat
  1908. \(when todo
  1909. \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
  1910. \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  1911. title
  1912. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
  1913. \(format \(concat \"\\\\begin{center}\\n\"
  1914. \"\\\\fbox{\\n\"
  1915. \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
  1916. \"%s\\n\\n\"
  1917. \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
  1918. \"%s\"
  1919. \"\\\\end{minipage}}\"
  1920. \"\\\\end{center}\"\)
  1921. full-title contents\)\)"
  1922. :group 'org-export-e-html
  1923. :type 'function)
  1924. ;; Src blocks
  1925. (defcustom org-e-html-listings nil
  1926. "Non-nil means export source code using the listings package.
  1927. This package will fontify source code, possibly even with color.
  1928. If you want to use this, you also need to make HTML use the
  1929. listings package, and if you want to have color, the color
  1930. package. Just add these to `org-export-latex-packages-alist',
  1931. for example using customize, or with something like:
  1932. \(require 'org-e-html)
  1933. \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"listings\"))
  1934. \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"color\"))
  1935. Alternatively,
  1936. \(setq org-e-html-listings 'minted)
  1937. causes source code to be exported using the minted package as
  1938. opposed to listings. If you want to use minted, you need to add
  1939. the minted package to `org-export-latex-packages-alist', for
  1940. example using customize, or with
  1941. \(require 'org-e-html)
  1942. \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"minted\"))
  1943. In addition, it is necessary to install pygments
  1944. \(http://pygments.org), and to configure the variable
  1945. `org-e-html-pdf-process' so that the -shell-escape option is
  1946. passed to pdflatex."
  1947. :group 'org-export-e-html
  1948. :type '(choice
  1949. (const :tag "Use listings" t)
  1950. (const :tag "Use minted" 'minted)
  1951. (const :tag "Export verbatim" nil)))
  1952. (defcustom org-e-html-listings-langs
  1953. '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
  1954. (c "C") (cc "C++")
  1955. (fortran "fortran")
  1956. (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
  1957. (html "HTML") (xml "XML")
  1958. (tex "TeX") (latex "TeX")
  1959. (shell-script "bash")
  1960. (gnuplot "Gnuplot")
  1961. (ocaml "Caml") (caml "Caml")
  1962. (sql "SQL") (sqlite "sql"))
  1963. "Alist mapping languages to their listing language counterpart.
  1964. The key is a symbol, the major mode symbol without the \"-mode\".
  1965. The value is the string that should be inserted as the language
  1966. parameter for the listings package. If the mode name and the
  1967. listings name are the same, the language does not need an entry
  1968. in this list - but it does not hurt if it is present."
  1969. :group 'org-export-e-html
  1970. :type '(repeat
  1971. (list
  1972. (symbol :tag "Major mode ")
  1973. (string :tag "Listings language"))))
  1974. (defcustom org-e-html-listings-options nil
  1975. "Association list of options for the latex listings package.
  1976. These options are supplied as a comma-separated list to the
  1977. \\lstset command. Each element of the association list should be
  1978. a list containing two strings: the name of the option, and the
  1979. value. For example,
  1980. (setq org-e-html-listings-options
  1981. '((\"basicstyle\" \"\\small\")
  1982. (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
  1983. will typeset the code in a small size font with underlined, bold
  1984. black keywords.
  1985. Note that the same options will be applied to blocks of all
  1986. languages."
  1987. :group 'org-export-e-html
  1988. :type '(repeat
  1989. (list
  1990. (string :tag "Listings option name ")
  1991. (string :tag "Listings option value"))))
  1992. (defcustom org-e-html-minted-langs
  1993. '((emacs-lisp "common-lisp")
  1994. (cc "c++")
  1995. (cperl "perl")
  1996. (shell-script "bash")
  1997. (caml "ocaml"))
  1998. "Alist mapping languages to their minted language counterpart.
  1999. The key is a symbol, the major mode symbol without the \"-mode\".
  2000. The value is the string that should be inserted as the language
  2001. parameter for the minted package. If the mode name and the
  2002. listings name are the same, the language does not need an entry
  2003. in this list - but it does not hurt if it is present.
  2004. Note that minted uses all lower case for language identifiers,
  2005. and that the full list of language identifiers can be obtained
  2006. with:
  2007. pygmentize -L lexers"
  2008. :group 'org-export-e-html
  2009. :type '(repeat
  2010. (list
  2011. (symbol :tag "Major mode ")
  2012. (string :tag "Minted language"))))
  2013. (defcustom org-e-html-minted-options nil
  2014. "Association list of options for the latex minted package.
  2015. These options are supplied within square brackets in
  2016. \\begin{minted} environments. Each element of the alist should
  2017. be a list containing two strings: the name of the option, and the
  2018. value. For example,
  2019. \(setq org-e-html-minted-options
  2020. '\((\"bgcolor\" \"bg\") \(\"frame\" \"lines\")))
  2021. will result in src blocks being exported with
  2022. \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
  2023. as the start of the minted environment. Note that the same
  2024. options will be applied to blocks of all languages."
  2025. :group 'org-export-e-html
  2026. :type '(repeat
  2027. (list
  2028. (string :tag "Minted option name ")
  2029. (string :tag "Minted option value"))))
  2030. (defvar org-e-html-custom-lang-environments nil
  2031. "Alist mapping languages to language-specific HTML environments.
  2032. It is used during export of src blocks by the listings and minted
  2033. latex packages. For example,
  2034. \(setq org-e-html-custom-lang-environments
  2035. '\(\(python \"pythoncode\"\)\)\)
  2036. would have the effect that if org encounters begin_src python
  2037. during latex export it will output
  2038. \\begin{pythoncode}
  2039. <src block body>
  2040. \\end{pythoncode}")
  2041. ;;;; Plain text
  2042. (defcustom org-e-html-quotes
  2043. '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
  2044. ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
  2045. "Alist for quotes to use when converting english double-quotes.
  2046. The CAR of each item in this alist is the language code.
  2047. The CDR of each item in this alist is a list of three CONS:
  2048. - the first CONS defines the opening quote;
  2049. - the second CONS defines the closing quote;
  2050. - the last CONS defines single quotes.
  2051. For each item in a CONS, the first string is a regexp
  2052. for allowed characters before/after the quote, the second
  2053. string defines the replacement string for this quote."
  2054. :group 'org-export-e-html
  2055. :type '(list
  2056. (cons :tag "Opening quote"
  2057. (string :tag "Regexp for char before")
  2058. (string :tag "Replacement quote "))
  2059. (cons :tag "Closing quote"
  2060. (string :tag "Regexp for char after ")
  2061. (string :tag "Replacement quote "))
  2062. (cons :tag "Single quote"
  2063. (string :tag "Regexp for char before")
  2064. (string :tag "Replacement quote "))))
  2065. ;;;; Compilation
  2066. (defcustom org-e-html-pdf-process
  2067. '("pdflatex -interaction nonstopmode -output-directory %o %f"
  2068. "pdflatex -interaction nonstopmode -output-directory %o %f"
  2069. "pdflatex -interaction nonstopmode -output-directory %o %f")
  2070. "Commands to process a HTML file to a PDF file.
  2071. This is a list of strings, each of them will be given to the
  2072. shell as a command. %f in the command will be replaced by the
  2073. full file name, %b by the file base name \(i.e. without
  2074. extension) and %o by the base directory of the file.
  2075. The reason why this is a list is that it usually takes several
  2076. runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
  2077. does not have a clever mechanism to detect which of these
  2078. commands have to be run to get to a stable result, and it also
  2079. does not do any error checking.
  2080. By default, Org uses 3 runs of `pdflatex' to do the processing.
  2081. If you have texi2dvi on your system and if that does not cause
  2082. the infamous egrep/locale bug:
  2083. http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
  2084. then `texi2dvi' is the superior choice. Org does offer it as one
  2085. of the customize options.
  2086. Alternatively, this may be a Lisp function that does the
  2087. processing, so you could use this to apply the machinery of
  2088. AUCTeX or the Emacs HTML mode. This function should accept the
  2089. file name as its single argument."
  2090. :group 'org-export-pdf
  2091. :type '(choice
  2092. (repeat :tag "Shell command sequence"
  2093. (string :tag "Shell command"))
  2094. (const :tag "2 runs of pdflatex"
  2095. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  2096. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  2097. (const :tag "3 runs of pdflatex"
  2098. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  2099. "pdflatex -interaction nonstopmode -output-directory %o %f"
  2100. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  2101. (const :tag "pdflatex,bibtex,pdflatex,pdflatex"
  2102. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  2103. "bibtex %b"
  2104. "pdflatex -interaction nonstopmode -output-directory %o %f"
  2105. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  2106. (const :tag "texi2dvi"
  2107. ("texi2dvi -p -b -c -V %f"))
  2108. (const :tag "rubber"
  2109. ("rubber -d --into %o %f"))
  2110. (function)))
  2111. (defcustom org-e-html-logfiles-extensions
  2112. '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
  2113. "The list of file extensions to consider as HTML logfiles."
  2114. :group 'org-export-e-html
  2115. :type '(repeat (string :tag "Extension")))
  2116. (defcustom org-e-html-remove-logfiles t
  2117. "Non-nil means remove the logfiles produced by PDF production.
  2118. These are the .aux, .log, .out, and .toc files."
  2119. :group 'org-export-e-html
  2120. :type 'boolean)
  2121. ;;; Internal Functions
  2122. (defun org-e-html--caption/label-string (caption label info)
  2123. "Return caption and label HTML string for floats.
  2124. CAPTION is a cons cell of secondary strings, the car being the
  2125. standard caption and the cdr its short form. LABEL is a string
  2126. representing the label. INFO is a plist holding contextual
  2127. information.
  2128. If there's no caption nor label, return the empty string.
  2129. For non-floats, see `org-e-html--wrap-label'."
  2130. (setq label nil) ;; FIXME
  2131. (let ((label-str (if label (format "\\label{%s}" label) "")))
  2132. (cond
  2133. ((and (not caption) (not label)) "")
  2134. ((not caption) (format "\\label{%s}\n" label))
  2135. ;; Option caption format with short name.
  2136. ((cdr caption)
  2137. (format "\\caption[%s]{%s%s}\n"
  2138. (org-export-secondary-string (cdr caption) 'e-html info)
  2139. label-str
  2140. (org-export-secondary-string (car caption) 'e-html info)))
  2141. ;; Standard caption format.
  2142. ;; (t (format "\\caption{%s%s}\n"
  2143. ;; label-str
  2144. ;; (org-export-secondary-string (car caption) 'e-html info)))
  2145. (t (org-export-secondary-string (car caption) 'e-html info)))))
  2146. (defun org-e-html--guess-inputenc (header)
  2147. "Set the coding system in inputenc to what the buffer is.
  2148. HEADER is the HTML header string.
  2149. Return the new header."
  2150. (let* ((cs (or (ignore-errors
  2151. (latexenc-coding-system-to-inputenc
  2152. buffer-file-coding-system))
  2153. "utf8")))
  2154. (if (not cs)
  2155. header
  2156. ;; First translate if that is requested.
  2157. (setq cs (or (cdr (assoc cs org-e-html-inputenc-alist)) cs))
  2158. ;; Then find the \usepackage statement and replace the option.
  2159. (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
  2160. cs header t nil 1))))
  2161. (defun org-e-html--find-verb-separator (s)
  2162. "Return a character not used in string S.
  2163. This is used to choose a separator for constructs like \\verb."
  2164. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  2165. (loop for c across ll
  2166. when (not (string-match (regexp-quote (char-to-string c)) s))
  2167. return (char-to-string c))))
  2168. (defun org-e-html--make-option-string (options)
  2169. "Return a comma separated string of keywords and values.
  2170. OPTIONS is an alist where the key is the options keyword as
  2171. a string, and the value a list containing the keyword value, or
  2172. nil."
  2173. (mapconcat (lambda (pair)
  2174. (concat (first pair)
  2175. (when (> (length (second pair)) 0)
  2176. (concat "=" (second pair)))))
  2177. options
  2178. ","))
  2179. (defun org-e-html--quotation-marks (text info)
  2180. "Export quotation marks depending on language conventions.
  2181. TEXT is a string containing quotation marks to be replaced. INFO
  2182. is a plist used as a communication channel."
  2183. (mapc (lambda(l)
  2184. (let ((start 0))
  2185. (while (setq start (string-match (car l) text start))
  2186. (let ((new-quote (concat (match-string 1 text) (cdr l))))
  2187. (setq text (replace-match new-quote t t text))))))
  2188. (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
  2189. ;; Falls back on English.
  2190. (assoc "en" org-e-html-quotes))))
  2191. text)
  2192. (defun org-e-html--wrap-label (element output)
  2193. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  2194. This function shouldn't be used for floats. See
  2195. `org-e-html--caption/label-string'."
  2196. ;; (let ((label (org-element-get-property :name element)))
  2197. ;; (if (or (not output) (not label) (string= output "") (string= label ""))
  2198. ;; output
  2199. ;; (concat (format "\\label{%s}\n" label) output)))
  2200. output)
  2201. ;;; Template
  2202. ;; (defun org-e-html-template (contents info)
  2203. ;; "Return complete document string after HTML conversion.
  2204. ;; CONTENTS is the transcoded contents string. INFO is a plist
  2205. ;; holding export options."
  2206. ;; (let ((title (org-export-secondary-string
  2207. ;; (plist-get info :title) 'e-html info)))
  2208. ;; (concat
  2209. ;; ;; 1. Time-stamp.
  2210. ;; (and (plist-get info :time-stamp-file)
  2211. ;; (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  2212. ;; ;; 2. Document class and packages.
  2213. ;; (let ((class (plist-get info :latex-class))
  2214. ;; (class-options (plist-get info :latex-class-options)))
  2215. ;; (org-element-normalize-string
  2216. ;; (let* ((header (nth 1 (assoc class org-e-html-classes)))
  2217. ;; (document-class-string
  2218. ;; (and (stringp header)
  2219. ;; (if class-options
  2220. ;; (replace-regexp-in-string
  2221. ;; "^[ \t]*\\\\documentclass\\(\\[.*?\\]\\)"
  2222. ;; class-options header t nil 1)
  2223. ;; header))))
  2224. ;; (org-e-html--guess-inputenc
  2225. ;; (org-splice-latex-header
  2226. ;; document-class-string
  2227. ;; org-export-latex-default-packages-alist ; defined in org.el
  2228. ;; org-export-latex-packages-alist nil ; defined in org.el
  2229. ;; (plist-get info :latex-header-extra))))))
  2230. ;; ;; 3. Define alert if not yet defined.
  2231. ;; "\\providecommand{\\alert}[1]{\\textbf{#1}}\n"
  2232. ;; ;; 4. Possibly limit depth for headline numbering.
  2233. ;; (let ((sec-num (plist-get info :section-numbers)))
  2234. ;; (when (integerp sec-num)
  2235. ;; (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
  2236. ;; ;; 5. Author.
  2237. ;; (let ((author (and (plist-get info :with-author)
  2238. ;; (let ((auth (plist-get info :author)))
  2239. ;; (and auth (org-export-secondary-string
  2240. ;; auth 'e-html info)))))
  2241. ;; (email (and (plist-get info :with-email)
  2242. ;; (org-export-secondary-string
  2243. ;; (plist-get info :email) 'e-html info))))
  2244. ;; (cond ((and author email (not (string= "" email)))
  2245. ;; (format "\\author{%s\\thanks{%s}}\n" author email))
  2246. ;; (author (format "\\author{%s}\n" author))
  2247. ;; (t "\\author{}\n")))
  2248. ;; ;; 6. Date.
  2249. ;; (let ((date (plist-get info :date)))
  2250. ;; (and date (format "\\date{%s}\n" date)))
  2251. ;; ;; 7. Title
  2252. ;; (format "\\title{%s}\n" title)
  2253. ;; ;; 8. Hyperref options.
  2254. ;; (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
  2255. ;; (or (plist-get info :keywords) "")
  2256. ;; (or (plist-get info :description) "")
  2257. ;; (if (not (plist-get info :with-creator)) ""
  2258. ;; (plist-get info :creator)))
  2259. ;; ;; 9. Document start.
  2260. ;; "\\begin{document}\n\n"
  2261. ;; ;; 10. Title command.
  2262. ;; (org-element-normalize-string
  2263. ;; (cond ((string= "" title) nil)
  2264. ;; ((not (stringp org-e-html-title-command)) nil)
  2265. ;; ((string-match "\\(?:[^%]\\|^\\)%s"
  2266. ;; org-e-html-title-command)
  2267. ;; (format org-e-html-title-command title))
  2268. ;; (t org-e-html-title-command)))
  2269. ;; ;; 11. Table of contents.
  2270. ;; (let ((depth (plist-get info :with-toc)))
  2271. ;; (when depth
  2272. ;; (concat (when (wholenump depth)
  2273. ;; (format "\\setcounter{tocdepth}{%d}\n" depth))
  2274. ;; "\\tableofcontents\n\\vspace*{1cm}\n\n")))
  2275. ;; ;; 12. Document's body.
  2276. ;; contents
  2277. ;; ;; 13. Creator.
  2278. ;; (let ((creator-info (plist-get info :with-creator)))
  2279. ;; (cond
  2280. ;; ((not creator-info) "")
  2281. ;; ((eq creator-info 'comment)
  2282. ;; (format "%% %s\n" (plist-get info :creator)))
  2283. ;; (t (concat (plist-get info :creator) "\n"))))
  2284. ;; ;; 14. Document end.
  2285. ;; "\\end{document}")))
  2286. (defun org-e-html-meta-info (info)
  2287. (concat
  2288. (format "
  2289. <title>%s</title>" (plist-get info :title))
  2290. (format "
  2291. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
  2292. (and coding-system-for-write
  2293. (fboundp 'coding-system-get)
  2294. (coding-system-get coding-system-for-write
  2295. 'mime-charset)))
  2296. (format "
  2297. <meta name=\"title\" content=\"%s\"/>" (plist-get info :title))
  2298. "
  2299. <meta name=\"generator\" content=\"Org-mode\"/>"
  2300. (format "
  2301. <meta name=\"generated\" content=\"%s\"/>" (org-e-html-format-date info))
  2302. (format "
  2303. <meta name=\"author\" content=\"%s\"/>" (plist-get info :author))
  2304. (format "
  2305. <meta name=\"description\" content=\"%s\"/>" (plist-get info :description))
  2306. (format "
  2307. <meta name=\"keywords\" content=\"%s\"/>" (plist-get info :keywords))))
  2308. (defun org-e-html-style (info)
  2309. (concat
  2310. (when (plist-get info :style-include-default)
  2311. org-export-e-html-style-default)
  2312. (plist-get info :style)
  2313. (plist-get info :style-extra)
  2314. "\n"
  2315. (when (plist-get info :style-include-scripts)
  2316. org-export-e-html-scripts)))
  2317. (defun org-e-html-mathjax (info)
  2318. (when (or (eq (plist-get info :HTML-fragments) 'mathjax)
  2319. (and org-export-have-math
  2320. (eq (plist-get info :HTML-fragments) t)))
  2321. (org-export-e-html-mathjax-config
  2322. org-export-e-html-mathjax-template
  2323. org-export-e-html-mathjax-options
  2324. (or (plist-get info :mathjax) ""))))
  2325. (defun org-e-html-preamble (info)
  2326. (when (plist-get info :html-preamble)
  2327. (let* ((title (plist-get info :title))
  2328. (date (org-e-html-format-date info))
  2329. (author (plist-get info :author))
  2330. (lang-words (or (assoc (plist-get info :language)
  2331. org-export-language-setup)
  2332. (assoc "en" org-export-language-setup)))
  2333. (email (plist-get info :email))
  2334. (html-pre-real-contents
  2335. (cond
  2336. ((functionp (plist-get info :html-preamble))
  2337. (with-temp-buffer
  2338. (funcall (plist-get info :html-preamble))
  2339. (buffer-string)))
  2340. ((stringp (plist-get info :html-preamble))
  2341. (format-spec (plist-get info :html-preamble)
  2342. `((?t . ,title) (?a . ,author)
  2343. (?d . ,date) (?e . ,email))))
  2344. (t
  2345. (format-spec
  2346. (or (cadr (assoc (nth 0 lang-words)
  2347. org-export-e-html-preamble-format))
  2348. (cadr (assoc "en" org-export-e-html-preamble-format)))
  2349. `((?t . ,title) (?a . ,author)
  2350. (?d . ,date) (?e . ,email)))))))
  2351. (when (not (equal html-pre-real-contents ""))
  2352. (concat
  2353. (format "
  2354. <div id=\"%s\"> " (nth 0 org-export-e-html-divs))
  2355. "
  2356. "
  2357. html-pre-real-contents
  2358. "
  2359. </div>")))))
  2360. ;; (defun org-e-html-footnote-section (info)
  2361. ;; (when org-e-html-footnotes-alist
  2362. ;; (setq org-e-html-footnotes-alist
  2363. ;; (sort org-e-html-footnotes-alist
  2364. ;; (lambda (n1 n2) (< (or (nth 1 n1) most-positive-fixnum)
  2365. ;; (or (nth 1 n2) most-positive-fixnum)))))
  2366. ;; (org-e-html-format-footnotes-section
  2367. ;; (nth 4 (or (assoc (plist-get info :language)
  2368. ;; org-export-language-setup)
  2369. ;; (assoc "en" org-export-language-setup)))
  2370. ;; (mapconcat
  2371. ;; (lambda (x)
  2372. ;; (org-e-html-format-footnote-definition (nth 2 x) (nth 1 x)))
  2373. ;; org-e-html-footnotes-alist "\n"))))
  2374. (defun org-e-html-bibliography ()
  2375. (org-export-e-html-get-bibliography))
  2376. (defun org-e-html-postamble (info)
  2377. (concat
  2378. (when (and (not body-only)
  2379. (plist-get info :html-postamble))
  2380. (let* ((html-post (plist-get info :html-postamble))
  2381. (date (org-e-html-format-date info))
  2382. (author (plist-get info :author))
  2383. (email (plist-get info :email))
  2384. (lang-words (or (assoc (plist-get info :language)
  2385. org-export-language-setup)
  2386. (assoc "en" org-export-language-setup)))
  2387. (email
  2388. (mapconcat (lambda(e)
  2389. (format "<a href=\"mailto:%s\">%s</a>" e e))
  2390. (split-string email ",+ *")
  2391. ", "))
  2392. (html-validation-link (or org-export-e-html-validation-link ""))
  2393. (creator-info
  2394. (concat "Org version " org-version " with Emacs version "
  2395. (number-to-string emacs-major-version))))
  2396. (concat
  2397. ;; begin postamble
  2398. "
  2399. <div id=\"" (nth 2 org-export-e-html-divs) "\">"
  2400. (cond
  2401. ;; auto postamble
  2402. ((eq (plist-get info :html-postamble) 'auto)
  2403. (concat
  2404. (when (plist-get info :time-stamp-file)
  2405. (format "
  2406. <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
  2407. (when (and (plist-get info :with-author) author)
  2408. (format "
  2409. <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
  2410. (when (and (plist-get info :with-email) email)
  2411. (format "
  2412. <p class=\"email\"> %s </p>" email))
  2413. (when (plist-get info :with-creator)
  2414. (format "
  2415. <p class=\"creator\"> %s </p>" creator-info))
  2416. html-validation-link "\n"))
  2417. ;; postamble from a string
  2418. ((stringp (plist-get info :html-postamble))
  2419. (format-spec (plist-get info :html-postamble)
  2420. `((?a . ,author) (?e . ,email)
  2421. (?d . ,date) (?c . ,creator-info)
  2422. (?v . ,html-validation-link))))
  2423. ;; postamble from a function
  2424. ((functionp (plist-get info :html-postamble))
  2425. (with-temp-buffer
  2426. (funcall (plist-get info :html-postamble))
  2427. (buffer-string)))
  2428. ;; default postamble
  2429. (t
  2430. (format-spec
  2431. (or (cadr (assoc (nth 0 lang-words)
  2432. org-export-e-html-postamble-format))
  2433. (cadr (assoc "en" org-export-e-html-postamble-format)))
  2434. `((?a . ,author) (?e . ,email)
  2435. (?d . ,date) (?c . ,creator-info)
  2436. (?v . ,html-validation-link)))))
  2437. "
  2438. </div>")))
  2439. org-export-e-html-html-helper-timestamp))
  2440. (defun org-e-html-template (contents info)
  2441. "Return complete document string after HTML conversion.
  2442. CONTENTS is the transcoded contents string. RAW-DATA is the
  2443. original parsed data. INFO is a plist holding export options."
  2444. (concat
  2445. (format
  2446. (or (and (stringp org-export-e-html-xml-declaration)
  2447. org-export-e-html-xml-declaration)
  2448. (cdr (assoc (plist-get info :html-extension)
  2449. org-export-e-html-xml-declaration))
  2450. (cdr (assoc "html" org-export-e-html-xml-declaration))
  2451. "")
  2452. (or (and coding-system-for-write
  2453. (fboundp 'coding-system-get)
  2454. (coding-system-get coding-system-for-write
  2455. 'mime-charset))
  2456. "iso-8859-1"))
  2457. "
  2458. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  2459. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
  2460. (format "
  2461. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
  2462. (plist-get info :language) (plist-get info :language))
  2463. "
  2464. <head>"
  2465. (org-e-html-meta-info info) ; meta
  2466. (org-e-html-style info) ; style
  2467. (org-e-html-mathjax info) ; mathjax
  2468. "
  2469. </head>"
  2470. "
  2471. <body>"
  2472. (let ((link-up (and (plist-get info :link-up)
  2473. (string-match "\\S-" (plist-get info :link-up))
  2474. (plist-get info :link-up)))
  2475. (link-home (and (plist-get info :link-home)
  2476. (string-match "\\S-" (plist-get info :link-home))
  2477. (plist-get info :link-home))))
  2478. (when (or link-up link-home)
  2479. (format org-export-e-html-home/up-format
  2480. (or link-up link-home)
  2481. (or link-home link-up))))
  2482. ;; preamble
  2483. (org-e-html-preamble info)
  2484. ;; content
  2485. (format "
  2486. <div id=\"%s\">" (or org-export-e-html-content-div
  2487. (nth 1 org-export-e-html-divs)))
  2488. (format "
  2489. <h1 class=\"title\"> %s </h1>\n" (plist-get info :title))
  2490. contents
  2491. (org-e-html-footnote-section info)
  2492. (org-e-html-bibliography)
  2493. (unless body-only
  2494. "
  2495. </div>")
  2496. ;; postamble
  2497. (org-e-html-postamble info)
  2498. (unless body-only
  2499. "
  2500. </body>")
  2501. "
  2502. </html>"))
  2503. ;;; Transcode Functions
  2504. ;;;; Block
  2505. (defun org-e-html-center-block (center-block contents info)
  2506. "Transcode a CENTER-BLOCK element from Org to HTML.
  2507. CONTENTS holds the contents of the block. INFO is a plist
  2508. holding contextual information."
  2509. ;; (org-e-html--wrap-label
  2510. ;; center-block
  2511. ;; (format "\\begin{center}\n%s\\end{center}" contents))
  2512. (org-e-html--wrap-label
  2513. center-block
  2514. (format "<div style=\"text-align: center\">\n%s</div>" contents)))
  2515. ;;;; Comment
  2516. ;; Comments are ignored.
  2517. ;;;; Comment Block
  2518. ;; Comment Blocks are ignored.
  2519. ;;;; Drawer
  2520. (defun org-e-html-drawer (drawer contents info)
  2521. "Transcode a DRAWER element from Org to HTML.
  2522. CONTENTS holds the contents of the block. INFO is a plist
  2523. holding contextual information."
  2524. (let* ((name (org-element-get-property :drawer-name drawer))
  2525. (output (if (functionp org-e-html-format-drawer-function)
  2526. (funcall org-e-html-format-drawer-function
  2527. name contents)
  2528. ;; If there's no user defined function: simply
  2529. ;; display contents of the drawer.
  2530. contents)))
  2531. (org-e-html--wrap-label drawer output)))
  2532. ;;;; Dynamic Block
  2533. (defun org-e-html-dynamic-block (dynamic-block contents info)
  2534. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  2535. CONTENTS holds the contents of the block. INFO is a plist
  2536. holding contextual information. See
  2537. `org-export-data'."
  2538. (org-e-html--wrap-label dynamic-block contents))
  2539. ;;;; Emphasis
  2540. (defun org-e-html-emphasis (emphasis contents info)
  2541. "Transcode EMPHASIS from Org to HTML.
  2542. CONTENTS is the contents of the emphasized text. INFO is a plist
  2543. holding contextual information.."
  2544. ;; (format (cdr (assoc (org-element-get-property :marker emphasis)
  2545. ;; org-e-html-emphasis-alist))
  2546. ;; contents)
  2547. (org-e-html-format-fontify
  2548. contents (cadr (assoc
  2549. (org-element-get-property :marker emphasis)
  2550. '(("*" bold)
  2551. ("/" emphasis)
  2552. ("_" underline)
  2553. ("=" code)
  2554. ("~" verbatim)
  2555. ("+" strike))))))
  2556. ;;;; Entity
  2557. (defun org-e-html-entity (entity contents info)
  2558. "Transcode an ENTITY object from Org to HTML.
  2559. CONTENTS are the definition itself. INFO is a plist holding
  2560. contextual information."
  2561. ;; (let ((ent (org-element-get-property :latex entity)))
  2562. ;; (if (org-element-get-property :latex-math-p entity)
  2563. ;; (format "$%s$" ent)
  2564. ;; ent))
  2565. (org-element-get-property :html entity))
  2566. ;;;; Example Block
  2567. ;; (defun org-odt-format-source-code-or-example-colored
  2568. ;; (lines lang caption textareap cols rows num cont rpllbl fmt))
  2569. (defun org-e-html-format-source-code-or-example-plain
  2570. (lines lang caption textareap cols rows num cont rpllbl fmt)
  2571. (setq lines
  2572. (concat
  2573. "<pre class=\"example\">\n"
  2574. (cond
  2575. (textareap
  2576. (concat
  2577. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
  2578. cols rows)
  2579. lines "</textarea>\n</p>\n"))
  2580. (t
  2581. (with-temp-buffer
  2582. (insert lines)
  2583. (goto-char (point-min))
  2584. (while (re-search-forward "[<>&]" nil t)
  2585. (replace-match (cdr (assq (char-before)
  2586. '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
  2587. t t))
  2588. (buffer-string))))
  2589. "</pre>\n"))
  2590. (unless textareap
  2591. (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
  2592. ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
  2593. ;; (setq lines (replace-match "\\1" t nil lines)))
  2594. lines)
  2595. (defun org-e-html-format-source-code-or-example-colored
  2596. (lines lang caption textareap cols rows num cont rpllbl fmt)
  2597. (let* ((lang-m (when lang
  2598. (or (cdr (assoc lang org-src-lang-modes))
  2599. lang)))
  2600. (mode (and lang-m (intern
  2601. (concat
  2602. (if (symbolp lang-m)
  2603. (symbol-name lang-m)
  2604. lang-m)
  2605. "-mode"))))
  2606. (org-inhibit-startup t)
  2607. (org-startup-folded nil))
  2608. (setq lines
  2609. (with-temp-buffer
  2610. (insert lines)
  2611. (if (functionp mode)
  2612. (funcall mode)
  2613. (fundamental-mode))
  2614. (font-lock-fontify-buffer)
  2615. ;; markup each line separately
  2616. (org-remove-formatting-on-newlines-in-region
  2617. (point-min) (point-max))
  2618. (org-src-mode)
  2619. (set-buffer-modified-p nil)
  2620. (org-export-e-htmlize-region-for-paste
  2621. (point-min) (point-max))))
  2622. (when (string-match "<pre\\([^>]*\\)>\n*" lines)
  2623. (setq lines (replace-match
  2624. (format "<pre class=\"src src-%s\">\n" lang) t t lines)))
  2625. (when caption
  2626. (setq lines
  2627. (concat
  2628. "<div class=\"org-src-container\">"
  2629. (format "<label class=\"org-src-name\">%s</label>" caption)
  2630. lines "</div>")))
  2631. (unless textareap
  2632. (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
  2633. ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
  2634. ;; (setq lines (replace-match "\\1" t nil lines)))
  2635. lines))
  2636. (defun org-e-html-format-source-code-or-example
  2637. (lang code &optional opts indent caption)
  2638. "Format CODE from language LANG and return it formatted for export.
  2639. The CODE is marked up in `org-export-current-backend' format.
  2640. Check if a function by name
  2641. \"org-<backend>-format-source-code-or-example\" is bound. If yes,
  2642. use it as the custom formatter. Otherwise, use the default
  2643. formatter. Default formatters are provided for docbook, html,
  2644. latex and ascii backends. For example, use
  2645. `org-e-html-format-source-code-or-example' to provide a custom
  2646. formatter for export to \"html\".
  2647. If LANG is nil, do not add any fontification.
  2648. OPTS contains formatting options, like `-n' for triggering numbering lines,
  2649. and `+n' for continuing previous numbering.
  2650. Code formatting according to language currently only works for HTML.
  2651. Numbering lines works for all three major backends (html, latex, and ascii).
  2652. INDENT was the original indentation of the block."
  2653. (save-match-data
  2654. (let* ((backend-formatter 'org-e-html-format-source-code-or-example-plain)
  2655. num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
  2656. (setq opts (or opts "")
  2657. num (string-match "[-+]n\\>" opts)
  2658. cont (string-match "\\+n\\>" opts)
  2659. rpllbl (string-match "-r\\>" opts)
  2660. keepp (string-match "-k\\>" opts)
  2661. textareap (string-match "-t\\>" opts)
  2662. preserve-indentp (or org-src-preserve-indentation
  2663. (string-match "-i\\>" opts))
  2664. cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
  2665. (string-to-number (match-string 1 opts))
  2666. 80)
  2667. rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
  2668. (string-to-number (match-string 1 opts))
  2669. (org-count-lines code))
  2670. fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
  2671. (match-string 1 opts)))
  2672. (when (and textareap
  2673. ;; (eq org-export-current-backend 'html)
  2674. )
  2675. ;; we cannot use numbering or highlighting.
  2676. (setq num nil cont nil lang nil))
  2677. (if keepp (setq rpllbl 'keep))
  2678. (setq rtn (if preserve-indentp code (org-remove-indentation code)))
  2679. (when (string-match "^," rtn)
  2680. (setq rtn (with-temp-buffer
  2681. (insert rtn)
  2682. ;; Free up the protected lines
  2683. (goto-char (point-min))
  2684. (while (re-search-forward "^," nil t)
  2685. (if (or (equal lang "org")
  2686. (save-match-data
  2687. (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
  2688. (replace-match ""))
  2689. (end-of-line 1))
  2690. (buffer-string))))
  2691. (when lang
  2692. (if (featurep 'xemacs)
  2693. (require 'htmlize)
  2694. (require 'htmlize nil t)))
  2695. (setq backend-formatter
  2696. (cond
  2697. ((fboundp 'htmlize-region-for-paste)
  2698. 'org-e-html-format-source-code-or-example-colored)
  2699. (t
  2700. (message
  2701. "htmlize.el 1.34 or later is needed for source code formatting")
  2702. 'org-e-html-format-source-code-or-example-plain)))
  2703. (funcall backend-formatter rtn lang caption textareap cols rows
  2704. num cont rpllbl fmt))))
  2705. (defun org-e-html-example-block (example-block contents info)
  2706. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  2707. CONTENTS is nil. INFO is a plist holding contextual information."
  2708. (let* ((options (or (org-element-get-property :options example-block) ""))
  2709. (value (org-export-handle-code example-block info)))
  2710. ;; (org-e-html--wrap-label
  2711. ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
  2712. (org-e-html--wrap-label
  2713. example-block (org-e-html-format-source-code-or-example nil value))))
  2714. ;;;; Export Snippet
  2715. (defun org-e-html-export-snippet (export-snippet contents info)
  2716. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  2717. CONTENTS is nil. INFO is a plist holding contextual information."
  2718. (org-element-get-property :value export-snippet))
  2719. ;;;; Export Block
  2720. (defun org-e-html-export-block (export-block contents info)
  2721. "Transcode a EXPORT-BLOCK element from Org to HTML.
  2722. CONTENTS is nil. INFO is a plist holding contextual information."
  2723. (when (string= (org-element-get-property :type export-block) "latex")
  2724. (org-remove-indentation (org-element-get-property :value export-block))))
  2725. ;;;; Fixed Width
  2726. (defun org-e-html-fixed-width (fixed-width contents info)
  2727. "Transcode a FIXED-WIDTH element from Org to HTML.
  2728. CONTENTS is nil. INFO is a plist holding contextual information."
  2729. (let* ((value (org-element-normalize-string
  2730. (replace-regexp-in-string
  2731. "^[ \t]*: ?" ""
  2732. (org-element-get-property :value fixed-width)))))
  2733. ;; (org-e-html--wrap-label
  2734. ;; fixed-width (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
  2735. (org-e-html--wrap-label
  2736. fixed-width (org-e-html-format-source-code-or-example nil value)) ;; FIXME
  2737. ))
  2738. ;;;; Footnote Definition
  2739. ;; Footnote Definitions are ignored.
  2740. ;;;; Footnote Reference
  2741. (defun org-e-html-footnote-reference (footnote-reference contents info)
  2742. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  2743. CONTENTS is nil. INFO is a plist holding contextual information."
  2744. (concat
  2745. ;; Insert separator between two footnotes in a row.
  2746. (let ((prev (org-export-get-previous-element footnote-reference info)))
  2747. (when (and (listp prev) (eq (car prev) 'footnote-reference))
  2748. org-e-html-footnote-separator))
  2749. ;; Use \footnotemark if the footnote has already been defined.
  2750. ;; Otherwise, define it with \footnote command.
  2751. (cond
  2752. ((not (org-export-footnote-first-reference-p footnote-reference info))
  2753. ;; (format "\\footnotemark[%s]"
  2754. ;; (org-export-get-footnote-number footnote-reference info))
  2755. (org-e-html-format-footnote-reference
  2756. (org-export-get-footnote-number footnote-reference info)
  2757. "FIXME" 100) ;; FIXME
  2758. )
  2759. ;; Inline definitions are secondary strings.
  2760. ((eq (org-element-get-property :type footnote-reference) 'inline)
  2761. ;; (format "\\footnote{%s}"
  2762. ;; (org-trim
  2763. ;; (org-export-secondary-string
  2764. ;; (org-export-get-footnote-definition footnote-reference info)
  2765. ;; 'e-html info)))
  2766. (let ((n (org-export-get-footnote-number footnote-reference info))
  2767. (def (format
  2768. "<p>%s</p>"
  2769. (org-trim
  2770. (org-export-secondary-string
  2771. (org-export-get-footnote-definition footnote-reference info)
  2772. 'e-html info)))))
  2773. (push (cons n def) org-e-html-footnotes-alist)
  2774. (org-e-html-format-footnote-reference n def 1)))
  2775. ;; Non-inline footnotes definitions are full Org data.
  2776. (t
  2777. ;; (format "\\footnote{%s}"
  2778. ;; (org-trim
  2779. ;; (org-export-data
  2780. ;; (org-export-get-footnote-definition footnote-reference info)
  2781. ;; 'e-html info)))
  2782. (let ((n (org-export-get-footnote-number footnote-reference info))
  2783. (def (org-trim
  2784. (org-export-data
  2785. (org-export-get-footnote-definition footnote-reference info)
  2786. 'e-html info))))
  2787. (push (cons n def) org-e-html-footnotes-alist)
  2788. (org-e-html-format-footnote-reference n def 1))
  2789. ))))
  2790. ;;;; Headline
  2791. (defun org-e-html-todo (todo)
  2792. (when todo
  2793. (org-e-html-format-fontify
  2794. (concat
  2795. ;; (ignore-errors (org-lparse-get 'TODO-KWD-CLASS-PREFIX))
  2796. org-export-e-html-todo-kwd-class-prefix
  2797. (org-e-html-fix-class-name todo))
  2798. (list (if (member todo org-done-keywords) "done" "todo")
  2799. todo))))
  2800. (defun org-e-html-headline (headline contents info)
  2801. "Transcode an HEADLINE element from Org to HTML.
  2802. CONTENTS holds the contents of the headline. INFO is a plist
  2803. holding contextual information."
  2804. (let* ((class (plist-get info :latex-class))
  2805. (numberedp (plist-get info :section-numbers))
  2806. ;; Get level relative to current parsed data.
  2807. (level (org-export-get-relative-level headline info))
  2808. (class-sectionning (assoc class org-e-html-classes))
  2809. ;; Section formatting will set two placeholders: one for the
  2810. ;; title and the other for the contents.
  2811. (section-fmt
  2812. (let ((sec (if (and (symbolp (nth 2 class-sectionning))
  2813. (fboundp (nth 2 class-sectionning)))
  2814. (funcall (nth 2 class-sectionning) level numberedp)
  2815. (nth (1+ level) class-sectionning))))
  2816. (cond
  2817. ;; No section available for that LEVEL.
  2818. ((not sec) nil)
  2819. ;; Section format directly returned by a function.
  2820. ((stringp sec) sec)
  2821. ;; (numbered-section . unnumbered-section)
  2822. ((not (consp (cdr sec)))
  2823. (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
  2824. ;; (numbered-open numbered-close)
  2825. ((= (length sec) 2)
  2826. (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
  2827. ;; (num-in num-out no-num-in no-num-out)
  2828. ((= (length sec) 4)
  2829. (if numberedp
  2830. (concat (car sec) "\n%s" (nth 1 sec))
  2831. (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
  2832. (text (org-export-secondary-string
  2833. (org-element-get-property :title headline) 'e-html info))
  2834. (todo (and (plist-get info :with-todo-keywords)
  2835. (let ((todo (org-element-get-property
  2836. :todo-keyword headline)))
  2837. (and todo
  2838. (org-export-secondary-string todo 'e-html info)))))
  2839. (todo-type (and todo (org-element-get-property :todo-type headline)))
  2840. (tags (and (plist-get info :with-tags)
  2841. (org-element-get-property :tags headline)))
  2842. (priority (and (plist-get info :with-priority)
  2843. (org-element-get-property :priority headline)))
  2844. ;; Create the headline text.
  2845. (full-text (if (functionp org-e-html-format-headline-function)
  2846. ;; User-defined formatting function.
  2847. (funcall org-e-html-format-headline-function
  2848. todo todo-type priority text tags)
  2849. ;; Default formatting.
  2850. (concat
  2851. ;; (when todo
  2852. ;; (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  2853. (org-e-html-todo todo) " "
  2854. (when priority (format "\\framebox{\\#%c} " priority))
  2855. text
  2856. ;; (when tags (format "\\hfill{}\\textsc{%s}" tags))
  2857. )))
  2858. ;; Associate some \label to the headline for internal links.
  2859. ;; (headline-label
  2860. ;; (format "\\label{sec-%s}\n"
  2861. ;; (mapconcat 'number-to-string
  2862. ;; (org-export-get-headline-number headline info)
  2863. ;; "-")))
  2864. ;; FIXME - begin
  2865. (headline-no (org-export-get-headline-number headline info))
  2866. (headline-label
  2867. (format "sec-%s" (mapconcat 'number-to-string headline-no "-")))
  2868. (headline-labels (list headline-label))
  2869. (headline-no (org-export-get-headline-number headline info))
  2870. (section-no (mapconcat 'number-to-string headline-no "."))
  2871. ;; FIXME - end
  2872. (pre-blanks (make-string
  2873. (org-element-get-property :pre-blank headline) 10)))
  2874. (cond
  2875. ;; Case 1: This is a footnote section: ignore it.
  2876. ((org-element-get-property :footnote-section-p headline) nil)
  2877. ;; Case 2. This is a deep sub-tree: export it as a list item.
  2878. ;; Also export as items headlines for which no section
  2879. ;; format has been found.
  2880. ;; ((or (not section-fmt) (org-export-low-level-p headline info)) FIXME
  2881. ;; ;; Build the real contents of the sub-tree.
  2882. ;; (let ((low-level-body
  2883. ;; (concat
  2884. ;; ;; If the headline is the first sibling, start a list.
  2885. ;; (when (org-export-first-sibling-p headline info)
  2886. ;; (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
  2887. ;; ;; Itemize headline
  2888. ;; "\\item " full-text "\n" headline-label pre-blanks contents)))
  2889. ;; ;; If headline in the last sibling, close the list, before any
  2890. ;; ;; blank line. Otherwise, simply return LOW-LEVEL-BODY.
  2891. ;; (if (org-export-last-sibling-p headline info)
  2892. ;; (replace-regexp-in-string
  2893. ;; "[ \t\n]*\\'"
  2894. ;; (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
  2895. ;; low-level-body)
  2896. ;; low-level-body)))
  2897. ;; Case 3. Standard headline. Export it as a section.
  2898. (t
  2899. ;; (format section-fmt full-text
  2900. ;; (concat headline-label pre-blanks contents))
  2901. (org-e-html-format-outline contents level section-no full-text tags
  2902. (car (last headline-labels))
  2903. (butlast headline-labels) nil)))))
  2904. ;;;; Horizontal Rule
  2905. (defun org-e-html-horizontal-rule (horizontal-rule contents info)
  2906. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  2907. CONTENTS is nil. INFO is a plist holding contextual information."
  2908. (let ((attr (mapconcat #'identity
  2909. (org-element-get-property :attr_html horizontal-rule)
  2910. " ")))
  2911. (org-e-html--wrap-label horizontal-rule
  2912. (org-e-html-format-horizontal-line))))
  2913. ;;;; Inline Babel Call
  2914. ;; Inline Babel Calls are ignored.
  2915. ;;;; Inline Src Block
  2916. (defun org-e-html-inline-src-block (inline-src-block contents info)
  2917. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  2918. CONTENTS holds the contents of the item. INFO is a plist holding
  2919. contextual information."
  2920. (let* ((code (org-element-get-property :value inline-src-block))
  2921. (separator (org-e-html--find-verb-separator code)))
  2922. (cond
  2923. ;; Do not use a special package: transcode it verbatim.
  2924. ((not org-e-html-listings)
  2925. (concat "\\verb" separator code separator))
  2926. ;; Use minted package.
  2927. ((eq org-e-html-listings 'minted)
  2928. (let* ((org-lang (org-element-get-property :language inline-src-block))
  2929. (mint-lang (or (cadr (assq (intern org-lang)
  2930. org-e-html-minted-langs))
  2931. org-lang))
  2932. (options (org-e-html--make-option-string
  2933. org-e-html-minted-options)))
  2934. (concat (format "\\mint%s{%s}"
  2935. (if (string= options "") "" (format "[%s]" options))
  2936. mint-lang)
  2937. separator code separator)))
  2938. ;; Use listings package.
  2939. (t
  2940. ;; Maybe translate language's name.
  2941. (let* ((org-lang (org-element-get-property :language inline-src-block))
  2942. (lst-lang (or (cadr (assq (intern org-lang)
  2943. org-e-html-listings-langs))
  2944. org-lang))
  2945. (options (org-e-html--make-option-string
  2946. (append org-e-html-listings-options
  2947. `(("language" ,lst-lang))))))
  2948. (concat (format "\\lstinline[%s]" options)
  2949. separator code separator))))))
  2950. ;;;; Inlinetask
  2951. (defun org-e-html-format-section (text class &optional id)
  2952. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  2953. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  2954. (defun org-e-html-inlinetask (inlinetask contents info)
  2955. "Transcode an INLINETASK element from Org to HTML.
  2956. CONTENTS holds the contents of the block. INFO is a plist
  2957. holding contextual information."
  2958. (let ((title (org-export-secondary-string
  2959. (org-element-get-property :title inlinetask) 'e-html info))
  2960. (todo (and (plist-get info :with-todo-keywords)
  2961. (let ((todo (org-element-get-property
  2962. :todo-keyword inlinetask)))
  2963. (and todo
  2964. (org-export-secondary-string todo 'e-html info)))))
  2965. (todo-type (org-element-get-property :todo-type inlinetask))
  2966. (tags (and (plist-get info :with-tags)
  2967. (org-element-get-property :tags inlinetask)))
  2968. (priority (and (plist-get info :with-priority)
  2969. (org-element-get-property :priority inlinetask))))
  2970. ;; If `org-e-html-format-inlinetask-function' is provided, call it
  2971. ;; with appropriate arguments.
  2972. (if (functionp org-e-html-format-inlinetask-function)
  2973. (funcall org-e-html-format-inlinetask-function
  2974. todo todo-type priority title tags contents)
  2975. ;; Otherwise, use a default template.
  2976. (org-e-html--wrap-label
  2977. inlinetask
  2978. (let ((full-title
  2979. (concat
  2980. (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  2981. (when priority (format "\\framebox{\\#%c} " priority))
  2982. title
  2983. (when tags (format "\\hfill{}\\textsc{%s}" tags)))))
  2984. (format (concat "\\begin{center}\n"
  2985. "\\fbox{\n"
  2986. "\\begin{minipage}[c]{.6\\textwidth}\n"
  2987. "%s\n\n"
  2988. "\\rule[.8em]{\\textwidth}{2pt}\n\n"
  2989. "%s"
  2990. "\\end{minipage}\n"
  2991. "}\n"
  2992. "\\end{center}")
  2993. full-title contents))))))
  2994. ;;;; Item
  2995. (defun org-e-html-format-list-item (contents type &optional arg headline)
  2996. (setq headline nil) ; FIXME
  2997. (concat
  2998. (case type
  2999. (ordered
  3000. (let* ((counter arg)
  3001. (extra (if counter (format " value=\"%s\"" counter) "")))
  3002. (format "<li%s>" extra)))
  3003. (unordered
  3004. (let* ((id arg)
  3005. (extra (if id (format " id=\"%s\"" id) "")))
  3006. (concat
  3007. (format "<li%s>" extra)
  3008. (when headline (concat headline "<br/>")))))
  3009. (descriptive
  3010. (let* ((desc-tag (or arg "(no term)")))
  3011. (concat (format "<dt> %s </dt>" desc-tag) "<dd>"))))
  3012. contents
  3013. (case type
  3014. (ordered "</li>")
  3015. (unordered "</li>")
  3016. (descriptive "</dd>"))))
  3017. (defun org-e-html-item (item contents info)
  3018. "Transcode an ITEM element from Org to HTML.
  3019. CONTENTS holds the contents of the item. INFO is a plist holding
  3020. contextual information."
  3021. ;; Grab `:level' from plain-list properties, which is always the
  3022. ;; first element above current item.
  3023. (let* ((plain-list (car (org-export-get-genealogy item info)))
  3024. (type (org-element-get-property :type plain-list))
  3025. (level (org-element-get-property
  3026. :level (car (plist-get info :genealogy))))
  3027. (counter (let ((count (org-element-get-property :counter item)))
  3028. (and count
  3029. (< level 4)
  3030. (format "\\setcounter{enum%s}{%s}\n"
  3031. (nth level '("i" "ii" "iii" "iv"))
  3032. (1- count)))))
  3033. (checkbox (let ((checkbox (org-element-get-property :checkbox item)))
  3034. (cond ((eq checkbox 'on) "$\\boxtimes$ ")
  3035. ((eq checkbox 'off) "$\\Box$ ")
  3036. ((eq checkbox 'trans) "$\\boxminus$ "))))
  3037. (tag (let ((tag (org-element-get-property :tag item)))
  3038. (and tag
  3039. (format "[%s]" (org-export-secondary-string
  3040. tag 'e-html info))))))
  3041. ;; (concat counter "\\item" tag " " checkbox contents)
  3042. (org-e-html-format-list-item contents type nil)
  3043. ))
  3044. ;;;; Keyword
  3045. (defun org-e-html-keyword (keyword contents info)
  3046. "Transcode a KEYWORD element from Org to HTML.
  3047. CONTENTS is nil. INFO is a plist holding contextual information."
  3048. (let ((key (downcase (org-element-get-property :key keyword)))
  3049. (value (org-element-get-property :value keyword)))
  3050. (cond
  3051. ((string= key "latex") value)
  3052. ((string= key "index") (format "\\index{%s}" value))
  3053. ((string= key "target")
  3054. (format "\\label{%s}" (org-export-solidify-link-text value)))
  3055. ((string= key "toc")
  3056. (let ((value (downcase value)))
  3057. (cond
  3058. ((string-match "\\<headlines\\>" value)
  3059. (let ((depth (or (and (string-match "[0-9]+" value)
  3060. (string-to-number (match-string 0 value)))
  3061. (plist-get info :with-toc))))
  3062. (concat
  3063. (when (wholenump depth)
  3064. (format "\\setcounter{tocdepth}{%s}\n" depth))
  3065. "\\tableofcontents")))
  3066. ((string= "tables" value) "\\listoftables")
  3067. ((string= "figures" value) "\\listoffigures")
  3068. ((string= "listings" value)
  3069. (cond
  3070. ((eq org-e-html-listings 'minted) "\\listoflistings")
  3071. (org-e-html-listings "\\lstlistoflistings")
  3072. ;; At the moment, src blocks with a caption are wrapped
  3073. ;; into a figure environment.
  3074. (t "\\listoffigures")))))))))
  3075. ;;;; Latex Environment
  3076. (defun org-e-html-format-latex (latex-frag processing-type)
  3077. (let* ((cache-relpath
  3078. (concat "ltxpng/" (file-name-sans-extension
  3079. (file-name-nondirectory (buffer-file-name)))))
  3080. (cache-dir (file-name-directory (buffer-file-name )))
  3081. (display-msg "Creating LaTeX Image..."))
  3082. (with-temp-buffer
  3083. (insert latex-frag)
  3084. (org-format-latex cache-relpath cache-dir nil display-msg
  3085. nil nil processing-type)
  3086. (buffer-string))))
  3087. (defun org-e-html-latex-environment (latex-environment contents info)
  3088. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  3089. CONTENTS is nil. INFO is a plist holding contextual information."
  3090. ;; (org-e-html--wrap-label
  3091. ;; latex-environment
  3092. ;; (org-remove-indentation (org-element-get-property :value latex-environment)))
  3093. (org-e-html--wrap-label
  3094. latex-environment
  3095. (let ((latex-frag
  3096. (org-remove-indentation
  3097. (org-element-get-property :value latex-environment)))
  3098. (processing-type (plist-get info :LaTeX-fragments)))
  3099. (cond
  3100. ((member processing-type '(t mathjax))
  3101. (org-e-html-format-latex latex-frag 'mathjax))
  3102. ((equal processing-type 'dvipng)
  3103. (let* ((formula-link (org-e-html-format-latex
  3104. latex-frag processing-type)))
  3105. (when (and formula-link
  3106. (string-match "file:\\([^]]*\\)" formula-link))
  3107. (setq formula-file (match-string 1 formula-link))
  3108. (org-e-html-format-inline-image formula-file))))
  3109. (t
  3110. latex-frag)))))
  3111. ;;;; Latex Fragment
  3112. (defun org-e-html-latex-fragment (latex-fragment contents info)
  3113. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  3114. CONTENTS is nil. INFO is a plist holding contextual information."
  3115. ;; (org-element-get-property :value latex-fragment)
  3116. (let* ((latex-frag (org-element-get-property :value latex-fragment)))
  3117. (cond
  3118. ((string-match "\\\\ref{\\([^{}\n]+\\)}" latex-frag)
  3119. (let* ((label (match-string 1 latex-frag))
  3120. (href (and label (org-export-solidify-link-text label)))
  3121. (text (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  3122. (substring label (match-beginning 1))
  3123. label)))
  3124. (org-e-html-format-internal-link text href)))
  3125. (t
  3126. (let ((processing-type (plist-get info :LaTeX-fragments)))
  3127. (cond
  3128. ((member processing-type '(t mathjax))
  3129. (org-e-html-format-latex latex-frag 'mathjax))
  3130. ((equal processing-type 'dvipng)
  3131. (let* ((formula-link (org-e-html-format-latex
  3132. latex-frag processing-type)))
  3133. (when (and formula-link
  3134. (string-match "file:\\([^]]*\\)" formula-link))
  3135. (setq formula-file (match-string 1 formula-link))
  3136. (org-e-html-format-inline-image formula-file))))
  3137. (t
  3138. latex-frag)))))))
  3139. ;;;; Line Break
  3140. (defun org-e-html-line-break (line-break contents info)
  3141. "Transcode a LINE-BREAK object from Org to HTML.
  3142. CONTENTS is nil. INFO is a plist holding contextual information."
  3143. "<br/>")
  3144. ;;;; Link
  3145. (defun org-e-html-link--inline-image (link info)
  3146. "Return HTML code for an inline image.
  3147. LINK is the link pointing to the inline image. INFO is a plist
  3148. used as a communication channel."
  3149. (let* ((parent (org-export-get-parent-paragraph link info))
  3150. (path (let ((raw-path (org-element-get-property :path link)))
  3151. (if (not (file-name-absolute-p raw-path)) raw-path
  3152. (expand-file-name raw-path))))
  3153. (caption (org-e-html--caption/label-string
  3154. (org-element-get-property :caption parent)
  3155. (org-element-get-property :name parent)
  3156. info))
  3157. (label (org-element-get-property :name parent))
  3158. ;; Retrieve latex attributes from the element around.
  3159. (attr (let ((raw-attr
  3160. (mapconcat #'identity
  3161. (org-element-get-property :attr_html parent)
  3162. " ")))
  3163. (unless (string= raw-attr "") raw-attr)))
  3164. (disposition
  3165. (cond
  3166. ((and attr (string-match "\\<wrap\\>" attr)) 'wrap)
  3167. ((and attr (string-match "\\<multicolumn\\>" attr)) 'multicolumn)
  3168. ((or (and attr (string-match "\\<float\\>" attr))
  3169. (not (string= caption "")))
  3170. 'float)))
  3171. (placement
  3172. (cond
  3173. ((and attr (string-match "\\<placement=\\(\\S-+\\)" attr))
  3174. (org-match-string-no-properties 1 attr))
  3175. ((eq disposition 'wrap) "{l}{0.5\\textwidth}")
  3176. ((eq disposition 'float)
  3177. (concat "[" org-e-html-default-figure-position "]"))
  3178. (t ""))))
  3179. ;; Now clear ATTR from any special keyword and set a default
  3180. ;; value if nothing is left.
  3181. (setq attr
  3182. (if (not attr) ""
  3183. (org-trim
  3184. (replace-regexp-in-string
  3185. "\\(wrap\\|multicolumn\\|float\\|placement=\\S-+\\)" "" attr))))
  3186. (setq attr (cond ((not (string= attr "")) attr)
  3187. ((eq disposition 'float) "width=0.7\\textwidth")
  3188. ((eq disposition 'wrap) "width=0.48\\textwidth")
  3189. (t (or org-e-html-image-default-option ""))))
  3190. ;; Return proper string, depending on DISPOSITION.
  3191. (case disposition
  3192. (wrap (format "\\begin{wrapfigure}%s
  3193. \\centering
  3194. \\includegraphics[%s]{%s}
  3195. %s\\end{wrapfigure}" placement attr path caption))
  3196. (mulicolumn (format "\\begin{figure*}%s
  3197. \\centering
  3198. \\includegraphics[%s]{%s}
  3199. %s\\end{figure*}" placement attr path caption))
  3200. (float (format "\\begin{figure}%s
  3201. \\centering
  3202. \\includegraphics[%s]{%s}
  3203. %s\\end{figure}" placement attr path caption))
  3204. (t (format "\\includegraphics[%s]{%s}" attr path)))
  3205. (let ((href (and label (org-export-solidify-link-text label))))
  3206. (org-e-html-format-inline-image path caption href attr))))
  3207. (defun org-e-html-link (link desc info)
  3208. "Transcode a LINK object from Org to HTML.
  3209. DESC is the description part of the link, or the empty string.
  3210. INFO is a plist holding contextual information. See
  3211. `org-export-data'."
  3212. (let* ((type (org-element-get-property :type link))
  3213. (raw-path (org-element-get-property :path link))
  3214. ;; Ensure DESC really exists, or set it to nil.
  3215. (desc (and (not (string= desc "")) desc))
  3216. (imagep (org-export-inline-image-p
  3217. link org-e-html-inline-image-rules))
  3218. (path (cond
  3219. ((member type '("http" "https" "ftp" "mailto"))
  3220. (concat type ":" raw-path))
  3221. ((string= type "file")
  3222. (when (string-match "\\(.+\\)::.+" raw-path)
  3223. (setq raw-path (match-string 1 raw-path)))
  3224. (if (file-name-absolute-p raw-path)
  3225. (concat "file://" (expand-file-name raw-path))
  3226. ;; TODO: Not implemented yet. Concat also:
  3227. ;; (org-export-directory :HTML info)
  3228. (concat "file://" raw-path)))
  3229. (t raw-path)))
  3230. protocol)
  3231. (cond
  3232. ;; Image file.
  3233. (imagep (org-e-html-link--inline-image link info))
  3234. ;; Target or radioed target: replace link with the normalized
  3235. ;; custom-id/target name.
  3236. ((member type '("target" "radio"))
  3237. ;; (format "\\hyperref[%s]{%s}"
  3238. ;; (org-export-solidify-link-text path)
  3239. ;; (or desc (org-export-secondary-string path 'e-html info)))
  3240. (org-e-html-format-internal-link
  3241. (or desc (org-export-secondary-string path 'e-html info))
  3242. (org-export-solidify-link-text path)))
  3243. ;; Links pointing to an headline: Find destination and build
  3244. ;; appropriate referencing commanding.
  3245. ((member type '("custom-id" "fuzzy" "id"))
  3246. (let ((destination (if (string= type "fuzzy")
  3247. (org-export-resolve-fuzzy-link link info)
  3248. (org-export-resolve-id-link link info))))
  3249. ;; Fuzzy link points to a target. Do as above.
  3250. (case (car destination)
  3251. (target
  3252. ;; (format "\\hyperref[%s]{%s}"
  3253. ;; (org-export-solidify-link-text
  3254. ;; (org-element-get-property :raw-value destination))
  3255. ;; (or desc
  3256. ;; (org-export-secondary-string
  3257. ;; (org-element-get-property :raw-link link)
  3258. ;; 'e-html info)))
  3259. (org-e-html-format-internal-link
  3260. (or desc
  3261. (org-export-secondary-string
  3262. (org-element-get-property :raw-link link)
  3263. 'e-html info))
  3264. (org-export-solidify-link-text
  3265. (org-element-get-property :raw-value destination))))
  3266. ;; Fuzzy link points to an headline. If headlines are
  3267. ;; numbered and the link has no description, display
  3268. ;; headline's number. Otherwise, display description or
  3269. ;; headline's title.
  3270. (headline
  3271. (let ((label
  3272. (format "sec-%s"
  3273. (mapconcat
  3274. 'number-to-string
  3275. (org-export-get-headline-number destination info)
  3276. "-"))))
  3277. (if (and (plist-get info :section-numbers) (not desc))
  3278. (format "\\ref{%s}" label)
  3279. ;; (format "\\hyperref[%s]{%s}" label
  3280. ;; (or desc
  3281. ;; (org-export-secondary-string
  3282. ;; (org-element-get-property :title destination)
  3283. ;; 'e-html info)))
  3284. (org-e-html-format-internal-link
  3285. (or desc
  3286. (org-export-secondary-string
  3287. (org-element-get-property :title destination)
  3288. 'e-html info)) label))))
  3289. ;; Fuzzy link points nowhere.
  3290. (otherwise
  3291. ;; (format "\\texttt{%s}"
  3292. ;; (or desc
  3293. ;; (org-export-secondary-string
  3294. ;; (org-element-get-property :raw-link link)
  3295. ;; 'e-html info)))
  3296. (org-e-html-format-fontify
  3297. (or desc
  3298. (org-export-secondary-string
  3299. (org-element-get-property :raw-link link)
  3300. 'e-html info)) 'emphasis)))))
  3301. ;; Coderef: replace link with the reference name or the
  3302. ;; equivalent line number.
  3303. ((string= type "coderef")
  3304. (format (org-export-get-coderef-format path (or desc ""))
  3305. (org-export-resolve-coderef path info)))
  3306. ;; Link type is handled by a special function.
  3307. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  3308. (funcall protocol (org-link-unescape path) desc 'html))
  3309. ;; External link with a description part.
  3310. ((and path desc)
  3311. ;; (format "\\href{%s}{%s}" path desc)
  3312. (org-e-html-format-link desc path))
  3313. ;; External link without a description part.
  3314. (path
  3315. ;; (format "\\url{%s}" path)
  3316. (org-e-html-format-link path path))
  3317. ;; No path, only description. Try to do something useful.
  3318. (t
  3319. ;; (format "\\texttt{%s}" desc)
  3320. (org-e-html-format-fontify desc 'emphasis)))))
  3321. ;;;; Babel Call
  3322. ;; Babel Calls are ignored.
  3323. ;;;; Macro
  3324. (defun org-e-html-macro (macro contents info)
  3325. "Transcode a MACRO element from Org to HTML.
  3326. CONTENTS is nil. INFO is a plist holding contextual information."
  3327. ;; Use available tools.
  3328. (org-export-expand-macro macro info))
  3329. ;;;; Paragraph
  3330. (defun org-e-html-paragraph (paragraph contents info)
  3331. "Transcode a PARAGRAPH element from Org to HTML.
  3332. CONTENTS is the contents of the paragraph, as a string. INFO is
  3333. the plist used as a communication channel."
  3334. (let* ((style nil) ; FIXME
  3335. (class (cdr (assoc style '((footnote . "footnote")
  3336. (verse . nil)))))
  3337. (extra (if class (format " class=\"%s\"" class) ""))
  3338. (parent (car (org-export-get-genealogy paragraph info))))
  3339. (cond
  3340. ;; is this the first paragraph in a list item
  3341. ;; (plain-list (car (org-export-get-genealogy item info)))
  3342. ;; (type (org-element-get-property :type plain-list))
  3343. ((and (equal parent 'item)
  3344. (= (org-element-get-property :begin paragraph)
  3345. (plist-get (plist-get info :parent-properties)
  3346. :contents-begin)))
  3347. contents)
  3348. (t
  3349. (concat (format "<p%s> " extra) contents "</p>")))))
  3350. ;;;; Plain List
  3351. (defun org-e-html-plain-list (plain-list contents info)
  3352. "Transcode a PLAIN-LIST element from Org to HTML.
  3353. CONTENTS is the contents of the list. INFO is a plist holding
  3354. contextual information."
  3355. (let* ((type (org-element-get-property :type plain-list))
  3356. (paralist-types '("inparaenum" "asparaenum" "inparaitem" "asparaitem"
  3357. "inparadesc" "asparadesc"))
  3358. (paralist-regexp (concat
  3359. "\\("
  3360. (mapconcat 'identity paralist-types "\\|")
  3361. "\\)"))
  3362. (attr (mapconcat #'identity
  3363. (org-element-get-property :attr_html plain-list)
  3364. " "))
  3365. (latex-type (cond
  3366. ((and attr
  3367. (string-match
  3368. (format "\\<%s\\>" paralist-regexp) attr))
  3369. (match-string 1 attr))
  3370. ((eq type 'ordered) "enumerate")
  3371. ((eq type 'unordered) "itemize")
  3372. ((eq type 'descriptive) "description")))
  3373. arg1 ;; FIXME
  3374. )
  3375. (org-e-html--wrap-label
  3376. plain-list
  3377. ;; (format "\\begin{%s}%s\n%s\\end{%s}"
  3378. ;; latex-type
  3379. ;; ;; Once special environment, if any, has been removed, the
  3380. ;; ;; rest of the attributes will be optional arguments.
  3381. ;; ;; They will be put inside square brackets if necessary.
  3382. ;; (let ((opt (replace-regexp-in-string
  3383. ;; (format " *%s *" paralist-regexp) "" attr)))
  3384. ;; (cond ((string= opt "") "")
  3385. ;; ((string-match "\\`\\[[^][]+\\]\\'" opt) opt)
  3386. ;; (t (format "[%s]" opt))))
  3387. ;; contents
  3388. ;; latex-type)
  3389. (format "%s\n%s%s"
  3390. (case type
  3391. (ordered
  3392. (format "<ol%s>" (if arg1
  3393. (format " start=\"%d\"" arg1)
  3394. "")))
  3395. (unordered "<ul>")
  3396. (descriptive "<dl>"))
  3397. contents
  3398. (case type
  3399. (ordered "</ol>")
  3400. (unordered "</ul>")
  3401. (descriptive "</dl>")))
  3402. )))
  3403. ;;;; Plain Text
  3404. (defun org-e-html-convert-special-strings (string)
  3405. "Convert special characters in STRING to HTML."
  3406. (let ((all org-export-e-html-special-string-regexps)
  3407. e a re rpl start)
  3408. (while (setq a (pop all))
  3409. (setq re (car a) rpl (cdr a) start 0)
  3410. (while (string-match re string start)
  3411. (setq string (replace-match rpl t nil string))))
  3412. string))
  3413. (defun org-e-html-encode-plain-text (s)
  3414. "Convert plain text characters to HTML equivalent.
  3415. Possible conversions are set in `org-export-html-protect-char-alist'."
  3416. (let ((cl org-export-e-html-protect-char-alist) c)
  3417. (while (setq c (pop cl))
  3418. (let ((start 0))
  3419. (while (string-match (car c) s start)
  3420. (setq s (replace-match (cdr c) t t s)
  3421. start (1+ (match-beginning 0))))))
  3422. s))
  3423. (defun org-e-html-plain-text (text info)
  3424. "Transcode a TEXT string from Org to HTML.
  3425. TEXT is the string to transcode. INFO is a plist holding
  3426. contextual information."
  3427. (setq text (org-e-html-encode-plain-text text))
  3428. ;; Protect %, #, &, $, ~, ^, _, { and }.
  3429. ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
  3430. ;; (setq text
  3431. ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
  3432. ;; Protect \
  3433. ;; (setq text (replace-regexp-in-string
  3434. ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
  3435. ;; "$\\backslash$" text nil t 1))
  3436. ;; HTML into \HTML{} and TeX into \TeX{}.
  3437. ;; (let ((case-fold-search nil)
  3438. ;; (start 0))
  3439. ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
  3440. ;; (setq text (replace-match
  3441. ;; (format "\\%s{}" (match-string 1 text)) nil t text)
  3442. ;; start (match-end 0))))
  3443. ;; Handle quotation marks
  3444. ;; (setq text (org-e-html--quotation-marks text info))
  3445. ;; Convert special strings.
  3446. ;; (when (plist-get info :with-special-strings)
  3447. ;; (while (string-match (regexp-quote "...") text)
  3448. ;; (setq text (replace-match "\\ldots{}" nil t text))))
  3449. (when (plist-get info :with-special-strings)
  3450. (setq text (org-e-html-convert-special-strings text)))
  3451. ;; Handle break preservation if required.
  3452. (when (plist-get info :preserve-breaks)
  3453. (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
  3454. text)))
  3455. ;; Return value.
  3456. text)
  3457. ;;;; Property Drawer
  3458. (defun org-e-html-property-drawer (property-drawer contents info)
  3459. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  3460. CONTENTS is nil. INFO is a plist holding contextual
  3461. information."
  3462. ;; The property drawer isn't exported but we want separating blank
  3463. ;; lines nonetheless.
  3464. "")
  3465. ;;;; Quote Block
  3466. (defun org-e-html-quote-block (quote-block contents info)
  3467. "Transcode a QUOTE-BLOCK element from Org to HTML.
  3468. CONTENTS holds the contents of the block. INFO is a plist
  3469. holding contextual information."
  3470. ;; (org-e-html--wrap-label
  3471. ;; quote-block
  3472. ;; (format "\\begin{quote}\n%s\\end{quote}" contents))
  3473. (org-e-html--wrap-label
  3474. quote-block (format "<blockquote>\n%s</blockquote>" contents)))
  3475. ;;;; Quote Section
  3476. (defun org-e-html-quote-section (quote-section contents info)
  3477. "Transcode a QUOTE-SECTION element from Org to HTML.
  3478. CONTENTS is nil. INFO is a plist holding contextual information."
  3479. (let ((value (org-remove-indentation
  3480. (org-element-get-property :value quote-section))))
  3481. (when value
  3482. ;; (format "\\begin{verbatim}\n%s\\end{verbatim}" value)
  3483. (format "<pre>\n%s</pre>" value))))
  3484. ;;;; Section
  3485. (defun org-e-html-section (section contents info)
  3486. "Transcode a SECTION element from Org to HTML.
  3487. CONTENTS holds the contents of the section. INFO is a plist
  3488. holding contextual information."
  3489. contents)
  3490. ;;;; Radio Target
  3491. (defun org-e-html-radio-target (radio-target text info)
  3492. "Transcode a RADIO-TARGET object from Org to HTML.
  3493. TEXT is the text of the target. INFO is a plist holding
  3494. contextual information."
  3495. ;; (format "\\label{%s}%s"
  3496. ;; (org-export-solidify-link-text
  3497. ;; (org-element-get-property :raw-value radio-target))
  3498. ;; text)
  3499. (org-e-html-format-anchor
  3500. text
  3501. (org-export-solidify-link-text
  3502. (org-element-get-property :raw-value radio-target))))
  3503. ;;;; Special Block
  3504. (defun org-e-html-special-block (special-block contents info)
  3505. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  3506. CONTENTS holds the contents of the block. INFO is a plist
  3507. holding contextual information."
  3508. (let ((type (downcase (org-element-get-property :type special-block))))
  3509. (org-e-html--wrap-label
  3510. special-block
  3511. (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
  3512. ;;;; Src Block
  3513. (defun org-e-html-src-block (src-block contents info)
  3514. "Transcode a SRC-BLOCK element from Org to HTML.
  3515. CONTENTS holds the contents of the item. INFO is a plist holding
  3516. contextual information."
  3517. (let* ((lang (org-element-get-property :language src-block))
  3518. (code (org-export-handle-code src-block info))
  3519. (caption (org-element-get-property :caption src-block))
  3520. (label (org-element-get-property :name src-block))
  3521. (custom-env (and lang
  3522. (cadr (assq (intern lang)
  3523. org-e-html-custom-lang-environments)))))
  3524. ;; FIXME: Handle caption
  3525. (org-e-html-format-source-code-or-example lang code)
  3526. ;; (cond
  3527. ;; ;; No source fontification.
  3528. ;; ((not org-e-html-listings)
  3529. ;; (let ((caption-str (org-e-html--caption/label-string
  3530. ;; caption label info))
  3531. ;; (float-env (when caption "\\begin{figure}[H]\n%s\n\\end{figure}")))
  3532. ;; (format (or float-env "%s")
  3533. ;; (concat
  3534. ;; caption-str
  3535. ;; (format "\\begin{verbatim}\n%s\\end{verbatim}" code)))))
  3536. ;; ;; Custom environment.
  3537. ;; (custom-env
  3538. ;; (format "\\begin{%s}\n%s\\end{%s}\n" custom-env code custom-env))
  3539. ;; ;; Use minted package.
  3540. ;; ((eq org-e-html-listings 'minted)
  3541. ;; (let* ((mint-lang (or (cadr (assq (intern lang) org-e-html-minted-langs))
  3542. ;; lang))
  3543. ;; (float-env (when (or label caption)
  3544. ;; (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
  3545. ;; (org-e-html--caption/label-string
  3546. ;; caption label info))))
  3547. ;; (body (format "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
  3548. ;; (org-e-html--make-option-string
  3549. ;; org-e-html-minted-options)
  3550. ;; mint-lang code)))
  3551. ;; (if float-env (format float-env body) body)))
  3552. ;; ;; Use listings package.
  3553. ;; (t
  3554. ;; (let ((lst-lang
  3555. ;; (or (cadr (assq (intern lang) org-e-html-listings-langs)) lang))
  3556. ;; (caption-str
  3557. ;; (when caption
  3558. ;; (let ((main (org-export-secondary-string
  3559. ;; (car caption) 'e-html info)))
  3560. ;; (if (not (cdr caption)) (format "{%s}" main)
  3561. ;; (format
  3562. ;; "{[%s]%s}"
  3563. ;; (org-export-secondary-string (cdr caption) 'e-html info)
  3564. ;; main))))))
  3565. ;; (concat (format "\\lstset{%s}\n"
  3566. ;; (org-e-html--make-option-string
  3567. ;; (append org-e-html-listings-options
  3568. ;; `(("language" ,lst-lang))
  3569. ;; (when label `(("label" ,label)))
  3570. ;; (when caption-str
  3571. ;; `(("caption" ,caption-str))))))
  3572. ;; (format "\\begin{lstlisting}\n%s\\end{lstlisting}" code)))))
  3573. ))
  3574. ;;;; Statistics Cookie
  3575. (defun org-e-html-statistics-cookie (statistics-cookie contents info)
  3576. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  3577. CONTENTS is nil. INFO is a plist holding contextual information."
  3578. (org-element-get-property :value statistics-cookie))
  3579. ;;;; Subscript
  3580. (defun org-e-html-subscript (subscript contents info)
  3581. "Transcode a SUBSCRIPT object from Org to HTML.
  3582. CONTENTS is the contents of the object. INFO is a plist holding
  3583. contextual information."
  3584. ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
  3585. (org-e-html-format-fontify contents 'subscript))
  3586. ;;;; Superscript
  3587. (defun org-e-html-superscript (superscript contents info)
  3588. "Transcode a SUPERSCRIPT object from Org to HTML.
  3589. CONTENTS is the contents of the object. INFO is a plist holding
  3590. contextual information."
  3591. ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
  3592. (org-e-html-format-fontify contents 'superscript))
  3593. ;;;; Table
  3594. (defun org-e-html-table--format-string (table table-info info)
  3595. "Return an appropriate format string for TABLE.
  3596. TABLE-INFO is the plist containing format info about the table,
  3597. as returned by `org-export-table-format-info'. INFO is a plist
  3598. used as a communication channel.
  3599. The format string leaves one placeholder for the body of the
  3600. table."
  3601. (let* ((label (org-element-get-property :name table))
  3602. (caption (org-e-html--caption/label-string
  3603. (org-element-get-property :caption table) label info))
  3604. (attr (mapconcat 'identity
  3605. (org-element-get-property :attr_html table)
  3606. " "))
  3607. ;; Determine alignment string.
  3608. (alignment (org-e-html-table--align-string attr table-info))
  3609. ;; Determine environment for the table: longtable, tabular...
  3610. (table-env (cond
  3611. ((not attr) org-e-html-default-table-environment)
  3612. ((string-match "\\<longtable\\>" attr) "longtable")
  3613. ((string-match "\\<tabular.?\\>" attr)
  3614. (org-match-string-no-properties 0 attr))
  3615. (t org-e-html-default-table-environment)))
  3616. ;; If table is a float, determine environment: table or table*.
  3617. (float-env (cond
  3618. ((string= "longtable" table-env) nil)
  3619. ((and attr
  3620. (or (string-match (regexp-quote "table*") attr)
  3621. (string-match "\\<multicolumn\\>" attr)))
  3622. "table*")
  3623. ((or (not (string= caption "")) label) "table")))
  3624. ;; Extract others display options.
  3625. (width (and attr (string-match "\\<width=\\(\\S-+\\)" attr)
  3626. (org-match-string-no-properties 1 attr)))
  3627. (placement
  3628. (if (and attr (string-match "\\<placement=\\(\\S-+\\)" attr))
  3629. (org-match-string-no-properties 1 attr)
  3630. (format "[%s]" org-e-html-default-figure-position))))
  3631. ;; Prepare the final format string for the table.
  3632. (cond
  3633. ;; Longtable.
  3634. ((string= "longtable" table-env)
  3635. (format
  3636. "\\begin{longtable}{%s}\n%s\n%%s\n%s\\end{longtable}"
  3637. alignment
  3638. (if (or (not org-e-html-table-caption-above) (string= "" caption)) ""
  3639. (concat (org-trim caption) "\\\\"))
  3640. (if (or org-e-html-table-caption-above (string= "" caption)) ""
  3641. (concat (org-trim caption) "\\\\\n"))))
  3642. ;; Others.
  3643. (t (concat (when float-env
  3644. (concat
  3645. (format "\\begin{%s}%s\n" float-env placement)
  3646. (if org-e-html-table-caption-above caption "")))
  3647. (when org-e-html-tables-centered "\\begin{center}\n")
  3648. (format "\\begin{%s}%s{%s}\n%%s\n\\end{%s}"
  3649. table-env
  3650. (if width (format "{%s}" width) "") alignment table-env)
  3651. (when org-e-html-tables-centered "\n\\end{center}")
  3652. (when float-env
  3653. (concat (if org-e-html-table-caption-above "" caption)
  3654. (format "\n\\end{%s}" float-env))))))))
  3655. (defun org-e-html-table--align-string (attr table-info)
  3656. "Return an appropriate HTML alignment string.
  3657. ATTR is a string containing table's HTML specific attributes.
  3658. TABLE-INFO is the plist containing format info about the table,
  3659. as returned by `org-export-table-format-info'."
  3660. (or (and attr
  3661. (string-match "\\<align=\\(\\S-+\\)" attr)
  3662. (match-string 1 attr))
  3663. (let* ((align (copy-sequence (plist-get table-info :alignment)))
  3664. (colgroups (copy-sequence (plist-get table-info :column-groups)))
  3665. (cols (length align))
  3666. (separators (make-vector (1+ cols) "")))
  3667. ;; Ignore the first column if it's special.
  3668. (when (plist-get table-info :special-column-p)
  3669. (aset align 0 "") (aset colgroups 0 nil))
  3670. (let ((col 0))
  3671. (mapc (lambda (el)
  3672. (let ((gr (aref colgroups col)))
  3673. (when (memq gr '(start start-end))
  3674. (aset separators col "|"))
  3675. (when (memq gr '(end start-end))
  3676. (aset separators (1+ col) "|")))
  3677. (incf col))
  3678. align))
  3679. ;; Build the HTML specific alignment string.
  3680. (loop for al across align
  3681. for sep across separators
  3682. concat (concat sep al) into output
  3683. finally return (concat output (aref separators cols))))))
  3684. ;; tables
  3685. (defun org-e-html-begin-table (caption label attributes)
  3686. (let* ((html-table-tag (or (plist-get info :html-table-tag) ; FIXME
  3687. org-export-e-html-table-tag))
  3688. (html-table-tag
  3689. (org-export-splice-attributes html-table-tag attributes)))
  3690. (when label
  3691. (setq html-table-tag
  3692. (org-export-splice-attributes
  3693. html-table-tag
  3694. (format "id=\"%s\"" (org-solidify-link-text label)))))
  3695. (concat "\n" html-table-tag
  3696. (format "\n<caption>%s</caption>" (or caption "")))))
  3697. (defun org-e-html-end-table ()
  3698. (when org-lparse-table-is-styled
  3699. ;; column groups
  3700. ;; (unless (car org-table-colgroup-info)
  3701. ;; (setq org-table-colgroup-info
  3702. ;; (cons :start (cdr org-table-colgroup-info))))
  3703. ;; column alignment
  3704. (let ((c -1))
  3705. ;; (mapc
  3706. ;; (lambda (x)
  3707. ;; (incf c)
  3708. ;; (setf (aref org-lparse-table-colalign-vector c)
  3709. ;; (or (aref org-lparse-table-colalign-vector c)
  3710. ;; (if (> (/ (float x) (1+ org-lparse-table-rownum))
  3711. ;; org-table-number-fraction)
  3712. ;; "right" "left"))))
  3713. ;; org-lparse-table-num-numeric-items-per-column)
  3714. ))
  3715. ;; html specific stuff starts here
  3716. ;; (org-e-html-end-table)
  3717. "</table>\n")
  3718. (defun org-e-html-format-table-cell (text r c horiz-span)
  3719. (let ((cell-style-cookie
  3720. (if org-export-e-html-table-align-individual-fields
  3721. (format (if (and (boundp 'org-e-html-format-table-no-css)
  3722. org-e-html-format-table-no-css)
  3723. " align=\"%s\"" " class=\"%s\"")
  3724. (or (aref (plist-get table-info :alignment) c) "left")) ""))) ;; FIXME
  3725. (cond
  3726. (org-lparse-table-cur-rowgrp-is-hdr
  3727. (concat
  3728. (format (car org-export-table-header-tags) "col" cell-style-cookie)
  3729. text (cdr org-export-table-header-tags)))
  3730. ((and (= c 0) org-export-e-html-table-use-header-tags-for-first-column)
  3731. (concat
  3732. (format (car org-export-table-header-tags) "row" cell-style-cookie)
  3733. text (cdr org-export-table-header-tags)))
  3734. (t
  3735. (concat
  3736. (format (car org-export-table-data-tags) cell-style-cookie)
  3737. text (cdr org-export-table-data-tags))))))
  3738. (defun org-e-html-format-table-row (row)
  3739. (concat (eval (car org-export-table-row-tags)) row
  3740. (eval (cdr org-export-table-row-tags))))
  3741. (defun org-e-html-table-row (fields &optional text-for-empty-fields)
  3742. (if org-lparse-table-ncols
  3743. ;; second and subsequent rows of the table
  3744. ;; (when (and org-lparse-list-table-p
  3745. ;; (> (length fields) org-lparse-table-ncols))
  3746. ;; (error "Table row has %d columns but header row claims %d columns"
  3747. ;; (length fields) org-lparse-table-ncols))
  3748. ;; first row of the table
  3749. (setq org-lparse-table-ncols (length fields))
  3750. ;; (when org-lparse-table-is-styled
  3751. ;; (setq org-lparse-table-num-numeric-items-per-column
  3752. ;; (make-vector org-lparse-table-ncols 0)))
  3753. )
  3754. (incf org-lparse-table-rownum)
  3755. (let ((i -1))
  3756. (org-e-html-format-table-row
  3757. (mapconcat
  3758. (lambda (x)
  3759. (when (and (string= x "") text-for-empty-fields)
  3760. (setq x text-for-empty-fields))
  3761. (incf i)
  3762. (let (col-cookie horiz-span)
  3763. (when org-lparse-table-is-styled
  3764. ;; (when (and (< i org-lparse-table-ncols)
  3765. ;; (string-match org-table-number-regexp x))
  3766. ;; (incf (aref org-lparse-table-num-numeric-items-per-column i)))
  3767. (setq col-cookie (cdr (assoc (1+ i) org-lparse-table-colalign-info))
  3768. horiz-span (nth 1 col-cookie)))
  3769. (org-e-html-format-table-cell
  3770. x org-lparse-table-rownum i (or horiz-span 0))))
  3771. fields "\n"))))
  3772. (defun org-e-html-end-table-rowgroup ()
  3773. (when org-lparse-table-rowgrp-open
  3774. (setq org-lparse-table-rowgrp-open nil)
  3775. (if org-lparse-table-cur-rowgrp-is-hdr "</thead>" "</tbody>")))
  3776. (defun org-e-html-begin-table-rowgroup (&optional is-header-row)
  3777. (concat
  3778. (when org-lparse-table-rowgrp-open
  3779. (org-e-html-end-table-rowgroup))
  3780. (progn
  3781. (setq org-lparse-table-rowgrp-open t)
  3782. (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row)
  3783. (if is-header-row "<thead>" "<tbody>"))))
  3784. (defun org-e-html-table-preamble ()
  3785. (let ((colgroup-vector (plist-get table-info :column-groups)) ;; FIXME
  3786. c gr colgropen preamble)
  3787. (unless (aref colgroup-vector 0)
  3788. (setf (aref colgroup-vector 0) 'start))
  3789. (dotimes (c columns-number preamble)
  3790. (setq gr (aref colgroup-vector c))
  3791. (setq preamble
  3792. (concat
  3793. preamble
  3794. (when (memq gr '(start start-end))
  3795. (prog1 (if colgropen "</colgroup>\n<colgroup>" "\n<colgroup>")
  3796. (setq colgropen t)))
  3797. (let* ((colalign-vector (plist-get table-info :alignment)) ;; FIXME
  3798. (align (cdr (assoc (aref colalign-vector c)
  3799. '(("l" . "left")
  3800. ("r" . "right")
  3801. ("c" . "center")))))
  3802. (alignspec (if (and (boundp 'org-e-html-format-table-no-css)
  3803. org-e-html-format-table-no-css)
  3804. " align=\"%s\"" " class=\"%s\""))
  3805. (extra (format alignspec align)))
  3806. (format "<col%s />" extra))
  3807. (when (memq gr '(end start-end))
  3808. (setq colgropen nil)
  3809. "</colgroup>"))))
  3810. (concat preamble (if colgropen "</colgroup>"))))
  3811. (defun org-e-html-list-table (lines &optional splice
  3812. caption label attributes head
  3813. org-lparse-table-colalign-info)
  3814. (or (featurep 'org-table) ; required for
  3815. (require 'org-table)) ; `org-table-number-regexp'
  3816. (let* ((org-lparse-table-rownum -1)
  3817. (org-lparse-table-ncols (length (plist-get info :alignment)))
  3818. i (cnt 0)
  3819. tbopen fields line
  3820. org-lparse-table-cur-rowgrp-is-hdr
  3821. org-lparse-table-rowgrp-open
  3822. ;; org-lparse-table-num-numeric-items-per-column
  3823. org-lparse-table-colalign-vector n
  3824. org-lparse-table-rowgrp-info
  3825. (org-lparse-table-style 'org-table)
  3826. org-lparse-table-is-styled)
  3827. (cond
  3828. (splice
  3829. (setq org-lparse-table-is-styled nil)
  3830. (mapconcat 'org-e-html-table-row lines "\n"))
  3831. (t
  3832. (setq org-lparse-table-is-styled t)
  3833. (concat
  3834. (org-e-html-begin-table caption label attributes)
  3835. (org-e-html-table-preamble)
  3836. (progn (push (cons (1+ org-lparse-table-rownum) :start)
  3837. org-lparse-table-rowgrp-info)
  3838. (org-e-html-begin-table-rowgroup head))
  3839. (mapconcat
  3840. (lambda (line)
  3841. (cond
  3842. ((equal line :hrule)
  3843. (push (cons (1+ org-lparse-table-rownum) :start)
  3844. org-lparse-table-rowgrp-info)
  3845. (org-e-html-begin-table-rowgroup))
  3846. (t
  3847. (org-e-html-table-row line))))
  3848. lines "\n")
  3849. (org-e-html-end-table-rowgroup)
  3850. (org-e-html-end-table))))))
  3851. (defun org-e-html-org-table-to-list-table (lines &optional splice)
  3852. "Convert org-table to list-table.
  3853. LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
  3854. element is a `string' representing a single row of org-table.
  3855. Thus each ROW has vertical separators \"|\" separating the table
  3856. fields. A ROW could also be a row-group separator of the form
  3857. \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
  3858. ...). ROW could either be symbol `:hrule' or a list of the
  3859. form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
  3860. (let (line lines-1)
  3861. (cond
  3862. (splice
  3863. (while (setq line (pop lines))
  3864. (unless (string-match "^[ \t]*|-" line)
  3865. (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))
  3866. (t
  3867. (while (setq line (pop lines))
  3868. (cond
  3869. ((string-match "^[ \t]*|-" line)
  3870. (when lines
  3871. (push :hrule lines-1)))
  3872. (t
  3873. (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))))
  3874. (nreverse lines-1)))
  3875. (defun org-e-html-table (table contents info)
  3876. "Transcode a TABLE element from Org to HTML.
  3877. CONTENTS is nil. INFO is a plist holding contextual information."
  3878. (let* (
  3879. ;; FIXME
  3880. ;; see `org-e-html-table--format-string'
  3881. (label (org-element-get-property :name table))
  3882. (caption (org-e-html--caption/label-string
  3883. (org-element-get-property :caption table) label info))
  3884. ;; FIXME
  3885. (attr (mapconcat #'identity
  3886. (org-element-get-property :attr_html table)
  3887. " "))
  3888. (raw-table (org-element-get-property :raw-table table)))
  3889. (cond
  3890. ;; Case 1: verbatim table.
  3891. ((or org-e-html-tables-verbatim
  3892. (and attr (string-match "\\<verbatim\\>" attr)))
  3893. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  3894. (org-export-clean-table
  3895. raw-table
  3896. (plist-get (org-export-table-format-info raw-table)
  3897. :special-column-p))))
  3898. ;; Case 2: table.el table. Convert it using appropriate tools.
  3899. ((eq (org-element-get-property :type table) 'table.el)
  3900. (require 'table)
  3901. ;; Ensure "*org-export-table*" buffer is empty.
  3902. (with-current-buffer (get-buffer-create "*org-export-table*")
  3903. (erase-buffer))
  3904. (let ((output (with-temp-buffer
  3905. (insert raw-table)
  3906. (goto-char 1)
  3907. (re-search-forward "^[ \t]*|[^|]" nil t)
  3908. (table-generate-source 'html "*org-export-table*")
  3909. (with-current-buffer "*org-export-table*"
  3910. (org-trim (buffer-string))))))
  3911. (kill-buffer (get-buffer "*org-export-table*"))
  3912. ;; Remove left out comments.
  3913. (while (string-match "^%.*\n" output)
  3914. (setq output (replace-match "" t t output)))
  3915. ;; When the "rmlines" attribute is provided, remove all hlines
  3916. ;; but the the one separating heading from the table body.
  3917. (when (and attr (string-match "\\<rmlines\\>" attr))
  3918. (let ((n 0) (pos 0))
  3919. (while (and (< (length output) pos)
  3920. (setq pos (string-match "^\\\\hline\n?" output pos)))
  3921. (incf n)
  3922. (unless (= n 2)
  3923. (setq output (replace-match "" nil nil output))))))
  3924. ;; (if (not org-e-html-tables-centered) output
  3925. ;; (format "\\begin{center}\n%s\n\\end{center}" output))
  3926. output))
  3927. ;; Case 3: Standard table.
  3928. (t
  3929. (let* ((table-info (org-export-table-format-info raw-table))
  3930. (columns-number (length (plist-get table-info :alignment)))
  3931. (longtablep (and attr (string-match "\\<longtable\\>" attr)))
  3932. (booktabsp
  3933. (or (and attr (string-match "\\<booktabs=\\(yes\\|t\\)\\>" attr))
  3934. org-e-html-tables-booktabs))
  3935. ;; CLEAN-TABLE is a table turned into a list, much like
  3936. ;; `org-table-to-lisp', with special column and
  3937. ;; formatting cookies removed, and cells already
  3938. ;; transcoded.
  3939. (lines (org-split-string
  3940. (org-export-clean-table
  3941. raw-table (plist-get table-info :special-column-p)) "\n"))
  3942. ;; (clean-table
  3943. ;; (mapcar
  3944. ;; (lambda (row)
  3945. ;; (if (string-match org-table-hline-regexp row) 'hline
  3946. ;; (mapcar
  3947. ;; (lambda (cell)
  3948. ;; (org-export-secondary-string
  3949. ;; (org-element-parse-secondary-string
  3950. ;; cell
  3951. ;; (cdr (assq 'table org-element-string-restrictions)))
  3952. ;; 'e-html info))
  3953. ;; (org-split-string row "[ \t]*|[ \t]*"))))
  3954. ;; lines))
  3955. )
  3956. (let ((splice nil) head)
  3957. (setq lines (org-e-html-org-table-to-list-table lines splice))
  3958. (org-e-html-list-table lines splice caption label attr head nil))
  3959. ;; If BOOKTABSP is non-nil, remove any rule at the beginning
  3960. ;; and the end of the table, since booktabs' special rules
  3961. ;; will be inserted instead.
  3962. ;; (when booktabsp
  3963. ;; (when (eq (car clean-table) 'hline)
  3964. ;; (setq clean-table (cdr clean-table)))
  3965. ;; (when (eq (car (last clean-table)) 'hline)
  3966. ;; (setq clean-table (butlast clean-table))))
  3967. ;; Convert ROWS to send them to `orgtbl-to-latex'. In
  3968. ;; particular, send each cell to
  3969. ;; `org-element-parse-secondary-string' to expand any Org
  3970. ;; object within. Eventually, flesh the format string out
  3971. ;; with the table.
  3972. ;; (format
  3973. ;; (org-e-html-table--format-string table table-info info)
  3974. ;; (orgtbl-to-latex
  3975. ;; clean-table
  3976. ;; ;; Parameters passed to `orgtbl-to-latex'.
  3977. ;; `(:tstart ,(and booktabsp "\\toprule")
  3978. ;; :tend ,(and booktabsp "\\bottomrule")
  3979. ;; :hline ,(if booktabsp "\\midrule" "\\hline")
  3980. ;; ;; Longtable environment requires specific header
  3981. ;; ;; lines end string.
  3982. ;; :hlend ,(and longtablep
  3983. ;; (format "\\\\
  3984. ;; %s
  3985. ;; \\endhead
  3986. ;; %s\\multicolumn{%d}{r}{Continued on next page}\\\\
  3987. ;; \\endfoot
  3988. ;; \\endlastfoot"
  3989. ;; (if booktabsp "\\midrule" "\\hline")
  3990. ;; (if booktabsp "\\midrule" "\\hline")
  3991. ;; columns-number)))))
  3992. )))))
  3993. ;;;; Target
  3994. (defun org-e-html-target (target text info)
  3995. "Transcode a TARGET object from Org to HTML.
  3996. TEXT is the text of the target. INFO is a plist holding
  3997. contextual information."
  3998. ;; (format "\\label{%s}%s"
  3999. ;; (org-export-solidify-link-text
  4000. ;; (org-element-get-property :raw-value target))
  4001. ;; text)
  4002. (org-e-html-format-anchor
  4003. text (org-export-solidify-link-text
  4004. (org-element-get-property :raw-value target))))
  4005. ;;;; Time-stamp
  4006. (defun org-e-html-time-stamp (time-stamp contents info)
  4007. "Transcode a TIME-STAMP object from Org to HTML.
  4008. CONTENTS is nil. INFO is a plist holding contextual
  4009. information."
  4010. ;; (let ((value (org-element-get-property :value time-stamp))
  4011. ;; (type (org-element-get-property :type time-stamp))
  4012. ;; (appt-type (org-element-get-property :appt-type time-stamp)))
  4013. ;; (concat (cond ((eq appt-type 'scheduled)
  4014. ;; (format "\\textbf{\\textsc{%s}} " org-scheduled-string))
  4015. ;; ((eq appt-type 'deadline)
  4016. ;; (format "\\textbf{\\textsc{%s}} " org-deadline-string))
  4017. ;; ((eq appt-type 'closed)
  4018. ;; (format "\\textbf{\\textsc{%s}} " org-closed-string)))
  4019. ;; (cond ((memq type '(active active-range))
  4020. ;; (format org-e-html-active-timestamp-format value))
  4021. ;; ((memq type '(inactive inactive-range))
  4022. ;; (format org-e-html-inactive-timestamp-format value))
  4023. ;; (t
  4024. ;; (format org-e-html-diary-timestamp-format value)))))
  4025. (let ((value (org-element-get-property :value time-stamp))
  4026. (type (org-element-get-property :type time-stamp))
  4027. (appt-type (org-element-get-property :appt-type time-stamp)))
  4028. (org-e-html-format-fontify
  4029. (concat
  4030. (org-e-html-format-fontify
  4031. (cond ((eq appt-type 'scheduled) org-scheduled-string)
  4032. ((eq appt-type 'deadline) org-deadline-string)
  4033. ((eq appt-type 'closed) org-closed-string)) "timestamp-kwd")
  4034. ;; FIXME: (org-translate-time value)
  4035. (org-e-html-format-fontify value "timestamp"))
  4036. "timestamp-wrapper")))
  4037. ;;;; Verbatim
  4038. (defun org-e-html-verbatim (verbatim contents info)
  4039. "Transcode a VERBATIM object from Org to HTML.
  4040. CONTENTS is nil. INFO is a plist used as a communication
  4041. channel."
  4042. (org-e-html-emphasis
  4043. verbatim (org-element-get-property :value verbatim) info)
  4044. ;; (let ((fmt (cdr (assoc (org-element-get-property :marker verbatim)
  4045. ;; org-e-html-emphasis-alist)))
  4046. ;; (value (org-element-get-property :value verbatim)))
  4047. ;; (cond
  4048. ;; ;; Handle the `verb' special case.
  4049. ;; ((eq 'verb fmt)
  4050. ;; (let ((separator (org-e-html--find-verb-separator value)))
  4051. ;; (concat "\\verb" separator value separator)))
  4052. ;; ;; Handle the `protectedtexttt' special case.
  4053. ;; ((eq 'protectedtexttt fmt)
  4054. ;; (let ((start 0)
  4055. ;; (trans '(("\\" . "\\textbackslash{}")
  4056. ;; ("~" . "\\textasciitilde{}")
  4057. ;; ("^" . "\\textasciicircum{}")))
  4058. ;; (rtn "")
  4059. ;; char)
  4060. ;; (while (string-match "[\\{}$%&_#~^]" value)
  4061. ;; (setq char (match-string 0 value))
  4062. ;; (if (> (match-beginning 0) 0)
  4063. ;; (setq rtn (concat rtn (substring value 0 (match-beginning 0)))))
  4064. ;; (setq value (substring value (1+ (match-beginning 0))))
  4065. ;; (setq char (or (cdr (assoc char trans)) (concat "\\" char))
  4066. ;; rtn (concat rtn char)))
  4067. ;; (setq value (concat rtn value)
  4068. ;; fmt "\\texttt{%s}")
  4069. ;; (while (string-match "--" value)
  4070. ;; (setq value (replace-match "-{}-" t t value)))
  4071. ;; (format fmt value)))
  4072. ;; ;; Else use format string.
  4073. ;; (t (format fmt value))))
  4074. )
  4075. ;;;; Verse Block
  4076. (defun org-e-html-verse-block (verse-block contents info)
  4077. "Transcode a VERSE-BLOCK element from Org to HTML.
  4078. CONTENTS is nil. INFO is a plist holding contextual information."
  4079. (org-e-html--wrap-label
  4080. verse-block
  4081. ;; In a verse environment, add a line break to each newline
  4082. ;; character and change each white space at beginning of a line
  4083. ;; into a space of 1 em. Also change each blank line with
  4084. ;; a vertical space of 1 em.
  4085. (progn
  4086. (setq contents (replace-regexp-in-string
  4087. "^ *\\\\\\\\$" "\\\\vspace*{1em}"
  4088. (replace-regexp-in-string
  4089. "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
  4090. (org-remove-indentation
  4091. (org-export-secondary-string
  4092. (org-element-get-property :value verse-block)
  4093. 'e-html info)))))
  4094. (while (string-match "^[ \t]+" contents)
  4095. (let ((new-str (format "\\hspace*{%dem}"
  4096. (length (match-string 0 contents)))))
  4097. (setq contents (replace-match new-str nil t contents))))
  4098. (format "\\begin{verse}\n%s\\end{verse}" contents)))
  4099. (org-e-html--wrap-label
  4100. verse-block
  4101. ;; In a verse environment, add a line break to each newline
  4102. ;; character and change each white space at beginning of a line
  4103. ;; into a space of 1 em. Also change each blank line with
  4104. ;; a vertical space of 1 em.
  4105. (progn
  4106. (setq contents (replace-regexp-in-string
  4107. "^ *\\\\\\\\$" "<br/>\n"
  4108. (replace-regexp-in-string
  4109. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
  4110. (org-remove-indentation
  4111. (org-export-secondary-string
  4112. (org-element-get-property :value verse-block)
  4113. 'e-html info)))))
  4114. (while (string-match "^[ \t]+" contents)
  4115. (let ((new-str (format "&nbsp;"
  4116. (length (match-string 0 contents)))))
  4117. (setq contents (replace-match new-str nil t contents))))
  4118. (format "<p class=\"verse\">\n%s</p>" contents)))
  4119. )
  4120. ;;; Interactive functions
  4121. (setq org-e-html-pp t)
  4122. (defun org-e-html-export-to-html
  4123. (&optional subtreep visible-only body-only ext-plist pub-dir)
  4124. "Export current buffer to a HTML file.
  4125. If narrowing is active in the current buffer, only export its
  4126. narrowed part.
  4127. If a region is active, export that region.
  4128. When optional argument SUBTREEP is non-nil, export the sub-tree
  4129. at point, extracting information from the headline properties
  4130. first.
  4131. When optional argument VISIBLE-ONLY is non-nil, don't export
  4132. contents of hidden elements.
  4133. When optional argument BODY-ONLY is non-nil, only write code
  4134. between \"\\begin{document}\" and \"\\end{document}\".
  4135. EXT-PLIST, when provided, is a property list with external
  4136. parameters overriding Org default settings, but still inferior to
  4137. file-local settings.
  4138. When optional argument PUB-DIR is set, use it as the publishing
  4139. directory.
  4140. Return output file's name."
  4141. (interactive)
  4142. (setq org-e-html-footnotes-alist nil)
  4143. ;; FIXME
  4144. (with-current-buffer (get-buffer-create "*debug*")
  4145. (erase-buffer))
  4146. (let ((outfile (org-export-output-file-name ".html" subtreep pub-dir)))
  4147. (org-export-to-file
  4148. 'e-html outfile subtreep visible-only body-only ext-plist)))
  4149. (defun org-e-html-export-to-pdf
  4150. (&optional subtreep visible-only body-only ext-plist pub-dir)
  4151. "Export current buffer to HTML then process through to PDF.
  4152. If narrowing is active in the current buffer, only export its
  4153. narrowed part.
  4154. If a region is active, export that region.
  4155. When optional argument SUBTREEP is non-nil, export the sub-tree
  4156. at point, extracting information from the headline properties
  4157. first.
  4158. When optional argument VISIBLE-ONLY is non-nil, don't export
  4159. contents of hidden elements.
  4160. When optional argument BODY-ONLY is non-nil, only write code
  4161. between \"\\begin{document}\" and \"\\end{document}\".
  4162. EXT-PLIST, when provided, is a property list with external
  4163. parameters overriding Org default settings, but still inferior to
  4164. file-local settings.
  4165. When optional argument PUB-DIR is set, use it as the publishing
  4166. directory.
  4167. Return PDF file's name."
  4168. (interactive)
  4169. (org-e-html-compile
  4170. (org-e-html-export-to-html
  4171. subtreep visible-only body-only ext-plist pub-dir)))
  4172. (defun org-e-html-compile (texfile)
  4173. "Compile a TeX file.
  4174. TEXFILE is the name of the file being compiled. Processing is
  4175. done through the command specified in `org-e-html-pdf-process'.
  4176. Return PDF file name or an error if it couldn't be produced."
  4177. (let* ((wconfig (current-window-configuration))
  4178. (texfile (file-truename texfile))
  4179. (base (file-name-sans-extension texfile))
  4180. errors)
  4181. (message (format "Processing HTML file %s ..." texfile))
  4182. (unwind-protect
  4183. (progn
  4184. (cond
  4185. ;; A function is provided: Apply it.
  4186. ((functionp org-latex-to-pdf-process)
  4187. (funcall org-latex-to-pdf-process (shell-quote-argument texfile)))
  4188. ;; A list is provided: Replace %b, %f and %o with appropriate
  4189. ;; values in each command before applying it. Output is
  4190. ;; redirected to "*Org PDF HTML Output*" buffer.
  4191. ((consp org-e-html-pdf-process)
  4192. (let* ((out-dir (or (file-name-directory texfile) "./"))
  4193. (outbuf (get-buffer-create "*Org PDF HTML Output*")))
  4194. (mapc
  4195. (lambda (command)
  4196. (shell-command
  4197. (replace-regexp-in-string
  4198. "%b" (shell-quote-argument base)
  4199. (replace-regexp-in-string
  4200. "%f" (shell-quote-argument texfile)
  4201. (replace-regexp-in-string
  4202. "%o" (shell-quote-argument out-dir) command)))
  4203. outbuf))
  4204. org-e-html-pdf-process)
  4205. ;; Collect standard errors from output buffer.
  4206. (setq errors (org-e-html-collect-errors outbuf))))
  4207. (t (error "No valid command to process to PDF")))
  4208. (let ((pdffile (concat base ".pdf")))
  4209. ;; Check for process failure. Provide collected errors if
  4210. ;; possible.
  4211. (if (not (file-exists-p pdffile))
  4212. (error (concat (format "PDF file %s wasn't produced" pdffile)
  4213. (when errors (concat ": " errors))))
  4214. ;; Else remove log files, when specified, and signal end of
  4215. ;; process to user, along with any error encountered.
  4216. (when org-e-html-remove-logfiles
  4217. (dolist (ext org-e-html-logfiles-extensions)
  4218. (let ((file (concat base "." ext)))
  4219. (when (file-exists-p file) (delete-file file)))))
  4220. (message (concat "Process completed"
  4221. (if (not errors) "."
  4222. (concat " with errors: " errors)))))
  4223. ;; Return output file name.
  4224. pdffile))
  4225. (set-window-configuration wconfig))))
  4226. (defun org-e-html-collect-errors (buffer)
  4227. "Collect some kind of errors from \"pdflatex\" command output.
  4228. BUFFER is the buffer containing output.
  4229. Return collected error types as a string, or nil if there was
  4230. none."
  4231. (with-current-buffer buffer
  4232. (save-excursion
  4233. (goto-char (point-max))
  4234. ;; Find final "pdflatex" run.
  4235. (when (re-search-backward "^[ \t]*This is pdf.*?TeX.*?Version" nil t)
  4236. (let ((case-fold-search t)
  4237. (errors ""))
  4238. (when (save-excursion
  4239. (re-search-forward "Reference.*?undefined" nil t))
  4240. (setq errors (concat errors " [undefined reference]")))
  4241. (when (save-excursion
  4242. (re-search-forward "Citation.*?undefined" nil t))
  4243. (setq errors (concat errors " [undefined citation]")))
  4244. (when (save-excursion
  4245. (re-search-forward "Undefined control sequence" nil t))
  4246. (setq errors (concat errors " [undefined control sequence]")))
  4247. (when (save-excursion
  4248. (re-search-forward "^! HTML.*?Error" nil t))
  4249. (setq errors (concat errors " [HTML error]")))
  4250. (when (save-excursion
  4251. (re-search-forward "^! Package.*?Error" nil t))
  4252. (setq errors (concat errors " [package error]")))
  4253. (and (org-string-nw-p errors) (org-trim errors)))))))
  4254. (provide 'org-e-html)
  4255. ;;; org-e-html.el ends here