org-e-html.el 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644
  1. ;;; org-e-html.el --- HTML Back-End For Org Export Engine
  2. ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This library implements a HTML back-end for Org generic exporter.
  17. ;; To test it, run
  18. ;;
  19. ;; M-: (org-export-to-buffer 'e-html "*Test e-HTML*") RET
  20. ;;
  21. ;; in an org-mode buffer then switch to the buffer to see the HTML
  22. ;; export. See contrib/lisp/org-export.el for more details on how
  23. ;; this exporter works.
  24. ;; It introduces three new buffer keywords: "LATEX_CLASS",
  25. ;; "LATEX_CLASS_OPTIONS" and "LATEX_HEADER".
  26. ;;; Code:
  27. ;;; org-xhtml.el
  28. (defvar org-e-html-debug nil)
  29. (defvar org-e-html-pp t)
  30. (defun org-e-html-debug (fmt &rest args)
  31. (when org-e-html-debug
  32. (with-current-buffer (get-buffer "*debug*")
  33. (insert "\n" (apply 'format fmt args)))))
  34. (defun org-element-debug (header text)
  35. (insert "\n" "===== [" header "] =====")
  36. (insert "\n" (pp-to-string text)))
  37. (defun org-elements-debug (args)
  38. (with-current-buffer "*debug*"
  39. (insert "\n\n\n\n\n-------------------------\n")
  40. (while args
  41. (let* ((header (pop args))
  42. (text (pop args)))
  43. (org-element-debug (format "%s" header) text)))
  44. (insert "\n--------------------------\n")))
  45. (defvar org-elements-debug-depth 0)
  46. (defmacro org-e-html-pp (&rest args)
  47. (if org-e-html-pp
  48. (let ((newargs))
  49. (while args
  50. (let ((e (pop args)))
  51. (setq newargs (append newargs (list e (eval e))))))
  52. ;; (pp-eval-expression 'newargs)
  53. `(org-elements-debug (quote ,newargs)))
  54. (list 'ignore)))
  55. (require 'org-exp)
  56. (require 'format-spec)
  57. (eval-when-compile (require 'cl) (require 'table))
  58. (declare-function org-id-find-id-file "org-id" (id))
  59. (declare-function htmlize-region "ext:htmlize" (beg end))
  60. (declare-function org-pop-to-buffer-same-window
  61. "org-compat" (&optional buffer-or-name norecord label))
  62. (defgroup org-export-e-html nil
  63. "Options specific for HTML export of Org-mode files."
  64. :tag "Org Export HTML"
  65. :group 'org-export)
  66. (defconst org-e-html-special-string-regexps
  67. '(("\\\\-" . "&shy;")
  68. ("---\\([^-]\\)" . "&mdash;\\1")
  69. ("--\\([^-]\\)" . "&ndash;\\1")
  70. ("\\.\\.\\." . "&hellip;"))
  71. "Regular expressions for special string conversion.")
  72. (defcustom org-e-html-footnotes-section "<div id=\"footnotes\">
  73. <h2 class=\"footnotes\">%s: </h2>
  74. <div id=\"text-footnotes\">
  75. %s
  76. </div>
  77. </div>"
  78. "Format for the footnotes section.
  79. Should contain a two instances of %s. The first will be replaced with the
  80. language-specific word for \"Footnotes\", the second one will be replaced
  81. by the footnotes themselves."
  82. :group 'org-export-e-html
  83. :type 'string)
  84. (defcustom org-e-html-footnote-format "<sup>%s</sup>"
  85. "The format for the footnote reference.
  86. %s will be replaced by the footnote reference itself."
  87. :group 'org-export-e-html
  88. :type 'string)
  89. (defcustom org-e-html-footnote-separator "<sup>, </sup>"
  90. "Text used to separate footnotes."
  91. :group 'org-export-e-html
  92. :type 'string)
  93. (defcustom org-e-html-coding-system nil
  94. "Coding system for HTML export, defaults to `buffer-file-coding-system'."
  95. :group 'org-export-e-html
  96. :type 'coding-system)
  97. (defcustom org-e-html-extension "html"
  98. "The extension for exported HTML files."
  99. :group 'org-export-e-html
  100. :type 'string)
  101. (defcustom org-e-html-xml-declaration
  102. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  103. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  104. "The extension for exported HTML files.
  105. %s will be replaced with the charset of the exported file.
  106. This may be a string, or an alist with export extensions
  107. and corresponding declarations."
  108. :group 'org-export-e-html
  109. :type '(choice
  110. (string :tag "Single declaration")
  111. (repeat :tag "Dependent on extension"
  112. (cons (string :tag "Extension")
  113. (string :tag "Declaration")))))
  114. (defcustom org-e-html-style-include-scripts t
  115. "Non-nil means include the JavaScript snippets in exported HTML files.
  116. The actual script is defined in `org-e-html-scripts' and should
  117. not be modified."
  118. :group 'org-export-e-html
  119. :type 'boolean)
  120. (defconst org-e-html-scripts
  121. "<script type=\"text/javascript\">
  122. <!--/*--><![CDATA[/*><!--*/
  123. function CodeHighlightOn(elem, id)
  124. {
  125. var target = document.getElementById(id);
  126. if(null != target) {
  127. elem.cacheClassElem = elem.className;
  128. elem.cacheClassTarget = target.className;
  129. target.className = \"code-highlighted\";
  130. elem.className = \"code-highlighted\";
  131. }
  132. }
  133. function CodeHighlightOff(elem, id)
  134. {
  135. var target = document.getElementById(id);
  136. if(elem.cacheClassElem)
  137. elem.className = elem.cacheClassElem;
  138. if(elem.cacheClassTarget)
  139. target.className = elem.cacheClassTarget;
  140. }
  141. /*]]>*///-->
  142. </script>"
  143. "Basic JavaScript that is needed by HTML files produced by Org-mode.")
  144. (defconst org-e-html-style-default
  145. "<style type=\"text/css\">
  146. <!--/*--><![CDATA[/*><!--*/
  147. html { font-family: Times, serif; font-size: 12pt; }
  148. .title { text-align: center; }
  149. .todo { color: red; }
  150. .done { color: green; }
  151. .tag { background-color: #add8e6; font-weight:normal }
  152. .target { }
  153. .timestamp { color: #bebebe; }
  154. .timestamp-kwd { color: #5f9ea0; }
  155. .right {margin-left:auto; margin-right:0px; text-align:right;}
  156. .left {margin-left:0px; margin-right:auto; text-align:left;}
  157. .center {margin-left:auto; margin-right:auto; text-align:center;}
  158. p.verse { margin-left: 3% }
  159. pre {
  160. border: 1pt solid #AEBDCC;
  161. background-color: #F3F5F7;
  162. padding: 5pt;
  163. font-family: courier, monospace;
  164. font-size: 90%;
  165. overflow:auto;
  166. }
  167. table { border-collapse: collapse; }
  168. td, th { vertical-align: top; }
  169. th.right { text-align:center; }
  170. th.left { text-align:center; }
  171. th.center { text-align:center; }
  172. td.right { text-align:right; }
  173. td.left { text-align:left; }
  174. td.center { text-align:center; }
  175. dt { font-weight: bold; }
  176. div.figure { padding: 0.5em; }
  177. div.figure p { text-align: center; }
  178. div.inlinetask {
  179. padding:10px;
  180. border:2px solid gray;
  181. margin:10px;
  182. background: #ffffcc;
  183. }
  184. textarea { overflow-x: auto; }
  185. .linenr { font-size:smaller }
  186. .code-highlighted {background-color:#ffff00;}
  187. .org-info-js_info-navigation { border-style:none; }
  188. #org-info-js_console-label { font-size:10px; font-weight:bold;
  189. white-space:nowrap; }
  190. .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
  191. font-weight:bold; }
  192. /*]]>*/-->
  193. </style>"
  194. "The default style specification for exported HTML files.
  195. Please use the variables `org-e-html-style' and
  196. `org-e-html-style-extra' to add to this style. If you wish to not
  197. have the default style included, customize the variable
  198. `org-e-html-style-include-default'.")
  199. (defcustom org-e-html-style-include-default t
  200. "Non-nil means include the default style in exported HTML files.
  201. The actual style is defined in `org-e-html-style-default' and should
  202. not be modified. Use the variables `org-e-html-style' to add
  203. your own style information."
  204. :group 'org-export-e-html
  205. :type 'boolean)
  206. ;;;###autoload
  207. (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
  208. (defcustom org-e-html-style ""
  209. "Org-wide style definitions for exported HTML files.
  210. This variable needs to contain the full HTML structure to provide a style,
  211. including the surrounding HTML tags. If you set the value of this variable,
  212. you should consider to include definitions for the following classes:
  213. title, todo, done, timestamp, timestamp-kwd, tag, target.
  214. For example, a valid value would be:
  215. <style type=\"text/css\">
  216. <![CDATA[
  217. p { font-weight: normal; color: gray; }
  218. h1 { color: black; }
  219. .title { text-align: center; }
  220. .todo, .timestamp-kwd { color: red; }
  221. .done { color: green; }
  222. ]]>
  223. </style>
  224. If you'd like to refer to an external style file, use something like
  225. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  226. As the value of this option simply gets inserted into the HTML <head> header,
  227. you can \"misuse\" it to add arbitrary text to the header.
  228. See also the variable `org-e-html-style-extra'."
  229. :group 'org-export-e-html
  230. :type 'string)
  231. ;;;###autoload
  232. (put 'org-e-html-style 'safe-local-variable 'stringp)
  233. (defcustom org-e-html-style-extra ""
  234. "Additional style information for HTML export.
  235. The value of this variable is inserted into the HTML buffer right after
  236. the value of `org-e-html-style'. Use this variable for per-file
  237. settings of style information, and do not forget to surround the style
  238. settings with <style>...</style> tags."
  239. :group 'org-export-e-html
  240. :type 'string)
  241. ;;;###autoload
  242. (put 'org-e-html-style-extra 'safe-local-variable 'stringp)
  243. (defcustom org-e-html-mathjax-options
  244. '((path "http://orgmode.org/mathjax/MathJax.js")
  245. (scale "100")
  246. (align "center")
  247. (indent "2em")
  248. (mathml nil))
  249. "Options for MathJax setup.
  250. path The path where to find MathJax
  251. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  252. align How to align display math: left, center, or right
  253. indent If align is not center, how far from the left/right side?
  254. mathml Should a MathML player be used if available?
  255. This is faster and reduces bandwidth use, but currently
  256. sometimes has lower spacing quality. Therefore, the default is
  257. nil. When browsers get better, this switch can be flipped.
  258. You can also customize this for each buffer, using something like
  259. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  260. :group 'org-export-e-html
  261. :type '(list :greedy t
  262. (list :tag "path (the path from where to load MathJax.js)"
  263. (const :format " " path) (string))
  264. (list :tag "scale (scaling for the displayed math)"
  265. (const :format " " scale) (string))
  266. (list :tag "align (alignment of displayed equations)"
  267. (const :format " " align) (string))
  268. (list :tag "indent (indentation with left or right alignment)"
  269. (const :format " " indent) (string))
  270. (list :tag "mathml (should MathML display be used is possible)"
  271. (const :format " " mathml) (boolean))))
  272. (defun org-e-html-mathjax-config (template options in-buffer)
  273. "Insert the user setup into the matchjax template."
  274. (let (name val (yes " ") (no "// ") x)
  275. (mapc
  276. (lambda (e)
  277. (setq name (car e) val (nth 1 e))
  278. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  279. (setq val (car (read-from-string
  280. (substring in-buffer (match-end 0))))))
  281. (if (not (stringp val)) (setq val (format "%s" val)))
  282. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  283. (setq template (replace-match val t t template))))
  284. options)
  285. (setq val (nth 1 (assq 'mathml options)))
  286. (if (string-match (concat "\\<mathml:") in-buffer)
  287. (setq val (car (read-from-string
  288. (substring in-buffer (match-end 0))))))
  289. ;; Exchange prefixes depending on mathml setting
  290. (if (not val) (setq x yes yes no no x))
  291. ;; Replace cookies to turn on or off the config/jax lines
  292. (if (string-match ":MMLYES:" template)
  293. (setq template (replace-match yes t t template)))
  294. (if (string-match ":MMLNO:" template)
  295. (setq template (replace-match no t t template)))
  296. ;; Return the modified template
  297. template))
  298. (defcustom org-e-html-mathjax-template
  299. "<script type=\"text/javascript\" src=\"%PATH\">
  300. <!--/*--><![CDATA[/*><!--*/
  301. MathJax.Hub.Config({
  302. // Only one of the two following lines, depending on user settings
  303. // First allows browser-native MathML display, second forces HTML/CSS
  304. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  305. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  306. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  307. \"TeX/noUndefined.js\"],
  308. tex2jax: {
  309. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  310. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  311. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  312. ignoreClass: \"tex2jax_ignore\",
  313. processEscapes: false,
  314. processEnvironments: true,
  315. preview: \"TeX\"
  316. },
  317. showProcessingMessages: true,
  318. displayAlign: \"%ALIGN\",
  319. displayIndent: \"%INDENT\",
  320. \"HTML-CSS\": {
  321. scale: %SCALE,
  322. availableFonts: [\"STIX\",\"TeX\"],
  323. preferredFont: \"TeX\",
  324. webFont: \"TeX\",
  325. imageFont: \"TeX\",
  326. showMathMenu: true,
  327. },
  328. MMLorHTML: {
  329. prefer: {
  330. MSIE: \"MML\",
  331. Firefox: \"MML\",
  332. Opera: \"HTML\",
  333. other: \"HTML\"
  334. }
  335. }
  336. });
  337. /*]]>*///-->
  338. </script>"
  339. "The MathJax setup for XHTML files."
  340. :group 'org-export-e-html
  341. :type 'string)
  342. (defcustom org-e-html-tag-class-prefix ""
  343. "Prefix to class names for TODO keywords.
  344. Each tag gets a class given by the tag itself, with this prefix.
  345. The default prefix is empty because it is nice to just use the keyword
  346. as a class name. But if you get into conflicts with other, existing
  347. CSS classes, then this prefix can be very useful."
  348. :group 'org-export-e-html
  349. :type 'string)
  350. (defcustom org-e-html-todo-kwd-class-prefix ""
  351. "Prefix to class names for TODO keywords.
  352. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  353. The default prefix is empty because it is nice to just use the keyword
  354. as a class name. But if you get into conflicts with other, existing
  355. CSS classes, then this prefix can be very useful."
  356. :group 'org-export-e-html
  357. :type 'string)
  358. (defcustom org-e-html-preamble t
  359. "Non-nil means insert a preamble in HTML export.
  360. When `t', insert a string as defined by one of the formatting
  361. strings in `org-e-html-preamble-format'. When set to a
  362. string, this string overrides `org-e-html-preamble-format'.
  363. When set to a function, apply this function and insert the
  364. returned string. The function takes the property list of export
  365. options as its only argument.
  366. Setting :html-preamble in publishing projects will take
  367. precedence over this variable."
  368. :group 'org-export-e-html
  369. :type '(choice (const :tag "No preamble" nil)
  370. (const :tag "Default preamble" t)
  371. (string :tag "Custom formatting string")
  372. (function :tag "Function (must return a string)")))
  373. (defcustom org-e-html-preamble-format '(("en" ""))
  374. "The format for the HTML preamble.
  375. %t stands for the title.
  376. %a stands for the author's name.
  377. %e stands for the author's email.
  378. %d stands for the date.
  379. If you need to use a \"%\" character, you need to escape it
  380. like that: \"%%\"."
  381. :group 'org-export-e-html
  382. :type 'string)
  383. (defcustom org-e-html-postamble 'auto
  384. "Non-nil means insert a postamble in HTML export.
  385. When `t', insert a string as defined by the formatting string in
  386. `org-e-html-postamble-format'. When set to a string, this
  387. string overrides `org-e-html-postamble-format'. When set to
  388. 'auto, discard `org-e-html-postamble-format' and honor
  389. `org-export-author/email/creator-info' variables. When set to a
  390. function, apply this function and insert the returned string.
  391. The function takes the property list of export options as its
  392. only argument.
  393. Setting :html-postamble in publishing projects will take
  394. precedence over this variable."
  395. :group 'org-export-e-html
  396. :type '(choice (const :tag "No postamble" nil)
  397. (const :tag "Auto preamble" 'auto)
  398. (const :tag "Default formatting string" t)
  399. (string :tag "Custom formatting string")
  400. (function :tag "Function (must return a string)")))
  401. (defcustom org-e-html-postamble-format
  402. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  403. <p class=\"date\">Date: %d</p>
  404. <p class=\"creator\">Generated by %c</p>
  405. <p class=\"xhtml-validation\">%v</p>
  406. "))
  407. "The format for the HTML postamble.
  408. %a stands for the author's name.
  409. %e stands for the author's email.
  410. %d stands for the date.
  411. %c will be replaced by information about Org/Emacs versions.
  412. %v will be replaced by `org-e-html-validation-link'.
  413. If you need to use a \"%\" character, you need to escape it
  414. like that: \"%%\"."
  415. :group 'org-export-e-html
  416. :type 'string)
  417. (defcustom org-e-html-home/up-format
  418. "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  419. <a accesskey=\"h\" href=\"%s\"> UP </a>
  420. |
  421. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  422. </div>"
  423. "Snippet used to insert the HOME and UP links.
  424. This is a format string, the first %s will receive the UP link,
  425. the second the HOME link. If both `org-e-html-link-up' and
  426. `org-e-html-link-home' are empty, the entire snippet will be
  427. ignored."
  428. :group 'org-export-e-html
  429. :type 'string)
  430. (defcustom org-e-html-toplevel-hlevel 2
  431. "The <H> level for level 1 headings in HTML export.
  432. This is also important for the classes that will be wrapped around headlines
  433. and outline structure. If this variable is 1, the top-level headlines will
  434. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  435. and outline-text-1. If this is 2, all of these will get a 2 instead.
  436. The default for this variable is 2, because we use <h1> for formatting the
  437. document title."
  438. :group 'org-export-e-html
  439. :type 'string)
  440. (defcustom org-e-html-link-org-files-as-html t
  441. "Non-nil means make file links to `file.org' point to `file.html'.
  442. When org-mode is exporting an org-mode file to HTML, links to
  443. non-html files are directly put into a href tag in HTML.
  444. However, links to other Org-mode files (recognized by the
  445. extension `.org.) should become links to the corresponding html
  446. file, assuming that the linked org-mode file will also be
  447. converted to HTML.
  448. When nil, the links still point to the plain `.org' file."
  449. :group 'org-export-e-html
  450. :type 'boolean)
  451. (defcustom org-e-html-inline-images 'maybe
  452. "Non-nil means inline images into exported HTML pages.
  453. This is done using an <img> tag. When nil, an anchor with href is used to
  454. link to the image. If this option is `maybe', then images in links with
  455. an empty description will be inlined, while images with a description will
  456. be linked only."
  457. :group 'org-export-e-html
  458. :type '(choice (const :tag "Never" nil)
  459. (const :tag "Always" t)
  460. (const :tag "When there is no description" maybe)))
  461. (defcustom org-e-html-inline-image-extensions
  462. '("png" "jpeg" "jpg" "gif" "svg")
  463. "Extensions of image files that can be inlined into HTML."
  464. :group 'org-export-e-html
  465. :type '(repeat (string :tag "Extension")))
  466. (defcustom org-e-html-table-tag
  467. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  468. "The HTML tag that is used to start a table.
  469. This must be a <table> tag, but you may change the options like
  470. borders and spacing."
  471. :group 'org-export-e-html
  472. :type 'string)
  473. (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  474. "The opening tag for table header fields.
  475. This is customizable so that alignment options can be specified.
  476. The first %s will be filled with the scope of the field, either row or col.
  477. The second %s will be replaced by a style entry to align the field.
  478. See also the variable `org-e-html-table-use-header-tags-for-first-column'.
  479. See also the variable `org-e-html-table-align-individual-fields'."
  480. :group 'org-export-tables
  481. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  482. (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
  483. "The opening tag for table data fields.
  484. This is customizable so that alignment options can be specified.
  485. The first %s will be filled with the scope of the field, either row or col.
  486. The second %s will be replaced by a style entry to align the field.
  487. See also the variable `org-e-html-table-align-individual-fields'."
  488. :group 'org-export-tables
  489. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  490. (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
  491. "The opening tag for table data fields.
  492. This is customizable so that alignment options can be specified.
  493. Instead of strings, these can be Lisp forms that will be evaluated
  494. for each row in order to construct the table row tags. During evaluation,
  495. the variable `head' will be true when this is a header line, nil when this
  496. is a body line. And the variable `nline' will contain the line number,
  497. starting from 1 in the first header line. For example
  498. (setq org-export-table-row-tags
  499. (cons '(if head
  500. \"<tr>\"
  501. (if (= (mod nline 2) 1)
  502. \"<tr class=\\\"tr-odd\\\">\"
  503. \"<tr class=\\\"tr-even\\\">\"))
  504. \"</tr>\"))
  505. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  506. :group 'org-export-tables
  507. :type '(cons
  508. (choice :tag "Opening tag"
  509. (string :tag "Specify")
  510. (sexp))
  511. (choice :tag "Closing tag"
  512. (string :tag "Specify")
  513. (sexp))))
  514. (defcustom org-e-html-table-align-individual-fields t
  515. "Non-nil means attach style attributes for alignment to each table field.
  516. When nil, alignment will only be specified in the column tags, but this
  517. is ignored by some browsers (like Firefox, Safari). Opera does it right
  518. though."
  519. :group 'org-export-tables
  520. :type 'boolean)
  521. (defcustom org-e-html-table-use-header-tags-for-first-column nil
  522. "Non-nil means format column one in tables with header tags.
  523. When nil, also column one will use data tags."
  524. :group 'org-export-tables
  525. :type 'boolean)
  526. (defcustom org-e-html-validation-link
  527. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  528. "Link to HTML validation service."
  529. :group 'org-export-e-html
  530. :type 'string)
  531. ;; FIXME Obsolete since Org 7.7
  532. ;; Use the :timestamp option or `org-export-time-stamp-file' instead
  533. (defvar org-e-html-with-timestamp nil
  534. "If non-nil, write container for HTML-helper-mode timestamp.")
  535. ;; FIXME Obsolete since Org 7.7
  536. (defvar org-e-html-html-helper-timestamp
  537. "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
  538. "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
  539. (defcustom org-e-html-protect-char-alist
  540. '(("&" . "&amp;")
  541. ("<" . "&lt;")
  542. (">" . "&gt;"))
  543. "Alist of characters to be converted by `org-e-html-protect'."
  544. :group 'org-export-e-html
  545. :type '(repeat (cons (string :tag "Character")
  546. (string :tag "HTML equivalent"))))
  547. (defgroup org-export-e-htmlize nil
  548. "Options for processing examples with htmlize.el."
  549. :tag "Org Export Htmlize"
  550. :group 'org-export-e-html)
  551. (defcustom org-export-e-htmlize-output-type 'inline-css
  552. "Output type to be used by htmlize when formatting code snippets.
  553. Choices are `css', to export the CSS selectors only, or `inline-css', to
  554. export the CSS attribute values inline in the HTML. We use as default
  555. `inline-css', in order to make the resulting HTML self-containing.
  556. However, this will fail when using Emacs in batch mode for export, because
  557. then no rich font definitions are in place. It will also not be good if
  558. people with different Emacs setup contribute HTML files to a website,
  559. because the fonts will represent the individual setups. In these cases,
  560. it is much better to let Org/Htmlize assign classes only, and to use
  561. a style file to define the look of these classes.
  562. To get a start for your css file, start Emacs session and make sure that
  563. all the faces you are interested in are defined, for example by loading files
  564. in all modes you want. Then, use the command
  565. \\[org-export-e-htmlize-generate-css] to extract class definitions."
  566. :group 'org-export-e-htmlize
  567. :type '(choice (const css) (const inline-css)))
  568. (defcustom org-export-e-htmlize-css-font-prefix "org-"
  569. "The prefix for CSS class names for htmlize font specifications."
  570. :group 'org-export-e-htmlize
  571. :type 'string)
  572. (defcustom org-export-e-htmlized-org-css-url nil
  573. "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
  574. Normally when creating an htmlized version of an Org buffer, htmlize will
  575. create CSS to define the font colors. However, this does not work when
  576. converting in batch mode, and it also can look bad if different people
  577. with different fontification setup work on the same website.
  578. When this variable is non-nil, creating an htmlized version of an Org buffer
  579. using `org-export-as-org' will remove the internal CSS section and replace it
  580. with a link to this URL."
  581. :group 'org-export-e-htmlize
  582. :type '(choice
  583. (const :tag "Keep internal css" nil)
  584. (string :tag "URL or local href")))
  585. ;; FIXME: The following variable is obsolete since Org 7.7 but is
  586. ;; still declared and checked within code for compatibility reasons.
  587. ;; Use the custom variables `org-e-html-divs' instead.
  588. (defvar org-e-html-content-div "content"
  589. "The name of the container DIV that holds all the page contents.
  590. This variable is obsolete since Org version 7.7.
  591. Please set `org-e-html-divs' instead.")
  592. (defcustom org-e-html-divs '("preamble" "content" "postamble")
  593. "The name of the main divs for HTML export.
  594. This is a list of three strings, the first one for the preamble
  595. DIV, the second one for the content DIV and the third one for the
  596. postamble DIV."
  597. :group 'org-export-e-html
  598. :type '(list
  599. (string :tag " Div for the preamble:")
  600. (string :tag " Div for the content:")
  601. (string :tag "Div for the postamble:")))
  602. ;;; Hooks
  603. (defvar org-e-html-after-blockquotes-hook nil
  604. "Hook run during HTML export, after blockquote, verse, center are done.")
  605. (defvar org-e-html-final-hook nil
  606. "Hook run at the end of HTML export, in the new buffer.")
  607. (defun org-e-html-preprocess-label-references ()
  608. (goto-char (point-min))
  609. (let (label l1)
  610. (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
  611. (org-if-unprotected-at (match-beginning 1)
  612. (setq label (match-string 1))
  613. (save-match-data
  614. (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  615. (setq l1 (substring label (match-beginning 1)))
  616. (setq l1 label)))
  617. (replace-match (format "[[#%s][%s]]" label l1) t t)))))
  618. (defun org-e-html-preprocess (parameters)
  619. (org-e-html-preprocess-label-references))
  620. (defvar html-table-tag nil) ; dynamically scoped into this.
  621. ;; FIXME: it already exists in org-e-html.el
  622. (defconst org-e-html-cvt-link-fn
  623. nil
  624. "Function to convert link URLs to exportable URLs.
  625. Takes two arguments, TYPE and PATH.
  626. Returns exportable url as (TYPE PATH), or nil to signal that it
  627. didn't handle this case.
  628. Intended to be locally bound around a call to `org-export-as-html'." )
  629. ;; FIXME: it already exists in org-e-html.el
  630. (defun org-e-html-cvt-org-as-html (opt-plist type path)
  631. "Convert an org filename to an equivalent html filename.
  632. If TYPE is not file, just return `nil'.
  633. See variable `org-e-html-link-org-files-as-html'"
  634. (save-match-data
  635. (and
  636. org-e-html-link-org-files-as-html
  637. (string= type "file")
  638. (string-match "\\.org$" path)
  639. (progn
  640. (list
  641. "file"
  642. (concat
  643. (substring path 0 (match-beginning 0))
  644. "."
  645. (plist-get opt-plist :html-extension)))))))
  646. (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
  647. descp)
  648. "Make an HTML link.
  649. OPT-PLIST is an options list.
  650. TYPE is the device-type of the link (THIS://foo.html).
  651. PATH is the path of the link (http://THIS#location).
  652. FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
  653. DESC is the link description, if any.
  654. ATTR is a string of other attributes of the \"a\" element."
  655. (declare (special org-lparse-par-open))
  656. (save-match-data
  657. (when (string= type-1 "coderef")
  658. (let ((ref fragment))
  659. (setq desc (format (org-export-get-coderef-format ref (and descp desc))
  660. (cdr (assoc ref org-export-code-refs)))
  661. fragment (concat "coderef-" ref)
  662. attr (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  663. fragment fragment))))
  664. (let* ((may-inline-p
  665. (and (member type-1 '("http" "https" "file"))
  666. (org-lparse-should-inline-p path descp)
  667. (not fragment)))
  668. (type (if (equal type-1 "id") "file" type-1))
  669. (filename path)
  670. ;;First pass. Just sanity stuff.
  671. (components-1
  672. (cond
  673. ((string= type "file")
  674. (list
  675. type
  676. ;;Substitute just if original path was absolute.
  677. ;;(Otherwise path must remain relative)
  678. (if (file-name-absolute-p path)
  679. (concat "file://" (expand-file-name path))
  680. path)))
  681. ((string= type "")
  682. (list nil path))
  683. (t (list type path))))
  684. ;;Second pass. Components converted so they can refer
  685. ;;to a remote site.
  686. (components-2
  687. (or
  688. (and org-e-html-cvt-link-fn
  689. (apply org-e-html-cvt-link-fn
  690. opt-plist components-1))
  691. (apply #'org-e-html-cvt-org-as-html
  692. opt-plist components-1)
  693. components-1))
  694. (type (first components-2))
  695. (thefile (second components-2)))
  696. ;;Third pass. Build final link except for leading type
  697. ;;spec.
  698. (cond
  699. ((or
  700. (not type)
  701. (string= type "http")
  702. (string= type "https")
  703. (string= type "file")
  704. (string= type "coderef"))
  705. (if fragment
  706. (setq thefile (concat thefile "#" fragment))))
  707. (t))
  708. ;;Final URL-build, for all types.
  709. (setq thefile
  710. (let
  711. ((str (org-xml-format-href thefile)))
  712. (if (and type (not (or (string= "file" type)
  713. (string= "coderef" type))))
  714. (concat type ":" str)
  715. str)))
  716. (if may-inline-p
  717. (org-e-html-format-image thefile)
  718. (org-lparse-format
  719. 'LINK (org-xml-format-desc desc) thefile attr)))))
  720. (defun org-e-html-format-inline-image (path &optional caption label attr)
  721. ;; FIXME: alt text missing here?
  722. (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
  723. path (file-name-nondirectory path))))
  724. (if (not label) inline-image
  725. (org-e-html-format-section inline-image "figure" label))))
  726. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  727. (defvar org-lparse-link-description-is-image)
  728. (defun org-e-html-format-image (src)
  729. "Create image tag with source and attributes."
  730. (save-match-data
  731. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  732. (attr (org-find-text-property-in-string 'org-attributes src))
  733. (label (org-find-text-property-in-string 'org-label src))
  734. (caption (and caption (org-xml-encode-org-text caption)))
  735. (img-extras (if (string-match "^ltxpng/" src)
  736. (format " alt=\"%s\""
  737. (org-find-text-property-in-string
  738. 'org-latex-src src))
  739. (if (string-match "\\<alt=" (or attr ""))
  740. (concat " " attr )
  741. (concat " " attr " alt=\"" src "\""))))
  742. (img (format "<img src=\"%s\"%s />" src img-extras))
  743. (extra (concat
  744. (and label
  745. (format "id=\"%s\" " (org-solidify-link-text label)))
  746. "class=\"figure\"")))
  747. (if caption
  748. (with-temp-buffer
  749. (with-org-lparse-preserve-paragraph-state
  750. (insert
  751. (org-lparse-format
  752. '("<div %s>" . "\n</div>")
  753. (concat
  754. (org-lparse-format '("\n<p>" . "</p>") img)
  755. (org-lparse-format '("\n<p>" . "</p>") caption))
  756. extra)))
  757. (buffer-string))
  758. img))))
  759. (defun org-e-html-bibliography ()
  760. "Find bibliography, cut it out and return it."
  761. (catch 'exit
  762. (let (beg end (cnt 1) bib)
  763. (save-excursion
  764. (goto-char (point-min))
  765. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  766. (setq beg (match-beginning 0))
  767. (while (re-search-forward "</?div\\>" nil t)
  768. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  769. (when (= cnt 0)
  770. (and (looking-at ">") (forward-char 1))
  771. (setq bib (buffer-substring beg (point)))
  772. (delete-region beg (point))
  773. (throw 'exit bib))))
  774. nil))))
  775. (defun org-e-html-format-table (lines olines)
  776. (let ((org-e-html-format-table-no-css nil))
  777. (org-lparse-format-table lines olines)))
  778. ;; Following variable is defined for native tables i.e., when
  779. ;; `org-lparse-table-is-styled' evals to t.
  780. (defvar org-e-html-format-table-no-css)
  781. (defvar org-table-number-regexp) ; defined in org-table.el
  782. (defun org-format-table-html (lines olines &optional no-css)
  783. "Find out which HTML converter to use and return the HTML code.
  784. NO-CSS is passed to the exporter."
  785. (error "FIXME"))
  786. (defun org-format-org-table-html (lines &optional splice no-css)
  787. (error "FIXME"))
  788. (defun org-export-splice-attributes (tag attributes)
  789. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  790. (if (not attributes)
  791. tag
  792. (let (oldatt newatt)
  793. (setq oldatt (org-extract-attributes-from-string tag)
  794. tag (pop oldatt)
  795. newatt (cdr (org-extract-attributes-from-string attributes)))
  796. (while newatt
  797. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  798. (if (string-match ">" tag)
  799. (setq tag
  800. (replace-match (concat (org-attributes-to-string oldatt) ">")
  801. t t tag)))
  802. tag)))
  803. (defun org-format-table-table-html (lines)
  804. (error "FIXME"))
  805. (defun org-export-splice-style (style extra)
  806. "Splice EXTRA into STYLE, just before \"</style>\"."
  807. (if (and (stringp extra)
  808. (string-match "\\S-" extra)
  809. (string-match "</style>" style))
  810. (concat (substring style 0 (match-beginning 0))
  811. "\n" extra "\n"
  812. (substring style (match-beginning 0)))
  813. style))
  814. (defvar htmlize-buffer-places) ; from htmlize.el
  815. (defun org-export-e-htmlize-region-for-paste (beg end)
  816. "Convert the region to HTML, using htmlize.el.
  817. This is much like `htmlize-region-for-paste', only that it uses
  818. the settings define in the org-... variables."
  819. (let* ((htmlize-output-type org-export-e-htmlize-output-type)
  820. (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
  821. (htmlbuf (htmlize-region beg end)))
  822. (unwind-protect
  823. (with-current-buffer htmlbuf
  824. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  825. (plist-get htmlize-buffer-places 'content-end)))
  826. (kill-buffer htmlbuf))))
  827. ;;;###autoload
  828. (defun org-export-e-htmlize-generate-css ()
  829. "Create the CSS for all font definitions in the current Emacs session.
  830. Use this to create face definitions in your CSS style file that can then
  831. be used by code snippets transformed by htmlize.
  832. This command just produces a buffer that contains class definitions for all
  833. faces used in the current Emacs session. You can copy and paste the ones you
  834. need into your CSS file.
  835. If you then set `org-export-e-htmlize-output-type' to `css', calls to
  836. the function `org-export-e-htmlize-region-for-paste' will produce code
  837. that uses these same face definitions."
  838. (interactive)
  839. (require 'htmlize)
  840. (and (get-buffer "*html*") (kill-buffer "*html*"))
  841. (with-temp-buffer
  842. (let ((fl (face-list))
  843. (htmlize-css-name-prefix "org-")
  844. (htmlize-output-type 'css)
  845. f i)
  846. (while (setq f (pop fl)
  847. i (and f (face-attribute f :inherit)))
  848. (when (and (symbolp f) (or (not i) (not (listp i))))
  849. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  850. (htmlize-region (point-min) (point-max))))
  851. (org-pop-to-buffer-same-window "*html*")
  852. (goto-char (point-min))
  853. (if (re-search-forward "<style" nil t)
  854. (delete-region (point-min) (match-beginning 0)))
  855. (if (re-search-forward "</style>" nil t)
  856. (delete-region (1+ (match-end 0)) (point-max)))
  857. (beginning-of-line 1)
  858. (if (looking-at " +") (replace-match ""))
  859. (goto-char (point-min)))
  860. (defvar body-only) ; dynamically scoped into this.
  861. ;; Following variable is let bound when `org-do-lparse' is in
  862. ;; progress. See org-lparse.el.
  863. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  864. (defvar org-lparse-toc)
  865. (defvar org-lparse-dyn-first-heading-pos)
  866. (defun org-e-html-end-export ()
  867. ;; insert the table of contents
  868. (when (and org-export-with-toc (not body-only) org-lparse-toc)
  869. (org-e-html-insert-toc org-lparse-toc))
  870. ;; Convert whitespace place holders
  871. (goto-char (point-min))
  872. (let (beg end n)
  873. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  874. (setq n (get-text-property beg 'org-whitespace)
  875. end (next-single-property-change beg 'org-whitespace))
  876. (goto-char beg)
  877. (delete-region beg end)
  878. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  879. (make-string n ?x)))))
  880. ;; Remove empty lines at the beginning of the file.
  881. (goto-char (point-min))
  882. (when (looking-at "\\s-+\n") (replace-match ""))
  883. ;; Remove display properties
  884. (remove-text-properties (point-min) (point-max) '(display t))
  885. ;; Run the hook
  886. (run-hooks 'org-e-html-final-hook))
  887. (defun org-e-html-format-toc-entry (snumber todo headline tags href)
  888. (setq headline (concat
  889. (and org-export-with-section-numbers
  890. (concat snumber " "))
  891. headline
  892. (and tags
  893. (concat
  894. (org-lparse-format 'SPACES 3)
  895. (org-lparse-format 'FONTIFY tags "tag")))))
  896. (when todo
  897. (setq headline (org-lparse-format 'FONTIFY headline "todo")))
  898. (org-lparse-format 'LINK headline (concat "#" href)))
  899. (defun org-e-html-format-toc-item (toc-entry level org-last-level)
  900. (when (> level org-last-level)
  901. (let ((cnt (- level org-last-level)))
  902. (while (>= (setq cnt (1- cnt)) 0)
  903. (org-lparse-begin-list 'unordered)
  904. (org-lparse-begin-list-item 'unordered))))
  905. (when (< level org-last-level)
  906. (let ((cnt (- org-last-level level)))
  907. (while (>= (setq cnt (1- cnt)) 0)
  908. (org-lparse-end-list-item-1)
  909. (org-lparse-end-list 'unordered))))
  910. (org-lparse-end-list-item-1)
  911. (org-lparse-begin-list-item 'unordered)
  912. (insert toc-entry))
  913. (defun org-e-html-begin-toc (lang-specific-heading max-level)
  914. (org-lparse-insert-tag "<div id=\"table-of-contents\">")
  915. (insert
  916. (org-lparse-format 'HEADING lang-specific-heading
  917. (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1)))
  918. (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
  919. (org-lparse-begin-list 'unordered)
  920. (org-lparse-begin-list-item 'unordered))
  921. (defun org-e-html-end-toc ()
  922. (while (> org-last-level (1- org-min-level))
  923. (setq org-last-level (1- org-last-level))
  924. (org-lparse-end-list-item-1)
  925. (org-lparse-end-list 'unordered))
  926. (org-lparse-insert-tag "</div>")
  927. (org-lparse-insert-tag "</div>")
  928. ;; cleanup empty list items in toc
  929. (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
  930. (replace-match "")))
  931. ;;;###autoload
  932. (defun org-export-as-html-and-open (arg)
  933. "Export the outline as HTML and immediately open it with a browser.
  934. If there is an active region, export only the region.
  935. The prefix ARG specifies how many levels of the outline should become
  936. headlines. The default is 3. Lower levels will become bulleted lists."
  937. (interactive "P")
  938. (error "FIXME"))
  939. ;;;###autoload
  940. (defun org-export-as-html-batch ()
  941. "Call the function `org-lparse-batch'.
  942. This function can be used in batch processing as:
  943. emacs --batch
  944. --load=$HOME/lib/emacs/org.el
  945. --eval \"(setq org-export-headline-levels 2)\"
  946. --visit=MyFile --funcall org-export-as-html-batch"
  947. (error "FIXME"))
  948. ;;;###autoload
  949. (defun org-export-as-html-to-buffer (arg)
  950. "Call `org-lparse-to-buffer` with output to a temporary buffer.
  951. No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
  952. (interactive "P")
  953. (error "FIXME"))
  954. ;;;###autoload
  955. (defun org-replace-region-by-html (beg end)
  956. "Assume the current region has org-mode syntax, and convert it to HTML.
  957. This can be used in any buffer. For example, you could write an
  958. itemized list in org-mode syntax in an HTML buffer and then use this
  959. command to convert it."
  960. (interactive "r")
  961. (error "FIXME"))
  962. ;;;###autoload
  963. (defun org-export-region-as-html (beg end &optional body-only buffer)
  964. "Convert region from BEG to END in `org-mode' buffer to HTML.
  965. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  966. contents, and only produce the region of converted text, useful for
  967. cut-and-paste operations.
  968. If BUFFER is a buffer or a string, use/create that buffer as a target
  969. of the converted HTML. If BUFFER is the symbol `string', return the
  970. produced HTML as a string and leave not buffer behind. For example,
  971. a Lisp program could call this function in the following way:
  972. (setq html (org-export-region-as-html beg end t 'string))
  973. When called interactively, the output buffer is selected, and shown
  974. in a window. A non-interactive call will only return the buffer."
  975. (interactive "r\nP")
  976. (error "FIXME"))
  977. ;;; org-export-as-html
  978. ;;;###autoload
  979. (defun org-export-as-html (arg &optional hidden ext-plist
  980. to-buffer body-only pub-dir)
  981. "Export the outline as a pretty HTML file.
  982. Use `org-lparse' internally to perform the actual export. This
  983. routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
  984. of `org-lparse' to \"html\"."
  985. (interactive "P")
  986. (error "FIXME"))
  987. (defun org-e-html-begin-outline (level1 snumber title tags
  988. target extra-targets extra-class)
  989. (let* ((class (format "outline-%d" level1))
  990. (class (if extra-class (concat class " " extra-class) class))
  991. (id (format "outline-container-%s"
  992. (org-lparse-suffix-from-snumber snumber)))
  993. (extra (concat (when id (format " id=\"%s\"" id))
  994. (when class (format " class=\"%s\"" class)))))
  995. (org-lparse-insert-tag "<div%s>" extra)
  996. (insert
  997. (org-lparse-format 'HEADING
  998. (org-lparse-format
  999. 'HEADLINE title extra-targets tags snumber level1)
  1000. level1 target))))
  1001. (defun org-e-html-end-outline ()
  1002. (org-lparse-insert-tag "</div>"))
  1003. ;; (defun org-e-html-format-heading (text level &optional id)
  1004. ;; (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
  1005. ;; (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
  1006. (defun org-e-html-suffix-from-snumber (snumber)
  1007. (let* ((snu (replace-regexp-in-string "\\." "-" snumber))
  1008. (href (cdr (assoc (concat "sec-" snu)
  1009. org-export-preferred-target-alist))))
  1010. (org-solidify-link-text (or href snu))))
  1011. (defun org-e-html-format-outline (contents level1 snumber title
  1012. tags target extra-targets extra-class)
  1013. (let* ((class (format "outline-%d" level1))
  1014. (class (if extra-class (concat class " " extra-class) class))
  1015. (id (and snumber ;; FIXME
  1016. (format "outline-container-%s"
  1017. (org-e-html-suffix-from-snumber snumber))))
  1018. (extra (concat (when id (format " id=\"%s\"" id))
  1019. (when class (format " class=\"%s\"" class)))))
  1020. (concat
  1021. (format "<div%s>\n" extra)
  1022. (org-e-html-format-heading
  1023. (org-e-html-format-headline title extra-targets tags snumber level1)
  1024. level1 target)
  1025. contents
  1026. "</div>")))
  1027. (defun org-e-html-begin-outline-text (level1 snumber extra-class)
  1028. (let* ((class (format "outline-text-%d" level1))
  1029. (class (if extra-class (concat class " " extra-class) class))
  1030. (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
  1031. (extra (concat (when id (format " id=\"%s\"" id))
  1032. (when class (format " class=\"%s\"" class)))))
  1033. (org-lparse-insert-tag "<div%s>" extra)))
  1034. (defun org-e-html-end-outline-text ()
  1035. (org-lparse-insert-tag "</div>"))
  1036. (defun org-e-html-begin-paragraph (&optional style)
  1037. (let* ((class (cdr (assoc style '((footnote . "footnote")
  1038. (verse . nil)))))
  1039. (extra (if class (format " class=\"%s\"" class) "")))
  1040. (org-lparse-insert-tag "<p%s>" extra)))
  1041. (defun org-e-html-end-paragraph ()
  1042. (insert "</p>"))
  1043. ;; Following variables are let bound when table emission is in
  1044. ;; progress. See org-lparse.el.
  1045. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  1046. (defvar org-lparse-table-rowgrp-open)
  1047. (defvar org-lparse-table-rownum)
  1048. (defvar org-lparse-table-cur-rowgrp-is-hdr)
  1049. (defvar org-lparse-table-is-styled)
  1050. (defun org-e-html-format-spaces (n)
  1051. (let (out) (dotimes (i n out) (setq out (concat out "&nbsp;")))))
  1052. (defun org-e-html-format-tabs (&optional n)
  1053. (ignore))
  1054. (defun org-e-html-format-line-break ()
  1055. (org-e-html-format-tags "<br/>" ""))
  1056. (defun org-e-html-format-horizontal-line ()
  1057. (concat "\n" "<hr/>" "\n"))
  1058. ;; (defun org-e-html-format-line (line)
  1059. ;; (case org-lparse-dyn-current-environment
  1060. ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
  1061. ;; (t (concat line "\n"))))
  1062. (defun org-e-html-format-comment (fmt &rest args)
  1063. (let ((comment (apply 'format fmt args)))
  1064. (format "\n<!-- %s -->\n" comment)))
  1065. (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
  1066. "Turn todo keyword into a valid class name.
  1067. Replaces invalid characters with \"_\"."
  1068. (save-match-data
  1069. (while (string-match "[^a-zA-Z0-9_]" kwd)
  1070. (setq kwd (replace-match "_" t t kwd))))
  1071. kwd)
  1072. (defun org-e-html-format-fontify (text style &optional id)
  1073. (let (class extra how)
  1074. (cond
  1075. ((eq style 'underline)
  1076. (setq extra " style=\"text-decoration:underline;\"" ))
  1077. ((setq how (cdr (assoc style
  1078. '((bold . ("<b>" . "</b>"))
  1079. (emphasis . ("<i>" . "</i>"))
  1080. (code . ("<code>" . "</code>"))
  1081. (verbatim . ("<code>" . "</code>"))
  1082. (strike . ("<del>" . "</del>"))
  1083. (subscript . ("<sub>" . "</sub>"))
  1084. (superscript . ("<sup>" . "</sup>")))))))
  1085. ((listp style)
  1086. (setq class (mapconcat 'identity style " ")))
  1087. ((stringp style)
  1088. (setq class style))
  1089. (t (error "Unknown style %S" style)))
  1090. (setq extra (concat (when class (format " class=\"%s\"" class))
  1091. (when id (format " id=\"%s\"" id))
  1092. extra))
  1093. (let ((tags (or how '("<span%s>" . "</span>"))))
  1094. (concat (format (car tags) extra) text (cdr tags)))))
  1095. (defun org-e-html-format-link (text href &optional extra)
  1096. (let ((extra (concat (format " href=\"%s\"" href)
  1097. (and extra (concat " " extra)))))
  1098. (format "<a%s>%s</a>" extra text)))
  1099. (defun org-e-html-format-internal-link (text href &optional extra)
  1100. (org-e-html-format-link text (concat "#" href) extra))
  1101. (defun org-e-html-format-heading (text level &optional id)
  1102. (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
  1103. (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
  1104. (defun org-e-html-format-anchor (text name &optional class)
  1105. (let* ((id name)
  1106. (extra (concat
  1107. (when name (format " name=\"%s\"" name))
  1108. (when id (format " id=\"%s\"" id))
  1109. (when class (format " class=\"%s\"" class)))))
  1110. (format "<a%s>%s</a>" extra text)))
  1111. (defun org-e-html-format-extra-targets (extra-targets)
  1112. (if (not extra-targets) ""
  1113. (mapconcat (lambda (x)
  1114. (when x
  1115. (setq x (org-solidify-link-text
  1116. (if (org-uuidgen-p x) (concat "ID-" x) x)))
  1117. (org-e-html-format-anchor "" x))) extra-targets "")))
  1118. (defun org-e-html-format-org-tags (tags)
  1119. (if (not tags) ""
  1120. (org-e-html-format-fontify
  1121. (mapconcat
  1122. (lambda (x)
  1123. (org-e-html-format-fontify
  1124. x (concat org-e-html-tag-class-prefix
  1125. (org-e-html-fix-class-name x))))
  1126. (org-split-string tags ":")
  1127. (org-e-html-format-spaces 1)) "tag")))
  1128. (defun org-e-html-format-section-number (&optional snumber level)
  1129. ;; FIXME
  1130. (and org-export-with-section-numbers
  1131. ;; (not org-lparse-body-only)
  1132. snumber level
  1133. (org-e-html-format-fontify snumber (format "section-number-%d" level))))
  1134. (defun org-e-html-format-headline (title extra-targets tags
  1135. &optional snumber level)
  1136. (concat
  1137. (org-e-html-format-extra-targets extra-targets)
  1138. (concat (org-e-html-format-section-number snumber level) " ")
  1139. title
  1140. (and tags (concat (org-e-html-format-spaces 3)
  1141. (org-e-html-format-org-tags tags)))))
  1142. (defun org-e-html-format-footnote-reference (n def refcnt)
  1143. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  1144. (format org-e-html-footnote-format
  1145. (format
  1146. "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
  1147. n extra n n))))
  1148. (defun org-e-html-format-footnotes-section (section-name definitions)
  1149. (if (not definitions) ""
  1150. (format org-e-html-footnotes-section section-name definitions)))
  1151. (defun org-e-html-format-footnote-definition (fn)
  1152. (let ((n (car fn)) (def (cdr fn)))
  1153. (format
  1154. "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
  1155. (format
  1156. (format org-e-html-footnote-format
  1157. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1158. n n n) def)))
  1159. (defun org-e-html-footnote-section (info)
  1160. (let* ((fn-alist (org-export-collect-footnote-definitions
  1161. (plist-get info :parse-tree) info))
  1162. (fn-alist
  1163. (loop for (n type raw) in fn-alist collect
  1164. (cons n (if (equal (car raw) 'org-data)
  1165. (org-trim (org-export-data raw 'e-html info))
  1166. (format "<p>%s</p>"
  1167. (org-trim (org-export-secondary-string
  1168. raw 'e-html info))))))))
  1169. (when fn-alist
  1170. (org-e-html-format-footnotes-section
  1171. (nth 4 (or (assoc (plist-get info :language)
  1172. org-export-language-setup)
  1173. (assoc "en" org-export-language-setup)))
  1174. (format
  1175. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">\n%s\n</table>\n"
  1176. (mapconcat 'org-e-html-format-footnote-definition fn-alist "\n"))))))
  1177. (defun org-e-html-format-org-entity (wd)
  1178. (org-entity-get-representation wd 'html))
  1179. (defun org-e-html-format-tags (tag text &rest args)
  1180. (let ((prefix ;; (when org-lparse-encode-pending "@")
  1181. )
  1182. (suffix ;; (when org-lparse-encode-pending "@")
  1183. ))
  1184. (apply 'org-lparse-format-tags tag text prefix suffix args)))
  1185. (defun org-e-html-get (what &optional opt-plist)
  1186. (case what
  1187. (BACKEND 'html)
  1188. (INIT-METHOD nil)
  1189. (SAVE-METHOD nil)
  1190. (CLEANUP-METHOD nil)
  1191. ;; (OTHER-BACKENDS
  1192. ;; ;; There is a provision to register a per-backend converter and
  1193. ;; ;; output formats. Refer `org-lparse-get-converter' and
  1194. ;; ;; `org-lparse-get-other-backends'.
  1195. ;; ;; The default behaviour is to use `org-lparse-convert-process'
  1196. ;; ;; and `org-lparse-convert-capabilities'.
  1197. ;; )
  1198. ;; (CONVERT-METHOD
  1199. ;; ;; See note above
  1200. ;; )
  1201. (EXPORT-DIR (org-export-directory :html opt-plist))
  1202. (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
  1203. (EXPORT-BUFFER-NAME "*Org HTML Export*")
  1204. (TOPLEVEL-HLEVEL org-e-html-toplevel-hlevel)
  1205. (SPECIAL-STRING-REGEXPS org-e-html-special-string-regexps)
  1206. (CODING-SYSTEM-FOR-WRITE org-e-html-coding-system)
  1207. (CODING-SYSTEM-FOR-SAVE org-e-html-coding-system)
  1208. (INLINE-IMAGES org-e-html-inline-images)
  1209. (INLINE-IMAGE-EXTENSIONS org-e-html-inline-image-extensions)
  1210. (PLAIN-TEXT-MAP org-e-html-protect-char-alist)
  1211. (TABLE-FIRST-COLUMN-AS-LABELS
  1212. org-e-html-table-use-header-tags-for-first-column)
  1213. (TODO-KWD-CLASS-PREFIX org-e-html-todo-kwd-class-prefix)
  1214. (TAG-CLASS-PREFIX org-e-html-tag-class-prefix)
  1215. (FOOTNOTE-SEPARATOR org-e-html-footnote-separator)
  1216. (t (error "Unknown property: %s" what))))
  1217. (defun org-e-html-get-coding-system-for-write ()
  1218. (or org-e-html-coding-system
  1219. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1220. (defun org-e-html-get-coding-system-for-save ()
  1221. (or org-e-html-coding-system
  1222. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1223. (defun org-e-html-format-date (info)
  1224. (let ((date (plist-get info :date)))
  1225. (cond
  1226. ((and date (string-match "%" date))
  1227. (format-time-string date))
  1228. (date date)
  1229. (t (format-time-string "%Y-%m-%d %T %Z")))))
  1230. (eval-when-compile (require 'cl))
  1231. ;;; org-e-html.el
  1232. (declare-function org-element-get-property "org-element" (property element))
  1233. (declare-function org-element-normalize-string "org-element" (s))
  1234. (declare-function org-element-parse-secondary-string
  1235. "org-element" (string restriction &optional buffer))
  1236. (defvar org-element-string-restrictions)
  1237. (declare-function org-export-clean-table "org-export" (table specialp))
  1238. (declare-function org-export-data "org-export" (data backend info))
  1239. (declare-function org-export-directory "org-export" (type plist))
  1240. (declare-function org-export-expand-macro "org-export" (macro info))
  1241. (declare-function org-export-first-sibling-p "org-export" (headline info))
  1242. (declare-function org-export-footnote-first-reference-p "org-export"
  1243. (footnote-reference info))
  1244. (declare-function org-export-get-coderef-format "org-export" (path desc))
  1245. (declare-function org-export-get-footnote-definition "org-export"
  1246. (footnote-reference info))
  1247. (declare-function org-export-get-footnote-number "org-export" (footnote info))
  1248. (declare-function org-export-get-previous-element "org-export" (blob info))
  1249. (declare-function org-export-get-relative-level "org-export" (headline info))
  1250. (declare-function org-export-handle-code
  1251. "org-export" (element info &optional num-fmt ref-fmt delayed))
  1252. (declare-function org-export-included-file "org-export" (keyword backend info))
  1253. (declare-function org-export-inline-image-p "org-export"
  1254. (link &optional extensions))
  1255. (declare-function org-export-last-sibling-p "org-export" (headline info))
  1256. (declare-function org-export-low-level-p "org-export" (headline info))
  1257. (declare-function org-export-output-file-name
  1258. "org-export" (extension &optional subtreep pub-dir))
  1259. (declare-function org-export-resolve-coderef "org-export" (ref info))
  1260. (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
  1261. (declare-function org-export-secondary-string "org-export"
  1262. (secondary backend info))
  1263. (declare-function org-export-solidify-link-text "org-export" (s))
  1264. (declare-function org-export-table-format-info "org-export" (table))
  1265. (declare-function
  1266. org-export-to-buffer "org-export"
  1267. (backend buffer &optional subtreep visible-only body-only ext-plist))
  1268. (declare-function
  1269. org-export-to-file "org-export"
  1270. (backend file &optional subtreep visible-only body-only ext-plist))
  1271. ;;; Internal Variables
  1272. (defconst org-e-html-option-alist
  1273. '((:agenda-style nil nil org-agenda-export-html-style)
  1274. (:convert-org-links nil nil org-e-html-link-org-files-as-html)
  1275. ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
  1276. ;; (:expand-quoted-html nil "@" org-e-html-expand)
  1277. (:inline-images nil nil org-e-html-inline-images)
  1278. ;; (:link-home nil nil org-e-html-link-home) FIXME
  1279. ;; (:link-up nil nil org-e-html-link-up) FIXME
  1280. (:style nil nil org-e-html-style)
  1281. (:style-extra nil nil org-e-html-style-extra)
  1282. (:style-include-default nil nil org-e-html-style-include-default)
  1283. (:style-include-scripts nil nil org-e-html-style-include-scripts)
  1284. (:timestamp nil nil org-e-html-with-timestamp)
  1285. (:html-extension nil nil org-e-html-extension)
  1286. (:html-postamble nil nil org-e-html-postamble)
  1287. (:html-preamble nil nil org-e-html-preamble)
  1288. (:html-table-tag nil nil org-e-html-table-tag)
  1289. (:xml-declaration nil nil org-e-html-xml-declaration)
  1290. (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments))
  1291. "Alist between export properties and ways to set them.
  1292. The car of the alist is the property name, and the cdr is a list
  1293. like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
  1294. KEYWORD is a string representing a buffer keyword, or nil.
  1295. OPTION is a string that could be found in an #+OPTIONS: line.
  1296. DEFAULT is the default value for the property.
  1297. BEHAVIOUR determine how Org should handle multiple keywords for
  1298. the same property. It is a symbol among:
  1299. nil Keep old value and discard the new one.
  1300. t Replace old value with the new one.
  1301. `space' Concatenate the values, separating them with a space.
  1302. `newline' Concatenate the values, separating them with
  1303. a newline.
  1304. `split' Split values at white spaces, and cons them to the
  1305. previous list.
  1306. KEYWORD and OPTION have precedence over DEFAULT.
  1307. All these properties should be back-end agnostic. For back-end
  1308. specific properties, define a similar variable named
  1309. `org-BACKEND-option-alist', replacing BACKEND with the name of
  1310. the appropriate back-end. You can also redefine properties
  1311. there, as they have precedence over these.")
  1312. ;;; User Configurable Variables
  1313. (defgroup org-export-e-html nil
  1314. "Options for exporting Org mode files to HTML."
  1315. :tag "Org Export HTML"
  1316. :group 'org-export)
  1317. ;;;; Preamble
  1318. (defcustom org-e-html-inputenc-alist nil
  1319. "Alist of inputenc coding system names, and what should really be used.
  1320. For example, adding an entry
  1321. (\"utf8\" . \"utf8x\")
  1322. will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
  1323. are written as utf8 files."
  1324. :group 'org-export-e-html
  1325. :type '(repeat
  1326. (cons
  1327. (string :tag "Derived from buffer")
  1328. (string :tag "Use this instead"))))
  1329. (defcustom org-e-html-date-format
  1330. "\\today"
  1331. "Format string for \\date{...}."
  1332. :group 'org-export-e-html
  1333. :type 'boolean)
  1334. (defcustom org-e-html-title-command "\\maketitle"
  1335. "The command used to insert the title just after \\begin{document}.
  1336. If this string contains the formatting specification \"%s\" then
  1337. it will be used as a formatting string, passing the title as an
  1338. argument."
  1339. :group 'org-export-e-html
  1340. :type 'string)
  1341. ;;;; Headline
  1342. (defcustom org-e-html-format-headline-function nil
  1343. "Function to format headline text.
  1344. This function will be called with 5 arguments:
  1345. TODO the todo keyword \(string or nil\).
  1346. TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
  1347. PRIORITY the priority of the headline \(integer or nil\)
  1348. TEXT the main headline text \(string\).
  1349. TAGS the tags string, separated with colons \(string or nil\).
  1350. The function result will be used in the section format string.
  1351. As an example, one could set the variable to the following, in
  1352. order to reproduce the default set-up:
  1353. \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
  1354. \"Default format function for an headline.\"
  1355. \(concat \(when todo
  1356. \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
  1357. \(when priority
  1358. \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  1359. text
  1360. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
  1361. :group 'org-export-e-html
  1362. :type 'function)
  1363. ;;;; Emphasis
  1364. (defcustom org-e-html-emphasis-alist
  1365. '(("*" . "\\textbf{%s}")
  1366. ("/" . "\\emph{%s}")
  1367. ("_" . "\\underline{%s}")
  1368. ("+" . "\\st{%s}")
  1369. ("=" . protectedtexttt)
  1370. ("~" . verb))
  1371. "Alist of HTML expressions to convert emphasis fontifiers.
  1372. The key is the character used as a marker for fontification. The
  1373. value is a formatting string to wrap fontified text with.
  1374. Value can also be set to the following symbols: `verb' and
  1375. `protectedtexttt'. For the former, Org will use \"\\verb\" to
  1376. create a format string and select a delimiter character that
  1377. isn't in the string. For the latter, Org will use \"\\texttt\"
  1378. to typeset and try to protect special characters."
  1379. :group 'org-export-e-html
  1380. :type 'alist)
  1381. ;;;; Footnotes
  1382. (defcustom org-e-html-footnote-separator "<sup>, </sup>"
  1383. "Text used to separate footnotes."
  1384. :group 'org-export-e-html
  1385. :type 'string)
  1386. ;;;; Time-stamps
  1387. (defcustom org-e-html-active-timestamp-format "\\textit{%s}"
  1388. "A printf format string to be applied to active time-stamps."
  1389. :group 'org-export-e-html
  1390. :type 'string)
  1391. (defcustom org-e-html-inactive-timestamp-format "\\textit{%s}"
  1392. "A printf format string to be applied to inactive time-stamps."
  1393. :group 'org-export-e-html
  1394. :type 'string)
  1395. (defcustom org-e-html-diary-timestamp-format "\\textit{%s}"
  1396. "A printf format string to be applied to diary time-stamps."
  1397. :group 'org-export-e-html
  1398. :type 'string)
  1399. ;;;; Links
  1400. (defcustom org-e-html-image-default-option "width=.9\\linewidth"
  1401. "Default option for images."
  1402. :group 'org-export-e-html
  1403. :type 'string)
  1404. (defcustom org-e-html-default-figure-position "htb"
  1405. "Default position for latex figures."
  1406. :group 'org-export-e-html
  1407. :type 'string)
  1408. (defcustom org-e-html-inline-image-rules
  1409. '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
  1410. "Rules characterizing image files that can be inlined into HTML.
  1411. A rule consists in an association whose key is the type of link
  1412. to consider, and value is a regexp that will be matched against
  1413. link's path.
  1414. Note that, by default, the image extension *actually* allowed
  1415. depend on the way the HTML file is processed. When used with
  1416. pdflatex, pdf, jpg and png images are OK. When processing
  1417. through dvi to Postscript, only ps and eps are allowed. The
  1418. default we use here encompasses both."
  1419. :group 'org-export-e-html
  1420. :type '(alist :key-type (string :tag "Type")
  1421. :value-type (regexp :tag "Path")))
  1422. ;;;; Tables
  1423. (defcustom org-e-html-default-table-environment "tabular"
  1424. "Default environment used to build tables."
  1425. :group 'org-export-e-html
  1426. :type 'string)
  1427. (defcustom org-e-html-tables-centered t
  1428. "When non-nil, tables are exported in a center environment."
  1429. :group 'org-export-e-html
  1430. :type 'boolean)
  1431. (defcustom org-e-html-tables-verbatim nil
  1432. "When non-nil, tables are exported verbatim."
  1433. :group 'org-export-e-html
  1434. :type 'boolean)
  1435. (defcustom org-e-html-table-caption-above t
  1436. "When non-nil, place caption string at the beginning of the table.
  1437. Otherwise, place it near the end."
  1438. :group 'org-export-e-html
  1439. :type 'boolean)
  1440. ;;;; Drawers
  1441. (defcustom org-e-html-format-drawer-function nil
  1442. "Function called to format a drawer in HTML code.
  1443. The function must accept two parameters:
  1444. NAME the drawer name, like \"LOGBOOK\"
  1445. CONTENTS the contents of the drawer.
  1446. The function should return the string to be exported.
  1447. For example, the variable could be set to the following function
  1448. in order to mimic default behaviour:
  1449. \(defun org-e-html-format-drawer-default \(name contents\)
  1450. \"Format a drawer element for HTML export.\"
  1451. contents\)"
  1452. :group 'org-export-e-html
  1453. :type 'function)
  1454. ;;;; Inlinetasks
  1455. (defcustom org-e-html-format-inlinetask-function nil
  1456. "Function called to format an inlinetask in HTML code.
  1457. The function must accept six parameters:
  1458. TODO the todo keyword, as a string
  1459. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  1460. PRIORITY the inlinetask priority, as a string
  1461. NAME the inlinetask name, as a string.
  1462. TAGS the inlinetask tags, as a string.
  1463. CONTENTS the contents of the inlinetask, as a string.
  1464. The function should return the string to be exported.
  1465. For example, the variable could be set to the following function
  1466. in order to mimic default behaviour:
  1467. \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
  1468. \"Format an inline task element for HTML export.\"
  1469. \(let \(\(full-title
  1470. \(concat
  1471. \(when todo
  1472. \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
  1473. \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  1474. title
  1475. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
  1476. \(format \(concat \"\\\\begin{center}\\n\"
  1477. \"\\\\fbox{\\n\"
  1478. \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
  1479. \"%s\\n\\n\"
  1480. \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
  1481. \"%s\"
  1482. \"\\\\end{minipage}}\"
  1483. \"\\\\end{center}\"\)
  1484. full-title contents\)\)"
  1485. :group 'org-export-e-html
  1486. :type 'function)
  1487. ;; Src blocks
  1488. ;;;; Plain text
  1489. (defcustom org-e-html-quotes
  1490. '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
  1491. ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
  1492. "Alist for quotes to use when converting english double-quotes.
  1493. The CAR of each item in this alist is the language code.
  1494. The CDR of each item in this alist is a list of three CONS:
  1495. - the first CONS defines the opening quote;
  1496. - the second CONS defines the closing quote;
  1497. - the last CONS defines single quotes.
  1498. For each item in a CONS, the first string is a regexp
  1499. for allowed characters before/after the quote, the second
  1500. string defines the replacement string for this quote."
  1501. :group 'org-export-e-html
  1502. :type '(list
  1503. (cons :tag "Opening quote"
  1504. (string :tag "Regexp for char before")
  1505. (string :tag "Replacement quote "))
  1506. (cons :tag "Closing quote"
  1507. (string :tag "Regexp for char after ")
  1508. (string :tag "Replacement quote "))
  1509. (cons :tag "Single quote"
  1510. (string :tag "Regexp for char before")
  1511. (string :tag "Replacement quote "))))
  1512. ;;;; Compilation
  1513. (defcustom org-e-html-pdf-process
  1514. '("pdflatex -interaction nonstopmode -output-directory %o %f"
  1515. "pdflatex -interaction nonstopmode -output-directory %o %f"
  1516. "pdflatex -interaction nonstopmode -output-directory %o %f")
  1517. "Commands to process a HTML file to a PDF file.
  1518. This is a list of strings, each of them will be given to the
  1519. shell as a command. %f in the command will be replaced by the
  1520. full file name, %b by the file base name \(i.e. without
  1521. extension) and %o by the base directory of the file.
  1522. The reason why this is a list is that it usually takes several
  1523. runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
  1524. does not have a clever mechanism to detect which of these
  1525. commands have to be run to get to a stable result, and it also
  1526. does not do any error checking.
  1527. By default, Org uses 3 runs of `pdflatex' to do the processing.
  1528. If you have texi2dvi on your system and if that does not cause
  1529. the infamous egrep/locale bug:
  1530. http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
  1531. then `texi2dvi' is the superior choice. Org does offer it as one
  1532. of the customize options.
  1533. Alternatively, this may be a Lisp function that does the
  1534. processing, so you could use this to apply the machinery of
  1535. AUCTeX or the Emacs HTML mode. This function should accept the
  1536. file name as its single argument."
  1537. :group 'org-export-pdf
  1538. :type '(choice
  1539. (repeat :tag "Shell command sequence"
  1540. (string :tag "Shell command"))
  1541. (const :tag "2 runs of pdflatex"
  1542. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  1543. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  1544. (const :tag "3 runs of pdflatex"
  1545. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  1546. "pdflatex -interaction nonstopmode -output-directory %o %f"
  1547. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  1548. (const :tag "pdflatex,bibtex,pdflatex,pdflatex"
  1549. ("pdflatex -interaction nonstopmode -output-directory %o %f"
  1550. "bibtex %b"
  1551. "pdflatex -interaction nonstopmode -output-directory %o %f"
  1552. "pdflatex -interaction nonstopmode -output-directory %o %f"))
  1553. (const :tag "texi2dvi"
  1554. ("texi2dvi -p -b -c -V %f"))
  1555. (const :tag "rubber"
  1556. ("rubber -d --into %o %f"))
  1557. (function)))
  1558. (defcustom org-e-html-logfiles-extensions
  1559. '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
  1560. "The list of file extensions to consider as HTML logfiles."
  1561. :group 'org-export-e-html
  1562. :type '(repeat (string :tag "Extension")))
  1563. (defcustom org-e-html-remove-logfiles t
  1564. "Non-nil means remove the logfiles produced by PDF production.
  1565. These are the .aux, .log, .out, and .toc files."
  1566. :group 'org-export-e-html
  1567. :type 'boolean)
  1568. ;;; Internal Functions
  1569. (defun org-e-html--caption/label-string (caption label info)
  1570. "Return caption and label HTML string for floats.
  1571. CAPTION is a cons cell of secondary strings, the car being the
  1572. standard caption and the cdr its short form. LABEL is a string
  1573. representing the label. INFO is a plist holding contextual
  1574. information.
  1575. If there's no caption nor label, return the empty string.
  1576. For non-floats, see `org-e-html--wrap-label'."
  1577. (setq label nil) ;; FIXME
  1578. (let ((label-str (if label (format "\\label{%s}" label) "")))
  1579. (cond
  1580. ((and (not caption) (not label)) "")
  1581. ((not caption) (format "\\label{%s}\n" label))
  1582. ;; Option caption format with short name.
  1583. ((cdr caption)
  1584. (format "\\caption[%s]{%s%s}\n"
  1585. (org-export-secondary-string (cdr caption) 'e-html info)
  1586. label-str
  1587. (org-export-secondary-string (car caption) 'e-html info)))
  1588. ;; Standard caption format.
  1589. ;; (t (format "\\caption{%s%s}\n"
  1590. ;; label-str
  1591. ;; (org-export-secondary-string (car caption) 'e-html info)))
  1592. (t (org-export-secondary-string (car caption) 'e-html info)))))
  1593. (defun org-e-html--find-verb-separator (s)
  1594. "Return a character not used in string S.
  1595. This is used to choose a separator for constructs like \\verb."
  1596. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1597. (loop for c across ll
  1598. when (not (string-match (regexp-quote (char-to-string c)) s))
  1599. return (char-to-string c))))
  1600. (defun org-e-html--make-option-string (options)
  1601. "Return a comma separated string of keywords and values.
  1602. OPTIONS is an alist where the key is the options keyword as
  1603. a string, and the value a list containing the keyword value, or
  1604. nil."
  1605. (mapconcat (lambda (pair)
  1606. (concat (first pair)
  1607. (when (> (length (second pair)) 0)
  1608. (concat "=" (second pair)))))
  1609. options
  1610. ","))
  1611. (defun org-e-html--quotation-marks (text info)
  1612. "Export quotation marks depending on language conventions.
  1613. TEXT is a string containing quotation marks to be replaced. INFO
  1614. is a plist used as a communication channel."
  1615. (mapc (lambda(l)
  1616. (let ((start 0))
  1617. (while (setq start (string-match (car l) text start))
  1618. (let ((new-quote (concat (match-string 1 text) (cdr l))))
  1619. (setq text (replace-match new-quote t t text))))))
  1620. (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
  1621. ;; Falls back on English.
  1622. (assoc "en" org-e-html-quotes))))
  1623. text)
  1624. (defun org-e-html--wrap-label (element output)
  1625. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  1626. This function shouldn't be used for floats. See
  1627. `org-e-html--caption/label-string'."
  1628. ;; (let ((label (org-element-get-property :name element)))
  1629. ;; (if (or (not output) (not label) (string= output "") (string= label ""))
  1630. ;; output
  1631. ;; (concat (format "\\label{%s}\n" label) output)))
  1632. output)
  1633. ;;; Template
  1634. ;; (defun org-e-html-template (contents info)
  1635. ;; "Return complete document string after HTML conversion.
  1636. ;; CONTENTS is the transcoded contents string. INFO is a plist
  1637. ;; holding export options."
  1638. ;; (let ((title (org-export-secondary-string
  1639. ;; (plist-get info :title) 'e-html info)))
  1640. ;; (concat
  1641. ;; ;; 1. Time-stamp.
  1642. ;; (and (plist-get info :time-stamp-file)
  1643. ;; (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  1644. ;; ;; 2. Document class and packages.
  1645. ;; (let ((class (plist-get info :latex-class))
  1646. ;; (class-options (plist-get info :latex-class-options)))
  1647. ;; (org-element-normalize-string
  1648. ;; (let* ((header (nth 1 (assoc class org-e-html-classes)))
  1649. ;; (document-class-string
  1650. ;; (and (stringp header)
  1651. ;; (if class-options
  1652. ;; (replace-regexp-in-string
  1653. ;; "^[ \t]*\\\\documentclass\\(\\[.*?\\]\\)"
  1654. ;; class-options header t nil 1)
  1655. ;; header))))
  1656. ;; (org-e-html--guess-inputenc
  1657. ;; (org-splice-latex-header
  1658. ;; document-class-string
  1659. ;; org-export-latex-default-packages-alist ; defined in org.el
  1660. ;; org-export-latex-packages-alist nil ; defined in org.el
  1661. ;; (plist-get info :latex-header-extra))))))
  1662. ;; ;; 3. Define alert if not yet defined.
  1663. ;; "\\providecommand{\\alert}[1]{\\textbf{#1}}\n"
  1664. ;; ;; 4. Possibly limit depth for headline numbering.
  1665. ;; (let ((sec-num (plist-get info :section-numbers)))
  1666. ;; (when (integerp sec-num)
  1667. ;; (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
  1668. ;; ;; 5. Author.
  1669. ;; (let ((author (and (plist-get info :with-author)
  1670. ;; (let ((auth (plist-get info :author)))
  1671. ;; (and auth (org-export-secondary-string
  1672. ;; auth 'e-html info)))))
  1673. ;; (email (and (plist-get info :with-email)
  1674. ;; (org-export-secondary-string
  1675. ;; (plist-get info :email) 'e-html info))))
  1676. ;; (cond ((and author email (not (string= "" email)))
  1677. ;; (format "\\author{%s\\thanks{%s}}\n" author email))
  1678. ;; (author (format "\\author{%s}\n" author))
  1679. ;; (t "\\author{}\n")))
  1680. ;; ;; 6. Date.
  1681. ;; (let ((date (plist-get info :date)))
  1682. ;; (and date (format "\\date{%s}\n" date)))
  1683. ;; ;; 7. Title
  1684. ;; (format "\\title{%s}\n" title)
  1685. ;; ;; 8. Hyperref options.
  1686. ;; (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
  1687. ;; (or (plist-get info :keywords) "")
  1688. ;; (or (plist-get info :description) "")
  1689. ;; (if (not (plist-get info :with-creator)) ""
  1690. ;; (plist-get info :creator)))
  1691. ;; ;; 9. Document start.
  1692. ;; "\\begin{document}\n\n"
  1693. ;; ;; 10. Title command.
  1694. ;; (org-element-normalize-string
  1695. ;; (cond ((string= "" title) nil)
  1696. ;; ((not (stringp org-e-html-title-command)) nil)
  1697. ;; ((string-match "\\(?:[^%]\\|^\\)%s"
  1698. ;; org-e-html-title-command)
  1699. ;; (format org-e-html-title-command title))
  1700. ;; (t org-e-html-title-command)))
  1701. ;; ;; 11. Table of contents.
  1702. ;; (let ((depth (plist-get info :with-toc)))
  1703. ;; (when depth
  1704. ;; (concat (when (wholenump depth)
  1705. ;; (format "\\setcounter{tocdepth}{%d}\n" depth))
  1706. ;; "\\tableofcontents\n\\vspace*{1cm}\n\n")))
  1707. ;; ;; 12. Document's body.
  1708. ;; contents
  1709. ;; ;; 13. Creator.
  1710. ;; (let ((creator-info (plist-get info :with-creator)))
  1711. ;; (cond
  1712. ;; ((not creator-info) "")
  1713. ;; ((eq creator-info 'comment)
  1714. ;; (format "%% %s\n" (plist-get info :creator)))
  1715. ;; (t (concat (plist-get info :creator) "\n"))))
  1716. ;; ;; 14. Document end.
  1717. ;; "\\end{document}")))
  1718. (defun org-e-html-meta-info (info)
  1719. (concat
  1720. (format "
  1721. <title>%s</title>" (plist-get info :title))
  1722. (format "
  1723. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
  1724. (and coding-system-for-write
  1725. (fboundp 'coding-system-get)
  1726. (coding-system-get coding-system-for-write
  1727. 'mime-charset)))
  1728. (format "
  1729. <meta name=\"title\" content=\"%s\"/>" (plist-get info :title))
  1730. "
  1731. <meta name=\"generator\" content=\"Org-mode\"/>"
  1732. (format "
  1733. <meta name=\"generated\" content=\"%s\"/>" (org-e-html-format-date info))
  1734. (format "
  1735. <meta name=\"author\" content=\"%s\"/>" (plist-get info :author))
  1736. (format "
  1737. <meta name=\"description\" content=\"%s\"/>" (plist-get info :description))
  1738. (format "
  1739. <meta name=\"keywords\" content=\"%s\"/>" (plist-get info :keywords))))
  1740. (defun org-e-html-style (info)
  1741. (concat
  1742. (when (plist-get info :style-include-default)
  1743. org-e-html-style-default)
  1744. (plist-get info :style)
  1745. (plist-get info :style-extra)
  1746. "\n"
  1747. (when (plist-get info :style-include-scripts)
  1748. org-e-html-scripts)))
  1749. (defun org-e-html-mathjax (info)
  1750. (when (or (eq (plist-get info :HTML-fragments) 'mathjax)
  1751. (and org-export-have-math
  1752. (eq (plist-get info :HTML-fragments) t)))
  1753. (org-e-html-mathjax-config
  1754. org-e-html-mathjax-template
  1755. org-e-html-mathjax-options
  1756. (or (plist-get info :mathjax) ""))))
  1757. (defun org-e-html-preamble (info)
  1758. (when (plist-get info :html-preamble)
  1759. (let* ((title (plist-get info :title))
  1760. (date (org-e-html-format-date info))
  1761. (author (plist-get info :author))
  1762. (lang-words (or (assoc (plist-get info :language)
  1763. org-export-language-setup)
  1764. (assoc "en" org-export-language-setup)))
  1765. (email (plist-get info :email))
  1766. (html-pre-real-contents
  1767. (cond
  1768. ((functionp (plist-get info :html-preamble))
  1769. (with-temp-buffer
  1770. (funcall (plist-get info :html-preamble))
  1771. (buffer-string)))
  1772. ((stringp (plist-get info :html-preamble))
  1773. (format-spec (plist-get info :html-preamble)
  1774. `((?t . ,title) (?a . ,author)
  1775. (?d . ,date) (?e . ,email))))
  1776. (t
  1777. (format-spec
  1778. (or (cadr (assoc (nth 0 lang-words)
  1779. org-e-html-preamble-format))
  1780. (cadr (assoc "en" org-e-html-preamble-format)))
  1781. `((?t . ,title) (?a . ,author)
  1782. (?d . ,date) (?e . ,email)))))))
  1783. (when (not (equal html-pre-real-contents ""))
  1784. (concat
  1785. (format "
  1786. <div id=\"%s\"> " (nth 0 org-e-html-divs))
  1787. "
  1788. "
  1789. html-pre-real-contents
  1790. "
  1791. </div>")))))
  1792. (defun org-e-html-postamble (info)
  1793. (concat
  1794. (when (and (not body-only)
  1795. (plist-get info :html-postamble))
  1796. (let* ((html-post (plist-get info :html-postamble))
  1797. (date (org-e-html-format-date info))
  1798. (author (plist-get info :author))
  1799. (email (plist-get info :email))
  1800. (lang-words (or (assoc (plist-get info :language)
  1801. org-export-language-setup)
  1802. (assoc "en" org-export-language-setup)))
  1803. (email
  1804. (mapconcat (lambda(e)
  1805. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1806. (split-string email ",+ *")
  1807. ", "))
  1808. (html-validation-link (or org-e-html-validation-link ""))
  1809. (creator-info
  1810. (concat "Org version " org-version " with Emacs version "
  1811. (number-to-string emacs-major-version))))
  1812. (concat
  1813. ;; begin postamble
  1814. "
  1815. <div id=\"" (nth 2 org-e-html-divs) "\">"
  1816. (cond
  1817. ;; auto postamble
  1818. ((eq (plist-get info :html-postamble) 'auto)
  1819. (concat
  1820. (when (plist-get info :time-stamp-file)
  1821. (format "
  1822. <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
  1823. (when (and (plist-get info :with-author) author)
  1824. (format "
  1825. <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
  1826. (when (and (plist-get info :with-email) email)
  1827. (format "
  1828. <p class=\"email\"> %s </p>" email))
  1829. (when (plist-get info :with-creator)
  1830. (format "
  1831. <p class=\"creator\"> %s </p>" creator-info))
  1832. html-validation-link "\n"))
  1833. ;; postamble from a string
  1834. ((stringp (plist-get info :html-postamble))
  1835. (format-spec (plist-get info :html-postamble)
  1836. `((?a . ,author) (?e . ,email)
  1837. (?d . ,date) (?c . ,creator-info)
  1838. (?v . ,html-validation-link))))
  1839. ;; postamble from a function
  1840. ((functionp (plist-get info :html-postamble))
  1841. (with-temp-buffer
  1842. (funcall (plist-get info :html-postamble))
  1843. (buffer-string)))
  1844. ;; default postamble
  1845. (t
  1846. (format-spec
  1847. (or (cadr (assoc (nth 0 lang-words)
  1848. org-e-html-postamble-format))
  1849. (cadr (assoc "en" org-e-html-postamble-format)))
  1850. `((?a . ,author) (?e . ,email)
  1851. (?d . ,date) (?c . ,creator-info)
  1852. (?v . ,html-validation-link)))))
  1853. "
  1854. </div>")))
  1855. org-e-html-html-helper-timestamp))
  1856. (defun org-e-html-template (contents info)
  1857. "Return complete document string after HTML conversion.
  1858. CONTENTS is the transcoded contents string. RAW-DATA is the
  1859. original parsed data. INFO is a plist holding export options."
  1860. (concat
  1861. (format
  1862. (or (and (stringp org-e-html-xml-declaration)
  1863. org-e-html-xml-declaration)
  1864. (cdr (assoc (plist-get info :html-extension)
  1865. org-e-html-xml-declaration))
  1866. (cdr (assoc "html" org-e-html-xml-declaration))
  1867. "")
  1868. (or (and coding-system-for-write
  1869. (fboundp 'coding-system-get)
  1870. (coding-system-get coding-system-for-write
  1871. 'mime-charset))
  1872. "iso-8859-1"))
  1873. "
  1874. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1875. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
  1876. (format "
  1877. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
  1878. (plist-get info :language) (plist-get info :language))
  1879. "
  1880. <head>"
  1881. (org-e-html-meta-info info) ; meta
  1882. (org-e-html-style info) ; style
  1883. (org-e-html-mathjax info) ; mathjax
  1884. "
  1885. </head>"
  1886. "
  1887. <body>"
  1888. (let ((link-up (and (plist-get info :link-up)
  1889. (string-match "\\S-" (plist-get info :link-up))
  1890. (plist-get info :link-up)))
  1891. (link-home (and (plist-get info :link-home)
  1892. (string-match "\\S-" (plist-get info :link-home))
  1893. (plist-get info :link-home))))
  1894. (when (or link-up link-home)
  1895. (format org-e-html-home/up-format
  1896. (or link-up link-home)
  1897. (or link-home link-up))))
  1898. ;; preamble
  1899. (org-e-html-preamble info)
  1900. ;; content
  1901. (format "
  1902. <div id=\"%s\">" (or org-e-html-content-div
  1903. (nth 1 org-e-html-divs)))
  1904. (format "
  1905. <h1 class=\"title\"> %s </h1>\n" (plist-get info :title))
  1906. contents
  1907. (org-e-html-footnote-section info)
  1908. (org-e-html-bibliography)
  1909. (unless body-only
  1910. "
  1911. </div>")
  1912. ;; postamble
  1913. (org-e-html-postamble info)
  1914. (unless body-only
  1915. "
  1916. </body>")
  1917. "
  1918. </html>"))
  1919. ;;; Transcode Functions
  1920. ;;;; Block
  1921. (defun org-e-html-center-block (center-block contents info)
  1922. "Transcode a CENTER-BLOCK element from Org to HTML.
  1923. CONTENTS holds the contents of the block. INFO is a plist
  1924. holding contextual information."
  1925. (org-e-html--wrap-label
  1926. center-block
  1927. (format "<div style=\"text-align: center\">\n%s</div>" contents)))
  1928. ;;;; Comment
  1929. ;; Comments are ignored.
  1930. ;;;; Comment Block
  1931. ;; Comment Blocks are ignored.
  1932. ;;;; Drawer
  1933. (defun org-e-html-drawer (drawer contents info)
  1934. "Transcode a DRAWER element from Org to HTML.
  1935. CONTENTS holds the contents of the block. INFO is a plist
  1936. holding contextual information."
  1937. (let* ((name (org-element-get-property :drawer-name drawer))
  1938. (output (if (functionp org-e-html-format-drawer-function)
  1939. (funcall org-e-html-format-drawer-function
  1940. name contents)
  1941. ;; If there's no user defined function: simply
  1942. ;; display contents of the drawer.
  1943. contents)))
  1944. (org-e-html--wrap-label drawer output)))
  1945. ;;;; Dynamic Block
  1946. (defun org-e-html-dynamic-block (dynamic-block contents info)
  1947. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1948. CONTENTS holds the contents of the block. INFO is a plist
  1949. holding contextual information. See
  1950. `org-export-data'."
  1951. (org-e-html--wrap-label dynamic-block contents))
  1952. ;;;; Emphasis
  1953. (defun org-e-html-emphasis (emphasis contents info)
  1954. "Transcode EMPHASIS from Org to HTML.
  1955. CONTENTS is the contents of the emphasized text. INFO is a plist
  1956. holding contextual information.."
  1957. ;; (format (cdr (assoc (org-element-get-property :marker emphasis)
  1958. ;; org-e-html-emphasis-alist))
  1959. ;; contents)
  1960. (org-e-html-format-fontify
  1961. contents (cadr (assoc
  1962. (org-element-get-property :marker emphasis)
  1963. '(("*" bold)
  1964. ("/" emphasis)
  1965. ("_" underline)
  1966. ("=" code)
  1967. ("~" verbatim)
  1968. ("+" strike))))))
  1969. ;;;; Entity
  1970. (defun org-e-html-entity (entity contents info)
  1971. "Transcode an ENTITY object from Org to HTML.
  1972. CONTENTS are the definition itself. INFO is a plist holding
  1973. contextual information."
  1974. ;; (let ((ent (org-element-get-property :latex entity)))
  1975. ;; (if (org-element-get-property :latex-math-p entity)
  1976. ;; (format "$%s$" ent)
  1977. ;; ent))
  1978. (org-element-get-property :html entity))
  1979. ;;;; Example Block
  1980. ;; (defun org-odt-format-source-code-or-example-colored
  1981. ;; (lines lang caption textareap cols rows num cont rpllbl fmt))
  1982. (defun org-e-html-format-source-code-or-example-plain
  1983. (lines lang caption textareap cols rows num cont rpllbl fmt)
  1984. (setq lines
  1985. (concat
  1986. "<pre class=\"example\">\n"
  1987. (cond
  1988. (textareap
  1989. (concat
  1990. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
  1991. cols rows)
  1992. lines "</textarea>\n</p>\n"))
  1993. (t
  1994. (with-temp-buffer
  1995. (insert lines)
  1996. (goto-char (point-min))
  1997. (while (re-search-forward "[<>&]" nil t)
  1998. (replace-match (cdr (assq (char-before)
  1999. '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
  2000. t t))
  2001. (buffer-string))))
  2002. "</pre>\n"))
  2003. (unless textareap
  2004. (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
  2005. ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
  2006. ;; (setq lines (replace-match "\\1" t nil lines)))
  2007. lines)
  2008. (defun org-e-html-format-source-code-or-example-colored
  2009. (lines lang caption textareap cols rows num cont rpllbl fmt)
  2010. (let* ((lang-m (when lang
  2011. (or (cdr (assoc lang org-src-lang-modes))
  2012. lang)))
  2013. (mode (and lang-m (intern
  2014. (concat
  2015. (if (symbolp lang-m)
  2016. (symbol-name lang-m)
  2017. lang-m)
  2018. "-mode"))))
  2019. (org-inhibit-startup t)
  2020. (org-startup-folded nil))
  2021. (setq lines
  2022. (with-temp-buffer
  2023. (insert lines)
  2024. (if (functionp mode)
  2025. (funcall mode)
  2026. (fundamental-mode))
  2027. (font-lock-fontify-buffer)
  2028. ;; markup each line separately
  2029. (org-remove-formatting-on-newlines-in-region
  2030. (point-min) (point-max))
  2031. (org-src-mode)
  2032. (set-buffer-modified-p nil)
  2033. (org-export-e-htmlize-region-for-paste
  2034. (point-min) (point-max))))
  2035. (when (string-match "<pre\\([^>]*\\)>\n*" lines)
  2036. (setq lines (replace-match
  2037. (format "<pre class=\"src src-%s\">\n" lang) t t lines)))
  2038. (when caption
  2039. (setq lines
  2040. (concat
  2041. "<div class=\"org-src-container\">"
  2042. (format "<label class=\"org-src-name\">%s</label>" caption)
  2043. lines "</div>")))
  2044. (unless textareap
  2045. (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
  2046. ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
  2047. ;; (setq lines (replace-match "\\1" t nil lines)))
  2048. lines))
  2049. (defun org-e-html-format-source-code-or-example
  2050. (lang code &optional opts indent caption)
  2051. "Format CODE from language LANG and return it formatted for export.
  2052. The CODE is marked up in `org-export-current-backend' format.
  2053. Check if a function by name
  2054. \"org-<backend>-format-source-code-or-example\" is bound. If yes,
  2055. use it as the custom formatter. Otherwise, use the default
  2056. formatter. Default formatters are provided for docbook, html,
  2057. latex and ascii backends. For example, use
  2058. `org-e-html-format-source-code-or-example' to provide a custom
  2059. formatter for export to \"html\".
  2060. If LANG is nil, do not add any fontification.
  2061. OPTS contains formatting options, like `-n' for triggering numbering lines,
  2062. and `+n' for continuing previous numbering.
  2063. Code formatting according to language currently only works for HTML.
  2064. Numbering lines works for all three major backends (html, latex, and ascii).
  2065. INDENT was the original indentation of the block."
  2066. (save-match-data
  2067. (let* ((backend-formatter 'org-e-html-format-source-code-or-example-plain)
  2068. num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
  2069. (setq opts (or opts "")
  2070. num (string-match "[-+]n\\>" opts)
  2071. cont (string-match "\\+n\\>" opts)
  2072. rpllbl (string-match "-r\\>" opts)
  2073. keepp (string-match "-k\\>" opts)
  2074. textareap (string-match "-t\\>" opts)
  2075. preserve-indentp (or org-src-preserve-indentation
  2076. (string-match "-i\\>" opts))
  2077. cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
  2078. (string-to-number (match-string 1 opts))
  2079. 80)
  2080. rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
  2081. (string-to-number (match-string 1 opts))
  2082. (org-count-lines code))
  2083. fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
  2084. (match-string 1 opts)))
  2085. (when (and textareap
  2086. ;; (eq org-export-current-backend 'html)
  2087. )
  2088. ;; we cannot use numbering or highlighting.
  2089. (setq num nil cont nil lang nil))
  2090. (if keepp (setq rpllbl 'keep))
  2091. (setq rtn (if preserve-indentp code (org-remove-indentation code)))
  2092. (when (string-match "^," rtn)
  2093. (setq rtn (with-temp-buffer
  2094. (insert rtn)
  2095. ;; Free up the protected lines
  2096. (goto-char (point-min))
  2097. (while (re-search-forward "^," nil t)
  2098. (if (or (equal lang "org")
  2099. (save-match-data
  2100. (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
  2101. (replace-match ""))
  2102. (end-of-line 1))
  2103. (buffer-string))))
  2104. (when lang
  2105. (if (featurep 'xemacs)
  2106. (require 'htmlize)
  2107. (require 'htmlize nil t)))
  2108. (setq backend-formatter
  2109. (cond
  2110. ((fboundp 'htmlize-region-for-paste)
  2111. 'org-e-html-format-source-code-or-example-colored)
  2112. (t
  2113. (message
  2114. "htmlize.el 1.34 or later is needed for source code formatting")
  2115. 'org-e-html-format-source-code-or-example-plain)))
  2116. (funcall backend-formatter rtn lang caption textareap cols rows
  2117. num cont rpllbl fmt))))
  2118. (defun org-e-html-example-block (example-block contents info)
  2119. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  2120. CONTENTS is nil. INFO is a plist holding contextual information."
  2121. (let* ((options (or (org-element-get-property :options example-block) ""))
  2122. (value (org-export-handle-code example-block info)))
  2123. ;; (org-e-html--wrap-label
  2124. ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
  2125. (org-e-html--wrap-label
  2126. example-block (org-e-html-format-source-code-or-example nil value))))
  2127. ;;;; Export Snippet
  2128. (defun org-e-html-export-snippet (export-snippet contents info)
  2129. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  2130. CONTENTS is nil. INFO is a plist holding contextual information."
  2131. (org-element-get-property :value export-snippet))
  2132. ;;;; Export Block
  2133. (defun org-e-html-export-block (export-block contents info)
  2134. "Transcode a EXPORT-BLOCK element from Org to HTML.
  2135. CONTENTS is nil. INFO is a plist holding contextual information."
  2136. (when (string= (org-element-get-property :type export-block) "latex")
  2137. (org-remove-indentation (org-element-get-property :value export-block))))
  2138. ;;;; Fixed Width
  2139. (defun org-e-html-fixed-width (fixed-width contents info)
  2140. "Transcode a FIXED-WIDTH element from Org to HTML.
  2141. CONTENTS is nil. INFO is a plist holding contextual information."
  2142. (let* ((value (org-element-normalize-string
  2143. (replace-regexp-in-string
  2144. "^[ \t]*: ?" ""
  2145. (org-element-get-property :value fixed-width)))))
  2146. (org-e-html--wrap-label
  2147. fixed-width (org-e-html-format-source-code-or-example nil value))))
  2148. ;;;; Footnote Definition
  2149. ;; Footnote Definitions are ignored.
  2150. ;;;; Footnote Reference
  2151. (defun org-e-html-footnote-reference (footnote-reference contents info)
  2152. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  2153. CONTENTS is nil. INFO is a plist holding contextual information."
  2154. (concat
  2155. ;; Insert separator between two footnotes in a row.
  2156. (let ((prev (org-export-get-previous-element footnote-reference info)))
  2157. (when (and (listp prev) (eq (car prev) 'footnote-reference))
  2158. org-e-html-footnote-separator))
  2159. (cond
  2160. ((not (org-export-footnote-first-reference-p footnote-reference info))
  2161. (org-e-html-format-footnote-reference
  2162. (org-export-get-footnote-number footnote-reference info)
  2163. "IGNORED" 100))
  2164. ;; Inline definitions are secondary strings.
  2165. ((eq (org-element-get-property :type footnote-reference) 'inline)
  2166. (org-e-html-format-footnote-reference
  2167. (org-export-get-footnote-number footnote-reference info)
  2168. "IGNORED" 1))
  2169. ;; Non-inline footnotes definitions are full Org data.
  2170. (t (org-e-html-format-footnote-reference
  2171. (org-export-get-footnote-number footnote-reference info)
  2172. "IGNORED" 1)))))
  2173. ;;;; Headline
  2174. (defun org-e-html-todo (todo)
  2175. (when todo
  2176. (org-e-html-format-fontify
  2177. (concat
  2178. ;; (ignore-errors (org-lparse-get 'TODO-KWD-CLASS-PREFIX))
  2179. org-e-html-todo-kwd-class-prefix
  2180. (org-e-html-fix-class-name todo))
  2181. (list (if (member todo org-done-keywords) "done" "todo")
  2182. todo))))
  2183. (defun org-e-html-headline (headline contents info)
  2184. "Transcode an HEADLINE element from Org to HTML.
  2185. CONTENTS holds the contents of the headline. INFO is a plist
  2186. holding contextual information."
  2187. (let* ((class (plist-get info :latex-class))
  2188. (numberedp (plist-get info :section-numbers))
  2189. ;; Get level relative to current parsed data.
  2190. (level (org-export-get-relative-level headline info))
  2191. ;; (class-sectionning (assoc class org-e-html-classes))
  2192. ;; Section formatting will set two placeholders: one for the
  2193. ;; title and the other for the contents.
  2194. ;; (section-fmt
  2195. ;; (let ((sec (if (and (symbolp (nth 2 class-sectionning))
  2196. ;; (fboundp (nth 2 class-sectionning)))
  2197. ;; (funcall (nth 2 class-sectionning) level numberedp)
  2198. ;; (nth (1+ level) class-sectionning))))
  2199. ;; (cond
  2200. ;; ;; No section available for that LEVEL.
  2201. ;; ((not sec) nil)
  2202. ;; ;; Section format directly returned by a function.
  2203. ;; ((stringp sec) sec)
  2204. ;; ;; (numbered-section . unnumbered-section)
  2205. ;; ((not (consp (cdr sec)))
  2206. ;; (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
  2207. ;; ;; (numbered-open numbered-close)
  2208. ;; ((= (length sec) 2)
  2209. ;; (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
  2210. ;; ;; (num-in num-out no-num-in no-num-out)
  2211. ;; ((= (length sec) 4)
  2212. ;; (if numberedp
  2213. ;; (concat (car sec) "\n%s" (nth 1 sec))
  2214. ;; (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
  2215. (text (org-export-secondary-string
  2216. (org-element-get-property :title headline) 'e-html info))
  2217. (todo (and (plist-get info :with-todo-keywords)
  2218. (let ((todo (org-element-get-property
  2219. :todo-keyword headline)))
  2220. (and todo
  2221. (org-export-secondary-string todo 'e-html info)))))
  2222. (todo-type (and todo (org-element-get-property :todo-type headline)))
  2223. (tags (and (plist-get info :with-tags)
  2224. (org-element-get-property :tags headline)))
  2225. (priority (and (plist-get info :with-priority)
  2226. (org-element-get-property :priority headline)))
  2227. ;; Create the headline text.
  2228. (full-text (if (functionp org-e-html-format-headline-function)
  2229. ;; User-defined formatting function.
  2230. (funcall org-e-html-format-headline-function
  2231. todo todo-type priority text tags)
  2232. ;; Default formatting.
  2233. (concat
  2234. ;; (when todo
  2235. ;; (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  2236. (org-e-html-todo todo) " "
  2237. (when priority (format "\\framebox{\\#%c} " priority))
  2238. text
  2239. ;; (when tags (format "\\hfill{}\\textsc{%s}" tags))
  2240. )))
  2241. ;; Associate some \label to the headline for internal links.
  2242. ;; (headline-label
  2243. ;; (format "\\label{sec-%s}\n"
  2244. ;; (mapconcat 'number-to-string
  2245. ;; (org-export-get-headline-number headline info)
  2246. ;; "-")))
  2247. ;; FIXME - begin
  2248. (headline-no (org-export-get-headline-number headline info))
  2249. (headline-label
  2250. (format "sec-%s" (mapconcat 'number-to-string headline-no "-")))
  2251. (headline-labels (list headline-label))
  2252. (headline-no (org-export-get-headline-number headline info))
  2253. (section-no (mapconcat 'number-to-string headline-no "."))
  2254. ;; FIXME - end
  2255. (pre-blanks (make-string
  2256. (org-element-get-property :pre-blank headline) 10)))
  2257. (cond
  2258. ;; Case 1: This is a footnote section: ignore it.
  2259. ((org-element-get-property :footnote-section-p headline) nil)
  2260. ;; Case 2. This is a deep sub-tree: export it as a list item.
  2261. ;; Also export as items headlines for which no section
  2262. ;; format has been found.
  2263. ;; ((or (not section-fmt) (org-export-low-level-p headline info)) FIXME
  2264. ;; ;; Build the real contents of the sub-tree.
  2265. ;; (let ((low-level-body
  2266. ;; (concat
  2267. ;; ;; If the headline is the first sibling, start a list.
  2268. ;; (when (org-export-first-sibling-p headline info)
  2269. ;; (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
  2270. ;; ;; Itemize headline
  2271. ;; "\\item " full-text "\n" headline-label pre-blanks contents)))
  2272. ;; ;; If headline in the last sibling, close the list, before any
  2273. ;; ;; blank line. Otherwise, simply return LOW-LEVEL-BODY.
  2274. ;; (if (org-export-last-sibling-p headline info)
  2275. ;; (replace-regexp-in-string
  2276. ;; "[ \t\n]*\\'"
  2277. ;; (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
  2278. ;; low-level-body)
  2279. ;; low-level-body)))
  2280. ;; Case 3. Standard headline. Export it as a section.
  2281. (t
  2282. ;; (format section-fmt full-text
  2283. ;; (concat headline-label pre-blanks contents))
  2284. (org-e-html-format-outline contents level section-no full-text tags
  2285. (car (last headline-labels))
  2286. (butlast headline-labels) nil)))))
  2287. ;;;; Horizontal Rule
  2288. (defun org-e-html-horizontal-rule (horizontal-rule contents info)
  2289. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  2290. CONTENTS is nil. INFO is a plist holding contextual information."
  2291. (let ((attr (mapconcat #'identity
  2292. (org-element-get-property :attr_html horizontal-rule)
  2293. " ")))
  2294. (org-e-html--wrap-label horizontal-rule
  2295. (org-e-html-format-horizontal-line))))
  2296. ;;;; Inline Babel Call
  2297. ;; Inline Babel Calls are ignored.
  2298. ;;;; Inline Src Block
  2299. (defun org-e-html-inline-src-block (inline-src-block contents info)
  2300. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  2301. CONTENTS holds the contents of the item. INFO is a plist holding
  2302. contextual information."
  2303. (let* ((org-lang (org-element-get-property :language inline-src-block))
  2304. (code (org-element-get-property :value inline-src-block))
  2305. (separator (org-e-html--find-verb-separator code)))
  2306. (error "FIXME")))
  2307. ;;;; Inlinetask
  2308. (defun org-e-html-format-section (text class &optional id)
  2309. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  2310. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  2311. (defun org-e-html-inlinetask (inlinetask contents info)
  2312. "Transcode an INLINETASK element from Org to HTML.
  2313. CONTENTS holds the contents of the block. INFO is a plist
  2314. holding contextual information."
  2315. (let ((title (org-export-secondary-string
  2316. (org-element-get-property :title inlinetask) 'e-html info))
  2317. (todo (and (plist-get info :with-todo-keywords)
  2318. (let ((todo (org-element-get-property
  2319. :todo-keyword inlinetask)))
  2320. (and todo
  2321. (org-export-secondary-string todo 'e-html info)))))
  2322. (todo-type (org-element-get-property :todo-type inlinetask))
  2323. (tags (and (plist-get info :with-tags)
  2324. (org-element-get-property :tags inlinetask)))
  2325. (priority (and (plist-get info :with-priority)
  2326. (org-element-get-property :priority inlinetask))))
  2327. ;; If `org-e-html-format-inlinetask-function' is provided, call it
  2328. ;; with appropriate arguments.
  2329. (if (functionp org-e-html-format-inlinetask-function)
  2330. (funcall org-e-html-format-inlinetask-function
  2331. todo todo-type priority title tags contents)
  2332. ;; Otherwise, use a default template.
  2333. (org-e-html--wrap-label
  2334. inlinetask
  2335. (let ((full-title
  2336. (concat
  2337. (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
  2338. (when priority (format "\\framebox{\\#%c} " priority))
  2339. title
  2340. (when tags (format "\\hfill{}\\textsc{%s}" tags)))))
  2341. (format (concat "\\begin{center}\n"
  2342. "\\fbox{\n"
  2343. "\\begin{minipage}[c]{.6\\textwidth}\n"
  2344. "%s\n\n"
  2345. "\\rule[.8em]{\\textwidth}{2pt}\n\n"
  2346. "%s"
  2347. "\\end{minipage}\n"
  2348. "}\n"
  2349. "\\end{center}")
  2350. full-title contents))))))
  2351. ;;;; Item
  2352. (defun org-e-html-format-list-item (contents type &optional arg headline)
  2353. (setq headline nil) ; FIXME
  2354. (concat
  2355. (case type
  2356. (ordered
  2357. (let* ((counter arg)
  2358. (extra (if counter (format " value=\"%s\"" counter) "")))
  2359. (format "<li%s>" extra)))
  2360. (unordered
  2361. (let* ((id arg)
  2362. (extra (if id (format " id=\"%s\"" id) "")))
  2363. (concat
  2364. (format "<li%s>" extra)
  2365. (when headline (concat headline "<br/>")))))
  2366. (descriptive
  2367. (let* ((desc-tag (or arg "(no term)")))
  2368. (concat (format "<dt> %s </dt>" desc-tag) "<dd>"))))
  2369. contents
  2370. (case type
  2371. (ordered "</li>")
  2372. (unordered "</li>")
  2373. (descriptive "</dd>"))))
  2374. (defun org-e-html-item (item contents info)
  2375. "Transcode an ITEM element from Org to HTML.
  2376. CONTENTS holds the contents of the item. INFO is a plist holding
  2377. contextual information."
  2378. ;; Grab `:level' from plain-list properties, which is always the
  2379. ;; first element above current item.
  2380. (let* ((plain-list (car (org-export-get-genealogy item info)))
  2381. (type (org-element-get-property :type plain-list))
  2382. (level (org-element-get-property
  2383. :level (car (plist-get info :genealogy))))
  2384. (counter (let ((count (org-element-get-property :counter item)))
  2385. (and count
  2386. (< level 4)
  2387. (format "\\setcounter{enum%s}{%s}\n"
  2388. (nth level '("i" "ii" "iii" "iv"))
  2389. (1- count)))))
  2390. (checkbox (let ((checkbox (org-element-get-property :checkbox item)))
  2391. (cond ((eq checkbox 'on) "$\\boxtimes$ ")
  2392. ((eq checkbox 'off) "$\\Box$ ")
  2393. ((eq checkbox 'trans) "$\\boxminus$ "))))
  2394. (tag (let ((tag (org-element-get-property :tag item)))
  2395. (and tag
  2396. (format "[%s]" (org-export-secondary-string
  2397. tag 'e-html info))))))
  2398. ;; (concat counter "\\item" tag " " checkbox contents)
  2399. (org-e-html-format-list-item contents type nil)))
  2400. ;;;; Keyword
  2401. (defun org-e-html-keyword (keyword contents info)
  2402. "Transcode a KEYWORD element from Org to HTML.
  2403. CONTENTS is nil. INFO is a plist holding contextual information."
  2404. (let ((key (downcase (org-element-get-property :key keyword)))
  2405. (value (org-element-get-property :value keyword)))
  2406. (cond
  2407. ((string= key "latex") value)
  2408. ((string= key "index") (format "\\index{%s}" value))
  2409. ((string= key "target")
  2410. (format "\\label{%s}" (org-export-solidify-link-text value)))
  2411. ((string= key "toc")
  2412. (let ((value (downcase value)))
  2413. (cond
  2414. ((string-match "\\<headlines\\>" value)
  2415. (let ((depth (or (and (string-match "[0-9]+" value)
  2416. (string-to-number (match-string 0 value)))
  2417. (plist-get info :with-toc))))
  2418. (concat
  2419. (when (wholenump depth)
  2420. (format "\\setcounter{tocdepth}{%s}\n" depth))
  2421. "\\tableofcontents")))
  2422. ((string= "tables" value) "\\listoftables")
  2423. ((string= "figures" value) "\\listoffigures")
  2424. ((string= "listings" value)
  2425. (cond
  2426. ;; At the moment, src blocks with a caption are wrapped
  2427. ;; into a figure environment.
  2428. (t "\\listoffigures")))))))))
  2429. ;;;; Latex Environment
  2430. (defun org-e-html-format-latex (latex-frag processing-type)
  2431. (let* ((cache-relpath
  2432. (concat "ltxpng/" (file-name-sans-extension
  2433. (file-name-nondirectory (buffer-file-name)))))
  2434. (cache-dir (file-name-directory (buffer-file-name )))
  2435. (display-msg "Creating LaTeX Image..."))
  2436. (with-temp-buffer
  2437. (insert latex-frag)
  2438. (org-format-latex cache-relpath cache-dir nil display-msg
  2439. nil nil processing-type)
  2440. (buffer-string))))
  2441. (defun org-e-html-latex-environment (latex-environment contents info)
  2442. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  2443. CONTENTS is nil. INFO is a plist holding contextual information."
  2444. (org-e-html--wrap-label
  2445. latex-environment
  2446. (let ((latex-frag
  2447. (org-remove-indentation
  2448. (org-element-get-property :value latex-environment)))
  2449. (processing-type (plist-get info :LaTeX-fragments)))
  2450. (cond
  2451. ((member processing-type '(t mathjax))
  2452. (org-e-html-format-latex latex-frag 'mathjax))
  2453. ((equal processing-type 'dvipng)
  2454. (let* ((formula-link (org-e-html-format-latex
  2455. latex-frag processing-type)))
  2456. (when (and formula-link
  2457. (string-match "file:\\([^]]*\\)" formula-link))
  2458. (org-e-html-format-inline-image (match-string 1 formula-link)))))
  2459. (t
  2460. latex-frag)))))
  2461. ;;;; Latex Fragment
  2462. (defun org-e-html-latex-fragment (latex-fragment contents info)
  2463. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2464. CONTENTS is nil. INFO is a plist holding contextual information."
  2465. ;; (org-element-get-property :value latex-fragment)
  2466. (let* ((latex-frag (org-element-get-property :value latex-fragment)))
  2467. (cond
  2468. ((string-match "\\\\ref{\\([^{}\n]+\\)}" latex-frag)
  2469. (let* ((label (match-string 1 latex-frag))
  2470. (href (and label (org-export-solidify-link-text label)))
  2471. (text (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  2472. (substring label (match-beginning 1))
  2473. label)))
  2474. (org-e-html-format-internal-link text href)))
  2475. (t (let ((processing-type (plist-get info :LaTeX-fragments)))
  2476. (cond
  2477. ((member processing-type '(t mathjax))
  2478. (org-e-html-format-latex latex-frag 'mathjax))
  2479. ((equal processing-type 'dvipng)
  2480. (let* ((formula-link (org-e-html-format-latex
  2481. latex-frag processing-type)))
  2482. (when (and formula-link
  2483. (string-match "file:\\([^]]*\\)" formula-link))
  2484. (org-e-html-format-inline-image
  2485. (match-string 1 formula-link)))))
  2486. (t latex-frag)))))))
  2487. ;;;; Line Break
  2488. (defun org-e-html-line-break (line-break contents info)
  2489. "Transcode a LINE-BREAK object from Org to HTML.
  2490. CONTENTS is nil. INFO is a plist holding contextual information."
  2491. "<br/>")
  2492. ;;;; Link
  2493. (defun org-e-html-link--inline-image (link info)
  2494. "Return HTML code for an inline image.
  2495. LINK is the link pointing to the inline image. INFO is a plist
  2496. used as a communication channel."
  2497. (let* ((parent (org-export-get-parent-paragraph link info))
  2498. (path (let ((raw-path (org-element-get-property :path link)))
  2499. (if (not (file-name-absolute-p raw-path)) raw-path
  2500. (expand-file-name raw-path))))
  2501. (caption (org-e-html--caption/label-string
  2502. (org-element-get-property :caption parent)
  2503. (org-element-get-property :name parent)
  2504. info))
  2505. (label (org-element-get-property :name parent))
  2506. ;; Retrieve latex attributes from the element around.
  2507. (attr (let ((raw-attr
  2508. (mapconcat #'identity
  2509. (org-element-get-property :attr_html parent)
  2510. " ")))
  2511. (unless (string= raw-attr "") raw-attr))))
  2512. ;; Now clear ATTR from any special keyword and set a default
  2513. ;; value if nothing is left.
  2514. (setq attr (if (not attr) "" (org-trim attr)))
  2515. ;; Return proper string, depending on DISPOSITION.
  2516. (let ((href (and label (org-export-solidify-link-text label))))
  2517. (org-e-html-format-inline-image path caption href attr))))
  2518. (defun org-e-html-link (link desc info)
  2519. "Transcode a LINK object from Org to HTML.
  2520. DESC is the description part of the link, or the empty string.
  2521. INFO is a plist holding contextual information. See
  2522. `org-export-data'."
  2523. (let* ((type (org-element-get-property :type link))
  2524. (raw-path (org-element-get-property :path link))
  2525. ;; Ensure DESC really exists, or set it to nil.
  2526. (desc (and (not (string= desc "")) desc))
  2527. (imagep (org-export-inline-image-p
  2528. link org-e-html-inline-image-rules))
  2529. (path (cond
  2530. ((member type '("http" "https" "ftp" "mailto"))
  2531. (concat type ":" raw-path))
  2532. ((string= type "file")
  2533. (when (string-match "\\(.+\\)::.+" raw-path)
  2534. (setq raw-path (match-string 1 raw-path)))
  2535. (if (file-name-absolute-p raw-path)
  2536. (concat "file://" (expand-file-name raw-path))
  2537. ;; TODO: Not implemented yet. Concat also:
  2538. ;; (org-export-directory :HTML info)
  2539. (concat "file://" raw-path)))
  2540. (t raw-path)))
  2541. protocol)
  2542. (cond
  2543. ;; Image file.
  2544. (imagep (org-e-html-link--inline-image link info))
  2545. ;; Target or radioed target: replace link with the normalized
  2546. ;; custom-id/target name.
  2547. ((member type '("target" "radio"))
  2548. (org-e-html-format-internal-link
  2549. (or desc (org-export-secondary-string path 'e-html info))
  2550. (org-export-solidify-link-text path)))
  2551. ;; Links pointing to an headline: Find destination and build
  2552. ;; appropriate referencing commanding.
  2553. ((member type '("custom-id" "fuzzy" "id"))
  2554. (let ((destination (if (string= type "fuzzy")
  2555. (org-export-resolve-fuzzy-link link info)
  2556. (org-export-resolve-id-link link info))))
  2557. ;; Fuzzy link points to a target. Do as above.
  2558. (case (car destination)
  2559. (target
  2560. (org-e-html-format-internal-link
  2561. (or desc
  2562. (org-export-secondary-string
  2563. (org-element-get-property :raw-link link)
  2564. 'e-html info))
  2565. (org-export-solidify-link-text
  2566. (org-element-get-property :raw-value destination))))
  2567. ;; Fuzzy link points to an headline. If headlines are
  2568. ;; numbered and the link has no description, display
  2569. ;; headline's number. Otherwise, display description or
  2570. ;; headline's title.
  2571. (headline
  2572. (let ((label
  2573. (format "sec-%s"
  2574. (mapconcat
  2575. 'number-to-string
  2576. (org-export-get-headline-number destination info)
  2577. "-"))))
  2578. (if (and (plist-get info :section-numbers) (not desc))
  2579. (format "\\ref{%s}" label)
  2580. (org-e-html-format-internal-link
  2581. (or desc
  2582. (org-export-secondary-string
  2583. (org-element-get-property :title destination)
  2584. 'e-html info)) label))))
  2585. ;; Fuzzy link points nowhere.
  2586. (otherwise
  2587. (org-e-html-format-fontify
  2588. (or desc
  2589. (org-export-secondary-string
  2590. (org-element-get-property :raw-link link)
  2591. 'e-html info)) 'emphasis)))))
  2592. ;; Coderef: replace link with the reference name or the
  2593. ;; equivalent line number.
  2594. ((string= type "coderef")
  2595. (format (org-export-get-coderef-format path (or desc ""))
  2596. (org-export-resolve-coderef path info)))
  2597. ;; Link type is handled by a special function.
  2598. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2599. (funcall protocol (org-link-unescape path) desc 'html))
  2600. ;; External link with a description part.
  2601. ((and path desc) (org-e-html-format-link desc path))
  2602. ;; External link without a description part.
  2603. (path (org-e-html-format-link path path))
  2604. ;; No path, only description. Try to do something useful.
  2605. (t (org-e-html-format-fontify desc 'emphasis)))))
  2606. ;;;; Babel Call
  2607. ;; Babel Calls are ignored.
  2608. ;;;; Macro
  2609. (defun org-e-html-macro (macro contents info)
  2610. "Transcode a MACRO element from Org to HTML.
  2611. CONTENTS is nil. INFO is a plist holding contextual information."
  2612. ;; Use available tools.
  2613. (org-export-expand-macro macro info))
  2614. ;;;; Paragraph
  2615. (defun org-e-html-paragraph (paragraph contents info)
  2616. "Transcode a PARAGRAPH element from Org to HTML.
  2617. CONTENTS is the contents of the paragraph, as a string. INFO is
  2618. the plist used as a communication channel."
  2619. (let* ((style nil) ; FIXME
  2620. (class (cdr (assoc style '((footnote . "footnote")
  2621. (verse . nil)))))
  2622. (extra (if class (format " class=\"%s\"" class) ""))
  2623. (parent (car (org-export-get-genealogy paragraph info))))
  2624. (cond
  2625. ;; is this the first paragraph in a list item
  2626. ;; (plain-list (car (org-export-get-genealogy item info)))
  2627. ;; (type (org-element-get-property :type plain-list))
  2628. ((and (equal parent 'item)
  2629. (= (org-element-get-property :begin paragraph)
  2630. (plist-get (plist-get info :parent-properties)
  2631. :contents-begin)))
  2632. contents)
  2633. (t
  2634. (concat (format "<p%s> " extra) contents "</p>")))))
  2635. ;;;; Plain List
  2636. (defun org-e-html-plain-list (plain-list contents info)
  2637. "Transcode a PLAIN-LIST element from Org to HTML.
  2638. CONTENTS is the contents of the list. INFO is a plist holding
  2639. contextual information."
  2640. (let* ((type (org-element-get-property :type plain-list))
  2641. (paralist-types '("inparaenum" "asparaenum" "inparaitem" "asparaitem"
  2642. "inparadesc" "asparadesc"))
  2643. (paralist-regexp (concat
  2644. "\\("
  2645. (mapconcat 'identity paralist-types "\\|")
  2646. "\\)"))
  2647. (attr (mapconcat #'identity
  2648. (org-element-get-property :attr_html plain-list)
  2649. " "))
  2650. (latex-type (cond
  2651. ((and attr
  2652. (string-match
  2653. (format "\\<%s\\>" paralist-regexp) attr))
  2654. (match-string 1 attr))
  2655. ((eq type 'ordered) "enumerate")
  2656. ((eq type 'unordered) "itemize")
  2657. ((eq type 'descriptive) "description")))
  2658. arg1 ;; FIXME
  2659. )
  2660. (org-e-html--wrap-label
  2661. plain-list
  2662. ;; (format "\\begin{%s}%s\n%s\\end{%s}"
  2663. ;; latex-type
  2664. ;; ;; Once special environment, if any, has been removed, the
  2665. ;; ;; rest of the attributes will be optional arguments.
  2666. ;; ;; They will be put inside square brackets if necessary.
  2667. ;; (let ((opt (replace-regexp-in-string
  2668. ;; (format " *%s *" paralist-regexp) "" attr)))
  2669. ;; (cond ((string= opt "") "")
  2670. ;; ((string-match "\\`\\[[^][]+\\]\\'" opt) opt)
  2671. ;; (t (format "[%s]" opt))))
  2672. ;; contents
  2673. ;; latex-type)
  2674. (format "%s\n%s%s"
  2675. (case type
  2676. (ordered
  2677. (format "<ol%s>" (if arg1
  2678. (format " start=\"%d\"" arg1)
  2679. "")))
  2680. (unordered "<ul>")
  2681. (descriptive "<dl>"))
  2682. contents
  2683. (case type
  2684. (ordered "</ol>")
  2685. (unordered "</ul>")
  2686. (descriptive "</dl>")))
  2687. )))
  2688. ;;;; Plain Text
  2689. (defun org-e-html-convert-special-strings (string)
  2690. "Convert special characters in STRING to HTML."
  2691. (let ((all org-e-html-special-string-regexps)
  2692. e a re rpl start)
  2693. (while (setq a (pop all))
  2694. (setq re (car a) rpl (cdr a) start 0)
  2695. (while (string-match re string start)
  2696. (setq string (replace-match rpl t nil string))))
  2697. string))
  2698. (defun org-e-html-encode-plain-text (s)
  2699. "Convert plain text characters to HTML equivalent.
  2700. Possible conversions are set in `org-export-html-protect-char-alist'."
  2701. (let ((cl org-e-html-protect-char-alist) c)
  2702. (while (setq c (pop cl))
  2703. (let ((start 0))
  2704. (while (string-match (car c) s start)
  2705. (setq s (replace-match (cdr c) t t s)
  2706. start (1+ (match-beginning 0))))))
  2707. s))
  2708. (defun org-e-html-plain-text (text info)
  2709. "Transcode a TEXT string from Org to HTML.
  2710. TEXT is the string to transcode. INFO is a plist holding
  2711. contextual information."
  2712. (setq text (org-e-html-encode-plain-text text))
  2713. ;; Protect %, #, &, $, ~, ^, _, { and }.
  2714. ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
  2715. ;; (setq text
  2716. ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
  2717. ;; Protect \
  2718. ;; (setq text (replace-regexp-in-string
  2719. ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
  2720. ;; "$\\backslash$" text nil t 1))
  2721. ;; HTML into \HTML{} and TeX into \TeX{}.
  2722. ;; (let ((case-fold-search nil)
  2723. ;; (start 0))
  2724. ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
  2725. ;; (setq text (replace-match
  2726. ;; (format "\\%s{}" (match-string 1 text)) nil t text)
  2727. ;; start (match-end 0))))
  2728. ;; Handle quotation marks
  2729. ;; (setq text (org-e-html--quotation-marks text info))
  2730. ;; Convert special strings.
  2731. ;; (when (plist-get info :with-special-strings)
  2732. ;; (while (string-match (regexp-quote "...") text)
  2733. ;; (setq text (replace-match "\\ldots{}" nil t text))))
  2734. (when (plist-get info :with-special-strings)
  2735. (setq text (org-e-html-convert-special-strings text)))
  2736. ;; Handle break preservation if required.
  2737. (when (plist-get info :preserve-breaks)
  2738. (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
  2739. text)))
  2740. ;; Return value.
  2741. text)
  2742. ;;;; Property Drawer
  2743. (defun org-e-html-property-drawer (property-drawer contents info)
  2744. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2745. CONTENTS is nil. INFO is a plist holding contextual
  2746. information."
  2747. ;; The property drawer isn't exported but we want separating blank
  2748. ;; lines nonetheless.
  2749. "")
  2750. ;;;; Quote Block
  2751. (defun org-e-html-quote-block (quote-block contents info)
  2752. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2753. CONTENTS holds the contents of the block. INFO is a plist
  2754. holding contextual information."
  2755. (org-e-html--wrap-label
  2756. quote-block (format "<blockquote>\n%s</blockquote>" contents)))
  2757. ;;;; Quote Section
  2758. (defun org-e-html-quote-section (quote-section contents info)
  2759. "Transcode a QUOTE-SECTION element from Org to HTML.
  2760. CONTENTS is nil. INFO is a plist holding contextual information."
  2761. (let ((value (org-remove-indentation
  2762. (org-element-get-property :value quote-section))))
  2763. (when value (format "<pre>\n%s</pre>" value))))
  2764. ;;;; Section
  2765. (defun org-e-html-section (section contents info)
  2766. "Transcode a SECTION element from Org to HTML.
  2767. CONTENTS holds the contents of the section. INFO is a plist
  2768. holding contextual information."
  2769. contents)
  2770. ;;;; Radio Target
  2771. (defun org-e-html-radio-target (radio-target text info)
  2772. "Transcode a RADIO-TARGET object from Org to HTML.
  2773. TEXT is the text of the target. INFO is a plist holding
  2774. contextual information."
  2775. (org-e-html-format-anchor
  2776. text (org-export-solidify-link-text
  2777. (org-element-get-property :raw-value radio-target))))
  2778. ;;;; Special Block
  2779. (defun org-e-html-special-block (special-block contents info)
  2780. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2781. CONTENTS holds the contents of the block. INFO is a plist
  2782. holding contextual information."
  2783. (let ((type (downcase (org-element-get-property :type special-block))))
  2784. (org-e-html--wrap-label
  2785. special-block
  2786. (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
  2787. ;;;; Src Block
  2788. (defun org-e-html-src-block (src-block contents info)
  2789. "Transcode a SRC-BLOCK element from Org to HTML.
  2790. CONTENTS holds the contents of the item. INFO is a plist holding
  2791. contextual information."
  2792. (let* ((lang (org-element-get-property :language src-block))
  2793. (code (org-export-handle-code src-block info))
  2794. (caption (org-element-get-property :caption src-block))
  2795. (label (org-element-get-property :name src-block)))
  2796. ;; FIXME: Handle caption
  2797. ;; caption-str (when caption)
  2798. ;; (main (org-export-secondary-string (car caption) 'e-html info))
  2799. ;; (secondary (org-export-secondary-string (cdr caption) 'e-html info))
  2800. ;; (caption-str (org-e-html--caption/label-string caption label info))
  2801. (org-e-html-format-source-code-or-example lang code)))
  2802. ;;;; Statistics Cookie
  2803. (defun org-e-html-statistics-cookie (statistics-cookie contents info)
  2804. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2805. CONTENTS is nil. INFO is a plist holding contextual information."
  2806. (org-element-get-property :value statistics-cookie))
  2807. ;;;; Subscript
  2808. (defun org-e-html-subscript (subscript contents info)
  2809. "Transcode a SUBSCRIPT object from Org to HTML.
  2810. CONTENTS is the contents of the object. INFO is a plist holding
  2811. contextual information."
  2812. ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
  2813. (org-e-html-format-fontify contents 'subscript))
  2814. ;;;; Superscript
  2815. (defun org-e-html-superscript (superscript contents info)
  2816. "Transcode a SUPERSCRIPT object from Org to HTML.
  2817. CONTENTS is the contents of the object. INFO is a plist holding
  2818. contextual information."
  2819. ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
  2820. (org-e-html-format-fontify contents 'superscript))
  2821. ;;;; Table
  2822. (defun org-e-html-begin-table (caption label attributes)
  2823. (let* ((html-table-tag (or (plist-get info :html-table-tag) ; FIXME
  2824. org-e-html-table-tag))
  2825. (html-table-tag
  2826. (org-export-splice-attributes html-table-tag attributes)))
  2827. (when label
  2828. (setq html-table-tag
  2829. (org-export-splice-attributes
  2830. html-table-tag
  2831. (format "id=\"%s\"" (org-solidify-link-text label)))))
  2832. (concat "\n" html-table-tag
  2833. (format "\n<caption>%s</caption>" (or caption "")))))
  2834. ;; org-table-number-fraction FIXME
  2835. (defun org-e-html-end-table ()
  2836. "</table>\n")
  2837. (defun org-e-html-format-table-cell (text r c horiz-span)
  2838. (let ((cell-style-cookie
  2839. (if org-e-html-table-align-individual-fields
  2840. (format (if (and (boundp 'org-e-html-format-table-no-css)
  2841. org-e-html-format-table-no-css)
  2842. " align=\"%s\"" " class=\"%s\"")
  2843. (or (aref (plist-get table-info :alignment) c) "left")) ""))) ;; FIXME
  2844. (cond
  2845. (org-lparse-table-cur-rowgrp-is-hdr
  2846. (concat
  2847. (format (car org-export-table-header-tags) "col" cell-style-cookie)
  2848. text (cdr org-export-table-header-tags)))
  2849. ((and (= c 0) org-e-html-table-use-header-tags-for-first-column)
  2850. (concat
  2851. (format (car org-export-table-header-tags) "row" cell-style-cookie)
  2852. text (cdr org-export-table-header-tags)))
  2853. (t
  2854. (concat
  2855. (format (car org-export-table-data-tags) cell-style-cookie)
  2856. text (cdr org-export-table-data-tags))))))
  2857. (defun org-e-html-format-table-row (row)
  2858. (concat (eval (car org-export-table-row-tags)) row
  2859. (eval (cdr org-export-table-row-tags))))
  2860. (defun org-e-html-table-row (fields &optional text-for-empty-fields)
  2861. (incf org-lparse-table-rownum)
  2862. (let ((i -1))
  2863. (org-e-html-format-table-row
  2864. (mapconcat
  2865. (lambda (x)
  2866. (when (and (string= x "") text-for-empty-fields)
  2867. (setq x text-for-empty-fields))
  2868. (incf i)
  2869. (let (horiz-span)
  2870. (org-e-html-format-table-cell
  2871. x org-lparse-table-rownum i (or horiz-span 0))))
  2872. fields "\n"))))
  2873. (defun org-e-html-end-table-rowgroup ()
  2874. (when org-lparse-table-rowgrp-open
  2875. (setq org-lparse-table-rowgrp-open nil)
  2876. (if org-lparse-table-cur-rowgrp-is-hdr "</thead>" "</tbody>")))
  2877. (defun org-e-html-begin-table-rowgroup (&optional is-header-row)
  2878. (concat
  2879. (when org-lparse-table-rowgrp-open
  2880. (org-e-html-end-table-rowgroup))
  2881. (progn
  2882. (setq org-lparse-table-rowgrp-open t)
  2883. (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row)
  2884. (if is-header-row "<thead>" "<tbody>"))))
  2885. (defun org-e-html-table-preamble ()
  2886. (let ((colgroup-vector (plist-get table-info :column-groups)) ;; FIXME
  2887. c gr colgropen preamble)
  2888. (unless (aref colgroup-vector 0)
  2889. (setf (aref colgroup-vector 0) 'start))
  2890. (dotimes (c columns-number preamble)
  2891. (setq gr (aref colgroup-vector c))
  2892. (setq preamble
  2893. (concat
  2894. preamble
  2895. (when (memq gr '(start start-end))
  2896. (prog1 (if colgropen "</colgroup>\n<colgroup>" "\n<colgroup>")
  2897. (setq colgropen t)))
  2898. (let* ((colalign-vector (plist-get table-info :alignment)) ;; FIXME
  2899. (align (cdr (assoc (aref colalign-vector c)
  2900. '(("l" . "left")
  2901. ("r" . "right")
  2902. ("c" . "center")))))
  2903. (alignspec (if (and (boundp 'org-e-html-format-table-no-css)
  2904. org-e-html-format-table-no-css)
  2905. " align=\"%s\"" " class=\"%s\""))
  2906. (extra (format alignspec align)))
  2907. (format "<col%s />" extra))
  2908. (when (memq gr '(end start-end))
  2909. (setq colgropen nil)
  2910. "</colgroup>"))))
  2911. (concat preamble (if colgropen "</colgroup>"))))
  2912. (defun org-e-html-list-table (lines &optional splice
  2913. caption label attributes head)
  2914. (or (featurep 'org-table) ; required for
  2915. (require 'org-table)) ; `org-table-number-regexp'
  2916. (let* ((org-lparse-table-rownum -1)
  2917. i (cnt 0)
  2918. tbopen fields line
  2919. org-lparse-table-cur-rowgrp-is-hdr
  2920. org-lparse-table-rowgrp-open
  2921. n
  2922. (org-lparse-table-style 'org-table)
  2923. org-lparse-table-is-styled)
  2924. (cond
  2925. (splice
  2926. (setq org-lparse-table-is-styled nil)
  2927. (mapconcat 'org-e-html-table-row lines "\n"))
  2928. (t
  2929. (setq org-lparse-table-is-styled t)
  2930. (concat
  2931. (org-e-html-begin-table caption label attributes)
  2932. (org-e-html-table-preamble)
  2933. (org-e-html-begin-table-rowgroup head)
  2934. (mapconcat
  2935. (lambda (line)
  2936. (cond
  2937. ((equal line :hrule) (org-e-html-begin-table-rowgroup))
  2938. (t (org-e-html-table-row line))))
  2939. lines "\n")
  2940. (org-e-html-end-table-rowgroup)
  2941. (org-e-html-end-table))))))
  2942. (defun org-e-html-org-table-to-list-table (lines &optional splice)
  2943. "Convert org-table to list-table.
  2944. LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
  2945. element is a `string' representing a single row of org-table.
  2946. Thus each ROW has vertical separators \"|\" separating the table
  2947. fields. A ROW could also be a row-group separator of the form
  2948. \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
  2949. ...). ROW could either be symbol `:hrule' or a list of the
  2950. form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
  2951. (let (line lines-1)
  2952. (cond
  2953. (splice
  2954. (while (setq line (pop lines))
  2955. (unless (string-match "^[ \t]*|-" line)
  2956. (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))
  2957. (t
  2958. (while (setq line (pop lines))
  2959. (cond
  2960. ((string-match "^[ \t]*|-" line)
  2961. (when lines
  2962. (push :hrule lines-1)))
  2963. (t
  2964. (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))))
  2965. (nreverse lines-1)))
  2966. (defun org-e-html-table (table contents info)
  2967. "Transcode a TABLE element from Org to HTML.
  2968. CONTENTS is nil. INFO is a plist holding contextual information."
  2969. (let* ((label (org-element-get-property :name table))
  2970. (caption (org-e-html--caption/label-string
  2971. (org-element-get-property :caption table) label info))
  2972. ;; FIXME
  2973. ;; org-e-html-table-caption-above
  2974. ;; (string= "" caption) (org-trim caption)
  2975. (attr (mapconcat #'identity
  2976. (org-element-get-property :attr_html table)
  2977. " "))
  2978. (raw-table (org-element-get-property :raw-table table)))
  2979. (cond
  2980. ;; Case 1: verbatim table.
  2981. ((or org-e-html-tables-verbatim
  2982. (and attr (string-match "\\<verbatim\\>" attr)))
  2983. (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
  2984. (org-export-clean-table
  2985. raw-table
  2986. (plist-get (org-export-table-format-info raw-table)
  2987. :special-column-p))))
  2988. ;; Case 2: table.el table. Convert it using appropriate tools.
  2989. ((eq (org-element-get-property :type table) 'table.el)
  2990. (require 'table)
  2991. ;; Ensure "*org-export-table*" buffer is empty.
  2992. (with-current-buffer (get-buffer-create "*org-export-table*")
  2993. (erase-buffer))
  2994. (let ((output (with-temp-buffer
  2995. (insert raw-table)
  2996. (goto-char 1)
  2997. (re-search-forward "^[ \t]*|[^|]" nil t)
  2998. (table-generate-source 'html "*org-export-table*")
  2999. (with-current-buffer "*org-export-table*"
  3000. (org-trim (buffer-string))))))
  3001. (kill-buffer (get-buffer "*org-export-table*"))
  3002. output))
  3003. ;; Case 3: Standard table.
  3004. (t
  3005. (let* ((table-info (org-export-table-format-info raw-table))
  3006. ;; (alignment (org-e-html-table--align-string attr table-info))
  3007. (columns-number (length (plist-get table-info :alignment)))
  3008. ;; CLEAN-TABLE is a table turned into a list, much like
  3009. ;; `org-table-to-lisp', with special column and
  3010. ;; formatting cookies removed, and cells already
  3011. ;; transcoded.
  3012. (lines (org-split-string
  3013. (org-export-clean-table
  3014. raw-table (plist-get table-info :special-column-p)) "\n"))
  3015. clean-table)
  3016. ;; (setq clean-table
  3017. ;; (mapcar
  3018. ;; (lambda (row)
  3019. ;; (if (string-match org-table-hline-regexp row) 'hline
  3020. ;; (mapcar
  3021. ;; (lambda (cell)
  3022. ;; (org-export-secondary-string
  3023. ;; (org-element-parse-secondary-string
  3024. ;; cell
  3025. ;; (cdr (assq 'table org-element-string-restrictions)))
  3026. ;; 'e-html info))
  3027. ;; (org-split-string row "[ \t]*|[ \t]*"))))
  3028. ;; lines))
  3029. ;; Convert ROWS to send them to `orgtbl-to-latex'. In
  3030. ;; particular, send each cell to
  3031. ;; `org-element-parse-secondary-string' to expand any Org
  3032. ;; object within. Eventually, flesh the format string out
  3033. ;; with the table.
  3034. ;; (format
  3035. ;; (org-e-html-table--format-string table table-info info)
  3036. ;; (orgtbl-to-latex clean-table params))
  3037. (let ((splice nil) head)
  3038. (setq lines (org-e-html-org-table-to-list-table lines splice))
  3039. (org-e-html-list-table lines splice caption label attr head)))))))
  3040. ;;;; Target
  3041. (defun org-e-html-target (target text info)
  3042. "Transcode a TARGET object from Org to HTML.
  3043. TEXT is the text of the target. INFO is a plist holding
  3044. contextual information."
  3045. (org-e-html-format-anchor
  3046. text (org-export-solidify-link-text
  3047. (org-element-get-property :raw-value target))))
  3048. ;;;; Time-stamp
  3049. (defun org-e-html-time-stamp (time-stamp contents info)
  3050. "Transcode a TIME-STAMP object from Org to HTML.
  3051. CONTENTS is nil. INFO is a plist holding contextual
  3052. information."
  3053. ;; (let ((value (org-element-get-property :value time-stamp))
  3054. ;; (type (org-element-get-property :type time-stamp))
  3055. ;; (appt-type (org-element-get-property :appt-type time-stamp)))
  3056. ;; (concat (cond ((eq appt-type 'scheduled)
  3057. ;; (format "\\textbf{\\textsc{%s}} " org-scheduled-string))
  3058. ;; ((eq appt-type 'deadline)
  3059. ;; (format "\\textbf{\\textsc{%s}} " org-deadline-string))
  3060. ;; ((eq appt-type 'closed)
  3061. ;; (format "\\textbf{\\textsc{%s}} " org-closed-string)))
  3062. ;; (cond ((memq type '(active active-range))
  3063. ;; (format org-e-html-active-timestamp-format value))
  3064. ;; ((memq type '(inactive inactive-range))
  3065. ;; (format org-e-html-inactive-timestamp-format value))
  3066. ;; (t
  3067. ;; (format org-e-html-diary-timestamp-format value)))))
  3068. (let ((value (org-element-get-property :value time-stamp))
  3069. (type (org-element-get-property :type time-stamp))
  3070. (appt-type (org-element-get-property :appt-type time-stamp)))
  3071. (org-e-html-format-fontify
  3072. (concat
  3073. (org-e-html-format-fontify
  3074. (cond ((eq appt-type 'scheduled) org-scheduled-string)
  3075. ((eq appt-type 'deadline) org-deadline-string)
  3076. ((eq appt-type 'closed) org-closed-string)) "timestamp-kwd")
  3077. ;; FIXME: (org-translate-time value)
  3078. (org-e-html-format-fontify value "timestamp"))
  3079. "timestamp-wrapper")))
  3080. ;;;; Verbatim
  3081. (defun org-e-html-verbatim (verbatim contents info)
  3082. "Transcode a VERBATIM object from Org to HTML.
  3083. CONTENTS is nil. INFO is a plist used as a communication
  3084. channel."
  3085. (org-e-html-emphasis
  3086. verbatim (org-element-get-property :value verbatim) info))
  3087. ;;;; Verse Block
  3088. (defun org-e-html-verse-block (verse-block contents info)
  3089. "Transcode a VERSE-BLOCK element from Org to HTML.
  3090. CONTENTS is nil. INFO is a plist holding contextual information."
  3091. ;; Replace each newline character with line break. Also replace
  3092. ;; each blank line with a line break.
  3093. (setq contents (replace-regexp-in-string
  3094. "^ *\\\\\\\\$" "<br/>\n"
  3095. (replace-regexp-in-string
  3096. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
  3097. (org-remove-indentation
  3098. (org-export-secondary-string
  3099. (org-element-get-property :value verse-block)
  3100. 'e-html info)))))
  3101. ;; Replace each white space at beginning of a line with a
  3102. ;; non-breaking space.
  3103. (while (string-match "^[ \t]+" contents)
  3104. (let ((new-str (org-e-html-format-spaces
  3105. (length (match-string 0 contents)))))
  3106. (setq contents (replace-match new-str nil t contents))))
  3107. (org-e-html--wrap-label
  3108. verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
  3109. ;;; Interactive functions
  3110. (defun org-e-html-export-to-html
  3111. (&optional subtreep visible-only body-only ext-plist pub-dir)
  3112. "Export current buffer to a HTML file.
  3113. If narrowing is active in the current buffer, only export its
  3114. narrowed part.
  3115. If a region is active, export that region.
  3116. When optional argument SUBTREEP is non-nil, export the sub-tree
  3117. at point, extracting information from the headline properties
  3118. first.
  3119. When optional argument VISIBLE-ONLY is non-nil, don't export
  3120. contents of hidden elements.
  3121. When optional argument BODY-ONLY is non-nil, only write code
  3122. between \"\\begin{document}\" and \"\\end{document}\".
  3123. EXT-PLIST, when provided, is a property list with external
  3124. parameters overriding Org default settings, but still inferior to
  3125. file-local settings.
  3126. When optional argument PUB-DIR is set, use it as the publishing
  3127. directory.
  3128. Return output file's name."
  3129. (interactive)
  3130. ;; FIXME
  3131. (with-current-buffer (get-buffer-create "*debug*")
  3132. (erase-buffer))
  3133. (let ((outfile (org-export-output-file-name ".html" subtreep pub-dir)))
  3134. (org-export-to-file
  3135. 'e-html outfile subtreep visible-only body-only ext-plist)))
  3136. (provide 'org-e-html)
  3137. ;;; org-e-html.el ends here