org-e-html.el 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878
  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 t)
  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-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-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-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-e-html-footnote-separator "<sup>, </sup>"
  90. "Text used to separate footnotes."
  91. :group 'org-export-e-html
  92. :type 'string)
  93. (defcustom org-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-e-html-extension "html"
  98. "The extension for exported HTML files."
  99. :group 'org-export-e-html
  100. :type 'string)
  101. (defcustom org-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-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-e-html-scripts' and should
  117. not be modified."
  118. :group 'org-export-e-html
  119. :type 'boolean)
  120. (defconst org-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-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-e-html-style' and
  196. `org-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-e-html-style-include-default'.")
  199. (defcustom org-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-e-html-style-default' and should
  202. not be modified. Use the variables `org-e-html-style' to add
  203. your own style information."
  204. :group 'org-export-e-html
  205. :type 'boolean)
  206. ;;;###autoload
  207. (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
  208. (defcustom org-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-e-html-style-extra'."
  229. :group 'org-export-e-html
  230. :type 'string)
  231. ;;;###autoload
  232. (put 'org-e-html-style 'safe-local-variable 'stringp)
  233. (defcustom org-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-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-e-html-style-extra 'safe-local-variable 'stringp)
  243. (defcustom org-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-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-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-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-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-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-e-html-preamble-format'. When set to a
  362. string, this string overrides `org-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-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-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-e-html-postamble-format'. When set to a string, this
  387. string overrides `org-e-html-postamble-format'. When set to
  388. 'auto, discard `org-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-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-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-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-e-html-link-up' and
  426. `org-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-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-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-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-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-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-e-html-table-use-header-tags-for-first-column'.
  479. See also the variable `org-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-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-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-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-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-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-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-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-e-html-divs' instead.
  588. (defvar org-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-e-html-divs' instead.")
  592. (defcustom org-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-e-html-after-blockquotes-hook nil
  604. "Hook run during HTML export, after blockquote, verse, center are done.")
  605. (defvar org-e-html-final-hook nil
  606. "Hook run at the end of HTML export, in the new buffer.")
  607. (defun org-e-html-preprocess-label-references ()
  608. (goto-char (point-min))
  609. (let (label l1)
  610. (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
  611. (org-if-unprotected-at (match-beginning 1)
  612. (setq label (match-string 1))
  613. (save-match-data
  614. (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  615. (setq l1 (substring label (match-beginning 1)))
  616. (setq l1 label)))
  617. (replace-match (format "[[#%s][%s]]" label l1) t t)))))
  618. (defun org-e-html-preprocess (parameters)
  619. (org-e-html-preprocess-label-references))
  620. (defvar html-table-tag nil) ; dynamically scoped into this.
  621. ;; FIXME: it already exists in org-e-html.el
  622. (defconst org-e-html-cvt-link-fn
  623. nil
  624. "Function to convert link URLs to exportable URLs.
  625. Takes two arguments, TYPE and PATH.
  626. Returns exportable url as (TYPE PATH), or nil to signal that it
  627. didn't handle this case.
  628. Intended to be locally bound around a call to `org-export-as-html'." )
  629. ;; FIXME: it already exists in org-e-html.el
  630. (defun org-e-html-cvt-org-as-html (opt-plist type path)
  631. "Convert an org filename to an equivalent html filename.
  632. If TYPE is not file, just return `nil'.
  633. See variable `org-e-html-link-org-files-as-html'"
  634. (save-match-data
  635. (and
  636. org-e-html-link-org-files-as-html
  637. (string= type "file")
  638. (string-match "\\.org$" path)
  639. (progn
  640. (list
  641. "file"
  642. (concat
  643. (substring path 0 (match-beginning 0))
  644. "."
  645. (plist-get opt-plist :html-extension)))))))
  646. (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
  647. descp)
  648. "Make an HTML link.
  649. OPT-PLIST is an options list.
  650. TYPE is the device-type of the link (THIS://foo.html).
  651. PATH is the path of the link (http://THIS#location).
  652. FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
  653. DESC is the link description, if any.
  654. ATTR is a string of other attributes of the \"a\" element."
  655. (declare (special org-lparse-par-open))
  656. (save-match-data
  657. (when (string= type-1 "coderef")
  658. (let ((ref fragment))
  659. (setq desc (format (org-export-get-coderef-format ref (and descp desc))
  660. (cdr (assoc ref org-export-code-refs)))
  661. fragment (concat "coderef-" ref)
  662. attr (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  663. fragment fragment))))
  664. (let* ((may-inline-p
  665. (and (member type-1 '("http" "https" "file"))
  666. (org-lparse-should-inline-p path descp)
  667. (not fragment)))
  668. (type (if (equal type-1 "id") "file" type-1))
  669. (filename path)
  670. ;;First pass. Just sanity stuff.
  671. (components-1
  672. (cond
  673. ((string= type "file")
  674. (list
  675. type
  676. ;;Substitute just if original path was absolute.
  677. ;;(Otherwise path must remain relative)
  678. (if (file-name-absolute-p path)
  679. (concat "file://" (expand-file-name path))
  680. path)))
  681. ((string= type "")
  682. (list nil path))
  683. (t (list type path))))
  684. ;;Second pass. Components converted so they can refer
  685. ;;to a remote site.
  686. (components-2
  687. (or
  688. (and org-e-html-cvt-link-fn
  689. (apply org-e-html-cvt-link-fn
  690. opt-plist components-1))
  691. (apply #'org-e-html-cvt-org-as-html
  692. opt-plist components-1)
  693. components-1))
  694. (type (first components-2))
  695. (thefile (second components-2)))
  696. ;;Third pass. Build final link except for leading type
  697. ;;spec.
  698. (cond
  699. ((or
  700. (not type)
  701. (string= type "http")
  702. (string= type "https")
  703. (string= type "file")
  704. (string= type "coderef"))
  705. (if fragment
  706. (setq thefile (concat thefile "#" fragment))))
  707. (t))
  708. ;;Final URL-build, for all types.
  709. (setq thefile
  710. (let
  711. ((str (org-xml-format-href thefile)))
  712. (if (and type (not (or (string= "file" type)
  713. (string= "coderef" type))))
  714. (concat type ":" str)
  715. str)))
  716. (if may-inline-p
  717. (org-e-html-format-image thefile)
  718. (org-lparse-format
  719. 'LINK (org-xml-format-desc desc) thefile attr)))))
  720. (defun org-e-html-format-inline-image (path &optional caption label attr)
  721. ;; FIXME: alt text missing here?
  722. (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
  723. path (file-name-nondirectory path))))
  724. (if (not label) inline-image
  725. (org-e-html-format-section inline-image "figure" label))))
  726. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  727. (defvar org-lparse-link-description-is-image)
  728. (defun org-e-html-format-image (src)
  729. "Create image tag with source and attributes."
  730. (save-match-data
  731. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  732. (attr (org-find-text-property-in-string 'org-attributes src))
  733. (label (org-find-text-property-in-string 'org-label src))
  734. (caption (and caption (org-xml-encode-org-text caption)))
  735. (img-extras (if (string-match "^ltxpng/" src)
  736. (format " alt=\"%s\""
  737. (org-find-text-property-in-string
  738. 'org-latex-src src))
  739. (if (string-match "\\<alt=" (or attr ""))
  740. (concat " " attr )
  741. (concat " " attr " alt=\"" src "\""))))
  742. (img (format "<img src=\"%s\"%s />" src img-extras))
  743. (extra (concat
  744. (and label
  745. (format "id=\"%s\" " (org-solidify-link-text label)))
  746. "class=\"figure\"")))
  747. (if caption
  748. (with-temp-buffer
  749. (with-org-lparse-preserve-paragraph-state
  750. (insert
  751. (org-lparse-format
  752. '("<div %s>" . "\n</div>")
  753. (concat
  754. (org-lparse-format '("\n<p>" . "</p>") img)
  755. (org-lparse-format '("\n<p>" . "</p>") caption))
  756. extra)))
  757. (buffer-string))
  758. img))))
  759. (defun org-e-html-bibliography ()
  760. "Find bibliography, cut it out and return it."
  761. (catch 'exit
  762. (let (beg end (cnt 1) bib)
  763. (save-excursion
  764. (goto-char (point-min))
  765. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  766. (setq beg (match-beginning 0))
  767. (while (re-search-forward "</?div\\>" nil t)
  768. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  769. (when (= cnt 0)
  770. (and (looking-at ">") (forward-char 1))
  771. (setq bib (buffer-substring beg (point)))
  772. (delete-region beg (point))
  773. (throw 'exit bib))))
  774. nil))))
  775. (defun org-e-html-format-table (lines olines)
  776. (let ((org-e-html-format-table-no-css nil))
  777. (org-lparse-format-table lines olines)))
  778. ;; Following variable is defined for native tables i.e., when
  779. ;; `org-lparse-table-is-styled' evals to t.
  780. (defvar org-e-html-format-table-no-css)
  781. (defvar org-table-number-regexp) ; defined in org-table.el
  782. (defun org-format-table-html (lines olines &optional no-css)
  783. "Find out which HTML converter to use and return the HTML code.
  784. NO-CSS is passed to the exporter."
  785. (error "FIXME"))
  786. (defun org-format-org-table-html (lines &optional splice no-css)
  787. (error "FIXME"))
  788. (defun org-export-splice-attributes (tag attributes)
  789. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  790. (if (not attributes)
  791. tag
  792. (let (oldatt newatt)
  793. (setq oldatt (org-extract-attributes-from-string tag)
  794. tag (pop oldatt)
  795. newatt (cdr (org-extract-attributes-from-string attributes)))
  796. (while newatt
  797. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  798. (if (string-match ">" tag)
  799. (setq tag
  800. (replace-match (concat (org-attributes-to-string oldatt) ">")
  801. t t tag)))
  802. tag)))
  803. (defun org-format-table-table-html (lines)
  804. (error "FIXME"))
  805. (defun org-export-splice-style (style extra)
  806. "Splice EXTRA into STYLE, just before \"</style>\"."
  807. (if (and (stringp extra)
  808. (string-match "\\S-" extra)
  809. (string-match "</style>" style))
  810. (concat (substring style 0 (match-beginning 0))
  811. "\n" extra "\n"
  812. (substring style (match-beginning 0)))
  813. style))
  814. (defvar htmlize-buffer-places) ; from htmlize.el
  815. (defun org-export-e-htmlize-region-for-paste (beg end)
  816. "Convert the region to HTML, using htmlize.el.
  817. This is much like `htmlize-region-for-paste', only that it uses
  818. the settings define in the org-... variables."
  819. (let* ((htmlize-output-type org-export-e-htmlize-output-type)
  820. (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
  821. (htmlbuf (htmlize-region beg end)))
  822. (unwind-protect
  823. (with-current-buffer htmlbuf
  824. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  825. (plist-get htmlize-buffer-places 'content-end)))
  826. (kill-buffer htmlbuf))))
  827. ;;;###autoload
  828. (defun org-export-e-htmlize-generate-css ()
  829. "Create the CSS for all font definitions in the current Emacs session.
  830. Use this to create face definitions in your CSS style file that can then
  831. be used by code snippets transformed by htmlize.
  832. This command just produces a buffer that contains class definitions for all
  833. faces used in the current Emacs session. You can copy and paste the ones you
  834. need into your CSS file.
  835. If you then set `org-export-e-htmlize-output-type' to `css', calls to
  836. the function `org-export-e-htmlize-region-for-paste' will produce code
  837. that uses these same face definitions."
  838. (interactive)
  839. (require 'htmlize)
  840. (and (get-buffer "*html*") (kill-buffer "*html*"))
  841. (with-temp-buffer
  842. (let ((fl (face-list))
  843. (htmlize-css-name-prefix "org-")
  844. (htmlize-output-type 'css)
  845. f i)
  846. (while (setq f (pop fl)
  847. i (and f (face-attribute f :inherit)))
  848. (when (and (symbolp f) (or (not i) (not (listp i))))
  849. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  850. (htmlize-region (point-min) (point-max))))
  851. (org-pop-to-buffer-same-window "*html*")
  852. (goto-char (point-min))
  853. (if (re-search-forward "<style" nil t)
  854. (delete-region (point-min) (match-beginning 0)))
  855. (if (re-search-forward "</style>" nil t)
  856. (delete-region (1+ (match-end 0)) (point-max)))
  857. (beginning-of-line 1)
  858. (if (looking-at " +") (replace-match ""))
  859. (goto-char (point-min)))
  860. (defvar body-only) ; dynamically scoped into this.
  861. ;; Following variable is let bound when `org-do-lparse' is in
  862. ;; progress. See org-lparse.el.
  863. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  864. (defvar org-lparse-toc)
  865. (defvar org-lparse-dyn-first-heading-pos)
  866. (defun org-e-html-end-export ()
  867. ;; insert the table of contents
  868. (when (and org-export-with-toc (not body-only) org-lparse-toc)
  869. (org-e-html-insert-toc org-lparse-toc))
  870. ;; Convert whitespace place holders
  871. (goto-char (point-min))
  872. (let (beg end n)
  873. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  874. (setq n (get-text-property beg 'org-whitespace)
  875. end (next-single-property-change beg 'org-whitespace))
  876. (goto-char beg)
  877. (delete-region beg end)
  878. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  879. (make-string n ?x)))))
  880. ;; Remove empty lines at the beginning of the file.
  881. (goto-char (point-min))
  882. (when (looking-at "\\s-+\n") (replace-match ""))
  883. ;; Remove display properties
  884. (remove-text-properties (point-min) (point-max) '(display t))
  885. ;; Run the hook
  886. (run-hooks 'org-e-html-final-hook))
  887. (defun org-e-html-format-toc-entry (snumber todo headline tags href)
  888. (setq headline (concat
  889. (and org-export-with-section-numbers
  890. (concat snumber " "))
  891. headline
  892. (and tags
  893. (concat
  894. (org-lparse-format 'SPACES 3)
  895. (org-lparse-format 'FONTIFY tags "tag")))))
  896. (when todo
  897. (setq headline (org-lparse-format 'FONTIFY headline "todo")))
  898. (org-lparse-format 'LINK headline (concat "#" href)))
  899. (defun org-e-html-format-toc-item (toc-entry level org-last-level)
  900. (when (> level org-last-level)
  901. (let ((cnt (- level org-last-level)))
  902. (while (>= (setq cnt (1- cnt)) 0)
  903. (org-lparse-begin-list 'unordered)
  904. (org-lparse-begin-list-item 'unordered))))
  905. (when (< level org-last-level)
  906. (let ((cnt (- org-last-level level)))
  907. (while (>= (setq cnt (1- cnt)) 0)
  908. (org-lparse-end-list-item-1)
  909. (org-lparse-end-list 'unordered))))
  910. (org-lparse-end-list-item-1)
  911. (org-lparse-begin-list-item 'unordered)
  912. (insert toc-entry))
  913. (defun org-e-html-begin-toc (lang-specific-heading max-level)
  914. (org-lparse-insert-tag "<div id=\"table-of-contents\">")
  915. (insert
  916. (org-lparse-format 'HEADING lang-specific-heading
  917. (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1)))
  918. (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
  919. (org-lparse-begin-list 'unordered)
  920. (org-lparse-begin-list-item 'unordered))
  921. (defun org-e-html-end-toc ()
  922. (while (> org-last-level (1- org-min-level))
  923. (setq org-last-level (1- org-last-level))
  924. (org-lparse-end-list-item-1)
  925. (org-lparse-end-list 'unordered))
  926. (org-lparse-insert-tag "</div>")
  927. (org-lparse-insert-tag "</div>")
  928. ;; cleanup empty list items in toc
  929. (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
  930. (replace-match "")))
  931. ;;;###autoload
  932. (defun org-export-as-html-and-open (arg)
  933. "Export the outline as HTML and immediately open it with a browser.
  934. If there is an active region, export only the region.
  935. The prefix ARG specifies how many levels of the outline should become
  936. headlines. The default is 3. Lower levels will become bulleted lists."
  937. (interactive "P")
  938. (error "FIXME"))
  939. ;;;###autoload
  940. (defun org-export-as-html-batch ()
  941. "Call the function `org-lparse-batch'.
  942. This function can be used in batch processing as:
  943. emacs --batch
  944. --load=$HOME/lib/emacs/org.el
  945. --eval \"(setq org-export-headline-levels 2)\"
  946. --visit=MyFile --funcall org-export-as-html-batch"
  947. (error "FIXME"))
  948. ;;;###autoload
  949. (defun org-export-as-html-to-buffer (arg)
  950. "Call `org-lparse-to-buffer` with output to a temporary buffer.
  951. No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
  952. (interactive "P")
  953. (error "FIXME"))
  954. ;;;###autoload
  955. (defun org-replace-region-by-html (beg end)
  956. "Assume the current region has org-mode syntax, and convert it to HTML.
  957. This can be used in any buffer. For example, you could write an
  958. itemized list in org-mode syntax in an HTML buffer and then use this
  959. command to convert it."
  960. (interactive "r")
  961. (error "FIXME"))
  962. ;;;###autoload
  963. (defun org-export-region-as-html (beg end &optional body-only buffer)
  964. "Convert region from BEG to END in `org-mode' buffer to HTML.
  965. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  966. contents, and only produce the region of converted text, useful for
  967. cut-and-paste operations.
  968. If BUFFER is a buffer or a string, use/create that buffer as a target
  969. of the converted HTML. If BUFFER is the symbol `string', return the
  970. produced HTML as a string and leave not buffer behind. For example,
  971. a Lisp program could call this function in the following way:
  972. (setq html (org-export-region-as-html beg end t 'string))
  973. When called interactively, the output buffer is selected, and shown
  974. in a window. A non-interactive call will only return the buffer."
  975. (interactive "r\nP")
  976. (error "FIXME"))
  977. ;;; org-export-as-html
  978. ;;;###autoload
  979. (defun org-export-as-html (arg &optional hidden ext-plist
  980. to-buffer body-only pub-dir)
  981. "Export the outline as a pretty HTML file.
  982. Use `org-lparse' internally to perform the actual export. This
  983. routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
  984. of `org-lparse' to \"html\"."
  985. (interactive "P")
  986. (error "FIXME"))
  987. (defun org-e-html-begin-outline (level1 snumber title tags
  988. target extra-targets extra-class)
  989. (let* ((class (format "outline-%d" level1))
  990. (class (if extra-class (concat class " " extra-class) class))
  991. (id (format "outline-container-%s"
  992. (org-lparse-suffix-from-snumber snumber)))
  993. (extra (concat (when id (format " id=\"%s\"" id))
  994. (when class (format " class=\"%s\"" class)))))
  995. (org-lparse-insert-tag "<div%s>" extra)
  996. (insert
  997. (org-lparse-format 'HEADING
  998. (org-lparse-format
  999. 'HEADLINE title extra-targets tags snumber level1)
  1000. level1 target))))
  1001. (defun org-e-html-end-outline ()
  1002. (org-lparse-insert-tag "</div>"))
  1003. ;; (defun org-e-html-format-heading (text level &optional id)
  1004. ;; (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
  1005. ;; (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
  1006. (defun org-e-html-suffix-from-snumber (snumber)
  1007. (let* ((snu (replace-regexp-in-string "\\." "-" snumber))
  1008. (href (cdr (assoc (concat "sec-" snu)
  1009. org-export-preferred-target-alist))))
  1010. (org-solidify-link-text (or href snu))))
  1011. (defun org-e-html-format-outline (contents level1 snumber title
  1012. tags target extra-targets extra-class)
  1013. (let* ((class (format "outline-%d" level1))
  1014. (class (if extra-class (concat class " " extra-class) class))
  1015. (id (and snumber ;; FIXME
  1016. (format "outline-container-%s"
  1017. (org-e-html-suffix-from-snumber snumber))))
  1018. (extra (concat (when id (format " id=\"%s\"" id))
  1019. (when class (format " class=\"%s\"" class)))))
  1020. (concat
  1021. (format "<div%s>\n" extra)
  1022. (org-e-html-format-heading
  1023. (org-e-html-format-headline title extra-targets tags snumber level1)
  1024. level1 target)
  1025. contents
  1026. "</div>")))
  1027. (defun org-e-html-begin-outline-text (level1 snumber extra-class)
  1028. (let* ((class (format "outline-text-%d" level1))
  1029. (class (if extra-class (concat class " " extra-class) class))
  1030. (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
  1031. (extra (concat (when id (format " id=\"%s\"" id))
  1032. (when class (format " class=\"%s\"" class)))))
  1033. (org-lparse-insert-tag "<div%s>" extra)))
  1034. (defun org-e-html-end-outline-text ()
  1035. (org-lparse-insert-tag "</div>"))
  1036. (defun org-e-html-begin-paragraph (&optional style)
  1037. (let* ((class (cdr (assoc style '((footnote . "footnote")
  1038. (verse . nil)))))
  1039. (extra (if class (format " class=\"%s\"" class) "")))
  1040. (org-lparse-insert-tag "<p%s>" extra)))
  1041. (defun org-e-html-end-paragraph ()
  1042. (insert "</p>"))
  1043. ;; Following variables are let bound when table emission is in
  1044. ;; progress. See org-lparse.el.
  1045. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  1046. (defvar org-lparse-table-begin-marker)
  1047. (defvar org-lparse-table-ncols)
  1048. (defvar org-lparse-table-rowgrp-open)
  1049. (defvar org-lparse-table-rownum)
  1050. (defvar org-lparse-table-cur-rowgrp-is-hdr)
  1051. (defvar org-lparse-table-is-styled)
  1052. (defvar org-lparse-table-rowgrp-info)
  1053. (defvar org-lparse-table-colalign-vector)
  1054. (defvar org-lparse-table-num-numeric-items-per-column)
  1055. (defun org-e-html-format-footnote-definition (contents n)
  1056. (concat
  1057. (format
  1058. (format org-e-html-footnote-format
  1059. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1060. n n n)
  1061. contents))
  1062. ;; (defun org-e-html-format-spaces (n)
  1063. ;; (let ((space (or (and org-lparse-encode-pending "\\nbsp") "&nbsp;")) out)
  1064. ;; (while (> n 0)
  1065. ;; (setq out (concat out space))
  1066. ;; (setq n (1- n))) out))
  1067. (defun org-e-html-format-tabs (&optional n)
  1068. (ignore))
  1069. (defun org-e-html-format-line-break ()
  1070. (org-e-html-format-tags "<br/>" ""))
  1071. (defun org-e-html-format-horizontal-line ()
  1072. (concat "\n" "<hr/>" "\n"))
  1073. ;; (defun org-e-html-format-line (line)
  1074. ;; (case org-lparse-dyn-current-environment
  1075. ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
  1076. ;; (t (concat line "\n"))))
  1077. (defun org-e-html-format-comment (fmt &rest args)
  1078. (let ((comment (apply 'format fmt args)))
  1079. (format "\n<!-- %s -->\n" comment)))
  1080. (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
  1081. "Turn todo keyword into a valid class name.
  1082. Replaces invalid characters with \"_\"."
  1083. (save-match-data
  1084. (while (string-match "[^a-zA-Z0-9_]" kwd)
  1085. (setq kwd (replace-match "_" t t kwd))))
  1086. kwd)
  1087. (defun org-e-html-format-fontify (text style &optional id)
  1088. (let (class extra how)
  1089. (cond
  1090. ((eq style 'underline)
  1091. (setq extra " style=\"text-decoration:underline;\"" ))
  1092. ((setq how (cdr (assoc style
  1093. '((bold . ("<b>" . "</b>"))
  1094. (emphasis . ("<i>" . "</i>"))
  1095. (code . ("<code>" . "</code>"))
  1096. (verbatim . ("<code>" . "</code>"))
  1097. (strike . ("<del>" . "</del>"))
  1098. (subscript . ("<sub>" . "</sub>"))
  1099. (superscript . ("<sup>" . "</sup>")))))))
  1100. ((listp style)
  1101. (setq class (mapconcat 'identity style " ")))
  1102. ((stringp style)
  1103. (setq class style))
  1104. (t (error "Unknown style %S" style)))
  1105. (setq extra (concat (when class (format " class=\"%s\"" class))
  1106. (when id (format " id=\"%s\"" id))
  1107. extra))
  1108. (let ((tags (or how '("<span%s>" . "</span>"))))
  1109. (concat (format (car tags) extra) text (cdr tags)))))
  1110. (defun org-e-html-format-link (text href &optional extra)
  1111. (let ((extra (concat (format " href=\"%s\"" href)
  1112. (and extra (concat " " extra)))))
  1113. (format "<a%s>%s</a>" extra text)))
  1114. (defun org-e-html-format-internal-link (text href &optional extra)
  1115. (org-e-html-format-link text (concat "#" href) extra))
  1116. (defun org-e-html-format-heading (text level &optional id)
  1117. (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
  1118. (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
  1119. (defun org-e-html-format-anchor (text name &optional class)
  1120. (let* ((id name)
  1121. (extra (concat
  1122. (when name (format " name=\"%s\"" name))
  1123. (when id (format " id=\"%s\"" id))
  1124. (when class (format " class=\"%s\"" class)))))
  1125. (format "<a%s>%s</a>" extra text)))
  1126. (defun org-e-html-format-extra-targets (extra-targets)
  1127. (if (not extra-targets) ""
  1128. (mapconcat (lambda (x)
  1129. (when x
  1130. (setq x (org-solidify-link-text
  1131. (if (org-uuidgen-p x) (concat "ID-" x) x)))
  1132. (org-e-html-format-anchor "" x))) extra-targets "")))
  1133. (defun org-e-html-format-spaces (n)
  1134. (let (out) (dotimes (i n out) (setq out (concat out "&nbsp;")))))
  1135. (defun org-e-html-format-org-tags (tags)
  1136. (if (not tags) ""
  1137. (org-e-html-format-fontify
  1138. (mapconcat
  1139. (lambda (x)
  1140. (org-e-html-format-fontify
  1141. x (concat org-e-html-tag-class-prefix
  1142. (org-e-html-fix-class-name x))))
  1143. (org-split-string tags ":")
  1144. (org-e-html-format-spaces 1)) "tag")))
  1145. (defun org-e-html-format-section-number (&optional snumber level)
  1146. ;; FIXME
  1147. (and org-export-with-section-numbers
  1148. ;; (not org-lparse-body-only)
  1149. snumber level
  1150. (org-e-html-format-fontify snumber (format "section-number-%d" level))))
  1151. (defun org-e-html-format-headline (title extra-targets tags
  1152. &optional snumber level)
  1153. (concat
  1154. (org-e-html-format-extra-targets extra-targets)
  1155. (concat (org-e-html-format-section-number snumber level) " ")
  1156. title
  1157. (and tags (concat (org-e-html-format-spaces 3)
  1158. (org-e-html-format-org-tags tags)))))
  1159. (defun org-e-html-format-footnote-reference (n def refcnt)
  1160. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  1161. (format org-e-html-footnote-format
  1162. (format
  1163. "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
  1164. n extra n n))))
  1165. (defun org-e-html-format-footnotes-section (section-name definitions)
  1166. (if (not definitions) ""
  1167. (format org-e-html-footnotes-section section-name definitions)))
  1168. (defun org-e-html-format-org-entity (wd)
  1169. (org-entity-get-representation wd 'html))
  1170. (defun org-e-html-format-tags (tag text &rest args)
  1171. (let ((prefix ;; (when org-lparse-encode-pending "@")
  1172. )
  1173. (suffix ;; (when org-lparse-encode-pending "@")
  1174. ))
  1175. (apply 'org-lparse-format-tags tag text prefix suffix args)))
  1176. (defun org-e-html-get (what &optional opt-plist)
  1177. (case what
  1178. (BACKEND 'html)
  1179. (INIT-METHOD nil)
  1180. (SAVE-METHOD nil)
  1181. (CLEANUP-METHOD nil)
  1182. ;; (OTHER-BACKENDS
  1183. ;; ;; There is a provision to register a per-backend converter and
  1184. ;; ;; output formats. Refer `org-lparse-get-converter' and
  1185. ;; ;; `org-lparse-get-other-backends'.
  1186. ;; ;; The default behaviour is to use `org-lparse-convert-process'
  1187. ;; ;; and `org-lparse-convert-capabilities'.
  1188. ;; )
  1189. ;; (CONVERT-METHOD
  1190. ;; ;; See note above
  1191. ;; )
  1192. (EXPORT-DIR (org-export-directory :html opt-plist))
  1193. (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
  1194. (EXPORT-BUFFER-NAME "*Org HTML Export*")
  1195. (TOPLEVEL-HLEVEL org-e-html-toplevel-hlevel)
  1196. (SPECIAL-STRING-REGEXPS org-e-html-special-string-regexps)
  1197. (CODING-SYSTEM-FOR-WRITE org-e-html-coding-system)
  1198. (CODING-SYSTEM-FOR-SAVE org-e-html-coding-system)
  1199. (INLINE-IMAGES org-e-html-inline-images)
  1200. (INLINE-IMAGE-EXTENSIONS org-e-html-inline-image-extensions)
  1201. (PLAIN-TEXT-MAP org-e-html-protect-char-alist)
  1202. (TABLE-FIRST-COLUMN-AS-LABELS
  1203. org-e-html-table-use-header-tags-for-first-column)
  1204. (TODO-KWD-CLASS-PREFIX org-e-html-todo-kwd-class-prefix)
  1205. (TAG-CLASS-PREFIX org-e-html-tag-class-prefix)
  1206. (FOOTNOTE-SEPARATOR org-e-html-footnote-separator)
  1207. (t (error "Unknown property: %s" what))))
  1208. (defun org-e-html-get-coding-system-for-write ()
  1209. (or org-e-html-coding-system
  1210. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1211. (defun org-e-html-get-coding-system-for-save ()
  1212. (or org-e-html-coding-system
  1213. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1214. (defun org-e-html-format-date (info)
  1215. (let ((date (plist-get info :date)))
  1216. (cond
  1217. ((and date (string-match "%" date))
  1218. (format-time-string date))
  1219. (date date)
  1220. (t (format-time-string "%Y-%m-%d %T %Z")))))
  1221. (defun org-e-html-footnote-section (info)
  1222. (when org-e-html-footnotes-alist
  1223. (setq org-e-html-footnotes-alist (nreverse org-e-html-footnotes-alist))
  1224. (org-e-html-format-footnotes-section
  1225. (nth 4 (or (assoc (plist-get info :language)
  1226. org-export-language-setup)
  1227. (assoc "en" org-export-language-setup)))
  1228. (format "
  1229. <table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">
  1230. %s
  1231. </table>
  1232. "
  1233. (mapconcat
  1234. (lambda (x)
  1235. (let ((n (car x))
  1236. (def (cdr x)))
  1237. (format "
  1238. <tr>
  1239. <td>%s</td>
  1240. <td>%s</td>
  1241. </tr>
  1242. "
  1243. (format
  1244. (format org-e-html-footnote-format
  1245. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1246. n n n) def)))
  1247. org-e-html-footnotes-alist "\n")))))
  1248. (eval-when-compile (require 'cl))
  1249. ;;; org-e-html.el
  1250. (declare-function org-element-get-property "org-element" (property element))
  1251. (declare-function org-element-normalize-string "org-element" (s))
  1252. (declare-function org-element-parse-secondary-string
  1253. "org-element" (string restriction &optional buffer))
  1254. (defvar org-element-string-restrictions)
  1255. (declare-function org-export-clean-table "org-export" (table specialp))
  1256. (declare-function org-export-data "org-export" (data backend info))
  1257. (declare-function org-export-directory "org-export" (type plist))
  1258. (declare-function org-export-expand-macro "org-export" (macro info))
  1259. (declare-function org-export-first-sibling-p "org-export" (headline info))
  1260. (declare-function org-export-footnote-first-reference-p "org-export"
  1261. (footnote-reference info))
  1262. (declare-function org-export-get-coderef-format "org-export" (path desc))
  1263. (declare-function org-export-get-footnote-definition "org-export"
  1264. (footnote-reference info))
  1265. (declare-function org-export-get-footnote-number "org-export" (footnote info))
  1266. (declare-function org-export-get-previous-element "org-export" (blob info))
  1267. (declare-function org-export-get-relative-level "org-export" (headline info))
  1268. (declare-function org-export-handle-code
  1269. "org-export" (element info &optional num-fmt ref-fmt delayed))
  1270. (declare-function org-export-included-file "org-export" (keyword backend info))
  1271. (declare-function org-export-inline-image-p "org-export"
  1272. (link &optional extensions))
  1273. (declare-function org-export-last-sibling-p "org-export" (headline info))
  1274. (declare-function org-export-low-level-p "org-export" (headline info))
  1275. (declare-function org-export-output-file-name
  1276. "org-export" (extension &optional subtreep pub-dir))
  1277. (declare-function org-export-resolve-coderef "org-export" (ref info))
  1278. (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
  1279. (declare-function org-export-secondary-string "org-export"
  1280. (secondary backend info))
  1281. (declare-function org-export-solidify-link-text "org-export" (s))
  1282. (declare-function org-export-table-format-info "org-export" (table))
  1283. (declare-function
  1284. org-export-to-buffer "org-export"
  1285. (backend buffer &optional subtreep visible-only body-only ext-plist))
  1286. (declare-function
  1287. org-export-to-file "org-export"
  1288. (backend file &optional subtreep visible-only body-only ext-plist))
  1289. ;;; Internal Variables
  1290. (defconst org-e-html-option-alist
  1291. '((:agenda-style nil nil org-agenda-export-html-style)
  1292. (:convert-org-links nil nil org-e-html-link-org-files-as-html)
  1293. ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
  1294. ;; (:expand-quoted-html nil "@" org-e-html-expand)
  1295. (:inline-images nil nil org-e-html-inline-images)
  1296. ;; (:link-home nil nil org-e-html-link-home) FIXME
  1297. ;; (:link-up nil nil org-e-html-link-up) FIXME
  1298. (:style nil nil org-e-html-style)
  1299. (:style-extra nil nil org-e-html-style-extra)
  1300. (:style-include-default nil nil org-e-html-style-include-default)
  1301. (:style-include-scripts nil nil org-e-html-style-include-scripts)
  1302. (:timestamp nil nil org-e-html-with-timestamp)
  1303. (:html-extension nil nil org-e-html-extension)
  1304. (:html-postamble nil nil org-e-html-postamble)
  1305. (:html-preamble nil nil org-e-html-preamble)
  1306. (:html-table-tag nil nil org-e-html-table-tag)
  1307. (:xml-declaration nil nil org-e-html-xml-declaration)
  1308. (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments))
  1309. "Alist between export properties and ways to set them.
  1310. The car of the alist is the property name, and the cdr is a list
  1311. like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
  1312. KEYWORD is a string representing a buffer keyword, or nil.
  1313. OPTION is a string that could be found in an #+OPTIONS: line.
  1314. DEFAULT is the default value for the property.
  1315. BEHAVIOUR determine how Org should handle multiple keywords for
  1316. the same property. It is a symbol among:
  1317. nil Keep old value and discard the new one.
  1318. t Replace old value with the new one.
  1319. `space' Concatenate the values, separating them with a space.
  1320. `newline' Concatenate the values, separating them with
  1321. a newline.
  1322. `split' Split values at white spaces, and cons them to the
  1323. previous list.
  1324. KEYWORD and OPTION have precedence over DEFAULT.
  1325. All these properties should be back-end agnostic. For back-end
  1326. specific properties, define a similar variable named
  1327. `org-BACKEND-option-alist', replacing BACKEND with the name of
  1328. the appropriate back-end. You can also redefine properties
  1329. there, as they have precedence over these.")
  1330. ;;; User Configurable Variables
  1331. (defgroup org-export-e-html nil
  1332. "Options for exporting Org mode files to HTML."
  1333. :tag "Org Export HTML"
  1334. :group 'org-export)
  1335. ;;;; Preamble
  1336. (defcustom org-e-html-inputenc-alist nil
  1337. "Alist of inputenc coding system names, and what should really be used.
  1338. For example, adding an entry
  1339. (\"utf8\" . \"utf8x\")
  1340. will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
  1341. are written as utf8 files."
  1342. :group 'org-export-e-html
  1343. :type '(repeat
  1344. (cons
  1345. (string :tag "Derived from buffer")
  1346. (string :tag "Use this instead"))))
  1347. (defcustom org-e-html-date-format
  1348. "\\today"
  1349. "Format string for \\date{...}."
  1350. :group 'org-export-e-html
  1351. :type 'boolean)
  1352. (defcustom org-e-html-title-command "\\maketitle"
  1353. "The command used to insert the title just after \\begin{document}.
  1354. If this string contains the formatting specification \"%s\" then
  1355. it will be used as a formatting string, passing the title as an
  1356. argument."
  1357. :group 'org-export-e-html
  1358. :type 'string)
  1359. ;;;; Headline
  1360. (defcustom org-e-html-format-headline-function nil
  1361. "Function to format headline text.
  1362. This function will be called with 5 arguments:
  1363. TODO the todo keyword \(string or nil\).
  1364. TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
  1365. PRIORITY the priority of the headline \(integer or nil\)
  1366. TEXT the main headline text \(string\).
  1367. TAGS the tags string, separated with colons \(string or nil\).
  1368. The function result will be used in the section format string.
  1369. As an example, one could set the variable to the following, in
  1370. order to reproduce the default set-up:
  1371. \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
  1372. \"Default format function for an headline.\"
  1373. \(concat \(when todo
  1374. \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
  1375. \(when priority
  1376. \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  1377. text
  1378. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
  1379. :group 'org-export-e-html
  1380. :type 'function)
  1381. ;;;; Emphasis
  1382. (defcustom org-e-html-emphasis-alist
  1383. '(("*" . "\\textbf{%s}")
  1384. ("/" . "\\emph{%s}")
  1385. ("_" . "\\underline{%s}")
  1386. ("+" . "\\st{%s}")
  1387. ("=" . protectedtexttt)
  1388. ("~" . verb))
  1389. "Alist of HTML expressions to convert emphasis fontifiers.
  1390. The key is the character used as a marker for fontification. The
  1391. value is a formatting string to wrap fontified text with.
  1392. Value can also be set to the following symbols: `verb' and
  1393. `protectedtexttt'. For the former, Org will use \"\\verb\" to
  1394. create a format string and select a delimiter character that
  1395. isn't in the string. For the latter, Org will use \"\\texttt\"
  1396. to typeset and try to protect special characters."
  1397. :group 'org-export-e-html
  1398. :type 'alist)
  1399. ;;;; Footnotes
  1400. (defcustom org-e-html-footnote-separator "<sup>, </sup>"
  1401. "Text used to separate footnotes."
  1402. :group 'org-export-e-html
  1403. :type 'string)
  1404. ;;;; Time-stamps
  1405. (defcustom org-e-html-active-timestamp-format "\\textit{%s}"
  1406. "A printf format string to be applied to active time-stamps."
  1407. :group 'org-export-e-html
  1408. :type 'string)
  1409. (defcustom org-e-html-inactive-timestamp-format "\\textit{%s}"
  1410. "A printf format string to be applied to inactive time-stamps."
  1411. :group 'org-export-e-html
  1412. :type 'string)
  1413. (defcustom org-e-html-diary-timestamp-format "\\textit{%s}"
  1414. "A printf format string to be applied to diary time-stamps."
  1415. :group 'org-export-e-html
  1416. :type 'string)
  1417. ;;;; Links
  1418. (defcustom org-e-html-image-default-option "width=.9\\linewidth"
  1419. "Default option for images."
  1420. :group 'org-export-e-html
  1421. :type 'string)
  1422. (defcustom org-e-html-default-figure-position "htb"
  1423. "Default position for latex figures."
  1424. :group 'org-export-e-html
  1425. :type 'string)
  1426. (defcustom org-e-html-inline-image-rules
  1427. '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
  1428. "Rules characterizing image files that can be inlined into HTML.
  1429. A rule consists in an association whose key is the type of link
  1430. to consider, and value is a regexp that will be matched against
  1431. link's path.
  1432. Note that, by default, the image extension *actually* allowed
  1433. depend on the way the HTML file is processed. When used with
  1434. pdflatex, pdf, jpg and png images are OK. When processing
  1435. through dvi to Postscript, only ps and eps are allowed. The
  1436. default we use here encompasses both."
  1437. :group 'org-export-e-html
  1438. :type '(alist :key-type (string :tag "Type")
  1439. :value-type (regexp :tag "Path")))
  1440. ;;;; Tables
  1441. (defcustom org-e-html-default-table-environment "tabular"
  1442. "Default environment used to build tables."
  1443. :group 'org-export-e-html
  1444. :type 'string)
  1445. (defcustom org-e-html-tables-centered t
  1446. "When non-nil, tables are exported in a center environment."
  1447. :group 'org-export-e-html
  1448. :type 'boolean)
  1449. (defcustom org-e-html-tables-verbatim nil
  1450. "When non-nil, tables are exported verbatim."
  1451. :group 'org-export-e-html
  1452. :type 'boolean)
  1453. (defcustom org-e-html-tables-booktabs nil
  1454. "When non-nil, display tables in a formal \"booktabs\" style.
  1455. This option assumes that the \"booktabs\" package is properly
  1456. loaded in the header of the document. This value can be ignored
  1457. locally with \"booktabs=yes\" and \"booktabs=no\" HTML
  1458. attributes."
  1459. :group 'org-export-e-html
  1460. :type 'boolean)
  1461. (defcustom org-e-html-table-caption-above t
  1462. "When non-nil, place caption string at the beginning of the table.
  1463. Otherwise, place it near the end."
  1464. :group 'org-export-e-html
  1465. :type 'boolean)
  1466. ;;;; Drawers
  1467. (defcustom org-e-html-format-drawer-function nil
  1468. "Function called to format a drawer in HTML code.
  1469. The function must accept two parameters:
  1470. NAME the drawer name, like \"LOGBOOK\"
  1471. CONTENTS the contents of the drawer.
  1472. The function should return the string to be exported.
  1473. For example, the variable could be set to the following function
  1474. in order to mimic default behaviour:
  1475. \(defun org-e-html-format-drawer-default \(name contents\)
  1476. \"Format a drawer element for HTML export.\"
  1477. contents\)"
  1478. :group 'org-export-e-html
  1479. :type 'function)
  1480. ;;;; Inlinetasks
  1481. (defcustom org-e-html-format-inlinetask-function nil
  1482. "Function called to format an inlinetask in HTML code.
  1483. The function must accept six parameters:
  1484. TODO the todo keyword, as a string
  1485. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  1486. PRIORITY the inlinetask priority, as a string
  1487. NAME the inlinetask name, as a string.
  1488. TAGS the inlinetask tags, as a string.
  1489. CONTENTS the contents of the inlinetask, as a string.
  1490. The function should return the string to be exported.
  1491. For example, the variable could be set to the following function
  1492. in order to mimic default behaviour:
  1493. \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
  1494. \"Format an inline task element for HTML export.\"
  1495. \(let \(\(full-title
  1496. \(concat
  1497. \(when todo
  1498. \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
  1499. \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  1500. title
  1501. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
  1502. \(format \(concat \"\\\\begin{center}\\n\"
  1503. \"\\\\fbox{\\n\"
  1504. \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
  1505. \"%s\\n\\n\"
  1506. \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
  1507. \"%s\"
  1508. \"\\\\end{minipage}}\"
  1509. \"\\\\end{center}\"\)
  1510. full-title contents\)\)"
  1511. :group 'org-export-e-html
  1512. :type 'function)
  1513. ;; Src blocks
  1514. ;;;; Plain text
  1515. (defcustom org-e-html-quotes
  1516. '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
  1517. ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
  1518. "Alist for quotes to use when converting english double-quotes.
  1519. The CAR of each item in this alist is the language code.
  1520. The CDR of each item in this alist is a list of three CONS:
  1521. - the first CONS defines the opening quote;
  1522. - the second CONS defines the closing quote;
  1523. - the last CONS defines single quotes.
  1524. For each item in a CONS, the first string is a regexp
  1525. for allowed characters before/after the quote, the second
  1526. string defines the replacement string for this quote."
  1527. :group 'org-export-e-html
  1528. :type '(list
  1529. (cons :tag "Opening quote"
  1530. (string :tag "Regexp for char before")
  1531. (string :tag "Replacement quote "))
  1532. (cons :tag "Closing quote"
  1533. (string :tag "Regexp for char after ")
  1534. (string :tag "Replacement quote "))
  1535. (cons :tag "Single quote"
  1536. (string :tag "Regexp for char before")
  1537. (string :tag "Replacement quote "))))
  1538. ;;;; Compilation
  1539. (defcustom org-e-html-pdf-process
  1540. '("pdflatex -interaction nonstopmode -output-directory %o %f"
  1541. "pdflatex -interaction nonstopmode -output-directory %o %f"
  1542. "pdflatex -interaction nonstopmode -output-directory %o %f")
  1543. "Commands to process a HTML file to a PDF file.
  1544. This is a list of strings, each of them will be given to the
  1545. shell as a command. %f in the command will be replaced by the
  1546. full file name, %b by the file base name \(i.e. without
  1547. extension) and %o by the base directory of the file.
  1548. The reason why this is a list is that it usually takes several
  1549. runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
  1550. does not have a clever mechanism to detect which of these
  1551. commands have to be run to get to a stable result, and it also
  1552. does not do any error checking.
  1553. By default, Org uses 3 runs of `pdflatex' to do the processing.
  1554. If you have texi2dvi on your system and if that does not cause
  1555. the infamous egrep/locale bug:
  1556. http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
  1557. then `texi2dvi' is the superior choice. Org does offer it as one
  1558. of the customize options.
  1559. Alternatively, this may be a Lisp function that does the
  1560. processing, so you could use this to apply the machinery of
  1561. AUCTeX or the Emacs HTML mode. This function should accept the
  1562. file name as its single argument."
  1563. :group 'org-export-pdf
  1564. :type '(choice
  1565. (repeat :tag "Shell command sequence"
  1566. (string :tag "Shell command"))
  1567. (const :tag "2 runs of pdflatex"
  1568. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  1569. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  1570. (const :tag "3 runs of pdflatex"
  1571. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  1572. "pdflatex -interaction nonstopmode -output-directory %o %f"
  1573. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  1574. (const :tag "pdflatex,bibtex,pdflatex,pdflatex"
  1575. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  1576. "bibtex %b"
  1577. "pdflatex -interaction nonstopmode -output-directory %o %f"
  1578. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  1579. (const :tag "texi2dvi"
  1580. ("texi2dvi -p -b -c -V %f"))
  1581. (const :tag "rubber"
  1582. ("rubber -d --into %o %f"))
  1583. (function)))
  1584. (defcustom org-e-html-logfiles-extensions
  1585. '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
  1586. "The list of file extensions to consider as HTML logfiles."
  1587. :group 'org-export-e-html
  1588. :type '(repeat (string :tag "Extension")))
  1589. (defcustom org-e-html-remove-logfiles t
  1590. "Non-nil means remove the logfiles produced by PDF production.
  1591. These are the .aux, .log, .out, and .toc files."
  1592. :group 'org-export-e-html
  1593. :type 'boolean)
  1594. ;;; Internal Functions
  1595. (defun org-e-html--caption/label-string (caption label info)
  1596. "Return caption and label HTML string for floats.
  1597. CAPTION is a cons cell of secondary strings, the car being the
  1598. standard caption and the cdr its short form. LABEL is a string
  1599. representing the label. INFO is a plist holding contextual
  1600. information.
  1601. If there's no caption nor label, return the empty string.
  1602. For non-floats, see `org-e-html--wrap-label'."
  1603. (setq label nil) ;; FIXME
  1604. (let ((label-str (if label (format "\\label{%s}" label) "")))
  1605. (cond
  1606. ((and (not caption) (not label)) "")
  1607. ((not caption) (format "\\label{%s}\n" label))
  1608. ;; Option caption format with short name.
  1609. ((cdr caption)
  1610. (format "\\caption[%s]{%s%s}\n"
  1611. (org-export-secondary-string (cdr caption) 'e-html info)
  1612. label-str
  1613. (org-export-secondary-string (car caption) 'e-html info)))
  1614. ;; Standard caption format.
  1615. ;; (t (format "\\caption{%s%s}\n"
  1616. ;; label-str
  1617. ;; (org-export-secondary-string (car caption) 'e-html info)))
  1618. (t (org-export-secondary-string (car caption) 'e-html info)))))
  1619. (defun org-e-html--find-verb-separator (s)
  1620. "Return a character not used in string S.
  1621. This is used to choose a separator for constructs like \\verb."
  1622. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1623. (loop for c across ll
  1624. when (not (string-match (regexp-quote (char-to-string c)) s))
  1625. return (char-to-string c))))
  1626. (defun org-e-html--make-option-string (options)
  1627. "Return a comma separated string of keywords and values.
  1628. OPTIONS is an alist where the key is the options keyword as
  1629. a string, and the value a list containing the keyword value, or
  1630. nil."
  1631. (mapconcat (lambda (pair)
  1632. (concat (first pair)
  1633. (when (> (length (second pair)) 0)
  1634. (concat "=" (second pair)))))
  1635. options
  1636. ","))
  1637. (defun org-e-html--quotation-marks (text info)
  1638. "Export quotation marks depending on language conventions.
  1639. TEXT is a string containing quotation marks to be replaced. INFO
  1640. is a plist used as a communication channel."
  1641. (mapc (lambda(l)
  1642. (let ((start 0))
  1643. (while (setq start (string-match (car l) text start))
  1644. (let ((new-quote (concat (match-string 1 text) (cdr l))))
  1645. (setq text (replace-match new-quote t t text))))))
  1646. (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
  1647. ;; Falls back on English.
  1648. (assoc "en" org-e-html-quotes))))
  1649. text)
  1650. (defun org-e-html--wrap-label (element output)
  1651. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  1652. This function shouldn't be used for floats. See
  1653. `org-e-html--caption/label-string'."
  1654. ;; (let ((label (org-element-get-property :name element)))
  1655. ;; (if (or (not output) (not label) (string= output "") (string= label ""))
  1656. ;; output
  1657. ;; (concat (format "\\label{%s}\n" label) output)))
  1658. output)
  1659. ;;; Template
  1660. ;; (defun org-e-html-template (contents info)
  1661. ;; "Return complete document string after HTML conversion.
  1662. ;; CONTENTS is the transcoded contents string. INFO is a plist
  1663. ;; holding export options."
  1664. ;; (let ((title (org-export-secondary-string
  1665. ;; (plist-get info :title) 'e-html info)))
  1666. ;; (concat
  1667. ;; ;; 1. Time-stamp.
  1668. ;; (and (plist-get info :time-stamp-file)
  1669. ;; (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  1670. ;; ;; 2. Document class and packages.
  1671. ;; (let ((class (plist-get info :latex-class))
  1672. ;; (class-options (plist-get info :latex-class-options)))
  1673. ;; (org-element-normalize-string
  1674. ;; (let* ((header (nth 1 (assoc class org-e-html-classes)))
  1675. ;; (document-class-string
  1676. ;; (and (stringp header)
  1677. ;; (if class-options
  1678. ;; (replace-regexp-in-string
  1679. ;; "^[ \t]*\\\\documentclass\\(\\[.*?\\]\\)"
  1680. ;; class-options header t nil 1)
  1681. ;; header))))
  1682. ;; (org-e-html--guess-inputenc
  1683. ;; (org-splice-latex-header
  1684. ;; document-class-string
  1685. ;; org-export-latex-default-packages-alist ; defined in org.el
  1686. ;; org-export-latex-packages-alist nil ; defined in org.el
  1687. ;; (plist-get info :latex-header-extra))))))
  1688. ;; ;; 3. Define alert if not yet defined.
  1689. ;; "\\providecommand{\\alert}[1]{\\textbf{#1}}\n"
  1690. ;; ;; 4. Possibly limit depth for headline numbering.
  1691. ;; (let ((sec-num (plist-get info :section-numbers)))
  1692. ;; (when (integerp sec-num)
  1693. ;; (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
  1694. ;; ;; 5. Author.
  1695. ;; (let ((author (and (plist-get info :with-author)
  1696. ;; (let ((auth (plist-get info :author)))
  1697. ;; (and auth (org-export-secondary-string
  1698. ;; auth 'e-html info)))))
  1699. ;; (email (and (plist-get info :with-email)
  1700. ;; (org-export-secondary-string
  1701. ;; (plist-get info :email) 'e-html info))))
  1702. ;; (cond ((and author email (not (string= "" email)))
  1703. ;; (format "\\author{%s\\thanks{%s}}\n" author email))
  1704. ;; (author (format "\\author{%s}\n" author))
  1705. ;; (t "\\author{}\n")))
  1706. ;; ;; 6. Date.
  1707. ;; (let ((date (plist-get info :date)))
  1708. ;; (and date (format "\\date{%s}\n" date)))
  1709. ;; ;; 7. Title
  1710. ;; (format "\\title{%s}\n" title)
  1711. ;; ;; 8. Hyperref options.
  1712. ;; (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
  1713. ;; (or (plist-get info :keywords) "")
  1714. ;; (or (plist-get info :description) "")
  1715. ;; (if (not (plist-get info :with-creator)) ""
  1716. ;; (plist-get info :creator)))
  1717. ;; ;; 9. Document start.
  1718. ;; "\\begin{document}\n\n"
  1719. ;; ;; 10. Title command.
  1720. ;; (org-element-normalize-string
  1721. ;; (cond ((string= "" title) nil)
  1722. ;; ((not (stringp org-e-html-title-command)) nil)
  1723. ;; ((string-match "\\(?:[^%]\\|^\\)%s"
  1724. ;; org-e-html-title-command)
  1725. ;; (format org-e-html-title-command title))
  1726. ;; (t org-e-html-title-command)))
  1727. ;; ;; 11. Table of contents.
  1728. ;; (let ((depth (plist-get info :with-toc)))
  1729. ;; (when depth
  1730. ;; (concat (when (wholenump depth)
  1731. ;; (format "\\setcounter{tocdepth}{%d}\n" depth))
  1732. ;; "\\tableofcontents\n\\vspace*{1cm}\n\n")))
  1733. ;; ;; 12. Document's body.
  1734. ;; contents
  1735. ;; ;; 13. Creator.
  1736. ;; (let ((creator-info (plist-get info :with-creator)))
  1737. ;; (cond
  1738. ;; ((not creator-info) "")
  1739. ;; ((eq creator-info 'comment)
  1740. ;; (format "%% %s\n" (plist-get info :creator)))
  1741. ;; (t (concat (plist-get info :creator) "\n"))))
  1742. ;; ;; 14. Document end.
  1743. ;; "\\end{document}")))
  1744. (defun org-e-html-meta-info (info)
  1745. (concat
  1746. (format "
  1747. <title>%s</title>" (plist-get info :title))
  1748. (format "
  1749. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
  1750. (and coding-system-for-write
  1751. (fboundp 'coding-system-get)
  1752. (coding-system-get coding-system-for-write
  1753. 'mime-charset)))
  1754. (format "
  1755. <meta name=\"title\" content=\"%s\"/>" (plist-get info :title))
  1756. "
  1757. <meta name=\"generator\" content=\"Org-mode\"/>"
  1758. (format "
  1759. <meta name=\"generated\" content=\"%s\"/>" (org-e-html-format-date info))
  1760. (format "
  1761. <meta name=\"author\" content=\"%s\"/>" (plist-get info :author))
  1762. (format "
  1763. <meta name=\"description\" content=\"%s\"/>" (plist-get info :description))
  1764. (format "
  1765. <meta name=\"keywords\" content=\"%s\"/>" (plist-get info :keywords))))
  1766. (defun org-e-html-style (info)
  1767. (concat
  1768. (when (plist-get info :style-include-default)
  1769. org-e-html-style-default)
  1770. (plist-get info :style)
  1771. (plist-get info :style-extra)
  1772. "\n"
  1773. (when (plist-get info :style-include-scripts)
  1774. org-e-html-scripts)))
  1775. (defun org-e-html-mathjax (info)
  1776. (when (or (eq (plist-get info :HTML-fragments) 'mathjax)
  1777. (and org-export-have-math
  1778. (eq (plist-get info :HTML-fragments) t)))
  1779. (org-e-html-mathjax-config
  1780. org-e-html-mathjax-template
  1781. org-e-html-mathjax-options
  1782. (or (plist-get info :mathjax) ""))))
  1783. (defun org-e-html-preamble (info)
  1784. (when (plist-get info :html-preamble)
  1785. (let* ((title (plist-get info :title))
  1786. (date (org-e-html-format-date info))
  1787. (author (plist-get info :author))
  1788. (lang-words (or (assoc (plist-get info :language)
  1789. org-export-language-setup)
  1790. (assoc "en" org-export-language-setup)))
  1791. (email (plist-get info :email))
  1792. (html-pre-real-contents
  1793. (cond
  1794. ((functionp (plist-get info :html-preamble))
  1795. (with-temp-buffer
  1796. (funcall (plist-get info :html-preamble))
  1797. (buffer-string)))
  1798. ((stringp (plist-get info :html-preamble))
  1799. (format-spec (plist-get info :html-preamble)
  1800. `((?t . ,title) (?a . ,author)
  1801. (?d . ,date) (?e . ,email))))
  1802. (t
  1803. (format-spec
  1804. (or (cadr (assoc (nth 0 lang-words)
  1805. org-e-html-preamble-format))
  1806. (cadr (assoc "en" org-e-html-preamble-format)))
  1807. `((?t . ,title) (?a . ,author)
  1808. (?d . ,date) (?e . ,email)))))))
  1809. (when (not (equal html-pre-real-contents ""))
  1810. (concat
  1811. (format "
  1812. <div id=\"%s\"> " (nth 0 org-e-html-divs))
  1813. "
  1814. "
  1815. html-pre-real-contents
  1816. "
  1817. </div>")))))
  1818. (defun org-e-html-postamble (info)
  1819. (concat
  1820. (when (and (not body-only)
  1821. (plist-get info :html-postamble))
  1822. (let* ((html-post (plist-get info :html-postamble))
  1823. (date (org-e-html-format-date info))
  1824. (author (plist-get info :author))
  1825. (email (plist-get info :email))
  1826. (lang-words (or (assoc (plist-get info :language)
  1827. org-export-language-setup)
  1828. (assoc "en" org-export-language-setup)))
  1829. (email
  1830. (mapconcat (lambda(e)
  1831. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1832. (split-string email ",+ *")
  1833. ", "))
  1834. (html-validation-link (or org-e-html-validation-link ""))
  1835. (creator-info
  1836. (concat "Org version " org-version " with Emacs version "
  1837. (number-to-string emacs-major-version))))
  1838. (concat
  1839. ;; begin postamble
  1840. "
  1841. <div id=\"" (nth 2 org-e-html-divs) "\">"
  1842. (cond
  1843. ;; auto postamble
  1844. ((eq (plist-get info :html-postamble) 'auto)
  1845. (concat
  1846. (when (plist-get info :time-stamp-file)
  1847. (format "
  1848. <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
  1849. (when (and (plist-get info :with-author) author)
  1850. (format "
  1851. <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
  1852. (when (and (plist-get info :with-email) email)
  1853. (format "
  1854. <p class=\"email\"> %s </p>" email))
  1855. (when (plist-get info :with-creator)
  1856. (format "
  1857. <p class=\"creator\"> %s </p>" creator-info))
  1858. html-validation-link "\n"))
  1859. ;; postamble from a string
  1860. ((stringp (plist-get info :html-postamble))
  1861. (format-spec (plist-get info :html-postamble)
  1862. `((?a . ,author) (?e . ,email)
  1863. (?d . ,date) (?c . ,creator-info)
  1864. (?v . ,html-validation-link))))
  1865. ;; postamble from a function
  1866. ((functionp (plist-get info :html-postamble))
  1867. (with-temp-buffer
  1868. (funcall (plist-get info :html-postamble))
  1869. (buffer-string)))
  1870. ;; default postamble
  1871. (t
  1872. (format-spec
  1873. (or (cadr (assoc (nth 0 lang-words)
  1874. org-e-html-postamble-format))
  1875. (cadr (assoc "en" org-e-html-postamble-format)))
  1876. `((?a . ,author) (?e . ,email)
  1877. (?d . ,date) (?c . ,creator-info)
  1878. (?v . ,html-validation-link)))))
  1879. "
  1880. </div>")))
  1881. org-e-html-html-helper-timestamp))
  1882. (defun org-e-html-template (contents info)
  1883. "Return complete document string after HTML conversion.
  1884. CONTENTS is the transcoded contents string. RAW-DATA is the
  1885. original parsed data. INFO is a plist holding export options."
  1886. (concat
  1887. (format
  1888. (or (and (stringp org-e-html-xml-declaration)
  1889. org-e-html-xml-declaration)
  1890. (cdr (assoc (plist-get info :html-extension)
  1891. org-e-html-xml-declaration))
  1892. (cdr (assoc "html" org-e-html-xml-declaration))
  1893. "")
  1894. (or (and coding-system-for-write
  1895. (fboundp 'coding-system-get)
  1896. (coding-system-get coding-system-for-write
  1897. 'mime-charset))
  1898. "iso-8859-1"))
  1899. "
  1900. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1901. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
  1902. (format "
  1903. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
  1904. (plist-get info :language) (plist-get info :language))
  1905. "
  1906. <head>"
  1907. (org-e-html-meta-info info) ; meta
  1908. (org-e-html-style info) ; style
  1909. (org-e-html-mathjax info) ; mathjax
  1910. "
  1911. </head>"
  1912. "
  1913. <body>"
  1914. (let ((link-up (and (plist-get info :link-up)
  1915. (string-match "\\S-" (plist-get info :link-up))
  1916. (plist-get info :link-up)))
  1917. (link-home (and (plist-get info :link-home)
  1918. (string-match "\\S-" (plist-get info :link-home))
  1919. (plist-get info :link-home))))
  1920. (when (or link-up link-home)
  1921. (format org-e-html-home/up-format
  1922. (or link-up link-home)
  1923. (or link-home link-up))))
  1924. ;; preamble
  1925. (org-e-html-preamble info)
  1926. ;; content
  1927. (format "
  1928. <div id=\"%s\">" (or org-e-html-content-div
  1929. (nth 1 org-e-html-divs)))
  1930. (format "
  1931. <h1 class=\"title\"> %s </h1>\n" (plist-get info :title))
  1932. contents
  1933. (org-e-html-footnote-section info)
  1934. (org-e-html-bibliography)
  1935. (unless body-only
  1936. "
  1937. </div>")
  1938. ;; postamble
  1939. (org-e-html-postamble info)
  1940. (unless body-only
  1941. "
  1942. </body>")
  1943. "
  1944. </html>"))
  1945. ;;; Transcode Functions
  1946. ;;;; Block
  1947. (defun org-e-html-center-block (center-block contents info)
  1948. "Transcode a CENTER-BLOCK element from Org to HTML.
  1949. CONTENTS holds the contents of the block. INFO is a plist
  1950. holding contextual information."
  1951. (org-e-html--wrap-label
  1952. center-block
  1953. (format "<div style=\"text-align: center\">\n%s</div>" contents)))
  1954. ;;;; Comment
  1955. ;; Comments are ignored.
  1956. ;;;; Comment Block
  1957. ;; Comment Blocks are ignored.
  1958. ;;;; Drawer
  1959. (defun org-e-html-drawer (drawer contents info)
  1960. "Transcode a DRAWER element from Org to HTML.
  1961. CONTENTS holds the contents of the block. INFO is a plist
  1962. holding contextual information."
  1963. (let* ((name (org-element-get-property :drawer-name drawer))
  1964. (output (if (functionp org-e-html-format-drawer-function)
  1965. (funcall org-e-html-format-drawer-function
  1966. name contents)
  1967. ;; If there's no user defined function: simply
  1968. ;; display contents of the drawer.
  1969. contents)))
  1970. (org-e-html--wrap-label drawer output)))
  1971. ;;;; Dynamic Block
  1972. (defun org-e-html-dynamic-block (dynamic-block contents info)
  1973. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1974. CONTENTS holds the contents of the block. INFO is a plist
  1975. holding contextual information. See
  1976. `org-export-data'."
  1977. (org-e-html--wrap-label dynamic-block contents))
  1978. ;;;; Emphasis
  1979. (defun org-e-html-emphasis (emphasis contents info)
  1980. "Transcode EMPHASIS from Org to HTML.
  1981. CONTENTS is the contents of the emphasized text. INFO is a plist
  1982. holding contextual information.."
  1983. ;; (format (cdr (assoc (org-element-get-property :marker emphasis)
  1984. ;; org-e-html-emphasis-alist))
  1985. ;; contents)
  1986. (org-e-html-format-fontify
  1987. contents (cadr (assoc
  1988. (org-element-get-property :marker emphasis)
  1989. '(("*" bold)
  1990. ("/" emphasis)
  1991. ("_" underline)
  1992. ("=" code)
  1993. ("~" verbatim)
  1994. ("+" strike))))))
  1995. ;;;; Entity
  1996. (defun org-e-html-entity (entity contents info)
  1997. "Transcode an ENTITY object from Org to HTML.
  1998. CONTENTS are the definition itself. INFO is a plist holding
  1999. contextual information."
  2000. ;; (let ((ent (org-element-get-property :latex entity)))
  2001. ;; (if (org-element-get-property :latex-math-p entity)
  2002. ;; (format "$%s$" ent)
  2003. ;; ent))
  2004. (org-element-get-property :html entity))
  2005. ;;;; Example Block
  2006. ;; (defun org-odt-format-source-code-or-example-colored
  2007. ;; (lines lang caption textareap cols rows num cont rpllbl fmt))
  2008. (defun org-e-html-format-source-code-or-example-plain
  2009. (lines lang caption textareap cols rows num cont rpllbl fmt)
  2010. (setq lines
  2011. (concat
  2012. "<pre class=\"example\">\n"
  2013. (cond
  2014. (textareap
  2015. (concat
  2016. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
  2017. cols rows)
  2018. lines "</textarea>\n</p>\n"))
  2019. (t
  2020. (with-temp-buffer
  2021. (insert lines)
  2022. (goto-char (point-min))
  2023. (while (re-search-forward "[<>&]" nil t)
  2024. (replace-match (cdr (assq (char-before)
  2025. '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
  2026. t t))
  2027. (buffer-string))))
  2028. "</pre>\n"))
  2029. (unless textareap
  2030. (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
  2031. ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
  2032. ;; (setq lines (replace-match "\\1" t nil lines)))
  2033. lines)
  2034. (defun org-e-html-format-source-code-or-example-colored
  2035. (lines lang caption textareap cols rows num cont rpllbl fmt)
  2036. (let* ((lang-m (when lang
  2037. (or (cdr (assoc lang org-src-lang-modes))
  2038. lang)))
  2039. (mode (and lang-m (intern
  2040. (concat
  2041. (if (symbolp lang-m)
  2042. (symbol-name lang-m)
  2043. lang-m)
  2044. "-mode"))))
  2045. (org-inhibit-startup t)
  2046. (org-startup-folded nil))
  2047. (setq lines
  2048. (with-temp-buffer
  2049. (insert lines)
  2050. (if (functionp mode)
  2051. (funcall mode)
  2052. (fundamental-mode))
  2053. (font-lock-fontify-buffer)
  2054. ;; markup each line separately
  2055. (org-remove-formatting-on-newlines-in-region
  2056. (point-min) (point-max))
  2057. (org-src-mode)
  2058. (set-buffer-modified-p nil)
  2059. (org-export-e-htmlize-region-for-paste
  2060. (point-min) (point-max))))
  2061. (when (string-match "<pre\\([^>]*\\)>\n*" lines)
  2062. (setq lines (replace-match
  2063. (format "<pre class=\"src src-%s\">\n" lang) t t lines)))
  2064. (when caption
  2065. (setq lines
  2066. (concat
  2067. "<div class=\"org-src-container\">"
  2068. (format "<label class=\"org-src-name\">%s</label>" caption)
  2069. lines "</div>")))
  2070. (unless textareap
  2071. (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
  2072. ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
  2073. ;; (setq lines (replace-match "\\1" t nil lines)))
  2074. lines))
  2075. (defun org-e-html-format-source-code-or-example
  2076. (lang code &optional opts indent caption)
  2077. "Format CODE from language LANG and return it formatted for export.
  2078. The CODE is marked up in `org-export-current-backend' format.
  2079. Check if a function by name
  2080. \"org-<backend>-format-source-code-or-example\" is bound. If yes,
  2081. use it as the custom formatter. Otherwise, use the default
  2082. formatter. Default formatters are provided for docbook, html,
  2083. latex and ascii backends. For example, use
  2084. `org-e-html-format-source-code-or-example' to provide a custom
  2085. formatter for export to \"html\".
  2086. If LANG is nil, do not add any fontification.
  2087. OPTS contains formatting options, like `-n' for triggering numbering lines,
  2088. and `+n' for continuing previous numbering.
  2089. Code formatting according to language currently only works for HTML.
  2090. Numbering lines works for all three major backends (html, latex, and ascii).
  2091. INDENT was the original indentation of the block."
  2092. (save-match-data
  2093. (let* ((backend-formatter 'org-e-html-format-source-code-or-example-plain)
  2094. num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
  2095. (setq opts (or opts "")
  2096. num (string-match "[-+]n\\>" opts)
  2097. cont (string-match "\\+n\\>" opts)
  2098. rpllbl (string-match "-r\\>" opts)
  2099. keepp (string-match "-k\\>" opts)
  2100. textareap (string-match "-t\\>" opts)
  2101. preserve-indentp (or org-src-preserve-indentation
  2102. (string-match "-i\\>" opts))
  2103. cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
  2104. (string-to-number (match-string 1 opts))
  2105. 80)
  2106. rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
  2107. (string-to-number (match-string 1 opts))
  2108. (org-count-lines code))
  2109. fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
  2110. (match-string 1 opts)))
  2111. (when (and textareap
  2112. ;; (eq org-export-current-backend 'html)
  2113. )
  2114. ;; we cannot use numbering or highlighting.
  2115. (setq num nil cont nil lang nil))
  2116. (if keepp (setq rpllbl 'keep))
  2117. (setq rtn (if preserve-indentp code (org-remove-indentation code)))
  2118. (when (string-match "^," rtn)
  2119. (setq rtn (with-temp-buffer
  2120. (insert rtn)
  2121. ;; Free up the protected lines
  2122. (goto-char (point-min))
  2123. (while (re-search-forward "^," nil t)
  2124. (if (or (equal lang "org")
  2125. (save-match-data
  2126. (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
  2127. (replace-match ""))
  2128. (end-of-line 1))
  2129. (buffer-string))))
  2130. (when lang
  2131. (if (featurep 'xemacs)
  2132. (require 'htmlize)
  2133. (require 'htmlize nil t)))
  2134. (setq backend-formatter
  2135. (cond
  2136. ((fboundp 'htmlize-region-for-paste)
  2137. 'org-e-html-format-source-code-or-example-colored)
  2138. (t
  2139. (message
  2140. "htmlize.el 1.34 or later is needed for source code formatting")
  2141. 'org-e-html-format-source-code-or-example-plain)))
  2142. (funcall backend-formatter rtn lang caption textareap cols rows
  2143. num cont rpllbl fmt))))
  2144. (defun org-e-html-example-block (example-block contents info)
  2145. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  2146. CONTENTS is nil. INFO is a plist holding contextual information."
  2147. (let* ((options (or (org-element-get-property :options example-block) ""))
  2148. (value (org-export-handle-code example-block info)))
  2149. ;; (org-e-html--wrap-label
  2150. ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
  2151. (org-e-html--wrap-label
  2152. example-block (org-e-html-format-source-code-or-example nil value))))
  2153. ;;;; Export Snippet
  2154. (defun org-e-html-export-snippet (export-snippet contents info)
  2155. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  2156. CONTENTS is nil. INFO is a plist holding contextual information."
  2157. (org-element-get-property :value export-snippet))
  2158. ;;;; Export Block
  2159. (defun org-e-html-export-block (export-block contents info)
  2160. "Transcode a EXPORT-BLOCK element from Org to HTML.
  2161. CONTENTS is nil. INFO is a plist holding contextual information."
  2162. (when (string= (org-element-get-property :type export-block) "latex")
  2163. (org-remove-indentation (org-element-get-property :value export-block))))
  2164. ;;;; Fixed Width
  2165. (defun org-e-html-fixed-width (fixed-width contents info)
  2166. "Transcode a FIXED-WIDTH element from Org to HTML.
  2167. CONTENTS is nil. INFO is a plist holding contextual information."
  2168. (let* ((value (org-element-normalize-string
  2169. (replace-regexp-in-string
  2170. "^[ \t]*: ?" ""
  2171. (org-element-get-property :value fixed-width)))))
  2172. (org-e-html--wrap-label
  2173. fixed-width (org-e-html-format-source-code-or-example nil value))))
  2174. ;;;; Footnote Definition
  2175. ;; Footnote Definitions are ignored.
  2176. ;;;; Footnote Reference
  2177. (defun org-e-html-footnote-reference (footnote-reference contents info)
  2178. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  2179. CONTENTS is nil. INFO is a plist holding contextual information."
  2180. (concat
  2181. ;; Insert separator between two footnotes in a row.
  2182. (let ((prev (org-export-get-previous-element footnote-reference info)))
  2183. (when (and (listp prev) (eq (car prev) 'footnote-reference))
  2184. org-e-html-footnote-separator))
  2185. (cond
  2186. ((not (org-export-footnote-first-reference-p footnote-reference info))
  2187. (org-e-html-format-footnote-reference
  2188. (org-export-get-footnote-number footnote-reference info)
  2189. "FIXME" 100))
  2190. ;; Inline definitions are secondary strings.
  2191. ((eq (org-element-get-property :type footnote-reference) 'inline)
  2192. (let ((n (org-export-get-footnote-number footnote-reference info))
  2193. (def (format
  2194. "<p>%s</p>"
  2195. (org-trim
  2196. (org-export-secondary-string
  2197. (org-export-get-footnote-definition footnote-reference info)
  2198. 'e-html info)))))
  2199. (push (cons n def) org-e-html-footnotes-alist)
  2200. (org-e-html-format-footnote-reference n def 1)))
  2201. ;; Non-inline footnotes definitions are full Org data.
  2202. (t
  2203. (let ((n (org-export-get-footnote-number footnote-reference info))
  2204. (def (org-trim
  2205. (org-export-data
  2206. (org-export-get-footnote-definition footnote-reference info)
  2207. 'e-html info))))
  2208. (push (cons n def) org-e-html-footnotes-alist)
  2209. (org-e-html-format-footnote-reference n def 1))))))
  2210. ;;;; Headline
  2211. (defun org-e-html-todo (todo)
  2212. (when todo
  2213. (org-e-html-format-fontify
  2214. (concat
  2215. ;; (ignore-errors (org-lparse-get 'TODO-KWD-CLASS-PREFIX))
  2216. org-e-html-todo-kwd-class-prefix
  2217. (org-e-html-fix-class-name todo))
  2218. (list (if (member todo org-done-keywords) "done" "todo")
  2219. todo))))
  2220. (defun org-e-html-headline (headline contents info)
  2221. "Transcode an HEADLINE element from Org to HTML.
  2222. CONTENTS holds the contents of the headline. INFO is a plist
  2223. holding contextual information."
  2224. (let* ((class (plist-get info :latex-class))
  2225. (numberedp (plist-get info :section-numbers))
  2226. ;; Get level relative to current parsed data.
  2227. (level (org-export-get-relative-level headline info))
  2228. ;; (class-sectionning (assoc class org-e-html-classes))
  2229. ;; Section formatting will set two placeholders: one for the
  2230. ;; title and the other for the contents.
  2231. ;; (section-fmt
  2232. ;; (let ((sec (if (and (symbolp (nth 2 class-sectionning))
  2233. ;; (fboundp (nth 2 class-sectionning)))
  2234. ;; (funcall (nth 2 class-sectionning) level numberedp)
  2235. ;; (nth (1+ level) class-sectionning))))
  2236. ;; (cond
  2237. ;; ;; No section available for that LEVEL.
  2238. ;; ((not sec) nil)
  2239. ;; ;; Section format directly returned by a function.
  2240. ;; ((stringp sec) sec)
  2241. ;; ;; (numbered-section . unnumbered-section)
  2242. ;; ((not (consp (cdr sec)))
  2243. ;; (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
  2244. ;; ;; (numbered-open numbered-close)
  2245. ;; ((= (length sec) 2)
  2246. ;; (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
  2247. ;; ;; (num-in num-out no-num-in no-num-out)
  2248. ;; ((= (length sec) 4)
  2249. ;; (if numberedp
  2250. ;; (concat (car sec) "\n%s" (nth 1 sec))
  2251. ;; (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
  2252. (text (org-export-secondary-string
  2253. (org-element-get-property :title headline) 'e-html info))
  2254. (todo (and (plist-get info :with-todo-keywords)
  2255. (let ((todo (org-element-get-property
  2256. :todo-keyword headline)))
  2257. (and todo
  2258. (org-export-secondary-string todo 'e-html info)))))
  2259. (todo-type (and todo (org-element-get-property :todo-type headline)))
  2260. (tags (and (plist-get info :with-tags)
  2261. (org-element-get-property :tags headline)))
  2262. (priority (and (plist-get info :with-priority)
  2263. (org-element-get-property :priority headline)))
  2264. ;; Create the headline text.
  2265. (full-text (if (functionp org-e-html-format-headline-function)
  2266. ;; User-defined formatting function.
  2267. (funcall org-e-html-format-headline-function
  2268. todo todo-type priority text tags)
  2269. ;; Default formatting.
  2270. (concat
  2271. ;; (when todo
  2272. ;; (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  2273. (org-e-html-todo todo) " "
  2274. (when priority (format "\\framebox{\\#%c} " priority))
  2275. text
  2276. ;; (when tags (format "\\hfill{}\\textsc{%s}" tags))
  2277. )))
  2278. ;; Associate some \label to the headline for internal links.
  2279. ;; (headline-label
  2280. ;; (format "\\label{sec-%s}\n"
  2281. ;; (mapconcat 'number-to-string
  2282. ;; (org-export-get-headline-number headline info)
  2283. ;; "-")))
  2284. ;; FIXME - begin
  2285. (headline-no (org-export-get-headline-number headline info))
  2286. (headline-label
  2287. (format "sec-%s" (mapconcat 'number-to-string headline-no "-")))
  2288. (headline-labels (list headline-label))
  2289. (headline-no (org-export-get-headline-number headline info))
  2290. (section-no (mapconcat 'number-to-string headline-no "."))
  2291. ;; FIXME - end
  2292. (pre-blanks (make-string
  2293. (org-element-get-property :pre-blank headline) 10)))
  2294. (cond
  2295. ;; Case 1: This is a footnote section: ignore it.
  2296. ((org-element-get-property :footnote-section-p headline) nil)
  2297. ;; Case 2. This is a deep sub-tree: export it as a list item.
  2298. ;; Also export as items headlines for which no section
  2299. ;; format has been found.
  2300. ;; ((or (not section-fmt) (org-export-low-level-p headline info)) FIXME
  2301. ;; ;; Build the real contents of the sub-tree.
  2302. ;; (let ((low-level-body
  2303. ;; (concat
  2304. ;; ;; If the headline is the first sibling, start a list.
  2305. ;; (when (org-export-first-sibling-p headline info)
  2306. ;; (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
  2307. ;; ;; Itemize headline
  2308. ;; "\\item " full-text "\n" headline-label pre-blanks contents)))
  2309. ;; ;; If headline in the last sibling, close the list, before any
  2310. ;; ;; blank line. Otherwise, simply return LOW-LEVEL-BODY.
  2311. ;; (if (org-export-last-sibling-p headline info)
  2312. ;; (replace-regexp-in-string
  2313. ;; "[ \t\n]*\\'"
  2314. ;; (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
  2315. ;; low-level-body)
  2316. ;; low-level-body)))
  2317. ;; Case 3. Standard headline. Export it as a section.
  2318. (t
  2319. ;; (format section-fmt full-text
  2320. ;; (concat headline-label pre-blanks contents))
  2321. (org-e-html-format-outline contents level section-no full-text tags
  2322. (car (last headline-labels))
  2323. (butlast headline-labels) nil)))))
  2324. ;;;; Horizontal Rule
  2325. (defun org-e-html-horizontal-rule (horizontal-rule contents info)
  2326. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  2327. CONTENTS is nil. INFO is a plist holding contextual information."
  2328. (let ((attr (mapconcat #'identity
  2329. (org-element-get-property :attr_html horizontal-rule)
  2330. " ")))
  2331. (org-e-html--wrap-label horizontal-rule
  2332. (org-e-html-format-horizontal-line))))
  2333. ;;;; Inline Babel Call
  2334. ;; Inline Babel Calls are ignored.
  2335. ;;;; Inline Src Block
  2336. (defun org-e-html-inline-src-block (inline-src-block contents info)
  2337. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  2338. CONTENTS holds the contents of the item. INFO is a plist holding
  2339. contextual information."
  2340. (let* ((org-lang (org-element-get-property :language inline-src-block))
  2341. (code (org-element-get-property :value inline-src-block))
  2342. (separator (org-e-html--find-verb-separator code)))
  2343. (error "FIXME")))
  2344. ;;;; Inlinetask
  2345. (defun org-e-html-format-section (text class &optional id)
  2346. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  2347. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  2348. (defun org-e-html-inlinetask (inlinetask contents info)
  2349. "Transcode an INLINETASK element from Org to HTML.
  2350. CONTENTS holds the contents of the block. INFO is a plist
  2351. holding contextual information."
  2352. (let ((title (org-export-secondary-string
  2353. (org-element-get-property :title inlinetask) 'e-html info))
  2354. (todo (and (plist-get info :with-todo-keywords)
  2355. (let ((todo (org-element-get-property
  2356. :todo-keyword inlinetask)))
  2357. (and todo
  2358. (org-export-secondary-string todo 'e-html info)))))
  2359. (todo-type (org-element-get-property :todo-type inlinetask))
  2360. (tags (and (plist-get info :with-tags)
  2361. (org-element-get-property :tags inlinetask)))
  2362. (priority (and (plist-get info :with-priority)
  2363. (org-element-get-property :priority inlinetask))))
  2364. ;; If `org-e-html-format-inlinetask-function' is provided, call it
  2365. ;; with appropriate arguments.
  2366. (if (functionp org-e-html-format-inlinetask-function)
  2367. (funcall org-e-html-format-inlinetask-function
  2368. todo todo-type priority title tags contents)
  2369. ;; Otherwise, use a default template.
  2370. (org-e-html--wrap-label
  2371. inlinetask
  2372. (let ((full-title
  2373. (concat
  2374. (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  2375. (when priority (format "\\framebox{\\#%c} " priority))
  2376. title
  2377. (when tags (format "\\hfill{}\\textsc{%s}" tags)))))
  2378. (format (concat "\\begin{center}\n"
  2379. "\\fbox{\n"
  2380. "\\begin{minipage}[c]{.6\\textwidth}\n"
  2381. "%s\n\n"
  2382. "\\rule[.8em]{\\textwidth}{2pt}\n\n"
  2383. "%s"
  2384. "\\end{minipage}\n"
  2385. "}\n"
  2386. "\\end{center}")
  2387. full-title contents))))))
  2388. ;;;; Item
  2389. (defun org-e-html-format-list-item (contents type &optional arg headline)
  2390. (setq headline nil) ; FIXME
  2391. (concat
  2392. (case type
  2393. (ordered
  2394. (let* ((counter arg)
  2395. (extra (if counter (format " value=\"%s\"" counter) "")))
  2396. (format "<li%s>" extra)))
  2397. (unordered
  2398. (let* ((id arg)
  2399. (extra (if id (format " id=\"%s\"" id) "")))
  2400. (concat
  2401. (format "<li%s>" extra)
  2402. (when headline (concat headline "<br/>")))))
  2403. (descriptive
  2404. (let* ((desc-tag (or arg "(no term)")))
  2405. (concat (format "<dt> %s </dt>" desc-tag) "<dd>"))))
  2406. contents
  2407. (case type
  2408. (ordered "</li>")
  2409. (unordered "</li>")
  2410. (descriptive "</dd>"))))
  2411. (defun org-e-html-item (item contents info)
  2412. "Transcode an ITEM element from Org to HTML.
  2413. CONTENTS holds the contents of the item. INFO is a plist holding
  2414. contextual information."
  2415. ;; Grab `:level' from plain-list properties, which is always the
  2416. ;; first element above current item.
  2417. (let* ((plain-list (car (org-export-get-genealogy item info)))
  2418. (type (org-element-get-property :type plain-list))
  2419. (level (org-element-get-property
  2420. :level (car (plist-get info :genealogy))))
  2421. (counter (let ((count (org-element-get-property :counter item)))
  2422. (and count
  2423. (< level 4)
  2424. (format "\\setcounter{enum%s}{%s}\n"
  2425. (nth level '("i" "ii" "iii" "iv"))
  2426. (1- count)))))
  2427. (checkbox (let ((checkbox (org-element-get-property :checkbox item)))
  2428. (cond ((eq checkbox 'on) "$\\boxtimes$ ")
  2429. ((eq checkbox 'off) "$\\Box$ ")
  2430. ((eq checkbox 'trans) "$\\boxminus$ "))))
  2431. (tag (let ((tag (org-element-get-property :tag item)))
  2432. (and tag
  2433. (format "[%s]" (org-export-secondary-string
  2434. tag 'e-html info))))))
  2435. ;; (concat counter "\\item" tag " " checkbox contents)
  2436. (org-e-html-format-list-item contents type nil)))
  2437. ;;;; Keyword
  2438. (defun org-e-html-keyword (keyword contents info)
  2439. "Transcode a KEYWORD element from Org to HTML.
  2440. CONTENTS is nil. INFO is a plist holding contextual information."
  2441. (let ((key (downcase (org-element-get-property :key keyword)))
  2442. (value (org-element-get-property :value keyword)))
  2443. (cond
  2444. ((string= key "latex") value)
  2445. ((string= key "index") (format "\\index{%s}" value))
  2446. ((string= key "target")
  2447. (format "\\label{%s}" (org-export-solidify-link-text value)))
  2448. ((string= key "toc")
  2449. (let ((value (downcase value)))
  2450. (cond
  2451. ((string-match "\\<headlines\\>" value)
  2452. (let ((depth (or (and (string-match "[0-9]+" value)
  2453. (string-to-number (match-string 0 value)))
  2454. (plist-get info :with-toc))))
  2455. (concat
  2456. (when (wholenump depth)
  2457. (format "\\setcounter{tocdepth}{%s}\n" depth))
  2458. "\\tableofcontents")))
  2459. ((string= "tables" value) "\\listoftables")
  2460. ((string= "figures" value) "\\listoffigures")
  2461. ((string= "listings" value)
  2462. (cond
  2463. ;; At the moment, src blocks with a caption are wrapped
  2464. ;; into a figure environment.
  2465. (t "\\listoffigures")))))))))
  2466. ;;;; Latex Environment
  2467. (defun org-e-html-format-latex (latex-frag processing-type)
  2468. (let* ((cache-relpath
  2469. (concat "ltxpng/" (file-name-sans-extension
  2470. (file-name-nondirectory (buffer-file-name)))))
  2471. (cache-dir (file-name-directory (buffer-file-name )))
  2472. (display-msg "Creating LaTeX Image..."))
  2473. (with-temp-buffer
  2474. (insert latex-frag)
  2475. (org-format-latex cache-relpath cache-dir nil display-msg
  2476. nil nil processing-type)
  2477. (buffer-string))))
  2478. (defun org-e-html-latex-environment (latex-environment contents info)
  2479. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  2480. CONTENTS is nil. INFO is a plist holding contextual information."
  2481. (org-e-html--wrap-label
  2482. latex-environment
  2483. (let ((latex-frag
  2484. (org-remove-indentation
  2485. (org-element-get-property :value latex-environment)))
  2486. (processing-type (plist-get info :LaTeX-fragments)))
  2487. (cond
  2488. ((member processing-type '(t mathjax))
  2489. (org-e-html-format-latex latex-frag 'mathjax))
  2490. ((equal processing-type 'dvipng)
  2491. (let* ((formula-link (org-e-html-format-latex
  2492. latex-frag processing-type)))
  2493. (when (and formula-link
  2494. (string-match "file:\\([^]]*\\)" formula-link))
  2495. (org-e-html-format-inline-image (match-string 1 formula-link)))))
  2496. (t
  2497. latex-frag)))))
  2498. ;;;; Latex Fragment
  2499. (defun org-e-html-latex-fragment (latex-fragment contents info)
  2500. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2501. CONTENTS is nil. INFO is a plist holding contextual information."
  2502. ;; (org-element-get-property :value latex-fragment)
  2503. (let* ((latex-frag (org-element-get-property :value latex-fragment)))
  2504. (cond
  2505. ((string-match "\\\\ref{\\([^{}\n]+\\)}" latex-frag)
  2506. (let* ((label (match-string 1 latex-frag))
  2507. (href (and label (org-export-solidify-link-text label)))
  2508. (text (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  2509. (substring label (match-beginning 1))
  2510. label)))
  2511. (org-e-html-format-internal-link text href)))
  2512. (t (let ((processing-type (plist-get info :LaTeX-fragments)))
  2513. (cond
  2514. ((member processing-type '(t mathjax))
  2515. (org-e-html-format-latex latex-frag 'mathjax))
  2516. ((equal processing-type 'dvipng)
  2517. (let* ((formula-link (org-e-html-format-latex
  2518. latex-frag processing-type)))
  2519. (when (and formula-link
  2520. (string-match "file:\\([^]]*\\)" formula-link))
  2521. (org-e-html-format-inline-image
  2522. (match-string 1 formula-link)))))
  2523. (t latex-frag)))))))
  2524. ;;;; Line Break
  2525. (defun org-e-html-line-break (line-break contents info)
  2526. "Transcode a LINE-BREAK object from Org to HTML.
  2527. CONTENTS is nil. INFO is a plist holding contextual information."
  2528. "<br/>")
  2529. ;;;; Link
  2530. (defun org-e-html-link--inline-image (link info)
  2531. "Return HTML code for an inline image.
  2532. LINK is the link pointing to the inline image. INFO is a plist
  2533. used as a communication channel."
  2534. (let* ((parent (org-export-get-parent-paragraph link info))
  2535. (path (let ((raw-path (org-element-get-property :path link)))
  2536. (if (not (file-name-absolute-p raw-path)) raw-path
  2537. (expand-file-name raw-path))))
  2538. (caption (org-e-html--caption/label-string
  2539. (org-element-get-property :caption parent)
  2540. (org-element-get-property :name parent)
  2541. info))
  2542. (label (org-element-get-property :name parent))
  2543. ;; Retrieve latex attributes from the element around.
  2544. (attr (let ((raw-attr
  2545. (mapconcat #'identity
  2546. (org-element-get-property :attr_html parent)
  2547. " ")))
  2548. (unless (string= raw-attr "") raw-attr))))
  2549. ;; Now clear ATTR from any special keyword and set a default
  2550. ;; value if nothing is left.
  2551. (setq attr (if (not attr) "" (org-trim attr)))
  2552. ;; Return proper string, depending on DISPOSITION.
  2553. (let ((href (and label (org-export-solidify-link-text label))))
  2554. (org-e-html-format-inline-image path caption href attr))))
  2555. (defun org-e-html-link (link desc info)
  2556. "Transcode a LINK object from Org to HTML.
  2557. DESC is the description part of the link, or the empty string.
  2558. INFO is a plist holding contextual information. See
  2559. `org-export-data'."
  2560. (let* ((type (org-element-get-property :type link))
  2561. (raw-path (org-element-get-property :path link))
  2562. ;; Ensure DESC really exists, or set it to nil.
  2563. (desc (and (not (string= desc "")) desc))
  2564. (imagep (org-export-inline-image-p
  2565. link org-e-html-inline-image-rules))
  2566. (path (cond
  2567. ((member type '("http" "https" "ftp" "mailto"))
  2568. (concat type ":" raw-path))
  2569. ((string= type "file")
  2570. (when (string-match "\\(.+\\)::.+" raw-path)
  2571. (setq raw-path (match-string 1 raw-path)))
  2572. (if (file-name-absolute-p raw-path)
  2573. (concat "file://" (expand-file-name raw-path))
  2574. ;; TODO: Not implemented yet. Concat also:
  2575. ;; (org-export-directory :HTML info)
  2576. (concat "file://" raw-path)))
  2577. (t raw-path)))
  2578. protocol)
  2579. (cond
  2580. ;; Image file.
  2581. (imagep (org-e-html-link--inline-image link info))
  2582. ;; Target or radioed target: replace link with the normalized
  2583. ;; custom-id/target name.
  2584. ((member type '("target" "radio"))
  2585. (org-e-html-format-internal-link
  2586. (or desc (org-export-secondary-string path 'e-html info))
  2587. (org-export-solidify-link-text path)))
  2588. ;; Links pointing to an headline: Find destination and build
  2589. ;; appropriate referencing commanding.
  2590. ((member type '("custom-id" "fuzzy" "id"))
  2591. (let ((destination (if (string= type "fuzzy")
  2592. (org-export-resolve-fuzzy-link link info)
  2593. (org-export-resolve-id-link link info))))
  2594. ;; Fuzzy link points to a target. Do as above.
  2595. (case (car destination)
  2596. (target
  2597. (org-e-html-format-internal-link
  2598. (or desc
  2599. (org-export-secondary-string
  2600. (org-element-get-property :raw-link link)
  2601. 'e-html info))
  2602. (org-export-solidify-link-text
  2603. (org-element-get-property :raw-value destination))))
  2604. ;; Fuzzy link points to an headline. If headlines are
  2605. ;; numbered and the link has no description, display
  2606. ;; headline's number. Otherwise, display description or
  2607. ;; headline's title.
  2608. (headline
  2609. (let ((label
  2610. (format "sec-%s"
  2611. (mapconcat
  2612. 'number-to-string
  2613. (org-export-get-headline-number destination info)
  2614. "-"))))
  2615. (if (and (plist-get info :section-numbers) (not desc))
  2616. (format "\\ref{%s}" label)
  2617. (org-e-html-format-internal-link
  2618. (or desc
  2619. (org-export-secondary-string
  2620. (org-element-get-property :title destination)
  2621. 'e-html info)) label))))
  2622. ;; Fuzzy link points nowhere.
  2623. (otherwise
  2624. (org-e-html-format-fontify
  2625. (or desc
  2626. (org-export-secondary-string
  2627. (org-element-get-property :raw-link link)
  2628. 'e-html info)) 'emphasis)))))
  2629. ;; Coderef: replace link with the reference name or the
  2630. ;; equivalent line number.
  2631. ((string= type "coderef")
  2632. (format (org-export-get-coderef-format path (or desc ""))
  2633. (org-export-resolve-coderef path info)))
  2634. ;; Link type is handled by a special function.
  2635. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2636. (funcall protocol (org-link-unescape path) desc 'html))
  2637. ;; External link with a description part.
  2638. ((and path desc) (org-e-html-format-link desc path))
  2639. ;; External link without a description part.
  2640. (path (org-e-html-format-link path path))
  2641. ;; No path, only description. Try to do something useful.
  2642. (t (org-e-html-format-fontify desc 'emphasis)))))
  2643. ;;;; Babel Call
  2644. ;; Babel Calls are ignored.
  2645. ;;;; Macro
  2646. (defun org-e-html-macro (macro contents info)
  2647. "Transcode a MACRO element from Org to HTML.
  2648. CONTENTS is nil. INFO is a plist holding contextual information."
  2649. ;; Use available tools.
  2650. (org-export-expand-macro macro info))
  2651. ;;;; Paragraph
  2652. (defun org-e-html-paragraph (paragraph contents info)
  2653. "Transcode a PARAGRAPH element from Org to HTML.
  2654. CONTENTS is the contents of the paragraph, as a string. INFO is
  2655. the plist used as a communication channel."
  2656. (let* ((style nil) ; FIXME
  2657. (class (cdr (assoc style '((footnote . "footnote")
  2658. (verse . nil)))))
  2659. (extra (if class (format " class=\"%s\"" class) ""))
  2660. (parent (car (org-export-get-genealogy paragraph info))))
  2661. (cond
  2662. ;; is this the first paragraph in a list item
  2663. ;; (plain-list (car (org-export-get-genealogy item info)))
  2664. ;; (type (org-element-get-property :type plain-list))
  2665. ((and (equal parent 'item)
  2666. (= (org-element-get-property :begin paragraph)
  2667. (plist-get (plist-get info :parent-properties)
  2668. :contents-begin)))
  2669. contents)
  2670. (t
  2671. (concat (format "<p%s> " extra) contents "</p>")))))
  2672. ;;;; Plain List
  2673. (defun org-e-html-plain-list (plain-list contents info)
  2674. "Transcode a PLAIN-LIST element from Org to HTML.
  2675. CONTENTS is the contents of the list. INFO is a plist holding
  2676. contextual information."
  2677. (let* ((type (org-element-get-property :type plain-list))
  2678. (paralist-types '("inparaenum" "asparaenum" "inparaitem" "asparaitem"
  2679. "inparadesc" "asparadesc"))
  2680. (paralist-regexp (concat
  2681. "\\("
  2682. (mapconcat 'identity paralist-types "\\|")
  2683. "\\)"))
  2684. (attr (mapconcat #'identity
  2685. (org-element-get-property :attr_html plain-list)
  2686. " "))
  2687. (latex-type (cond
  2688. ((and attr
  2689. (string-match
  2690. (format "\\<%s\\>" paralist-regexp) attr))
  2691. (match-string 1 attr))
  2692. ((eq type 'ordered) "enumerate")
  2693. ((eq type 'unordered) "itemize")
  2694. ((eq type 'descriptive) "description")))
  2695. arg1 ;; FIXME
  2696. )
  2697. (org-e-html--wrap-label
  2698. plain-list
  2699. ;; (format "\\begin{%s}%s\n%s\\end{%s}"
  2700. ;; latex-type
  2701. ;; ;; Once special environment, if any, has been removed, the
  2702. ;; ;; rest of the attributes will be optional arguments.
  2703. ;; ;; They will be put inside square brackets if necessary.
  2704. ;; (let ((opt (replace-regexp-in-string
  2705. ;; (format " *%s *" paralist-regexp) "" attr)))
  2706. ;; (cond ((string= opt "") "")
  2707. ;; ((string-match "\\`\\[[^][]+\\]\\'" opt) opt)
  2708. ;; (t (format "[%s]" opt))))
  2709. ;; contents
  2710. ;; latex-type)
  2711. (format "%s\n%s%s"
  2712. (case type
  2713. (ordered
  2714. (format "<ol%s>" (if arg1
  2715. (format " start=\"%d\"" arg1)
  2716. "")))
  2717. (unordered "<ul>")
  2718. (descriptive "<dl>"))
  2719. contents
  2720. (case type
  2721. (ordered "</ol>")
  2722. (unordered "</ul>")
  2723. (descriptive "</dl>")))
  2724. )))
  2725. ;;;; Plain Text
  2726. (defun org-e-html-convert-special-strings (string)
  2727. "Convert special characters in STRING to HTML."
  2728. (let ((all org-e-html-special-string-regexps)
  2729. e a re rpl start)
  2730. (while (setq a (pop all))
  2731. (setq re (car a) rpl (cdr a) start 0)
  2732. (while (string-match re string start)
  2733. (setq string (replace-match rpl t nil string))))
  2734. string))
  2735. (defun org-e-html-encode-plain-text (s)
  2736. "Convert plain text characters to HTML equivalent.
  2737. Possible conversions are set in `org-export-html-protect-char-alist'."
  2738. (let ((cl org-e-html-protect-char-alist) c)
  2739. (while (setq c (pop cl))
  2740. (let ((start 0))
  2741. (while (string-match (car c) s start)
  2742. (setq s (replace-match (cdr c) t t s)
  2743. start (1+ (match-beginning 0))))))
  2744. s))
  2745. (defun org-e-html-plain-text (text info)
  2746. "Transcode a TEXT string from Org to HTML.
  2747. TEXT is the string to transcode. INFO is a plist holding
  2748. contextual information."
  2749. (setq text (org-e-html-encode-plain-text text))
  2750. ;; Protect %, #, &, $, ~, ^, _, { and }.
  2751. ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
  2752. ;; (setq text
  2753. ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
  2754. ;; Protect \
  2755. ;; (setq text (replace-regexp-in-string
  2756. ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
  2757. ;; "$\\backslash$" text nil t 1))
  2758. ;; HTML into \HTML{} and TeX into \TeX{}.
  2759. ;; (let ((case-fold-search nil)
  2760. ;; (start 0))
  2761. ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
  2762. ;; (setq text (replace-match
  2763. ;; (format "\\%s{}" (match-string 1 text)) nil t text)
  2764. ;; start (match-end 0))))
  2765. ;; Handle quotation marks
  2766. ;; (setq text (org-e-html--quotation-marks text info))
  2767. ;; Convert special strings.
  2768. ;; (when (plist-get info :with-special-strings)
  2769. ;; (while (string-match (regexp-quote "...") text)
  2770. ;; (setq text (replace-match "\\ldots{}" nil t text))))
  2771. (when (plist-get info :with-special-strings)
  2772. (setq text (org-e-html-convert-special-strings text)))
  2773. ;; Handle break preservation if required.
  2774. (when (plist-get info :preserve-breaks)
  2775. (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
  2776. text)))
  2777. ;; Return value.
  2778. text)
  2779. ;;;; Property Drawer
  2780. (defun org-e-html-property-drawer (property-drawer contents info)
  2781. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2782. CONTENTS is nil. INFO is a plist holding contextual
  2783. information."
  2784. ;; The property drawer isn't exported but we want separating blank
  2785. ;; lines nonetheless.
  2786. "")
  2787. ;;;; Quote Block
  2788. (defun org-e-html-quote-block (quote-block contents info)
  2789. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2790. CONTENTS holds the contents of the block. INFO is a plist
  2791. holding contextual information."
  2792. (org-e-html--wrap-label
  2793. quote-block (format "<blockquote>\n%s</blockquote>" contents)))
  2794. ;;;; Quote Section
  2795. (defun org-e-html-quote-section (quote-section contents info)
  2796. "Transcode a QUOTE-SECTION element from Org to HTML.
  2797. CONTENTS is nil. INFO is a plist holding contextual information."
  2798. (let ((value (org-remove-indentation
  2799. (org-element-get-property :value quote-section))))
  2800. (when value (format "<pre>\n%s</pre>" value))))
  2801. ;;;; Section
  2802. (defun org-e-html-section (section contents info)
  2803. "Transcode a SECTION element from Org to HTML.
  2804. CONTENTS holds the contents of the section. INFO is a plist
  2805. holding contextual information."
  2806. contents)
  2807. ;;;; Radio Target
  2808. (defun org-e-html-radio-target (radio-target text info)
  2809. "Transcode a RADIO-TARGET object from Org to HTML.
  2810. TEXT is the text of the target. INFO is a plist holding
  2811. contextual information."
  2812. (org-e-html-format-anchor
  2813. text (org-export-solidify-link-text
  2814. (org-element-get-property :raw-value radio-target))))
  2815. ;;;; Special Block
  2816. (defun org-e-html-special-block (special-block contents info)
  2817. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2818. CONTENTS holds the contents of the block. INFO is a plist
  2819. holding contextual information."
  2820. (let ((type (downcase (org-element-get-property :type special-block))))
  2821. (org-e-html--wrap-label
  2822. special-block
  2823. (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
  2824. ;;;; Src Block
  2825. (defun org-e-html-src-block (src-block contents info)
  2826. "Transcode a SRC-BLOCK element from Org to HTML.
  2827. CONTENTS holds the contents of the item. INFO is a plist holding
  2828. contextual information."
  2829. (let* ((lang (org-element-get-property :language src-block))
  2830. (code (org-export-handle-code src-block info))
  2831. (caption (org-element-get-property :caption src-block))
  2832. (label (org-element-get-property :name src-block)))
  2833. ;; FIXME: Handle caption
  2834. ;; caption-str (when caption)
  2835. ;; (main (org-export-secondary-string (car caption) 'e-html info))
  2836. ;; (secondary (org-export-secondary-string (cdr caption) 'e-html info))
  2837. ;; (caption-str (org-e-html--caption/label-string caption label info))
  2838. (org-e-html-format-source-code-or-example lang code)))
  2839. ;;;; Statistics Cookie
  2840. (defun org-e-html-statistics-cookie (statistics-cookie contents info)
  2841. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2842. CONTENTS is nil. INFO is a plist holding contextual information."
  2843. (org-element-get-property :value statistics-cookie))
  2844. ;;;; Subscript
  2845. (defun org-e-html-subscript (subscript contents info)
  2846. "Transcode a SUBSCRIPT object from Org to HTML.
  2847. CONTENTS is the contents of the object. INFO is a plist holding
  2848. contextual information."
  2849. ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
  2850. (org-e-html-format-fontify contents 'subscript))
  2851. ;;;; Superscript
  2852. (defun org-e-html-superscript (superscript contents info)
  2853. "Transcode a SUPERSCRIPT object from Org to HTML.
  2854. CONTENTS is the contents of the object. INFO is a plist holding
  2855. contextual information."
  2856. ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
  2857. (org-e-html-format-fontify contents 'superscript))
  2858. ;;;; Table
  2859. (defun org-e-html-table--format-string (table table-info info)
  2860. "Return an appropriate format string for TABLE.
  2861. TABLE-INFO is the plist containing format info about the table,
  2862. as returned by `org-export-table-format-info'. INFO is a plist
  2863. used as a communication channel.
  2864. The format string leaves one placeholder for the body of the
  2865. table."
  2866. (let* ((label (org-element-get-property :name table))
  2867. (caption (org-e-html--caption/label-string
  2868. (org-element-get-property :caption table) label info))
  2869. (attr (mapconcat 'identity
  2870. (org-element-get-property :attr_html table)
  2871. " "))
  2872. ;; Determine alignment string.
  2873. (alignment (org-e-html-table--align-string attr table-info))
  2874. ;; Determine environment for the table: longtable, tabular...
  2875. (table-env (cond
  2876. ((not attr) org-e-html-default-table-environment)
  2877. ((string-match "\\<longtable\\>" attr) "longtable")
  2878. ((string-match "\\<tabular.?\\>" attr)
  2879. (org-match-string-no-properties 0 attr))
  2880. (t org-e-html-default-table-environment)))
  2881. ;; If table is a float, determine environment: table or table*.
  2882. (float-env (cond
  2883. ((string= "longtable" table-env) nil)
  2884. ((and attr
  2885. (or (string-match (regexp-quote "table*") attr)
  2886. (string-match "\\<multicolumn\\>" attr)))
  2887. "table*")
  2888. ((or (not (string= caption "")) label) "table")))
  2889. ;; Extract others display options.
  2890. (width (and attr (string-match "\\<width=\\(\\S-+\\)" attr)
  2891. (org-match-string-no-properties 1 attr)))
  2892. (placement
  2893. (if (and attr (string-match "\\<placement=\\(\\S-+\\)" attr))
  2894. (org-match-string-no-properties 1 attr)
  2895. (format "[%s]" org-e-html-default-figure-position))))
  2896. ;; Prepare the final format string for the table.
  2897. (cond
  2898. ;; Longtable.
  2899. ((string= "longtable" table-env)
  2900. (format
  2901. "\\begin{longtable}{%s}\n%s\n%%s\n%s\\end{longtable}"
  2902. alignment
  2903. (if (or (not org-e-html-table-caption-above) (string= "" caption)) ""
  2904. (concat (org-trim caption) "\\\\"))
  2905. (if (or org-e-html-table-caption-above (string= "" caption)) ""
  2906. (concat (org-trim caption) "\\\\\n"))))
  2907. ;; Others.
  2908. (t (concat (when float-env
  2909. (concat
  2910. (format "\\begin{%s}%s\n" float-env placement)
  2911. (if org-e-html-table-caption-above caption "")))
  2912. (when org-e-html-tables-centered "\\begin{center}\n")
  2913. (format "\\begin{%s}%s{%s}\n%%s\n\\end{%s}"
  2914. table-env
  2915. (if width (format "{%s}" width) "") alignment table-env)
  2916. (when org-e-html-tables-centered "\n\\end{center}")
  2917. (when float-env
  2918. (concat (if org-e-html-table-caption-above "" caption)
  2919. (format "\n\\end{%s}" float-env))))))))
  2920. (defun org-e-html-table--align-string (attr table-info)
  2921. "Return an appropriate HTML alignment string.
  2922. ATTR is a string containing table's HTML specific attributes.
  2923. TABLE-INFO is the plist containing format info about the table,
  2924. as returned by `org-export-table-format-info'."
  2925. (or (and attr
  2926. (string-match "\\<align=\\(\\S-+\\)" attr)
  2927. (match-string 1 attr))
  2928. (let* ((align (copy-sequence (plist-get table-info :alignment)))
  2929. (colgroups (copy-sequence (plist-get table-info :column-groups)))
  2930. (cols (length align))
  2931. (separators (make-vector (1+ cols) "")))
  2932. ;; Ignore the first column if it's special.
  2933. (when (plist-get table-info :special-column-p)
  2934. (aset align 0 "") (aset colgroups 0 nil))
  2935. (let ((col 0))
  2936. (mapc (lambda (el)
  2937. (let ((gr (aref colgroups col)))
  2938. (when (memq gr '(start start-end))
  2939. (aset separators col "|"))
  2940. (when (memq gr '(end start-end))
  2941. (aset separators (1+ col) "|")))
  2942. (incf col))
  2943. align))
  2944. ;; Build the HTML specific alignment string.
  2945. (loop for al across align
  2946. for sep across separators
  2947. concat (concat sep al) into output
  2948. finally return (concat output (aref separators cols))))))
  2949. ;; tables
  2950. (defun org-e-html-begin-table (caption label attributes)
  2951. (let* ((html-table-tag (or (plist-get info :html-table-tag) ; FIXME
  2952. org-e-html-table-tag))
  2953. (html-table-tag
  2954. (org-export-splice-attributes html-table-tag attributes)))
  2955. (when label
  2956. (setq html-table-tag
  2957. (org-export-splice-attributes
  2958. html-table-tag
  2959. (format "id=\"%s\"" (org-solidify-link-text label)))))
  2960. (concat "\n" html-table-tag
  2961. (format "\n<caption>%s</caption>" (or caption "")))))
  2962. (defun org-e-html-end-table ()
  2963. (when org-lparse-table-is-styled
  2964. ;; column groups
  2965. ;; (unless (car org-table-colgroup-info)
  2966. ;; (setq org-table-colgroup-info
  2967. ;; (cons :start (cdr org-table-colgroup-info))))
  2968. ;; column alignment
  2969. (let ((c -1))
  2970. ;; (mapc
  2971. ;; (lambda (x)
  2972. ;; (incf c)
  2973. ;; (setf (aref org-lparse-table-colalign-vector c)
  2974. ;; (or (aref org-lparse-table-colalign-vector c)
  2975. ;; (if (> (/ (float x) (1+ org-lparse-table-rownum))
  2976. ;; org-table-number-fraction)
  2977. ;; "right" "left"))))
  2978. ;; org-lparse-table-num-numeric-items-per-column)
  2979. ))
  2980. ;; html specific stuff starts here
  2981. ;; (org-e-html-end-table)
  2982. "</table>\n")
  2983. (defun org-e-html-format-table-cell (text r c horiz-span)
  2984. (let ((cell-style-cookie
  2985. (if org-e-html-table-align-individual-fields
  2986. (format (if (and (boundp 'org-e-html-format-table-no-css)
  2987. org-e-html-format-table-no-css)
  2988. " align=\"%s\"" " class=\"%s\"")
  2989. (or (aref (plist-get table-info :alignment) c) "left")) ""))) ;; FIXME
  2990. (cond
  2991. (org-lparse-table-cur-rowgrp-is-hdr
  2992. (concat
  2993. (format (car org-export-table-header-tags) "col" cell-style-cookie)
  2994. text (cdr org-export-table-header-tags)))
  2995. ((and (= c 0) org-e-html-table-use-header-tags-for-first-column)
  2996. (concat
  2997. (format (car org-export-table-header-tags) "row" cell-style-cookie)
  2998. text (cdr org-export-table-header-tags)))
  2999. (t
  3000. (concat
  3001. (format (car org-export-table-data-tags) cell-style-cookie)
  3002. text (cdr org-export-table-data-tags))))))
  3003. (defun org-e-html-format-table-row (row)
  3004. (concat (eval (car org-export-table-row-tags)) row
  3005. (eval (cdr org-export-table-row-tags))))
  3006. (defun org-e-html-table-row (fields &optional text-for-empty-fields)
  3007. (if org-lparse-table-ncols
  3008. ;; second and subsequent rows of the table
  3009. ;; (when (and org-lparse-list-table-p
  3010. ;; (> (length fields) org-lparse-table-ncols))
  3011. ;; (error "Table row has %d columns but header row claims %d columns"
  3012. ;; (length fields) org-lparse-table-ncols))
  3013. ;; first row of the table
  3014. (setq org-lparse-table-ncols (length fields))
  3015. ;; (when org-lparse-table-is-styled
  3016. ;; (setq org-lparse-table-num-numeric-items-per-column
  3017. ;; (make-vector org-lparse-table-ncols 0)))
  3018. )
  3019. (incf org-lparse-table-rownum)
  3020. (let ((i -1))
  3021. (org-e-html-format-table-row
  3022. (mapconcat
  3023. (lambda (x)
  3024. (when (and (string= x "") text-for-empty-fields)
  3025. (setq x text-for-empty-fields))
  3026. (incf i)
  3027. (let (col-cookie horiz-span)
  3028. (when org-lparse-table-is-styled
  3029. ;; (when (and (< i org-lparse-table-ncols)
  3030. ;; (string-match org-table-number-regexp x))
  3031. ;; (incf (aref org-lparse-table-num-numeric-items-per-column i)))
  3032. (setq col-cookie (cdr (assoc (1+ i) org-lparse-table-colalign-info))
  3033. horiz-span (nth 1 col-cookie)))
  3034. (org-e-html-format-table-cell
  3035. x org-lparse-table-rownum i (or horiz-span 0))))
  3036. fields "\n"))))
  3037. (defun org-e-html-end-table-rowgroup ()
  3038. (when org-lparse-table-rowgrp-open
  3039. (setq org-lparse-table-rowgrp-open nil)
  3040. (if org-lparse-table-cur-rowgrp-is-hdr "</thead>" "</tbody>")))
  3041. (defun org-e-html-begin-table-rowgroup (&optional is-header-row)
  3042. (concat
  3043. (when org-lparse-table-rowgrp-open
  3044. (org-e-html-end-table-rowgroup))
  3045. (progn
  3046. (setq org-lparse-table-rowgrp-open t)
  3047. (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row)
  3048. (if is-header-row "<thead>" "<tbody>"))))
  3049. (defun org-e-html-table-preamble ()
  3050. (let ((colgroup-vector (plist-get table-info :column-groups)) ;; FIXME
  3051. c gr colgropen preamble)
  3052. (unless (aref colgroup-vector 0)
  3053. (setf (aref colgroup-vector 0) 'start))
  3054. (dotimes (c columns-number preamble)
  3055. (setq gr (aref colgroup-vector c))
  3056. (setq preamble
  3057. (concat
  3058. preamble
  3059. (when (memq gr '(start start-end))
  3060. (prog1 (if colgropen "</colgroup>\n<colgroup>" "\n<colgroup>")
  3061. (setq colgropen t)))
  3062. (let* ((colalign-vector (plist-get table-info :alignment)) ;; FIXME
  3063. (align (cdr (assoc (aref colalign-vector c)
  3064. '(("l" . "left")
  3065. ("r" . "right")
  3066. ("c" . "center")))))
  3067. (alignspec (if (and (boundp 'org-e-html-format-table-no-css)
  3068. org-e-html-format-table-no-css)
  3069. " align=\"%s\"" " class=\"%s\""))
  3070. (extra (format alignspec align)))
  3071. (format "<col%s />" extra))
  3072. (when (memq gr '(end start-end))
  3073. (setq colgropen nil)
  3074. "</colgroup>"))))
  3075. (concat preamble (if colgropen "</colgroup>"))))
  3076. (defun org-e-html-list-table (lines &optional splice
  3077. caption label attributes head
  3078. org-lparse-table-colalign-info)
  3079. (or (featurep 'org-table) ; required for
  3080. (require 'org-table)) ; `org-table-number-regexp'
  3081. (let* ((org-lparse-table-rownum -1)
  3082. (org-lparse-table-ncols (length (plist-get info :alignment)))
  3083. i (cnt 0)
  3084. tbopen fields line
  3085. org-lparse-table-cur-rowgrp-is-hdr
  3086. org-lparse-table-rowgrp-open
  3087. ;; org-lparse-table-num-numeric-items-per-column
  3088. org-lparse-table-colalign-vector n
  3089. org-lparse-table-rowgrp-info
  3090. (org-lparse-table-style 'org-table)
  3091. org-lparse-table-is-styled)
  3092. (cond
  3093. (splice
  3094. (setq org-lparse-table-is-styled nil)
  3095. (mapconcat 'org-e-html-table-row lines "\n"))
  3096. (t
  3097. (setq org-lparse-table-is-styled t)
  3098. (concat
  3099. (org-e-html-begin-table caption label attributes)
  3100. (org-e-html-table-preamble)
  3101. (progn (push (cons (1+ org-lparse-table-rownum) :start)
  3102. org-lparse-table-rowgrp-info)
  3103. (org-e-html-begin-table-rowgroup head))
  3104. (mapconcat
  3105. (lambda (line)
  3106. (cond
  3107. ((equal line :hrule)
  3108. (push (cons (1+ org-lparse-table-rownum) :start)
  3109. org-lparse-table-rowgrp-info)
  3110. (org-e-html-begin-table-rowgroup))
  3111. (t
  3112. (org-e-html-table-row line))))
  3113. lines "\n")
  3114. (org-e-html-end-table-rowgroup)
  3115. (org-e-html-end-table))))))
  3116. (defun org-e-html-org-table-to-list-table (lines &optional splice)
  3117. "Convert org-table to list-table.
  3118. LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
  3119. element is a `string' representing a single row of org-table.
  3120. Thus each ROW has vertical separators \"|\" separating the table
  3121. fields. A ROW could also be a row-group separator of the form
  3122. \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
  3123. ...). ROW could either be symbol `:hrule' or a list of the
  3124. form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
  3125. (let (line lines-1)
  3126. (cond
  3127. (splice
  3128. (while (setq line (pop lines))
  3129. (unless (string-match "^[ \t]*|-" line)
  3130. (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))
  3131. (t
  3132. (while (setq line (pop lines))
  3133. (cond
  3134. ((string-match "^[ \t]*|-" line)
  3135. (when lines
  3136. (push :hrule lines-1)))
  3137. (t
  3138. (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))))
  3139. (nreverse lines-1)))
  3140. (defun org-e-html-table (table contents info)
  3141. "Transcode a TABLE element from Org to HTML.
  3142. CONTENTS is nil. INFO is a plist holding contextual information."
  3143. (let* (
  3144. ;; FIXME
  3145. ;; see `org-e-html-table--format-string'
  3146. (label (org-element-get-property :name table))
  3147. (caption (org-e-html--caption/label-string
  3148. (org-element-get-property :caption table) label info))
  3149. ;; FIXME
  3150. (attr (mapconcat #'identity
  3151. (org-element-get-property :attr_html table)
  3152. " "))
  3153. (raw-table (org-element-get-property :raw-table table)))
  3154. (cond
  3155. ;; Case 1: verbatim table.
  3156. ((or org-e-html-tables-verbatim
  3157. (and attr (string-match "\\<verbatim\\>" attr)))
  3158. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  3159. (org-export-clean-table
  3160. raw-table
  3161. (plist-get (org-export-table-format-info raw-table)
  3162. :special-column-p))))
  3163. ;; Case 2: table.el table. Convert it using appropriate tools.
  3164. ((eq (org-element-get-property :type table) 'table.el)
  3165. (require 'table)
  3166. ;; Ensure "*org-export-table*" buffer is empty.
  3167. (with-current-buffer (get-buffer-create "*org-export-table*")
  3168. (erase-buffer))
  3169. (let ((output (with-temp-buffer
  3170. (insert raw-table)
  3171. (goto-char 1)
  3172. (re-search-forward "^[ \t]*|[^|]" nil t)
  3173. (table-generate-source 'html "*org-export-table*")
  3174. (with-current-buffer "*org-export-table*"
  3175. (org-trim (buffer-string))))))
  3176. (kill-buffer (get-buffer "*org-export-table*"))
  3177. ;; Remove left out comments.
  3178. (while (string-match "^%.*\n" output)
  3179. (setq output (replace-match "" t t output)))
  3180. ;; When the "rmlines" attribute is provided, remove all hlines
  3181. ;; but the the one separating heading from the table body.
  3182. (when (and attr (string-match "\\<rmlines\\>" attr))
  3183. (let ((n 0) (pos 0))
  3184. (while (and (< (length output) pos)
  3185. (setq pos (string-match "^\\\\hline\n?" output pos)))
  3186. (incf n)
  3187. (unless (= n 2)
  3188. (setq output (replace-match "" nil nil output))))))
  3189. ;; (if (not org-e-html-tables-centered) output
  3190. ;; (format "\\begin{center}\n%s\n\\end{center}" output))
  3191. output))
  3192. ;; Case 3: Standard table.
  3193. (t
  3194. (let* ((table-info (org-export-table-format-info raw-table))
  3195. (columns-number (length (plist-get table-info :alignment)))
  3196. (longtablep (and attr (string-match "\\<longtable\\>" attr)))
  3197. (booktabsp
  3198. (or (and attr (string-match "\\<booktabs=\\(yes\\|t\\)\\>" attr))
  3199. org-e-html-tables-booktabs))
  3200. ;; CLEAN-TABLE is a table turned into a list, much like
  3201. ;; `org-table-to-lisp', with special column and
  3202. ;; formatting cookies removed, and cells already
  3203. ;; transcoded.
  3204. (lines (org-split-string
  3205. (org-export-clean-table
  3206. raw-table (plist-get table-info :special-column-p)) "\n"))
  3207. ;; (clean-table
  3208. ;; (mapcar
  3209. ;; (lambda (row)
  3210. ;; (if (string-match org-table-hline-regexp row) 'hline
  3211. ;; (mapcar
  3212. ;; (lambda (cell)
  3213. ;; (org-export-secondary-string
  3214. ;; (org-element-parse-secondary-string
  3215. ;; cell
  3216. ;; (cdr (assq 'table org-element-string-restrictions)))
  3217. ;; 'e-html info))
  3218. ;; (org-split-string row "[ \t]*|[ \t]*"))))
  3219. ;; lines))
  3220. )
  3221. (let ((splice nil) head)
  3222. (setq lines (org-e-html-org-table-to-list-table lines splice))
  3223. (org-e-html-list-table lines splice caption label attr head nil))
  3224. ;; If BOOKTABSP is non-nil, remove any rule at the beginning
  3225. ;; and the end of the table, since booktabs' special rules
  3226. ;; will be inserted instead.
  3227. ;; (when booktabsp
  3228. ;; (when (eq (car clean-table) 'hline)
  3229. ;; (setq clean-table (cdr clean-table)))
  3230. ;; (when (eq (car (last clean-table)) 'hline)
  3231. ;; (setq clean-table (butlast clean-table))))
  3232. ;; Convert ROWS to send them to `orgtbl-to-latex'. In
  3233. ;; particular, send each cell to
  3234. ;; `org-element-parse-secondary-string' to expand any Org
  3235. ;; object within. Eventually, flesh the format string out
  3236. ;; with the table.
  3237. ;; (format
  3238. ;; (org-e-html-table--format-string table table-info info)
  3239. ;; (orgtbl-to-latex
  3240. ;; clean-table
  3241. ;; ;; Parameters passed to `orgtbl-to-latex'.
  3242. ;; `(:tstart ,(and booktabsp "\\toprule")
  3243. ;; :tend ,(and booktabsp "\\bottomrule")
  3244. ;; :hline ,(if booktabsp "\\midrule" "\\hline")
  3245. ;; ;; Longtable environment requires specific header
  3246. ;; ;; lines end string.
  3247. ;; :hlend ,(and longtablep
  3248. ;; (format "\\\\
  3249. ;; %s
  3250. ;; \\endhead
  3251. ;; %s\\multicolumn{%d}{r}{Continued on next page}\\\\
  3252. ;; \\endfoot
  3253. ;; \\endlastfoot"
  3254. ;; (if booktabsp "\\midrule" "\\hline")
  3255. ;; (if booktabsp "\\midrule" "\\hline")
  3256. ;; columns-number)))))
  3257. )))))
  3258. ;;;; Target
  3259. (defun org-e-html-target (target text info)
  3260. "Transcode a TARGET object from Org to HTML.
  3261. TEXT is the text of the target. INFO is a plist holding
  3262. contextual information."
  3263. (org-e-html-format-anchor
  3264. text (org-export-solidify-link-text
  3265. (org-element-get-property :raw-value target))))
  3266. ;;;; Time-stamp
  3267. (defun org-e-html-time-stamp (time-stamp contents info)
  3268. "Transcode a TIME-STAMP object from Org to HTML.
  3269. CONTENTS is nil. INFO is a plist holding contextual
  3270. information."
  3271. ;; (let ((value (org-element-get-property :value time-stamp))
  3272. ;; (type (org-element-get-property :type time-stamp))
  3273. ;; (appt-type (org-element-get-property :appt-type time-stamp)))
  3274. ;; (concat (cond ((eq appt-type 'scheduled)
  3275. ;; (format "\\textbf{\\textsc{%s}} " org-scheduled-string))
  3276. ;; ((eq appt-type 'deadline)
  3277. ;; (format "\\textbf{\\textsc{%s}} " org-deadline-string))
  3278. ;; ((eq appt-type 'closed)
  3279. ;; (format "\\textbf{\\textsc{%s}} " org-closed-string)))
  3280. ;; (cond ((memq type '(active active-range))
  3281. ;; (format org-e-html-active-timestamp-format value))
  3282. ;; ((memq type '(inactive inactive-range))
  3283. ;; (format org-e-html-inactive-timestamp-format value))
  3284. ;; (t
  3285. ;; (format org-e-html-diary-timestamp-format value)))))
  3286. (let ((value (org-element-get-property :value time-stamp))
  3287. (type (org-element-get-property :type time-stamp))
  3288. (appt-type (org-element-get-property :appt-type time-stamp)))
  3289. (org-e-html-format-fontify
  3290. (concat
  3291. (org-e-html-format-fontify
  3292. (cond ((eq appt-type 'scheduled) org-scheduled-string)
  3293. ((eq appt-type 'deadline) org-deadline-string)
  3294. ((eq appt-type 'closed) org-closed-string)) "timestamp-kwd")
  3295. ;; FIXME: (org-translate-time value)
  3296. (org-e-html-format-fontify value "timestamp"))
  3297. "timestamp-wrapper")))
  3298. ;;;; Verbatim
  3299. (defun org-e-html-verbatim (verbatim contents info)
  3300. "Transcode a VERBATIM object from Org to HTML.
  3301. CONTENTS is nil. INFO is a plist used as a communication
  3302. channel."
  3303. (org-e-html-emphasis
  3304. verbatim (org-element-get-property :value verbatim) info))
  3305. ;;;; Verse Block
  3306. (defun org-e-html-verse-block (verse-block contents info)
  3307. "Transcode a VERSE-BLOCK element from Org to HTML.
  3308. CONTENTS is nil. INFO is a plist holding contextual information."
  3309. ;; Replace each newline character with line break. Also replace
  3310. ;; each blank line with a line break.
  3311. (setq contents (replace-regexp-in-string
  3312. "^ *\\\\\\\\$" "<br/>\n"
  3313. (replace-regexp-in-string
  3314. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
  3315. (org-remove-indentation
  3316. (org-export-secondary-string
  3317. (org-element-get-property :value verse-block)
  3318. 'e-html info)))))
  3319. ;; Replace each white space at beginning of a line with a
  3320. ;; non-breaking space.
  3321. (while (string-match "^[ \t]+" contents)
  3322. (let ((new-str (format "&nbsp;"
  3323. (length (match-string 0 contents)))))
  3324. (setq contents (replace-match new-str nil t contents))))
  3325. (org-e-html--wrap-label
  3326. verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
  3327. ;;; Interactive functions
  3328. (defun org-e-html-export-to-html
  3329. (&optional subtreep visible-only body-only ext-plist pub-dir)
  3330. "Export current buffer to a HTML file.
  3331. If narrowing is active in the current buffer, only export its
  3332. narrowed part.
  3333. If a region is active, export that region.
  3334. When optional argument SUBTREEP is non-nil, export the sub-tree
  3335. at point, extracting information from the headline properties
  3336. first.
  3337. When optional argument VISIBLE-ONLY is non-nil, don't export
  3338. contents of hidden elements.
  3339. When optional argument BODY-ONLY is non-nil, only write code
  3340. between \"\\begin{document}\" and \"\\end{document}\".
  3341. EXT-PLIST, when provided, is a property list with external
  3342. parameters overriding Org default settings, but still inferior to
  3343. file-local settings.
  3344. When optional argument PUB-DIR is set, use it as the publishing
  3345. directory.
  3346. Return output file's name."
  3347. (interactive)
  3348. (setq org-e-html-footnotes-alist nil)
  3349. ;; FIXME
  3350. (with-current-buffer (get-buffer-create "*debug*")
  3351. (erase-buffer))
  3352. (let ((outfile (org-export-output-file-name ".html" subtreep pub-dir)))
  3353. (org-export-to-file
  3354. 'e-html outfile subtreep visible-only body-only ext-plist)))
  3355. (provide 'org-e-html)
  3356. ;;; org-e-html.el ends here