org-e-html.el 127 KB

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