ox-html.el 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257
  1. ;;; ox-html.el --- HTML Back-End for Org Export Engine
  2. ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
  3. ;; Author: Jambunathan K <kjambunathan at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; GNU Emacs 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. ;; GNU Emacs 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 GNU Emacs. 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-x org-export-as-html
  20. ;;
  21. ;; in an Org mode buffer. See ox.el for more details on how this
  22. ;; exporter works.
  23. ;;; Code:
  24. ;;; Dependencies
  25. (require 'ox)
  26. (require 'ox-publish)
  27. (require 'format-spec)
  28. (eval-when-compile (require 'cl) (require 'table))
  29. ;;; Function Declarations
  30. (declare-function org-id-find-id-file "org-id" (id))
  31. (declare-function htmlize-region "ext:htmlize" (beg end))
  32. (declare-function org-pop-to-buffer-same-window
  33. "org-compat" (&optional buffer-or-name norecord label))
  34. (declare-function mm-url-decode-entities "mm-url" ())
  35. ;;; Define Back-End
  36. (org-export-define-backend html
  37. ((bold . org-html-bold)
  38. (center-block . org-html-center-block)
  39. (clock . org-html-clock)
  40. (code . org-html-code)
  41. (drawer . org-html-drawer)
  42. (dynamic-block . org-html-dynamic-block)
  43. (entity . org-html-entity)
  44. (example-block . org-html-example-block)
  45. (export-block . org-html-export-block)
  46. (export-snippet . org-html-export-snippet)
  47. (fixed-width . org-html-fixed-width)
  48. (footnote-definition . org-html-footnote-definition)
  49. (footnote-reference . org-html-footnote-reference)
  50. (headline . org-html-headline)
  51. (horizontal-rule . org-html-horizontal-rule)
  52. (inline-src-block . org-html-inline-src-block)
  53. (inlinetask . org-html-inlinetask)
  54. (inner-template . org-html-inner-template)
  55. (italic . org-html-italic)
  56. (item . org-html-item)
  57. (keyword . org-html-keyword)
  58. (latex-environment . org-html-latex-environment)
  59. (latex-fragment . org-html-latex-fragment)
  60. (line-break . org-html-line-break)
  61. (link . org-html-link)
  62. (paragraph . org-html-paragraph)
  63. (plain-list . org-html-plain-list)
  64. (plain-text . org-html-plain-text)
  65. (planning . org-html-planning)
  66. (property-drawer . org-html-property-drawer)
  67. (quote-block . org-html-quote-block)
  68. (quote-section . org-html-quote-section)
  69. (radio-target . org-html-radio-target)
  70. (section . org-html-section)
  71. (special-block . org-html-special-block)
  72. (src-block . org-html-src-block)
  73. (statistics-cookie . org-html-statistics-cookie)
  74. (strike-through . org-html-strike-through)
  75. (subscript . org-html-subscript)
  76. (superscript . org-html-superscript)
  77. (table . org-html-table)
  78. (table-cell . org-html-table-cell)
  79. (table-row . org-html-table-row)
  80. (target . org-html-target)
  81. (template . org-html-template)
  82. (timestamp . org-html-timestamp)
  83. (underline . org-html-underline)
  84. (verbatim . org-html-verbatim)
  85. (verse-block . org-html-verse-block))
  86. :export-block "HTML"
  87. :filters-alist ((:filter-options . org-html-infojs-install-script)
  88. (:filter-final-output . org-html-final-function))
  89. :menu-entry
  90. (?h "Export to HTML"
  91. ((?H "As HTML buffer" org-html-export-as-html)
  92. (?h "As HTML file" org-html-export-to-html)
  93. (?o "As HTML file and open"
  94. (lambda (a s v b)
  95. (if a (org-html-export-to-html t s v b)
  96. (org-open-file (org-html-export-to-html nil s v b)))))))
  97. :options-alist
  98. ((:html-extension nil nil org-html-extension)
  99. (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
  100. (:html-container "HTML_CONTAINER" nil org-html-container-element)
  101. (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
  102. (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
  103. (:html-mathjax "HTML_MATHJAX" nil "" space)
  104. (:html-postamble nil "html-postamble" org-html-postamble)
  105. (:html-preamble nil "html-preamble" org-html-preamble)
  106. (:html-head "HTML_HEAD" nil org-html-head newline)
  107. (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
  108. (:html-head-include-default-style "HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline)
  109. (:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline)
  110. (:html-table-tag nil nil org-html-table-tag)
  111. ;; Redefine regular options.
  112. (:creator "CREATOR" nil org-html-creator-string)
  113. (:with-latex nil "tex" org-html-with-latex)
  114. ;; Leave room for "ox-infojs.el" extension.
  115. (:infojs-opt "INFOJS_OPT" nil nil)))
  116. ;;; Internal Variables
  117. (defvar org-html-format-table-no-css)
  118. (defvar htmlize-buffer-places) ; from htmlize.el
  119. (defvar org-html--timestamp-format "%Y-%m-%d %a %H:%M"
  120. "FORMAT used by `format-time-string' for timestamps in
  121. preamble, postamble and metadata.")
  122. (defconst org-html-special-string-regexps
  123. '(("\\\\-" . "&#x00ad;") ; shy
  124. ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
  125. ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
  126. ("\\.\\.\\." . "&#x2026;")) ; hellip
  127. "Regular expressions for special string conversion.")
  128. (defconst org-html-scripts
  129. "<script type=\"text/javascript\">
  130. /*
  131. @licstart The following is the entire license notice for the
  132. JavaScript code in this tag.
  133. Copyright (C) 2012 Free Software Foundation, Inc.
  134. The JavaScript code in this tag is free software: you can
  135. redistribute it and/or modify it under the terms of the GNU
  136. General Public License (GNU GPL) as published by the Free Software
  137. Foundation, either version 3 of the License, or (at your option)
  138. any later version. The code is distributed WITHOUT ANY WARRANTY;
  139. without even the implied warranty of MERCHANTABILITY or FITNESS
  140. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  141. As additional permission under GNU GPL version 3 section 7, you
  142. may distribute non-source (e.g., minimized or compacted) forms of
  143. that code without the copy of the GNU GPL normally required by
  144. section 4, provided you include this license notice and a URL
  145. through which recipients can access the Corresponding Source.
  146. @licend The above is the entire license notice
  147. for the JavaScript code in this tag.
  148. */
  149. <!--/*--><![CDATA[/*><!--*/
  150. function CodeHighlightOn(elem, id)
  151. {
  152. var target = document.getElementById(id);
  153. if(null != target) {
  154. elem.cacheClassElem = elem.className;
  155. elem.cacheClassTarget = target.className;
  156. target.className = \"code-highlighted\";
  157. elem.className = \"code-highlighted\";
  158. }
  159. }
  160. function CodeHighlightOff(elem, id)
  161. {
  162. var target = document.getElementById(id);
  163. if(elem.cacheClassElem)
  164. elem.className = elem.cacheClassElem;
  165. if(elem.cacheClassTarget)
  166. target.className = elem.cacheClassTarget;
  167. }
  168. /*]]>*///-->
  169. </script>"
  170. "Basic JavaScript that is needed by HTML files produced by Org mode.")
  171. (defconst org-html-style-default
  172. "<style type=\"text/css\">
  173. <!--/*--><![CDATA[/*><!--*/
  174. .title { text-align: center; }
  175. .todo { font-family: monospace; color: red; }
  176. .done { color: green; }
  177. .tag { background-color: #eee; font-family: monospace;
  178. padding: 2px; font-size: 80%; font-weight: normal; }
  179. .timestamp { color: #bebebe; }
  180. .timestamp-kwd { color: #5f9ea0; }
  181. .right { margin-left: auto; margin-right: 0px; text-align: right; }
  182. .left { margin-left: 0px; margin-right: auto; text-align: left; }
  183. .center { margin-left: auto; margin-right: auto; text-align: center; }
  184. .underline { text-decoration: underline; }
  185. #postamble p, #preamble p { font-size: 90%; margin: .2em; }
  186. p.verse { margin-left: 3%; }
  187. pre {
  188. border: 1px solid #ccc;
  189. box-shadow: 3px 3px 3px #eee;
  190. padding: 8pt;
  191. font-family: monospace;
  192. overflow: auto;
  193. margin: 1.2em;
  194. }
  195. pre.src {
  196. position: relative;
  197. overflow: visible;
  198. padding-top: 1.2em;
  199. }
  200. pre.src:before {
  201. display: none;
  202. position: absolute;
  203. background-color: white;
  204. top: -10px;
  205. right: 10px;
  206. padding: 3px;
  207. border: 1px solid black;
  208. }
  209. pre.src:hover:before { display: inline;}
  210. pre.src-sh:before { content: 'sh'; }
  211. pre.src-bash:before { content: 'sh'; }
  212. pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
  213. pre.src-R:before { content: 'R'; }
  214. pre.src-perl:before { content: 'Perl'; }
  215. pre.src-java:before { content: 'Java'; }
  216. pre.src-sql:before { content: 'SQL'; }
  217. table { border-collapse:collapse; }
  218. td, th { vertical-align:top; }
  219. th.right { text-align: center; }
  220. th.left { text-align: center; }
  221. th.center { text-align: center; }
  222. td.right { text-align: right; }
  223. td.left { text-align: left; }
  224. td.center { text-align: center; }
  225. dt { font-weight: bold; }
  226. .footpara:nth-child(2) { display: inline; }
  227. .footpara { display: block; }
  228. .footdef { margin-bottom: 1em; }
  229. .figure { padding: 1em; }
  230. .figure p { text-align: center; }
  231. .inlinetask {
  232. padding: 10px;
  233. border: 2px solid gray;
  234. margin: 10px;
  235. background: #ffffcc;
  236. }
  237. #org-div-home-and-up
  238. { text-align: right; font-size: 70%; white-space: nowrap; }
  239. textarea { overflow-x: auto; }
  240. .linenr { font-size: smaller }
  241. .code-highlighted { background-color: #ffff00; }
  242. .org-info-js_info-navigation { border-style: none; }
  243. #org-info-js_console-label
  244. { font-size: 10px; font-weight: bold; white-space: nowrap; }
  245. .org-info-js_search-highlight
  246. { background-color: #ffff00; color: #000000; font-weight: bold; }
  247. /*]]>*/-->
  248. </style>"
  249. "The default style specification for exported HTML files.
  250. You can use `org-html-head' and `org-html-head-extra' to add to
  251. this style. If you don't want to include this default style,
  252. customize `org-html-head-include-default-style'.")
  253. ;;; User Configuration Variables
  254. (defgroup org-export-html nil
  255. "Options for exporting Org mode files to HTML."
  256. :tag "Org Export HTML"
  257. :group 'org-export)
  258. ;;;; Handle infojs
  259. (defvar org-html-infojs-opts-table
  260. '((path PATH "http://orgmode.org/org-info.js")
  261. (view VIEW "info")
  262. (toc TOC :with-toc)
  263. (ftoc FIXED_TOC "0")
  264. (tdepth TOC_DEPTH "max")
  265. (sdepth SECTION_DEPTH "max")
  266. (mouse MOUSE_HINT "underline")
  267. (buttons VIEW_BUTTONS "0")
  268. (ltoc LOCAL_TOC "1")
  269. (up LINK_UP :html-link-up)
  270. (home LINK_HOME :html-link-home))
  271. "JavaScript options, long form for script, default values.")
  272. (defcustom org-html-use-infojs 'when-configured
  273. "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
  274. This option can be nil or t to never or always use the script.
  275. It can also be the symbol `when-configured', meaning that the
  276. script will be linked into the export file if and only if there
  277. is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
  278. `org-html-infojs-options'."
  279. :group 'org-export-html
  280. :version "24.4"
  281. :package-version '(Org . "8.0")
  282. :type '(choice
  283. (const :tag "Never" nil)
  284. (const :tag "When configured in buffer" when-configured)
  285. (const :tag "Always" t)))
  286. (defcustom org-html-infojs-options
  287. (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
  288. "Options settings for the INFOJS JavaScript.
  289. Each of the options must have an entry in `org-html-infojs-opts-table'.
  290. The value can either be a string that will be passed to the script, or
  291. a property. This property is then assumed to be a property that is defined
  292. by the Export/Publishing setup of Org.
  293. The `sdepth' and `tdepth' parameters can also be set to \"max\", which
  294. means to use the maximum value consistent with other options."
  295. :group 'org-export-html
  296. :version "24.4"
  297. :package-version '(Org . "8.0")
  298. :type
  299. `(set :greedy t :inline t
  300. ,@(mapcar
  301. (lambda (x)
  302. (list 'cons (list 'const (car x))
  303. '(choice
  304. (symbol :tag "Publishing/Export property")
  305. (string :tag "Value"))))
  306. org-html-infojs-opts-table)))
  307. (defcustom org-html-infojs-template
  308. "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
  309. /**
  310. *
  311. * @source: %SCRIPT_PATH
  312. *
  313. * @licstart The following is the entire license notice for the
  314. * JavaScript code in %SCRIPT_PATH.
  315. *
  316. * Copyright (C) 2012-2013 Sebastian Rose
  317. *
  318. *
  319. * The JavaScript code in this tag is free software: you can
  320. * redistribute it and/or modify it under the terms of the GNU
  321. * General Public License (GNU GPL) as published by the Free Software
  322. * Foundation, either version 3 of the License, or (at your option)
  323. * any later version. The code is distributed WITHOUT ANY WARRANTY;
  324. * without even the implied warranty of MERCHANTABILITY or FITNESS
  325. * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  326. *
  327. * As additional permission under GNU GPL version 3 section 7, you
  328. * may distribute non-source (e.g., minimized or compacted) forms of
  329. * that code without the copy of the GNU GPL normally required by
  330. * section 4, provided you include this license notice and a URL
  331. * through which recipients can access the Corresponding Source.
  332. *
  333. * @licend The above is the entire license notice
  334. * for the JavaScript code in %SCRIPT_PATH.
  335. *
  336. */
  337. </script>
  338. <script type=\"text/javascript\">
  339. /*
  340. @licstart The following is the entire license notice for the
  341. JavaScript code in this tag.
  342. Copyright (C) 2012-2013 Free Software Foundation, Inc.
  343. The JavaScript code in this tag is free software: you can
  344. redistribute it and/or modify it under the terms of the GNU
  345. General Public License (GNU GPL) as published by the Free Software
  346. Foundation, either version 3 of the License, or (at your option)
  347. any later version. The code is distributed WITHOUT ANY WARRANTY;
  348. without even the implied warranty of MERCHANTABILITY or FITNESS
  349. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  350. As additional permission under GNU GPL version 3 section 7, you
  351. may distribute non-source (e.g., minimized or compacted) forms of
  352. that code without the copy of the GNU GPL normally required by
  353. section 4, provided you include this license notice and a URL
  354. through which recipients can access the Corresponding Source.
  355. @licend The above is the entire license notice
  356. for the JavaScript code in this tag.
  357. */
  358. <!--/*--><![CDATA[/*><!--*/
  359. %MANAGER_OPTIONS
  360. org_html_manager.setup(); // activate after the parameters are set
  361. /*]]>*///-->
  362. </script>"
  363. "The template for the export style additions when org-info.js is used.
  364. Option settings will replace the %MANAGER-OPTIONS cookie."
  365. :group 'org-export-html
  366. :version "24.4"
  367. :package-version '(Org . "8.0")
  368. :type 'string)
  369. (defun org-html-infojs-install-script (exp-plist backend)
  370. "Install script in export options when appropriate.
  371. EXP-PLIST is a plist containing export options. BACKEND is the
  372. export back-end currently used."
  373. (unless (or (memq 'body-only (plist-get exp-plist :export-options))
  374. (not org-html-use-infojs)
  375. (and (eq org-html-use-infojs 'when-configured)
  376. (or (not (plist-get exp-plist :infojs-opt))
  377. (string-match "\\<view:nil\\>"
  378. (plist-get exp-plist :infojs-opt)))))
  379. (let* ((template org-html-infojs-template)
  380. (ptoc (plist-get exp-plist :with-toc))
  381. (hlevels (plist-get exp-plist :headline-levels))
  382. (sdepth hlevels)
  383. (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
  384. (options (plist-get exp-plist :infojs-opt))
  385. (table org-html-infojs-opts-table)
  386. style)
  387. (dolist (entry table)
  388. (let* ((opt (car entry))
  389. (var (nth 1 entry))
  390. ;; Compute default values for script option OPT from
  391. ;; `org-html-infojs-options' variable.
  392. (default
  393. (let ((default (cdr (assq opt org-html-infojs-options))))
  394. (if (and (symbolp default) (not (memq default '(t nil))))
  395. (plist-get exp-plist default)
  396. default)))
  397. ;; Value set through INFOJS_OPT keyword has precedence
  398. ;; over the default one.
  399. (val (if (and options
  400. (string-match (format "\\<%s:\\(\\S-+\\)" opt)
  401. options))
  402. (match-string 1 options)
  403. default)))
  404. (case opt
  405. (path (setq template
  406. (replace-regexp-in-string
  407. "%SCRIPT_PATH" val template t t)))
  408. (sdepth (when (integerp (read val))
  409. (setq sdepth (min (read val) sdepth))))
  410. (tdepth (when (integerp (read val))
  411. (setq tdepth (min (read val) tdepth))))
  412. (otherwise (setq val
  413. (cond
  414. ((or (eq val t) (equal val "t")) "1")
  415. ((or (eq val nil) (equal val "nil")) "0")
  416. ((stringp val) val)
  417. (t (format "%s" val))))
  418. (push (cons var val) style)))))
  419. ;; Now we set the depth of the *generated* TOC to SDEPTH,
  420. ;; because the toc will actually determine the splitting. How
  421. ;; much of the toc will actually be displayed is governed by the
  422. ;; TDEPTH option.
  423. (setq exp-plist (plist-put exp-plist :with-toc sdepth))
  424. ;; The table of contents should not show more sections than we
  425. ;; generate.
  426. (setq tdepth (min tdepth sdepth))
  427. (push (cons "TOC_DEPTH" tdepth) style)
  428. ;; Build style string.
  429. (setq style (mapconcat
  430. (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
  431. (car x)
  432. (cdr x)))
  433. style "\n"))
  434. (when (and style (> (length style) 0))
  435. (and (string-match "%MANAGER_OPTIONS" template)
  436. (setq style (replace-match style t t template))
  437. (setq exp-plist
  438. (plist-put
  439. exp-plist :html-head-extra
  440. (concat (or (plist-get exp-plist :html-head-extra) "")
  441. "\n"
  442. style)))))
  443. ;; This script absolutely needs the table of contents, so we
  444. ;; change that setting.
  445. (unless (plist-get exp-plist :with-toc)
  446. (setq exp-plist (plist-put exp-plist :with-toc t)))
  447. ;; Return the modified property list.
  448. exp-plist)))
  449. ;;;; Bold, etc.
  450. (defcustom org-html-text-markup-alist
  451. '((bold . "<b>%s</b>")
  452. (code . "<code>%s</code>")
  453. (italic . "<i>%s</i>")
  454. (strike-through . "<del>%s</del>")
  455. (underline . "<span class=\"underline\">%s</span>")
  456. (verbatim . "<code>%s</code>"))
  457. "Alist of HTML expressions to convert text markup.
  458. The key must be a symbol among `bold', `code', `italic',
  459. `strike-through', `underline' and `verbatim'. The value is
  460. a formatting string to wrap fontified text with.
  461. If no association can be found for a given markup, text will be
  462. returned as-is."
  463. :group 'org-export-html
  464. :type '(alist :key-type (symbol :tag "Markup type")
  465. :value-type (string :tag "Format string"))
  466. :options '(bold code italic strike-through underline verbatim))
  467. (defcustom org-html-indent t
  468. "Non-nil means to indent the generated HTML."
  469. :group 'org-export-html
  470. :version "24.4"
  471. :package-version '(Org . "8.0")
  472. :type 'boolean)
  473. (defcustom org-html-use-unicode-chars nil
  474. "Non-nil means to use unicode characters instead of HTML entities."
  475. :group 'org-export-html
  476. :version "24.4"
  477. :package-version '(Org . "8.0")
  478. :type 'boolean)
  479. ;;;; Drawers
  480. (defcustom org-html-format-drawer-function nil
  481. "Function called to format a drawer in HTML code.
  482. The function must accept two parameters:
  483. NAME the drawer name, like \"LOGBOOK\"
  484. CONTENTS the contents of the drawer.
  485. The function should return the string to be exported.
  486. For example, the variable could be set to the following function
  487. in order to mimic default behaviour:
  488. \(defun org-html-format-drawer-default \(name contents\)
  489. \"Format a drawer element for HTML export.\"
  490. contents\)"
  491. :group 'org-export-html
  492. :type 'function)
  493. ;;;; Footnotes
  494. (defcustom org-html-footnotes-section "<div id=\"footnotes\">
  495. <h2 class=\"footnotes\">%s: </h2>
  496. <div id=\"text-footnotes\">
  497. %s
  498. </div>
  499. </div>"
  500. "Format for the footnotes section.
  501. Should contain a two instances of %s. The first will be replaced with the
  502. language-specific word for \"Footnotes\", the second one will be replaced
  503. by the footnotes themselves."
  504. :group 'org-export-html
  505. :type 'string)
  506. (defcustom org-html-footnote-format "<sup>%s</sup>"
  507. "The format for the footnote reference.
  508. %s will be replaced by the footnote reference itself."
  509. :group 'org-export-html
  510. :type 'string)
  511. (defcustom org-html-footnote-separator "<sup>, </sup>"
  512. "Text used to separate footnotes."
  513. :group 'org-export-html
  514. :type 'string)
  515. ;;;; Headline
  516. (defcustom org-html-toplevel-hlevel 2
  517. "The <H> level for level 1 headings in HTML export.
  518. This is also important for the classes that will be wrapped around headlines
  519. and outline structure. If this variable is 1, the top-level headlines will
  520. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  521. and outline-text-1. If this is 2, all of these will get a 2 instead.
  522. The default for this variable is 2, because we use <h1> for formatting the
  523. document title."
  524. :group 'org-export-html
  525. :type 'integer)
  526. (defcustom org-html-format-headline-function nil
  527. "Function to format headline text.
  528. This function will be called with 5 arguments:
  529. TODO the todo keyword (string or nil).
  530. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  531. PRIORITY the priority of the headline (integer or nil)
  532. TEXT the main headline text (string).
  533. TAGS the tags (string or nil).
  534. The function result will be used in the section format string."
  535. :group 'org-export-html
  536. :type 'function)
  537. ;;;; HTML-specific
  538. (defcustom org-html-allow-name-attribute-in-anchors t
  539. "When nil, do not set \"name\" attribute in anchors.
  540. By default, anchors are formatted with both \"id\" and \"name\"
  541. attributes, when appropriate."
  542. :group 'org-export-html
  543. :version "24.4"
  544. :package-version '(Org . "8.0")
  545. :type 'boolean)
  546. ;;;; Inlinetasks
  547. (defcustom org-html-format-inlinetask-function nil
  548. "Function called to format an inlinetask in HTML code.
  549. The function must accept six parameters:
  550. TODO the todo keyword, as a string
  551. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  552. PRIORITY the inlinetask priority, as a string
  553. NAME the inlinetask name, as a string.
  554. TAGS the inlinetask tags, as a list of strings.
  555. CONTENTS the contents of the inlinetask, as a string.
  556. The function should return the string to be exported."
  557. :group 'org-export-html
  558. :type 'function)
  559. ;;;; LaTeX
  560. (defcustom org-html-with-latex org-export-with-latex
  561. "Non-nil means process LaTeX math snippets.
  562. When set, the exporter will process LaTeX environments and
  563. fragments.
  564. This option can also be set with the +OPTIONS line,
  565. e.g. \"tex:mathjax\". Allowed values are:
  566. nil Ignore math snippets.
  567. `verbatim' Keep everything in verbatim
  568. `dvipng' Process the LaTeX fragments to images. This will also
  569. include processing of non-math environments.
  570. `imagemagick' Convert the LaTeX fragments to pdf files and use
  571. imagemagick to convert pdf files to png files.
  572. `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
  573. be loaded.
  574. t Synonym for `mathjax'."
  575. :group 'org-export-html
  576. :version "24.4"
  577. :package-version '(Org . "8.0")
  578. :type '(choice
  579. (const :tag "Do not process math in any way" nil)
  580. (const :tag "Use dvipng to make images" dvipng)
  581. (const :tag "Use imagemagick to make images" imagemagick)
  582. (const :tag "Use MathJax to display math" mathjax)
  583. (const :tag "Leave math verbatim" verbatim)))
  584. ;;;; Links :: Generic
  585. (defcustom org-html-link-org-files-as-html t
  586. "Non-nil means make file links to `file.org' point to `file.html'.
  587. When `org-mode' is exporting an `org-mode' file to HTML, links to
  588. non-html files are directly put into a href tag in HTML.
  589. However, links to other Org-mode files (recognized by the
  590. extension `.org.) should become links to the corresponding html
  591. file, assuming that the linked `org-mode' file will also be
  592. converted to HTML.
  593. When nil, the links still point to the plain `.org' file."
  594. :group 'org-export-html
  595. :type 'boolean)
  596. ;;;; Links :: Inline images
  597. (defcustom org-html-inline-images 'maybe
  598. "Non-nil means inline images into exported HTML pages.
  599. This is done using an <img> tag. When nil, an anchor with href is used to
  600. link to the image. If this option is `maybe', then images in links with
  601. an empty description will be inlined, while images with a description will
  602. be linked only."
  603. :group 'org-export-html
  604. :type '(choice (const :tag "Never" nil)
  605. (const :tag "Always" t)
  606. (const :tag "When there is no description" maybe)))
  607. (defcustom org-html-inline-image-rules
  608. '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
  609. ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
  610. ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
  611. "Rules characterizing image files that can be inlined into HTML.
  612. A rule consists in an association whose key is the type of link
  613. to consider, and value is a regexp that will be matched against
  614. link's path.
  615. Note that, by default, the image extension *actually* allowed
  616. depend on the way the HTML file is processed. When used with
  617. pdflatex, pdf, jpg and png images are OK. When processing
  618. through dvi to Postscript, only ps and eps are allowed. The
  619. default we use here encompasses both."
  620. :group 'org-export-html
  621. :version "24.4"
  622. :package-version '(Org . "8.0")
  623. :type '(alist :key-type (string :tag "Type")
  624. :value-type (regexp :tag "Path")))
  625. ;;;; Plain Text
  626. (defcustom org-html-protect-char-alist
  627. '(("&" . "&amp;")
  628. ("<" . "&lt;")
  629. (">" . "&gt;"))
  630. "Alist of characters to be converted by `org-html-protect'."
  631. :group 'org-export-html
  632. :type '(repeat (cons (string :tag "Character")
  633. (string :tag "HTML equivalent"))))
  634. ;;;; Src Block
  635. (defcustom org-html-htmlize-output-type 'inline-css
  636. "Output type to be used by htmlize when formatting code snippets.
  637. Choices are `css', to export the CSS selectors only, or `inline-css', to
  638. export the CSS attribute values inline in the HTML. We use as default
  639. `inline-css', in order to make the resulting HTML self-containing.
  640. However, this will fail when using Emacs in batch mode for export, because
  641. then no rich font definitions are in place. It will also not be good if
  642. people with different Emacs setup contribute HTML files to a website,
  643. because the fonts will represent the individual setups. In these cases,
  644. it is much better to let Org/Htmlize assign classes only, and to use
  645. a style file to define the look of these classes.
  646. To get a start for your css file, start Emacs session and make sure that
  647. all the faces you are interested in are defined, for example by loading files
  648. in all modes you want. Then, use the command
  649. \\[org-html-htmlize-generate-css] to extract class definitions."
  650. :group 'org-export-html
  651. :type '(choice (const css) (const inline-css)))
  652. (defcustom org-html-htmlize-font-prefix "org-"
  653. "The prefix for CSS class names for htmlize font specifications."
  654. :group 'org-export-html
  655. :type 'string)
  656. ;;;; Table
  657. (defcustom org-html-table-tag
  658. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  659. "The HTML tag that is used to start a table.
  660. This must be a <table> tag, but you may change the options like
  661. borders and spacing."
  662. :group 'org-export-html
  663. :type 'string)
  664. (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  665. "The opening tag for table header fields.
  666. This is customizable so that alignment options can be specified.
  667. The first %s will be filled with the scope of the field, either row or col.
  668. The second %s will be replaced by a style entry to align the field.
  669. See also the variable `org-html-table-use-header-tags-for-first-column'.
  670. See also the variable `org-html-table-align-individual-fields'."
  671. :group 'org-export-html
  672. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  673. (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
  674. "The opening tag for table data fields.
  675. This is customizable so that alignment options can be specified.
  676. The first %s will be filled with the scope of the field, either row or col.
  677. The second %s will be replaced by a style entry to align the field.
  678. See also the variable `org-html-table-align-individual-fields'."
  679. :group 'org-export-html
  680. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  681. (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
  682. "The opening tag for table data fields.
  683. This is customizable so that alignment options can be specified.
  684. Instead of strings, these can be Lisp forms that will be evaluated
  685. for each row in order to construct the table row tags. During evaluation,
  686. the variable `head' will be true when this is a header line, nil when this
  687. is a body line. And the variable `nline' will contain the line number,
  688. starting from 1 in the first header line. For example
  689. (setq org-html-table-row-tags
  690. (cons '(if head
  691. \"<tr>\"
  692. (if (= (mod nline 2) 1)
  693. \"<tr class=\\\"tr-odd\\\">\"
  694. \"<tr class=\\\"tr-even\\\">\"))
  695. \"</tr>\"))
  696. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  697. :group 'org-export-html
  698. :type '(cons
  699. (choice :tag "Opening tag"
  700. (string :tag "Specify")
  701. (sexp))
  702. (choice :tag "Closing tag"
  703. (string :tag "Specify")
  704. (sexp))))
  705. (defcustom org-html-table-align-individual-fields t
  706. "Non-nil means attach style attributes for alignment to each table field.
  707. When nil, alignment will only be specified in the column tags, but this
  708. is ignored by some browsers (like Firefox, Safari). Opera does it right
  709. though."
  710. :group 'org-export-html
  711. :type 'boolean)
  712. (defcustom org-html-table-use-header-tags-for-first-column nil
  713. "Non-nil means format column one in tables with header tags.
  714. When nil, also column one will use data tags."
  715. :group 'org-export-html
  716. :type 'boolean)
  717. (defcustom org-html-table-caption-above t
  718. "When non-nil, place caption string at the beginning of the table.
  719. Otherwise, place it near the end."
  720. :group 'org-export-html
  721. :type 'boolean)
  722. ;;;; Tags
  723. (defcustom org-html-tag-class-prefix ""
  724. "Prefix to class names for TODO keywords.
  725. Each tag gets a class given by the tag itself, with this prefix.
  726. The default prefix is empty because it is nice to just use the keyword
  727. as a class name. But if you get into conflicts with other, existing
  728. CSS classes, then this prefix can be very useful."
  729. :group 'org-export-html
  730. :type 'string)
  731. ;;;; Template :: Generic
  732. (defcustom org-html-extension "html"
  733. "The extension for exported HTML files."
  734. :group 'org-export-html
  735. :type 'string)
  736. (defcustom org-html-xml-declaration
  737. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  738. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  739. "The extension for exported HTML files.
  740. %s will be replaced with the charset of the exported file.
  741. This may be a string, or an alist with export extensions
  742. and corresponding declarations."
  743. :group 'org-export-html
  744. :type '(choice
  745. (string :tag "Single declaration")
  746. (repeat :tag "Dependent on extension"
  747. (cons (string :tag "Extension")
  748. (string :tag "Declaration")))))
  749. (defcustom org-html-coding-system 'utf-8
  750. "Coding system for HTML export.
  751. Use utf-8 as the default value."
  752. :group 'org-export-html
  753. :version "24.4"
  754. :package-version '(Org . "8.0")
  755. :type 'coding-system)
  756. (defcustom org-html-doctype
  757. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  758. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
  759. "Document type definition to use for exported HTML files.
  760. Can be set with the in-buffer HTML_DOCTYPE property or for
  761. publishing, with :html-doctype."
  762. :group 'org-export-html
  763. :version "24.4"
  764. :package-version '(Org . "8.0")
  765. :type 'string)
  766. (defcustom org-html-container-element "div"
  767. "HTML element to use for wrapping top level sections.
  768. Can be set with the in-buffer HTML_CONTAINER property or for
  769. publishing, with :html-container.
  770. Note that changing the default will prevent you from using
  771. org-info.js for your website."
  772. :group 'org-export-html
  773. :version "24.4"
  774. :package-version '(Org . "8.0")
  775. :type 'string)
  776. (defcustom org-html-divs
  777. '((preamble "div" "preamble")
  778. (content "div" "content")
  779. (postamble "div" "postamble"))
  780. "Alist of the threed section elements for HTML export.
  781. The car of each entry is one of 'preamble, 'content or 'postamble.
  782. The cdrs of each entry are the ELEMENT_TYPE and ID for each
  783. section of the exported document.
  784. Note that changing the default will prevent you from using
  785. org-info.js for your website."
  786. :group 'org-export-html
  787. :version "24.4"
  788. :package-version '(Org . "8.0")
  789. :type '(list :greedy t
  790. (list :tag "Preamble"
  791. (const :format "" preamble)
  792. (string :tag "element") (string :tag " id"))
  793. (list :tag "Content"
  794. (const :format "" content)
  795. (string :tag "element") (string :tag " id"))
  796. (list :tag "Postamble" (const :format "" postamble)
  797. (string :tag " id") (string :tag "element"))))
  798. ;;;; Template :: Mathjax
  799. (defcustom org-html-mathjax-options
  800. '((path "http://orgmode.org/mathjax/MathJax.js")
  801. (scale "100")
  802. (align "center")
  803. (indent "2em")
  804. (mathml nil))
  805. "Options for MathJax setup.
  806. path The path where to find MathJax
  807. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  808. align How to align display math: left, center, or right
  809. indent If align is not center, how far from the left/right side?
  810. mathml Should a MathML player be used if available?
  811. This is faster and reduces bandwidth use, but currently
  812. sometimes has lower spacing quality. Therefore, the default is
  813. nil. When browsers get better, this switch can be flipped.
  814. You can also customize this for each buffer, using something like
  815. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  816. :group 'org-export-html
  817. :type '(list :greedy t
  818. (list :tag "path (the path from where to load MathJax.js)"
  819. (const :format " " path) (string))
  820. (list :tag "scale (scaling for the displayed math)"
  821. (const :format " " scale) (string))
  822. (list :tag "align (alignment of displayed equations)"
  823. (const :format " " align) (string))
  824. (list :tag "indent (indentation with left or right alignment)"
  825. (const :format " " indent) (string))
  826. (list :tag "mathml (should MathML display be used is possible)"
  827. (const :format " " mathml) (boolean))))
  828. (defcustom org-html-mathjax-template
  829. "<script type=\"text/javascript\" src=\"%PATH\">
  830. <!--/*--><![CDATA[/*><!--*/
  831. MathJax.Hub.Config({
  832. // Only one of the two following lines, depending on user settings
  833. // First allows browser-native MathML display, second forces HTML/CSS
  834. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  835. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  836. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  837. \"TeX/noUndefined.js\"],
  838. tex2jax: {
  839. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  840. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  841. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  842. ignoreClass: \"tex2jax_ignore\",
  843. processEscapes: false,
  844. processEnvironments: true,
  845. preview: \"TeX\"
  846. },
  847. showProcessingMessages: true,
  848. displayAlign: \"%ALIGN\",
  849. displayIndent: \"%INDENT\",
  850. \"HTML-CSS\": {
  851. scale: %SCALE,
  852. availableFonts: [\"STIX\",\"TeX\"],
  853. preferredFont: \"TeX\",
  854. webFont: \"TeX\",
  855. imageFont: \"TeX\",
  856. showMathMenu: true,
  857. },
  858. MMLorHTML: {
  859. prefer: {
  860. MSIE: \"MML\",
  861. Firefox: \"MML\",
  862. Opera: \"HTML\",
  863. other: \"HTML\"
  864. }
  865. }
  866. });
  867. /*]]>*///-->
  868. </script>"
  869. "The MathJax setup for XHTML files."
  870. :group 'org-export-html
  871. :type 'string)
  872. ;;;; Template :: Postamble
  873. (defcustom org-html-postamble 'auto
  874. "Non-nil means insert a postamble in HTML export.
  875. When set to 'auto, check against the
  876. `org-export-with-author/email/creator/date' variables to set the
  877. content of the postamble. When set to a string, use this string
  878. as the postamble. When t, insert a string as defined by the
  879. formatting string in `org-html-postamble-format'.
  880. When set to a function, apply this function and insert the
  881. returned string. The function takes the property list of export
  882. options as its only argument.
  883. Setting :html-postamble in publishing projects will take
  884. precedence over this variable."
  885. :group 'org-export-html
  886. :type '(choice (const :tag "No postamble" nil)
  887. (const :tag "Auto postamble" 'auto)
  888. (const :tag "Default formatting string" t)
  889. (string :tag "Custom formatting string")
  890. (function :tag "Function (must return a string)")))
  891. (defcustom org-html-postamble-format
  892. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  893. <p class=\"date\">Date: %d</p>
  894. <p class=\"creator\">Generated by %c</p>
  895. <p class=\"xhtml-validation\">%v</p>"))
  896. "Alist of languages and format strings for the HTML postamble.
  897. The first element of each list is the language code, as used for
  898. the #+LANGUAGE keyword.
  899. The second element of each list is a format string to format the
  900. postamble itself. This format string can contain these elements:
  901. %t stands for the title.
  902. %a stands for the author's name.
  903. %e stands for the author's email.
  904. %d stands for the date.
  905. %c will be replaced by information about Org/Emacs versions.
  906. %v will be replaced by `org-html-validation-link'.
  907. %T will be replace by the creation time of the file.
  908. If you need to use a \"%\" character, you need to escape it
  909. like that: \"%%\"."
  910. :group 'org-export-html
  911. :type '(alist :key-type (string :tag "Language")
  912. :value-type (string :tag "Format string")))
  913. (defcustom org-html-validation-link
  914. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  915. "Link to HTML validation service."
  916. :group 'org-export-html
  917. :type 'string)
  918. (defcustom org-html-creator-string
  919. (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
  920. (if (fboundp 'org-version) (org-version) "(Unknown)")
  921. emacs-version)
  922. "String to insert at the end of the HTML document."
  923. :group 'org-export-html
  924. :type '(string :tag "Creator string"))
  925. ;;;; Template :: Preamble
  926. (defcustom org-html-preamble t
  927. "Non-nil means insert a preamble in HTML export.
  928. When t, insert a string as defined by the formatting string in
  929. `org-html-preamble-format'. When set to a string, use this
  930. formatting string instead (see `org-html-postamble-format' for an
  931. example of such a formatting string).
  932. When set to a function, apply this function and insert the
  933. returned string. The function takes the property list of export
  934. options as its only argument.
  935. Setting :html-preamble in publishing projects will take
  936. precedence over this variable."
  937. :group 'org-export-html
  938. :type '(choice (const :tag "No preamble" nil)
  939. (const :tag "Default preamble" t)
  940. (string :tag "Custom formatting string")
  941. (function :tag "Function (must return a string)")))
  942. (defcustom org-html-preamble-format '(("en" ""))
  943. "Alist of languages and format strings for the HTML preamble.
  944. The first element of each list is the language code, as used for
  945. the #+LANGUAGE keyword.
  946. The second element of each list is a format string to format the
  947. preamble itself. This format string can contain these elements:
  948. %t stands for the title.
  949. %a stands for the author's name.
  950. %e stands for the author's email.
  951. %d stands for the date.
  952. %c will be replaced by information about Org/Emacs versions.
  953. %v will be replaced by `org-html-validation-link'.
  954. %T will be replace by the creation time of the file.
  955. If you need to use a \"%\" character, you need to escape it
  956. like that: \"%%\".
  957. See the default value of `org-html-postamble-format' for an
  958. example."
  959. :group 'org-export-html
  960. :type '(alist :key-type (string :tag "Language")
  961. :value-type (string :tag "Format string")))
  962. (defcustom org-html-link-up ""
  963. "Where should the \"UP\" link of exported HTML pages lead?"
  964. :group 'org-export-html
  965. :type '(string :tag "File or URL"))
  966. (defcustom org-html-link-home ""
  967. "Where should the \"HOME\" link of exported HTML pages lead?"
  968. :group 'org-export-html
  969. :type '(string :tag "File or URL"))
  970. (defcustom org-html-home/up-format
  971. "<div id=\"org-div-home-and-up\">
  972. <a accesskey=\"h\" href=\"%s\"> UP </a>
  973. |
  974. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  975. </div>"
  976. "Snippet used to insert the HOME and UP links.
  977. This is a format string, the first %s will receive the UP link,
  978. the second the HOME link. If both `org-html-link-up' and
  979. `org-html-link-home' are empty, the entire snippet will be
  980. ignored."
  981. :group 'org-export-html
  982. :type 'string)
  983. ;;;; Template :: Scripts
  984. (define-obsolete-variable-alias
  985. 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
  986. (defcustom org-html-head-include-scripts t
  987. "Non-nil means include the JavaScript snippets in exported HTML files.
  988. The actual script is defined in `org-html-scripts' and should
  989. not be modified."
  990. :group 'org-export-html
  991. :version "24.4"
  992. :package-version '(Org . "8.0")
  993. :type 'boolean)
  994. ;;;; Template :: Styles
  995. (define-obsolete-variable-alias
  996. 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
  997. (defcustom org-html-head-include-default-style t
  998. "Non-nil means include the default style in exported HTML files.
  999. The actual style is defined in `org-html-style-default' and
  1000. should not be modified. Use `org-html-head' to use your own
  1001. style information."
  1002. :group 'org-export-html
  1003. :version "24.4"
  1004. :package-version '(Org . "8.0")
  1005. :type 'boolean)
  1006. ;;;###autoload
  1007. (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
  1008. (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
  1009. (defcustom org-html-head ""
  1010. "Org-wide head definitions for exported HTML files.
  1011. This variable can contain the full HTML structure to provide a
  1012. style, including the surrounding HTML tags. You can consider
  1013. including definitions for the following classes: title, todo,
  1014. done, timestamp, timestamp-kwd, tag, target.
  1015. For example, a valid value would be:
  1016. <style type=\"text/css\">
  1017. <![CDATA[
  1018. p { font-weight: normal; color: gray; }
  1019. h1 { color: black; }
  1020. .title { text-align: center; }
  1021. .todo, .timestamp-kwd { color: red; }
  1022. .done { color: green; }
  1023. ]]>
  1024. </style>
  1025. If you want to refer to an external style, use something like
  1026. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
  1027. As the value of this option simply gets inserted into the HTML
  1028. <head> header, you can use it to add any arbitrary text to the
  1029. header.
  1030. You can set this on a per-file basis using #+HTML_HEAD:,
  1031. or for publication projects using the :html-head property."
  1032. :group 'org-export-html
  1033. :version "24.4"
  1034. :package-version '(Org . "8.0")
  1035. :type 'string)
  1036. ;;;###autoload
  1037. (put 'org-html-head 'safe-local-variable 'stringp)
  1038. (defcustom org-html-head-extra ""
  1039. "More head information to add in the HTML output.
  1040. You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
  1041. or for publication projects using the :html-head-extra property."
  1042. :group 'org-export-html
  1043. :version "24.4"
  1044. :package-version '(Org . "8.0")
  1045. :type 'string)
  1046. ;;;###autoload
  1047. (put 'org-html-head-extra 'safe-local-variable 'stringp)
  1048. ;;;; Todos
  1049. (defcustom org-html-todo-kwd-class-prefix ""
  1050. "Prefix to class names for TODO keywords.
  1051. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  1052. The default prefix is empty because it is nice to just use the keyword
  1053. as a class name. But if you get into conflicts with other, existing
  1054. CSS classes, then this prefix can be very useful."
  1055. :group 'org-export-html
  1056. :type 'string)
  1057. ;;; Internal Functions
  1058. (defun org-html-format-inline-image (src &optional
  1059. caption label attr standalone-p)
  1060. "Format an inline image from SRC.
  1061. CAPTION, LABEL and ATTR are optional arguments providing the
  1062. caption, the label and the attribute of the image.
  1063. When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
  1064. (let* ((id (if (not label) ""
  1065. (format " id=\"%s\"" (org-export-solidify-link-text label))))
  1066. (attr (concat attr
  1067. (cond
  1068. ((string-match "\\<alt=" (or attr "")) "")
  1069. ((string-match "^ltxpng/" src)
  1070. (format " alt=\"%s\""
  1071. (org-html-encode-plain-text
  1072. (org-find-text-property-in-string
  1073. 'org-latex-src src))))
  1074. (t (format " alt=\"%s\""
  1075. (file-name-nondirectory src)))))))
  1076. (cond
  1077. (standalone-p
  1078. (let ((img (format "<img src=\"%s\" %s/>" src attr)))
  1079. (format "\n<div%s class=\"figure\">%s%s\n</div>"
  1080. id (format "\n<p>%s</p>" img)
  1081. (if (and caption (not (string= caption "")))
  1082. (format "\n<p>%s</p>" caption) ""))))
  1083. (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
  1084. (defun org-html--textarea-block (element)
  1085. "Transcode ELEMENT into a textarea block.
  1086. ELEMENT is either a src block or an example block."
  1087. (let* ((code (car (org-export-unravel-code element)))
  1088. (attr (org-export-read-attribute :attr_html element)))
  1089. (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
  1090. (or (plist-get attr :width) 80)
  1091. (or (plist-get attr :height) (org-count-lines code))
  1092. code)))
  1093. ;;;; Bibliography
  1094. (defun org-html-bibliography ()
  1095. "Find bibliography, cut it out and return it."
  1096. (catch 'exit
  1097. (let (beg end (cnt 1) bib)
  1098. (save-excursion
  1099. (goto-char (point-min))
  1100. (when (re-search-forward
  1101. "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  1102. (setq beg (match-beginning 0))
  1103. (while (re-search-forward "</?div\\>" nil t)
  1104. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  1105. (when (= cnt 0)
  1106. (and (looking-at ">") (forward-char 1))
  1107. (setq bib (buffer-substring beg (point)))
  1108. (delete-region beg (point))
  1109. (throw 'exit bib))))
  1110. nil))))
  1111. ;;;; Table
  1112. (defun org-html-splice-attributes (tag attributes)
  1113. "Return a HTML TAG edited wrt ATTRIBUTES."
  1114. (if (not attributes)
  1115. tag
  1116. (let (oldatt newatt)
  1117. (setq oldatt (org-extract-attributes-from-string tag)
  1118. tag (pop oldatt)
  1119. newatt (cdr (org-extract-attributes-from-string attributes)))
  1120. (while newatt
  1121. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  1122. (if (string-match ">" tag)
  1123. (setq tag
  1124. (replace-match (concat (org-attributes-to-string oldatt) ">")
  1125. t t tag)))
  1126. tag)))
  1127. (defun org-export-splice-style (style extra)
  1128. "Return STYLE updated wrt EXTRA."
  1129. (if (and (stringp extra)
  1130. (string-match "\\S-" extra)
  1131. (string-match "</style>" style))
  1132. (concat (substring style 0 (match-beginning 0))
  1133. "\n" extra "\n"
  1134. (substring style (match-beginning 0)))
  1135. style))
  1136. (defun org-html-htmlize-region-for-paste (beg end)
  1137. "Convert the region between BEG and END to HTML, using htmlize.el.
  1138. This is much like `htmlize-region-for-paste', only that it uses
  1139. the settings define in the org-... variables."
  1140. (let* ((htmlize-output-type org-html-htmlize-output-type)
  1141. (htmlize-css-name-prefix org-html-htmlize-font-prefix)
  1142. (htmlbuf (htmlize-region beg end)))
  1143. (unwind-protect
  1144. (with-current-buffer htmlbuf
  1145. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  1146. (plist-get htmlize-buffer-places 'content-end)))
  1147. (kill-buffer htmlbuf))))
  1148. ;;;###autoload
  1149. (defun org-html-htmlize-generate-css ()
  1150. "Create the CSS for all font definitions in the current Emacs session.
  1151. Use this to create face definitions in your CSS style file that can then
  1152. be used by code snippets transformed by htmlize.
  1153. This command just produces a buffer that contains class definitions for all
  1154. faces used in the current Emacs session. You can copy and paste the ones you
  1155. need into your CSS file.
  1156. If you then set `org-html-htmlize-output-type' to `css', calls
  1157. to the function `org-html-htmlize-region-for-paste' will
  1158. produce code that uses these same face definitions."
  1159. (interactive)
  1160. (require 'htmlize)
  1161. (and (get-buffer "*html*") (kill-buffer "*html*"))
  1162. (with-temp-buffer
  1163. (let ((fl (face-list))
  1164. (htmlize-css-name-prefix "org-")
  1165. (htmlize-output-type 'css)
  1166. f i)
  1167. (while (setq f (pop fl)
  1168. i (and f (face-attribute f :inherit)))
  1169. (when (and (symbolp f) (or (not i) (not (listp i))))
  1170. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  1171. (htmlize-region (point-min) (point-max))))
  1172. (org-pop-to-buffer-same-window "*html*")
  1173. (goto-char (point-min))
  1174. (if (re-search-forward "<style" nil t)
  1175. (delete-region (point-min) (match-beginning 0)))
  1176. (if (re-search-forward "</style>" nil t)
  1177. (delete-region (1+ (match-end 0)) (point-max)))
  1178. (beginning-of-line 1)
  1179. (if (looking-at " +") (replace-match ""))
  1180. (goto-char (point-min)))
  1181. (defun org-html--make-string (n string)
  1182. "Build a string by concatenating N times STRING."
  1183. (let (out) (dotimes (i n out) (setq out (concat string out)))))
  1184. (defun org-html-fix-class-name (kwd) ; audit callers of this function
  1185. "Turn todo keyword KWD into a valid class name.
  1186. Replaces invalid characters with \"_\"."
  1187. (save-match-data
  1188. (while (string-match "[^a-zA-Z0-9_]" kwd)
  1189. (setq kwd (replace-match "_" t t kwd))))
  1190. kwd)
  1191. (defun org-html-format-footnote-reference (n def refcnt)
  1192. "Format footnote reference N with definition DEF into HTML."
  1193. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  1194. (format org-html-footnote-format
  1195. (let* ((id (format "fnr.%s%s" n extra))
  1196. (href (format " href=\"#fn.%s\"" n))
  1197. (attributes (concat " class=\"footref\"" href)))
  1198. (org-html--anchor id n attributes)))))
  1199. (defun org-html-format-footnotes-section (section-name definitions)
  1200. "Format footnotes section SECTION-NAME."
  1201. (if (not definitions) ""
  1202. (format org-html-footnotes-section section-name definitions)))
  1203. (defun org-html-format-footnote-definition (fn)
  1204. "Format the footnote definition FN."
  1205. (let ((n (car fn)) (def (cdr fn)))
  1206. (format
  1207. "<div class=\"footdef\">%s %s</div>\n"
  1208. (format org-html-footnote-format
  1209. (let* ((id (format "fn.%s" n))
  1210. (href (format " href=\"#fnr.%s\"" n))
  1211. (attributes (concat " class=\"footnum\"" href)))
  1212. (org-html--anchor id n attributes)))
  1213. def)))
  1214. (defun org-html-footnote-section (info)
  1215. "Format the footnote section.
  1216. INFO is a plist used as a communication channel."
  1217. (let* ((fn-alist (org-export-collect-footnote-definitions
  1218. (plist-get info :parse-tree) info))
  1219. (fn-alist
  1220. (loop for (n type raw) in fn-alist collect
  1221. (cons n (if (eq (org-element-type raw) 'org-data)
  1222. (org-trim (org-export-data raw info))
  1223. (format "<p>%s</p>"
  1224. (org-trim (org-export-data raw info))))))))
  1225. (when fn-alist
  1226. (org-html-format-footnotes-section
  1227. (org-html--translate "Footnotes" info)
  1228. (format
  1229. "\n%s\n"
  1230. (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
  1231. ;;; Template
  1232. (defun org-html--build-meta-info (info)
  1233. "Return meta tags for exported document.
  1234. INFO is a plist used as a communication channel."
  1235. (let* ((title (org-export-data (plist-get info :title) info))
  1236. (author (and (plist-get info :with-author)
  1237. (let ((auth (plist-get info :author)))
  1238. (and auth (org-export-data auth info)))))
  1239. (description (plist-get info :description))
  1240. (keywords (plist-get info :keywords)))
  1241. (concat
  1242. (format "<title>%s</title>\n" title)
  1243. (format
  1244. (when :time-stamp-file
  1245. (format-time-string
  1246. (concat "<!-- " org-html--timestamp-format " -->\n")))
  1247. "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
  1248. (or (and org-html-coding-system
  1249. (fboundp 'coding-system-get)
  1250. (coding-system-get org-html-coding-system 'mime-charset))
  1251. "iso-8859-1"))
  1252. (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
  1253. (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
  1254. (and description
  1255. (format "<meta name=\"description\" content=\"%s\"/>\n" description))
  1256. (and keywords
  1257. (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
  1258. (defun org-html--build-head (info)
  1259. "Return information for the <head>..</head> of the HTML output.
  1260. INFO is a plist used as a communication channel."
  1261. (org-element-normalize-string
  1262. (concat
  1263. (when (plist-get info :html-head-include-default-style)
  1264. (org-element-normalize-string org-html-style-default))
  1265. (org-element-normalize-string (plist-get info :html-head))
  1266. (org-element-normalize-string (plist-get info :html-head-extra))
  1267. (when (and (plist-get info :html-htmlized-css-url)
  1268. (eq org-html-htmlize-output-type 'css))
  1269. (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
  1270. (plist-get info :html-htmlized-css-url)))
  1271. (when (plist-get info :html-head-include-scripts) org-html-scripts))))
  1272. (defun org-html--build-mathjax-config (info)
  1273. "Insert the user setup into the mathjax template.
  1274. INFO is a plist used as a communication channel."
  1275. (when (and (memq (plist-get info :with-latex) '(mathjax t))
  1276. (org-element-map (plist-get info :parse-tree)
  1277. '(latex-fragment latex-environment) 'identity info t))
  1278. (let ((template org-html-mathjax-template)
  1279. (options org-html-mathjax-options)
  1280. (in-buffer (or (plist-get info :html-mathjax) ""))
  1281. name val (yes " ") (no "// ") x)
  1282. (mapc
  1283. (lambda (e)
  1284. (setq name (car e) val (nth 1 e))
  1285. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  1286. (setq val (car (read-from-string
  1287. (substring in-buffer (match-end 0))))))
  1288. (if (not (stringp val)) (setq val (format "%s" val)))
  1289. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  1290. (setq template (replace-match val t t template))))
  1291. options)
  1292. (setq val (nth 1 (assq 'mathml options)))
  1293. (if (string-match (concat "\\<mathml:") in-buffer)
  1294. (setq val (car (read-from-string
  1295. (substring in-buffer (match-end 0))))))
  1296. ;; Exchange prefixes depending on mathml setting.
  1297. (if (not val) (setq x yes yes no no x))
  1298. ;; Replace cookies to turn on or off the config/jax lines.
  1299. (if (string-match ":MMLYES:" template)
  1300. (setq template (replace-match yes t t template)))
  1301. (if (string-match ":MMLNO:" template)
  1302. (setq template (replace-match no t t template)))
  1303. ;; Return the modified template.
  1304. (org-element-normalize-string template))))
  1305. (defun org-html--build-pre/postamble (type info)
  1306. "Return document preamble or postamble as a string, or nil.
  1307. TYPE is either 'preamble or 'postamble, INFO is a plist used as a
  1308. communication channel."
  1309. (let ((section (plist-get info (intern (format ":html-%s" type))))
  1310. (spec `((?t . ,(org-export-data (plist-get info :title) info))
  1311. (?d . ,(org-export-data (plist-get info :date) info))
  1312. (?T . ,(format-time-string org-html--timestamp-format))
  1313. (?a . ,(org-export-data (plist-get info :author) info))
  1314. (?e . ,(mapconcat
  1315. (lambda (e)
  1316. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1317. (split-string (plist-get info :email) ",+ *")
  1318. ", "))
  1319. (?c . ,(plist-get info :creator))
  1320. (?v . ,(or org-html-validation-link "")))))
  1321. (when section
  1322. (let ((section-contents
  1323. (if (functionp section) (funcall section info)
  1324. (cond
  1325. ((stringp section) (format-spec section spec))
  1326. ((eq section 'auto)
  1327. (let ((date (cdr (assq ?d spec)))
  1328. (author (cdr (assq ?a spec)))
  1329. (email (cdr (assq ?e spec)))
  1330. (creator (cdr (assq ?c spec)))
  1331. (timestamp (cdr (assq ?T spec)))
  1332. (validation-link (cdr (assq ?v spec))))
  1333. (concat
  1334. (when (and (plist-get info :with-date)
  1335. (org-string-nw-p date))
  1336. (format "<p class=\"date\">%s: %s</p>\n"
  1337. (org-html--translate "Date" info)
  1338. date))
  1339. (when (and (plist-get info :with-author)
  1340. (org-string-nw-p author))
  1341. (format "<p class=\"author\">%s: %s</p>\n"
  1342. (org-html--translate "Author" info)
  1343. author))
  1344. (when (and (plist-get info :with-email)
  1345. (org-string-nw-p email))
  1346. (format "<p class=\"email\">%s: %s</p>\n"
  1347. (org-html--translate "Email" info)
  1348. email))
  1349. (when (plist-get info :time-stamp-file)
  1350. (format
  1351. "<p class=\"date\">%s: %s</p>\n"
  1352. (org-html--translate "Created" info)
  1353. (format-time-string org-html--timestamp-format)))
  1354. (when (plist-get info :with-creator)
  1355. (format "<p class=\"creator\">%s</p>\n"
  1356. creator))
  1357. (format "<p class=\"xhtml-validation\">%s</p>\n"
  1358. validation-link))))
  1359. (t (format-spec
  1360. (or (cadr (assoc
  1361. (plist-get info :language)
  1362. (eval (intern
  1363. (format "org-html-%s-format" type)))))
  1364. (cadr
  1365. (assoc
  1366. "en"
  1367. (eval
  1368. (intern (format "org-html-%s-format" type))))))
  1369. spec))))))
  1370. (when (org-string-nw-p section-contents)
  1371. (concat
  1372. (format "<%s id=\"%s\">\n"
  1373. (nth 1 (assq type org-html-divs))
  1374. (nth 2 (assq type org-html-divs)))
  1375. (org-element-normalize-string section-contents)
  1376. (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
  1377. (defun org-html-inner-template (contents info)
  1378. "Return body of document string after HTML conversion.
  1379. CONTENTS is the transcoded contents string. INFO is a plist
  1380. holding export options."
  1381. (concat
  1382. ;; Table of contents.
  1383. (let ((depth (plist-get info :with-toc)))
  1384. (when depth (org-html-toc depth info)))
  1385. ;; Document contents.
  1386. contents
  1387. ;; Footnotes section.
  1388. (org-html-footnote-section info)
  1389. ;; Bibliography.
  1390. (org-html-bibliography)))
  1391. (defun org-html-template (contents info)
  1392. "Return complete document string after HTML conversion.
  1393. CONTENTS is the transcoded contents string. INFO is a plist
  1394. holding export options."
  1395. (concat
  1396. (format
  1397. (or (and (stringp org-html-xml-declaration)
  1398. org-html-xml-declaration)
  1399. (cdr (assoc (plist-get info :html-extension)
  1400. org-html-xml-declaration))
  1401. (cdr (assoc "html" org-html-xml-declaration))
  1402. "")
  1403. (or (and org-html-coding-system
  1404. (fboundp 'coding-system-get)
  1405. (coding-system-get org-html-coding-system 'mime-charset))
  1406. "iso-8859-1"))
  1407. "\n"
  1408. (plist-get info :html-doctype)
  1409. "\n"
  1410. (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
  1411. (plist-get info :language) (plist-get info :language))
  1412. "<head>\n"
  1413. (org-html--build-meta-info info)
  1414. (org-html--build-head info)
  1415. (org-html--build-mathjax-config info)
  1416. "</head>\n"
  1417. "<body>\n"
  1418. (let ((link-up (org-trim (plist-get info :html-link-up)))
  1419. (link-home (org-trim (plist-get info :html-link-home))))
  1420. (unless (and (string= link-up "") (string= link-up ""))
  1421. (format org-html-home/up-format
  1422. (or link-up link-home)
  1423. (or link-home link-up))))
  1424. ;; Preamble.
  1425. (org-html--build-pre/postamble 'preamble info)
  1426. ;; Document contents.
  1427. (format "<%s id=\"%s\">\n"
  1428. (nth 1 (assq 'content org-html-divs))
  1429. (nth 2 (assq 'content org-html-divs)))
  1430. ;; Document title.
  1431. (let ((title (plist-get info :title)))
  1432. (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
  1433. contents
  1434. (format "</%s>\n"
  1435. (nth 1 (assq 'content org-html-divs)))
  1436. ;; Postamble.
  1437. (org-html--build-pre/postamble 'postamble info)
  1438. ;; Closing document.
  1439. "</body>\n</html>"))
  1440. (defun org-html--translate (s info)
  1441. "Translate string S according to specified language.
  1442. INFO is a plist used as a communication channel."
  1443. (org-export-translate s :html info))
  1444. ;;;; Anchor
  1445. (defun org-html--anchor (&optional id desc attributes)
  1446. "Format a HTML anchor."
  1447. (let* ((name (and org-html-allow-name-attribute-in-anchors id))
  1448. (attributes (concat (and id (format " id=\"%s\"" id))
  1449. (and name (format " name=\"%s\"" name))
  1450. attributes)))
  1451. (format "<a%s>%s</a>" attributes (or desc ""))))
  1452. ;;;; Todo
  1453. (defun org-html--todo (todo)
  1454. "Format TODO keywords into HTML."
  1455. (when todo
  1456. (format "<span class=\"%s %s%s\">%s</span>"
  1457. (if (member todo org-done-keywords) "done" "todo")
  1458. org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
  1459. todo)))
  1460. ;;;; Tags
  1461. (defun org-html--tags (tags)
  1462. "Format TAGS into HTML."
  1463. (when tags
  1464. (format "<span class=\"tag\">%s</span>"
  1465. (mapconcat
  1466. (lambda (tag)
  1467. (format "<span class=\"%s\">%s</span>"
  1468. (concat org-html-tag-class-prefix
  1469. (org-html-fix-class-name tag))
  1470. tag))
  1471. tags "&#xa0;"))))
  1472. ;;;; Headline
  1473. (defun* org-html-format-headline
  1474. (todo todo-type priority text tags
  1475. &key level section-number headline-label &allow-other-keys)
  1476. "Format a headline in HTML."
  1477. (let ((section-number
  1478. (when section-number
  1479. (format "<span class=\"section-number-%d\">%s</span> "
  1480. level section-number)))
  1481. (todo (org-html--todo todo))
  1482. (tags (org-html--tags tags)))
  1483. (concat section-number todo (and todo " ") text
  1484. (and tags "&#xa0;&#xa0;&#xa0;") tags)))
  1485. ;;;; Src Code
  1486. (defun org-html-fontify-code (code lang)
  1487. "Color CODE with htmlize library.
  1488. CODE is a string representing the source code to colorize. LANG
  1489. is the language used for CODE, as a string, or nil."
  1490. (when code
  1491. (cond
  1492. ;; Case 1: No lang. Possibly an example block.
  1493. ((not lang)
  1494. ;; Simple transcoding.
  1495. (org-html-encode-plain-text code))
  1496. ;; Case 2: No htmlize or an inferior version of htmlize
  1497. ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
  1498. ;; Emit a warning.
  1499. (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
  1500. ;; Simple transcoding.
  1501. (org-html-encode-plain-text code))
  1502. (t
  1503. ;; Map language
  1504. (setq lang (or (assoc-default lang org-src-lang-modes) lang))
  1505. (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
  1506. (cond
  1507. ;; Case 1: Language is not associated with any Emacs mode
  1508. ((not (functionp lang-mode))
  1509. ;; Simple transcoding.
  1510. (org-html-encode-plain-text code))
  1511. ;; Case 2: Default. Fontify code.
  1512. (t
  1513. ;; htmlize
  1514. (setq code (with-temp-buffer
  1515. ;; Switch to language-specific mode.
  1516. (funcall lang-mode)
  1517. (insert code)
  1518. ;; Fontify buffer.
  1519. (font-lock-fontify-buffer)
  1520. ;; Remove formatting on newline characters.
  1521. (save-excursion
  1522. (let ((beg (point-min))
  1523. (end (point-max)))
  1524. (goto-char beg)
  1525. (while (progn (end-of-line) (< (point) end))
  1526. (put-text-property (point) (1+ (point)) 'face nil)
  1527. (forward-char 1))))
  1528. (org-src-mode)
  1529. (set-buffer-modified-p nil)
  1530. ;; Htmlize region.
  1531. (org-html-htmlize-region-for-paste
  1532. (point-min) (point-max))))
  1533. ;; Strip any enclosing <pre></pre> tags.
  1534. (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
  1535. (end (and beg (string-match "</pre>\\'" code))))
  1536. (if (and beg end) (substring code beg end) code)))))))))
  1537. (defun org-html-do-format-code
  1538. (code &optional lang refs retain-labels num-start)
  1539. "Format CODE string as source code.
  1540. Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
  1541. respectively, the language of the source code, as a string, an
  1542. alist between line numbers and references (as returned by
  1543. `org-export-unravel-code'), a boolean specifying if labels should
  1544. appear in the source code, and the number associated to the first
  1545. line of code."
  1546. (let* ((code-lines (org-split-string code "\n"))
  1547. (code-length (length code-lines))
  1548. (num-fmt
  1549. (and num-start
  1550. (format "%%%ds: "
  1551. (length (number-to-string (+ code-length num-start))))))
  1552. (code (org-html-fontify-code code lang)))
  1553. (org-export-format-code
  1554. code
  1555. (lambda (loc line-num ref)
  1556. (setq loc
  1557. (concat
  1558. ;; Add line number, if needed.
  1559. (when num-start
  1560. (format "<span class=\"linenr\">%s</span>"
  1561. (format num-fmt line-num)))
  1562. ;; Transcoded src line.
  1563. loc
  1564. ;; Add label, if needed.
  1565. (when (and ref retain-labels) (format " (%s)" ref))))
  1566. ;; Mark transcoded line as an anchor, if needed.
  1567. (if (not ref) loc
  1568. (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
  1569. ref loc)))
  1570. num-start refs)))
  1571. (defun org-html-format-code (element info)
  1572. "Format contents of ELEMENT as source code.
  1573. ELEMENT is either an example block or a src block. INFO is
  1574. a plist used as a communication channel."
  1575. (let* ((lang (org-element-property :language element))
  1576. ;; Extract code and references.
  1577. (code-info (org-export-unravel-code element))
  1578. (code (car code-info))
  1579. (refs (cdr code-info))
  1580. ;; Does the src block contain labels?
  1581. (retain-labels (org-element-property :retain-labels element))
  1582. ;; Does it have line numbers?
  1583. (num-start (case (org-element-property :number-lines element)
  1584. (continued (org-export-get-loc element info))
  1585. (new 0))))
  1586. (org-html-do-format-code code lang refs retain-labels num-start)))
  1587. ;;; Tables of Contents
  1588. (defun org-html-toc (depth info)
  1589. "Build a table of contents.
  1590. DEPTH is an integer specifying the depth of the table. INFO is a
  1591. plist used as a communication channel. Return the table of
  1592. contents as a string, or nil if it is empty."
  1593. (let ((toc-entries
  1594. (mapcar (lambda (headline)
  1595. (cons (org-html--format-toc-headline headline info)
  1596. (org-export-get-relative-level headline info)))
  1597. (org-export-collect-headlines info depth))))
  1598. (when toc-entries
  1599. (concat "<div id=\"table-of-contents\">\n"
  1600. (format "<h%d>%s</h%d>\n"
  1601. org-html-toplevel-hlevel
  1602. (org-html--translate "Table of Contents" info)
  1603. org-html-toplevel-hlevel)
  1604. "<div id=\"text-table-of-contents\">"
  1605. (org-html--toc-text toc-entries)
  1606. "</div>\n"
  1607. "</div>\n"))))
  1608. (defun org-html--toc-text (toc-entries)
  1609. "Return innards of a table of contents, as a string.
  1610. TOC-ENTRIES is an alist where key is an entry title, as a string,
  1611. and value is its relative level, as an integer."
  1612. (let* ((prev-level (1- (cdar toc-entries)))
  1613. (start-level prev-level))
  1614. (concat
  1615. (mapconcat
  1616. (lambda (entry)
  1617. (let ((headline (car entry))
  1618. (level (cdr entry)))
  1619. (concat
  1620. (let* ((cnt (- level prev-level))
  1621. (times (if (> cnt 0) (1- cnt) (- cnt)))
  1622. rtn)
  1623. (setq prev-level level)
  1624. (concat
  1625. (org-html--make-string
  1626. times (cond ((> cnt 0) "\n<ul>\n<li>")
  1627. ((< cnt 0) "</li>\n</ul>\n")))
  1628. (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
  1629. headline)))
  1630. toc-entries "")
  1631. (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
  1632. (defun org-html--format-toc-headline (headline info)
  1633. "Return an appropriate table of contents entry for HEADLINE.
  1634. INFO is a plist used as a communication channel."
  1635. (let* ((headline-number (org-export-get-headline-number headline info))
  1636. (section-number
  1637. (and (not (org-export-low-level-p headline info))
  1638. (org-export-numbered-headline-p headline info)
  1639. (concat (mapconcat 'number-to-string headline-number ".") ". ")))
  1640. (tags (and (eq (plist-get info :with-tags) t)
  1641. (org-export-get-tags headline info))))
  1642. (format "<a href=\"#%s\">%s</a>"
  1643. ;; Label.
  1644. (org-export-solidify-link-text
  1645. (or (org-element-property :CUSTOM_ID headline)
  1646. (concat "sec-" (mapconcat 'number-to-string
  1647. headline-number "-"))))
  1648. ;; Body.
  1649. (concat section-number
  1650. (org-export-data-with-translations
  1651. (org-export-get-alt-title headline info)
  1652. ;; Ignore any footnote-reference, link,
  1653. ;; radio-target and target in table of contents.
  1654. (append
  1655. '((footnote-reference . ignore)
  1656. (link . (lambda (link desc i) desc))
  1657. (radio-target . (lambda (radio desc i) desc))
  1658. (target . ignore))
  1659. (org-export-backend-translate-table 'html))
  1660. info)
  1661. (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
  1662. (defun org-html-list-of-listings (info)
  1663. "Build a list of listings.
  1664. INFO is a plist used as a communication channel. Return the list
  1665. of listings as a string, or nil if it is empty."
  1666. (let ((lol-entries (org-export-collect-listings info)))
  1667. (when lol-entries
  1668. (concat "<div id=\"list-of-listings\">\n"
  1669. (format "<h%d>%s</h%d>\n"
  1670. org-html-toplevel-hlevel
  1671. (org-html--translate "List of Listings" info)
  1672. org-html-toplevel-hlevel)
  1673. "<div id=\"text-list-of-listings\">\n<ul>\n"
  1674. (let ((count 0)
  1675. (initial-fmt (org-html--translate "Listing %d:" info)))
  1676. (mapconcat
  1677. (lambda (entry)
  1678. (let ((label (org-element-property :name entry))
  1679. (title (org-trim
  1680. (org-export-data
  1681. (or (org-export-get-caption entry t)
  1682. (org-export-get-caption entry))
  1683. info))))
  1684. (concat
  1685. "<li>"
  1686. (if (not label)
  1687. (concat (format initial-fmt (incf count)) " " title)
  1688. (format "<a href=\"#%s\">%s %s</a>"
  1689. (org-export-solidify-link-text label)
  1690. (format initial-fmt (incf count))
  1691. title))
  1692. "</li>")))
  1693. lol-entries "\n"))
  1694. "\n</ul>\n</div>\n</div>"))))
  1695. (defun org-html-list-of-tables (info)
  1696. "Build a list of tables.
  1697. INFO is a plist used as a communication channel. Return the list
  1698. of tables as a string, or nil if it is empty."
  1699. (let ((lol-entries (org-export-collect-tables info)))
  1700. (when lol-entries
  1701. (concat "<div id=\"list-of-tables\">\n"
  1702. (format "<h%d>%s</h%d>\n"
  1703. org-html-toplevel-hlevel
  1704. (org-html--translate "List of Tables" info)
  1705. org-html-toplevel-hlevel)
  1706. "<div id=\"text-list-of-tables\">\n<ul>\n"
  1707. (let ((count 0)
  1708. (initial-fmt (org-html--translate "Table %d:" info)))
  1709. (mapconcat
  1710. (lambda (entry)
  1711. (let ((label (org-element-property :name entry))
  1712. (title (org-trim
  1713. (org-export-data
  1714. (or (org-export-get-caption entry t)
  1715. (org-export-get-caption entry))
  1716. info))))
  1717. (concat
  1718. "<li>"
  1719. (if (not label)
  1720. (concat (format initial-fmt (incf count)) " " title)
  1721. (format "<a href=\"#%s\">%s %s</a>"
  1722. (org-export-solidify-link-text label)
  1723. (format initial-fmt (incf count))
  1724. title))
  1725. "</li>")))
  1726. lol-entries "\n"))
  1727. "\n</ul>\n</div>\n</div>"))))
  1728. ;;; Transcode Functions
  1729. ;;;; Bold
  1730. (defun org-html-bold (bold contents info)
  1731. "Transcode BOLD from Org to HTML.
  1732. CONTENTS is the text with bold markup. INFO is a plist holding
  1733. contextual information."
  1734. (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
  1735. contents))
  1736. ;;;; Center Block
  1737. (defun org-html-center-block (center-block contents info)
  1738. "Transcode a CENTER-BLOCK element from Org to HTML.
  1739. CONTENTS holds the contents of the block. INFO is a plist
  1740. holding contextual information."
  1741. (format "<div class=\"center\">\n%s</div>" contents))
  1742. ;;;; Clock
  1743. (defun org-html-clock (clock contents info)
  1744. "Transcode a CLOCK element from Org to HTML.
  1745. CONTENTS is nil. INFO is a plist used as a communication
  1746. channel."
  1747. (format "<p>
  1748. <span class=\"timestamp-wrapper\">
  1749. <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
  1750. </span>
  1751. </p>"
  1752. org-clock-string
  1753. (org-translate-time
  1754. (org-element-property :raw-value
  1755. (org-element-property :value clock)))
  1756. (let ((time (org-element-property :duration clock)))
  1757. (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
  1758. ;;;; Code
  1759. (defun org-html-code (code contents info)
  1760. "Transcode CODE from Org to HTML.
  1761. CONTENTS is nil. INFO is a plist holding contextual
  1762. information."
  1763. (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
  1764. (org-html-plain-text (org-element-property :value code) info)))
  1765. ;;;; Drawer
  1766. (defun org-html-drawer (drawer contents info)
  1767. "Transcode a DRAWER element from Org to HTML.
  1768. CONTENTS holds the contents of the block. INFO is a plist
  1769. holding contextual information."
  1770. (if (functionp org-html-format-drawer-function)
  1771. (funcall org-html-format-drawer-function
  1772. (org-element-property :drawer-name drawer)
  1773. contents)
  1774. ;; If there's no user defined function: simply
  1775. ;; display contents of the drawer.
  1776. contents))
  1777. ;;;; Dynamic Block
  1778. (defun org-html-dynamic-block (dynamic-block contents info)
  1779. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1780. CONTENTS holds the contents of the block. INFO is a plist
  1781. holding contextual information. See `org-export-data'."
  1782. contents)
  1783. ;;;; Entity
  1784. (defun org-html-entity (entity contents info)
  1785. "Transcode an ENTITY object from Org to HTML.
  1786. CONTENTS are the definition itself. INFO is a plist holding
  1787. contextual information."
  1788. (org-element-property :html entity))
  1789. ;;;; Example Block
  1790. (defun org-html-example-block (example-block contents info)
  1791. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  1792. CONTENTS is nil. INFO is a plist holding contextual
  1793. information."
  1794. (if (org-export-read-attribute :attr_html example-block :textarea)
  1795. (org-html--textarea-block example-block)
  1796. (format "<pre class=\"example\">\n%s</pre>"
  1797. (org-html-format-code example-block info))))
  1798. ;;;; Export Snippet
  1799. (defun org-html-export-snippet (export-snippet contents info)
  1800. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  1801. CONTENTS is nil. INFO is a plist holding contextual
  1802. information."
  1803. (when (eq (org-export-snippet-backend export-snippet) 'html)
  1804. (org-element-property :value export-snippet)))
  1805. ;;;; Export Block
  1806. (defun org-html-export-block (export-block contents info)
  1807. "Transcode a EXPORT-BLOCK element from Org to HTML.
  1808. CONTENTS is nil. INFO is a plist holding contextual information."
  1809. (when (string= (org-element-property :type export-block) "HTML")
  1810. (org-remove-indentation (org-element-property :value export-block))))
  1811. ;;;; Fixed Width
  1812. (defun org-html-fixed-width (fixed-width contents info)
  1813. "Transcode a FIXED-WIDTH element from Org to HTML.
  1814. CONTENTS is nil. INFO is a plist holding contextual information."
  1815. (format "<pre class=\"example\">\n%s</pre>"
  1816. (org-html-do-format-code
  1817. (org-remove-indentation
  1818. (org-element-property :value fixed-width)))))
  1819. ;;;; Footnote Reference
  1820. (defun org-html-footnote-reference (footnote-reference contents info)
  1821. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  1822. CONTENTS is nil. INFO is a plist holding contextual information."
  1823. (concat
  1824. ;; Insert separator between two footnotes in a row.
  1825. (let ((prev (org-export-get-previous-element footnote-reference info)))
  1826. (when (eq (org-element-type prev) 'footnote-reference)
  1827. org-html-footnote-separator))
  1828. (cond
  1829. ((not (org-export-footnote-first-reference-p footnote-reference info))
  1830. (org-html-format-footnote-reference
  1831. (org-export-get-footnote-number footnote-reference info)
  1832. "IGNORED" 100))
  1833. ;; Inline definitions are secondary strings.
  1834. ((eq (org-element-property :type footnote-reference) 'inline)
  1835. (org-html-format-footnote-reference
  1836. (org-export-get-footnote-number footnote-reference info)
  1837. "IGNORED" 1))
  1838. ;; Non-inline footnotes definitions are full Org data.
  1839. (t (org-html-format-footnote-reference
  1840. (org-export-get-footnote-number footnote-reference info)
  1841. "IGNORED" 1)))))
  1842. ;;;; Headline
  1843. (defun org-html-format-headline--wrap
  1844. (headline info &optional format-function &rest extra-keys)
  1845. "Transcode a HEADLINE element from Org to HTML.
  1846. CONTENTS holds the contents of the headline. INFO is a plist
  1847. holding contextual information."
  1848. (let* ((level (+ (org-export-get-relative-level headline info)
  1849. (1- org-html-toplevel-hlevel)))
  1850. (headline-number (org-export-get-headline-number headline info))
  1851. (section-number (and (not (org-export-low-level-p headline info))
  1852. (org-export-numbered-headline-p headline info)
  1853. (mapconcat 'number-to-string
  1854. headline-number ".")))
  1855. (todo (and (plist-get info :with-todo-keywords)
  1856. (let ((todo (org-element-property :todo-keyword headline)))
  1857. (and todo (org-export-data todo info)))))
  1858. (todo-type (and todo (org-element-property :todo-type headline)))
  1859. (priority (and (plist-get info :with-priority)
  1860. (org-element-property :priority headline)))
  1861. (text (org-export-data (org-element-property :title headline) info))
  1862. (tags (and (plist-get info :with-tags)
  1863. (org-export-get-tags headline info)))
  1864. (headline-label (or (org-element-property :CUSTOM_ID headline)
  1865. (concat "sec-" (mapconcat 'number-to-string
  1866. headline-number "-"))))
  1867. (format-function (cond
  1868. ((functionp format-function) format-function)
  1869. ((functionp org-html-format-headline-function)
  1870. (function*
  1871. (lambda (todo todo-type priority text tags
  1872. &allow-other-keys)
  1873. (funcall org-html-format-headline-function
  1874. todo todo-type priority text tags))))
  1875. (t 'org-html-format-headline))))
  1876. (apply format-function
  1877. todo todo-type priority text tags
  1878. :headline-label headline-label :level level
  1879. :section-number section-number extra-keys)))
  1880. (defun org-html-headline (headline contents info)
  1881. "Transcode a HEADLINE element from Org to HTML.
  1882. CONTENTS holds the contents of the headline. INFO is a plist
  1883. holding contextual information."
  1884. ;; Empty contents?
  1885. (setq contents (or contents ""))
  1886. (let* ((numberedp (org-export-numbered-headline-p headline info))
  1887. (level (org-export-get-relative-level headline info))
  1888. (text (org-export-data (org-element-property :title headline) info))
  1889. (todo (and (plist-get info :with-todo-keywords)
  1890. (let ((todo (org-element-property :todo-keyword headline)))
  1891. (and todo (org-export-data todo info)))))
  1892. (todo-type (and todo (org-element-property :todo-type headline)))
  1893. (tags (and (plist-get info :with-tags)
  1894. (org-export-get-tags headline info)))
  1895. (priority (and (plist-get info :with-priority)
  1896. (org-element-property :priority headline)))
  1897. (section-number (and (org-export-numbered-headline-p headline info)
  1898. (mapconcat 'number-to-string
  1899. (org-export-get-headline-number
  1900. headline info) ".")))
  1901. ;; Create the headline text.
  1902. (full-text (org-html-format-headline--wrap headline info)))
  1903. (cond
  1904. ;; Case 1: This is a footnote section: ignore it.
  1905. ((org-element-property :footnote-section-p headline) nil)
  1906. ;; Case 2. This is a deep sub-tree: export it as a list item.
  1907. ;; Also export as items headlines for which no section
  1908. ;; format has been found.
  1909. ((org-export-low-level-p headline info)
  1910. ;; Build the real contents of the sub-tree.
  1911. (let* ((type (if numberedp 'ordered 'unordered))
  1912. (itemized-body (org-html-format-list-item
  1913. contents type nil nil full-text)))
  1914. (concat
  1915. (and (org-export-first-sibling-p headline info)
  1916. (org-html-begin-plain-list type))
  1917. itemized-body
  1918. (and (org-export-last-sibling-p headline info)
  1919. (org-html-end-plain-list type)))))
  1920. ;; Case 3. Standard headline. Export it as a section.
  1921. (t
  1922. (let* ((section-number (mapconcat 'number-to-string
  1923. (org-export-get-headline-number
  1924. headline info) "-"))
  1925. (ids (remove 'nil
  1926. (list (org-element-property :CUSTOM_ID headline)
  1927. (concat "sec-" section-number)
  1928. (org-element-property :ID headline))))
  1929. (preferred-id (car ids))
  1930. (extra-ids (cdr ids))
  1931. (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
  1932. (level1 (+ level (1- org-html-toplevel-hlevel)))
  1933. (first-content (car (org-element-contents headline))))
  1934. (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
  1935. (if (= 1 (org-export-get-relative-level headline info))
  1936. (plist-get info :html-container)
  1937. "div")
  1938. (format "outline-container-%s"
  1939. (or (org-element-property :CUSTOM_ID headline)
  1940. section-number))
  1941. (concat (format "outline-%d" level1) (and extra-class " ")
  1942. extra-class)
  1943. (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
  1944. level1
  1945. preferred-id
  1946. (mapconcat
  1947. (lambda (x)
  1948. (let ((id (org-export-solidify-link-text
  1949. (if (org-uuidgen-p x) (concat "ID-" x)
  1950. x))))
  1951. (org-html--anchor id)))
  1952. extra-ids "")
  1953. full-text
  1954. level1)
  1955. ;; When there is no section, pretend there is an empty
  1956. ;; one to get the correct <div class="outline- ...>
  1957. ;; which is needed by `org-info.js'.
  1958. (if (not (eq (org-element-type first-content) 'section))
  1959. (concat (org-html-section first-content "" info)
  1960. contents)
  1961. contents)
  1962. (if (= 1 (org-export-get-relative-level headline info))
  1963. (plist-get info :html-container)
  1964. "div")))))))
  1965. ;;;; Horizontal Rule
  1966. (defun org-html-horizontal-rule (horizontal-rule contents info)
  1967. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  1968. CONTENTS is nil. INFO is a plist holding contextual information."
  1969. "<hr/>")
  1970. ;;;; Inline Src Block
  1971. (defun org-html-inline-src-block (inline-src-block contents info)
  1972. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  1973. CONTENTS holds the contents of the item. INFO is a plist holding
  1974. contextual information."
  1975. (let* ((org-lang (org-element-property :language inline-src-block))
  1976. (code (org-element-property :value inline-src-block)))
  1977. (error "Cannot export inline src block")))
  1978. ;;;; Inlinetask
  1979. (defun org-html-format-section (text class &optional id)
  1980. "Format a section with TEXT into a HTML div with CLASS and ID."
  1981. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  1982. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  1983. (defun org-html-inlinetask (inlinetask contents info)
  1984. "Transcode an INLINETASK element from Org to HTML.
  1985. CONTENTS holds the contents of the block. INFO is a plist
  1986. holding contextual information."
  1987. (cond
  1988. ;; If `org-html-format-inlinetask-function' is provided, call it
  1989. ;; with appropriate arguments.
  1990. ((functionp org-html-format-inlinetask-function)
  1991. (let ((format-function
  1992. (function*
  1993. (lambda (todo todo-type priority text tags
  1994. &key contents &allow-other-keys)
  1995. (funcall org-html-format-inlinetask-function
  1996. todo todo-type priority text tags contents)))))
  1997. (org-html-format-headline--wrap
  1998. inlinetask info format-function :contents contents)))
  1999. ;; Otherwise, use a default template.
  2000. (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
  2001. (org-html-format-headline--wrap inlinetask info)
  2002. contents))))
  2003. ;;;; Italic
  2004. (defun org-html-italic (italic contents info)
  2005. "Transcode ITALIC from Org to HTML.
  2006. CONTENTS is the text with italic markup. INFO is a plist holding
  2007. contextual information."
  2008. (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
  2009. ;;;; Item
  2010. (defun org-html-checkbox (checkbox)
  2011. "Format CHECKBOX into HTML."
  2012. (case checkbox (on "<code>[X]</code>")
  2013. (off "<code>[&#xa0;]</code>")
  2014. (trans "<code>[-]</code>")
  2015. (t "")))
  2016. (defun org-html-format-list-item (contents type checkbox
  2017. &optional term-counter-id
  2018. headline)
  2019. "Format a list item into HTML."
  2020. (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
  2021. (concat
  2022. (case type
  2023. (ordered
  2024. (let* ((counter term-counter-id)
  2025. (extra (if counter (format " value=\"%s\"" counter) "")))
  2026. (concat
  2027. (format "<li%s>" extra)
  2028. (when headline (concat headline "<br/>")))))
  2029. (unordered
  2030. (let* ((id term-counter-id)
  2031. (extra (if id (format " id=\"%s\"" id) "")))
  2032. (concat
  2033. (format "<li%s>" extra)
  2034. (when headline (concat headline "<br/>")))))
  2035. (descriptive
  2036. (let* ((term term-counter-id))
  2037. (setq term (or term "(no term)"))
  2038. ;; Check-boxes in descriptive lists are associated to tag.
  2039. (concat (format "<dt> %s </dt>"
  2040. (concat checkbox term))
  2041. "<dd>"))))
  2042. (unless (eq type 'descriptive) checkbox)
  2043. contents
  2044. (case type
  2045. (ordered "</li>")
  2046. (unordered "</li>")
  2047. (descriptive "</dd>")))))
  2048. (defun org-html-item (item contents info)
  2049. "Transcode an ITEM element from Org to HTML.
  2050. CONTENTS holds the contents of the item. INFO is a plist holding
  2051. contextual information."
  2052. (let* ((plain-list (org-export-get-parent item))
  2053. (type (org-element-property :type plain-list))
  2054. (counter (org-element-property :counter item))
  2055. (checkbox (org-element-property :checkbox item))
  2056. (tag (let ((tag (org-element-property :tag item)))
  2057. (and tag (org-export-data tag info)))))
  2058. (org-html-format-list-item
  2059. contents type checkbox (or tag counter))))
  2060. ;;;; Keyword
  2061. (defun org-html-keyword (keyword contents info)
  2062. "Transcode a KEYWORD element from Org to HTML.
  2063. CONTENTS is nil. INFO is a plist holding contextual information."
  2064. (let ((key (org-element-property :key keyword))
  2065. (value (org-element-property :value keyword)))
  2066. (cond
  2067. ((string= key "HTML") value)
  2068. ;; Invisible targets.
  2069. ((string= key "TARGET") nil)
  2070. ((string= key "TOC")
  2071. (let ((value (downcase value)))
  2072. (cond
  2073. ((string-match "\\<headlines\\>" value)
  2074. (let ((depth (or (and (string-match "[0-9]+" value)
  2075. (string-to-number (match-string 0 value)))
  2076. (plist-get info :with-toc))))
  2077. (org-html-toc depth info)))
  2078. ((string= "listings" value) (org-html-list-of-listings info))
  2079. ((string= "tables" value) (org-html-list-of-tables info))))))))
  2080. ;;;; Latex Environment
  2081. (defun org-html-format-latex (latex-frag processing-type)
  2082. "Format the LaTeX fragment LATEX-FRAG into HTML."
  2083. (let ((cache-relpath "") (cache-dir "") bfn)
  2084. (unless (eq processing-type 'mathjax)
  2085. (setq bfn (buffer-file-name)
  2086. cache-relpath
  2087. (concat "ltxpng/"
  2088. (file-name-sans-extension
  2089. (file-name-nondirectory bfn)))
  2090. cache-dir (file-name-directory bfn)))
  2091. (with-temp-buffer
  2092. (insert latex-frag)
  2093. (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
  2094. nil nil processing-type)
  2095. (buffer-string))))
  2096. (defun org-html-latex-environment (latex-environment contents info)
  2097. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  2098. CONTENTS is nil. INFO is a plist holding contextual information."
  2099. (let ((processing-type (plist-get info :with-latex))
  2100. (latex-frag (org-remove-indentation
  2101. (org-element-property :value latex-environment)))
  2102. (caption (org-export-data
  2103. (org-export-get-caption latex-environment) info))
  2104. (attr nil) ; FIXME
  2105. (label (org-element-property :name latex-environment)))
  2106. (cond
  2107. ((memq processing-type '(t mathjax))
  2108. (org-html-format-latex latex-frag 'mathjax))
  2109. ((eq processing-type 'dvipng)
  2110. (let* ((formula-link (org-html-format-latex
  2111. latex-frag processing-type)))
  2112. (when (and formula-link
  2113. (string-match "file:\\([^]]*\\)" formula-link))
  2114. (org-html-format-inline-image
  2115. (match-string 1 formula-link) caption label attr t))))
  2116. (t latex-frag))))
  2117. ;;;; Latex Fragment
  2118. (defun org-html-latex-fragment (latex-fragment contents info)
  2119. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2120. CONTENTS is nil. INFO is a plist holding contextual information."
  2121. (let ((latex-frag (org-element-property :value latex-fragment))
  2122. (processing-type (plist-get info :with-latex)))
  2123. (case processing-type
  2124. ((t mathjax)
  2125. (org-html-format-latex latex-frag 'mathjax))
  2126. (dvipng
  2127. (let* ((formula-link (org-html-format-latex
  2128. latex-frag processing-type)))
  2129. (when (and formula-link
  2130. (string-match "file:\\([^]]*\\)" formula-link))
  2131. (org-html-format-inline-image
  2132. (match-string 1 formula-link)))))
  2133. (t latex-frag))))
  2134. ;;;; Line Break
  2135. (defun org-html-line-break (line-break contents info)
  2136. "Transcode a LINE-BREAK object from Org to HTML.
  2137. CONTENTS is nil. INFO is a plist holding contextual information."
  2138. "<br/>\n")
  2139. ;;;; Link
  2140. (defun org-html-link--inline-image (link desc info)
  2141. "Return HTML code for an inline image.
  2142. LINK is the link pointing to the inline image. INFO is a plist
  2143. used as a communication channel."
  2144. (let* ((type (org-element-property :type link))
  2145. (raw-path (org-element-property :path link))
  2146. (path (cond ((member type '("http" "https"))
  2147. (concat type ":" raw-path))
  2148. ((file-name-absolute-p raw-path)
  2149. (expand-file-name raw-path))
  2150. (t raw-path)))
  2151. (parent (org-export-get-parent-element link))
  2152. (caption (org-export-data (org-export-get-caption parent) info))
  2153. (label (org-element-property :name parent))
  2154. (attr (mapconcat #'identity (org-element-property :attr_html parent) " ")))
  2155. ;; Return proper string, depending on DISPOSITION.
  2156. (org-html-format-inline-image
  2157. path caption label attr (org-html-standalone-image-p link info))))
  2158. (defvar org-html-standalone-image-predicate)
  2159. (defun org-html-standalone-image-p (element info &optional predicate)
  2160. "Test if ELEMENT is a standalone image for the purpose HTML export.
  2161. INFO is a plist holding contextual information.
  2162. Return non-nil, if ELEMENT is of type paragraph and it's sole
  2163. content, save for whitespaces, is a link that qualifies as an
  2164. inline image.
  2165. Return non-nil, if ELEMENT is of type link and it's containing
  2166. paragraph has no other content save for leading and trailing
  2167. whitespaces.
  2168. Return nil, otherwise.
  2169. Bind `org-html-standalone-image-predicate' to constrain
  2170. paragraph further. For example, to check for only captioned
  2171. standalone images, do the following.
  2172. \(setq org-html-standalone-image-predicate
  2173. \(lambda \(paragraph\)
  2174. \(org-element-property :caption paragraph\)\)\)"
  2175. (let ((paragraph (case (org-element-type element)
  2176. (paragraph element)
  2177. (link (and (org-export-inline-image-p
  2178. element org-html-inline-image-rules)
  2179. (org-export-get-parent element)))
  2180. (t nil))))
  2181. (when (eq (org-element-type paragraph) 'paragraph)
  2182. (when (or (not (and (boundp 'org-html-standalone-image-predicate)
  2183. (functionp org-html-standalone-image-predicate)))
  2184. (funcall org-html-standalone-image-predicate paragraph))
  2185. (let ((contents (org-element-contents paragraph)))
  2186. (loop for x in contents
  2187. with inline-image-count = 0
  2188. always (cond
  2189. ((eq (org-element-type x) 'plain-text)
  2190. (not (org-string-nw-p x)))
  2191. ((eq (org-element-type x) 'link)
  2192. (when (org-export-inline-image-p
  2193. x org-html-inline-image-rules)
  2194. (= (incf inline-image-count) 1)))
  2195. (t nil))))))))
  2196. (defun org-html-link (link desc info)
  2197. "Transcode a LINK object from Org to HTML.
  2198. DESC is the description part of the link, or the empty string.
  2199. INFO is a plist holding contextual information. See
  2200. `org-export-data'."
  2201. (let* ((link-org-files-as-html-maybe
  2202. (function
  2203. (lambda (raw-path info)
  2204. "Treat links to `file.org' as links to `file.html', if needed.
  2205. See `org-html-link-org-files-as-html'."
  2206. (cond
  2207. ((and org-html-link-org-files-as-html
  2208. (string= ".org"
  2209. (downcase (file-name-extension raw-path "."))))
  2210. (concat (file-name-sans-extension raw-path) "."
  2211. (plist-get info :html-extension)))
  2212. (t raw-path)))))
  2213. (type (org-element-property :type link))
  2214. (raw-path (org-element-property :path link))
  2215. ;; Ensure DESC really exists, or set it to nil.
  2216. (desc (and (not (string= desc "")) desc))
  2217. (path
  2218. (cond
  2219. ((member type '("http" "https" "ftp" "mailto"))
  2220. (concat type ":" raw-path))
  2221. ((string= type "file")
  2222. ;; Treat links to ".org" files as ".html", if needed.
  2223. (setq raw-path
  2224. (funcall link-org-files-as-html-maybe raw-path info))
  2225. ;; If file path is absolute, prepend it with protocol
  2226. ;; component - "file://".
  2227. (when (file-name-absolute-p raw-path)
  2228. (setq raw-path
  2229. (concat "file://" (expand-file-name raw-path))))
  2230. ;; Add search option, if any. A search option can be
  2231. ;; relative to a custom-id or a headline title. Any other
  2232. ;; option is ignored.
  2233. (let ((option (org-element-property :search-option link)))
  2234. (cond ((not option) raw-path)
  2235. ((eq (aref option 0) ?#) (concat raw-path option))
  2236. ;; External fuzzy link: try to resolve it if path
  2237. ;; belongs to current project, if any.
  2238. ((eq (aref option 0) ?*)
  2239. (concat
  2240. raw-path
  2241. (let ((numbers
  2242. (org-publish-resolve-external-fuzzy-link
  2243. (org-element-property :path link) option)))
  2244. (and numbers (concat "#sec-"
  2245. (mapconcat 'number-to-string
  2246. numbers "-"))))))
  2247. (t raw-path))))
  2248. (t raw-path)))
  2249. attributes protocol)
  2250. ;; Extract attributes from parent's paragraph. HACK: Only do this
  2251. ;; for the first link in parent. This is needed as long as
  2252. ;; attributes cannot be set on a per link basis.
  2253. (and (setq attributes
  2254. (let ((parent (org-export-get-parent-element link)))
  2255. (if (not (eq (org-element-map parent 'link 'identity info t)
  2256. link))
  2257. ""
  2258. (mapconcat
  2259. 'identity
  2260. (let ((att (org-element-property :attr_html parent)))
  2261. (unless (and desc att
  2262. (string-match (regexp-quote (car att)) desc))
  2263. att))
  2264. " "))))
  2265. (unless (string= attributes "")
  2266. (setq attributes (concat " " attributes))))
  2267. (cond
  2268. ;; Image file.
  2269. ((and (or (eq t org-html-inline-images)
  2270. (and org-html-inline-images (not desc)))
  2271. (org-export-inline-image-p link org-html-inline-image-rules))
  2272. (org-html-link--inline-image link desc info))
  2273. ;; Radio target: Transcode target's contents and use them as
  2274. ;; link's description.
  2275. ((string= type "radio")
  2276. (let ((destination (org-export-resolve-radio-link link info)))
  2277. (when destination
  2278. (format "<a href=\"#%s\"%s>%s</a>"
  2279. (org-export-solidify-link-text path)
  2280. attributes
  2281. (org-export-data (org-element-contents destination) info)))))
  2282. ;; Links pointing to a headline: Find destination and build
  2283. ;; appropriate referencing command.
  2284. ((member type '("custom-id" "fuzzy" "id"))
  2285. (let ((destination (if (string= type "fuzzy")
  2286. (org-export-resolve-fuzzy-link link info)
  2287. (org-export-resolve-id-link link info))))
  2288. (case (org-element-type destination)
  2289. ;; ID link points to an external file.
  2290. (plain-text
  2291. (let ((fragment (concat "ID-" path))
  2292. ;; Treat links to ".org" files as ".html", if needed.
  2293. (path (funcall link-org-files-as-html-maybe
  2294. destination info)))
  2295. (format "<a href=\"%s#%s\"%s>%s</a>"
  2296. path fragment attributes (or desc destination))))
  2297. ;; Fuzzy link points nowhere.
  2298. ((nil)
  2299. (format "<i>%s</i>"
  2300. (or desc
  2301. (org-export-data
  2302. (org-element-property :raw-link link) info))))
  2303. ;; Fuzzy link points to an invisible target.
  2304. (keyword nil)
  2305. ;; Link points to a headline.
  2306. (headline
  2307. (let ((href
  2308. ;; What href to use?
  2309. (cond
  2310. ;; Case 1: Headline is linked via it's CUSTOM_ID
  2311. ;; property. Use CUSTOM_ID.
  2312. ((string= type "custom-id")
  2313. (org-element-property :CUSTOM_ID destination))
  2314. ;; Case 2: Headline is linked via it's ID property
  2315. ;; or through other means. Use the default href.
  2316. ((member type '("id" "fuzzy"))
  2317. (format "sec-%s"
  2318. (mapconcat 'number-to-string
  2319. (org-export-get-headline-number
  2320. destination info) "-")))
  2321. (t (error "Shouldn't reach here"))))
  2322. ;; What description to use?
  2323. (desc
  2324. ;; Case 1: Headline is numbered and LINK has no
  2325. ;; description or LINK's description matches
  2326. ;; headline's title. Display section number.
  2327. (if (and (org-export-numbered-headline-p destination info)
  2328. (or (not desc)
  2329. (string= desc (org-element-property
  2330. :raw-value destination))))
  2331. (mapconcat 'number-to-string
  2332. (org-export-get-headline-number
  2333. destination info) ".")
  2334. ;; Case 2: Either the headline is un-numbered or
  2335. ;; LINK has a custom description. Display LINK's
  2336. ;; description or headline's title.
  2337. (or desc (org-export-data (org-element-property
  2338. :title destination) info)))))
  2339. (format "<a href=\"#%s\"%s>%s</a>"
  2340. (org-export-solidify-link-text href) attributes desc)))
  2341. ;; Fuzzy link points to a target. Do as above.
  2342. (t
  2343. (let ((path (org-export-solidify-link-text path)) number)
  2344. (unless desc
  2345. (setq number (cond
  2346. ((org-html-standalone-image-p destination info)
  2347. (org-export-get-ordinal
  2348. (assoc 'link (org-element-contents destination))
  2349. info 'link 'org-html-standalone-image-p))
  2350. (t (org-export-get-ordinal destination info))))
  2351. (setq desc (when number
  2352. (if (atom number) (number-to-string number)
  2353. (mapconcat 'number-to-string number ".")))))
  2354. (format "<a href=\"#%s\"%s>%s</a>"
  2355. path attributes (or desc "No description for this link")))))))
  2356. ;; Coderef: replace link with the reference name or the
  2357. ;; equivalent line number.
  2358. ((string= type "coderef")
  2359. (let ((fragment (concat "coderef-" path)))
  2360. (format "<a href=\"#%s\"%s%s>%s</a>"
  2361. fragment
  2362. (org-trim
  2363. (format (concat "class=\"coderef\""
  2364. " onmouseover=\"CodeHighlightOn(this, '%s');\""
  2365. " onmouseout=\"CodeHighlightOff(this, '%s');\"")
  2366. fragment fragment))
  2367. attributes
  2368. (format (org-export-get-coderef-format path desc)
  2369. (org-export-resolve-coderef path info)))))
  2370. ;; Link type is handled by a special function.
  2371. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2372. (funcall protocol (org-link-unescape path) desc 'html))
  2373. ;; External link with a description part.
  2374. ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
  2375. ;; External link without a description part.
  2376. (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
  2377. ;; No path, only description. Try to do something useful.
  2378. (t (format "<i>%s</i>" desc)))))
  2379. ;;;; Paragraph
  2380. (defun org-html-paragraph (paragraph contents info)
  2381. "Transcode a PARAGRAPH element from Org to HTML.
  2382. CONTENTS is the contents of the paragraph, as a string. INFO is
  2383. the plist used as a communication channel."
  2384. (let* ((parent (org-export-get-parent paragraph))
  2385. (parent-type (org-element-type parent))
  2386. (style '((footnote-definition " class=\"footpara\"")))
  2387. (extra (or (cadr (assoc parent-type style)) "")))
  2388. (cond
  2389. ((and (eq (org-element-type parent) 'item)
  2390. (= (org-element-property :begin paragraph)
  2391. (org-element-property :contents-begin parent)))
  2392. ;; leading paragraph in a list item have no tags
  2393. contents)
  2394. ((org-html-standalone-image-p paragraph info)
  2395. ;; standalone image
  2396. contents)
  2397. (t (format "<p%s>\n%s</p>" extra contents)))))
  2398. ;;;; Plain List
  2399. ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
  2400. ;; the correct value for the item counter
  2401. (defun org-html-begin-plain-list (type &optional arg1)
  2402. "Insert the beginning of the HTML list depending on TYPE.
  2403. When ARG1 is a string, use it as the start parameter for ordered
  2404. lists."
  2405. (case type
  2406. (ordered
  2407. (format "<ol class=\"org-ol\"%s>"
  2408. (if arg1 (format " start=\"%d\"" arg1) "")))
  2409. (unordered "<ul class=\"org-ul\">")
  2410. (descriptive "<dl class=\"org-dl\">")))
  2411. (defun org-html-end-plain-list (type)
  2412. "Insert the end of the HTML list depending on TYPE."
  2413. (case type
  2414. (ordered "</ol>")
  2415. (unordered "</ul>")
  2416. (descriptive "</dl>")))
  2417. (defun org-html-plain-list (plain-list contents info)
  2418. "Transcode a PLAIN-LIST element from Org to HTML.
  2419. CONTENTS is the contents of the list. INFO is a plist holding
  2420. contextual information."
  2421. (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
  2422. (type (org-element-property :type plain-list)))
  2423. (format "%s\n%s%s"
  2424. (org-html-begin-plain-list type)
  2425. contents (org-html-end-plain-list type))))
  2426. ;;;; Plain Text
  2427. (defun org-html-convert-special-strings (string)
  2428. "Convert special characters in STRING to HTML."
  2429. (let ((all org-html-special-string-regexps)
  2430. e a re rpl start)
  2431. (while (setq a (pop all))
  2432. (setq re (car a) rpl (cdr a) start 0)
  2433. (while (string-match re string start)
  2434. (setq string (replace-match rpl t nil string))))
  2435. string))
  2436. (defun org-html-encode-plain-text (text)
  2437. "Convert plain text characters from TEXT to HTML equivalent.
  2438. Possible conversions are set in `org-html-protect-char-alist'."
  2439. (mapc
  2440. (lambda (pair)
  2441. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
  2442. org-html-protect-char-alist)
  2443. text)
  2444. (defun org-html-plain-text (text info)
  2445. "Transcode a TEXT string from Org to HTML.
  2446. TEXT is the string to transcode. INFO is a plist holding
  2447. contextual information."
  2448. (let ((output text))
  2449. ;; Protect following characters: <, >, &.
  2450. (setq output (org-html-encode-plain-text output))
  2451. ;; Handle smart quotes. Be sure to provide original string since
  2452. ;; OUTPUT may have been modified.
  2453. (when (plist-get info :with-smart-quotes)
  2454. (setq output (org-export-activate-smart-quotes output :html info text)))
  2455. ;; Handle special strings.
  2456. (when (plist-get info :with-special-strings)
  2457. (setq output (org-html-convert-special-strings output)))
  2458. ;; Handle break preservation if required.
  2459. (when (plist-get info :preserve-breaks)
  2460. (setq output
  2461. (replace-regexp-in-string
  2462. "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
  2463. ;; Return value.
  2464. output))
  2465. ;; Planning
  2466. (defun org-html-planning (planning contents info)
  2467. "Transcode a PLANNING element from Org to HTML.
  2468. CONTENTS is nil. INFO is a plist used as a communication
  2469. channel."
  2470. (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
  2471. (format
  2472. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  2473. (mapconcat
  2474. 'identity
  2475. (delq nil
  2476. (list
  2477. (let ((closed (org-element-property :closed planning)))
  2478. (when closed
  2479. (format span-fmt org-closed-string
  2480. (org-translate-time
  2481. (org-element-property :raw-value closed)))))
  2482. (let ((deadline (org-element-property :deadline planning)))
  2483. (when deadline
  2484. (format span-fmt org-deadline-string
  2485. (org-translate-time
  2486. (org-element-property :raw-value deadline)))))
  2487. (let ((scheduled (org-element-property :scheduled planning)))
  2488. (when scheduled
  2489. (format span-fmt org-scheduled-string
  2490. (org-translate-time
  2491. (org-element-property :raw-value scheduled)))))))
  2492. " "))))
  2493. ;;;; Property Drawer
  2494. (defun org-html-property-drawer (property-drawer contents info)
  2495. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2496. CONTENTS is nil. INFO is a plist holding contextual
  2497. information."
  2498. ;; The property drawer isn't exported but we want separating blank
  2499. ;; lines nonetheless.
  2500. "")
  2501. ;;;; Quote Block
  2502. (defun org-html-quote-block (quote-block contents info)
  2503. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2504. CONTENTS holds the contents of the block. INFO is a plist
  2505. holding contextual information."
  2506. (format "<blockquote>\n%s</blockquote>" contents))
  2507. ;;;; Quote Section
  2508. (defun org-html-quote-section (quote-section contents info)
  2509. "Transcode a QUOTE-SECTION element from Org to HTML.
  2510. CONTENTS is nil. INFO is a plist holding contextual information."
  2511. (let ((value (org-remove-indentation
  2512. (org-element-property :value quote-section))))
  2513. (when value (format "<pre>\n%s</pre>" value))))
  2514. ;;;; Section
  2515. (defun org-html-section (section contents info)
  2516. "Transcode a SECTION element from Org to HTML.
  2517. CONTENTS holds the contents of the section. INFO is a plist
  2518. holding contextual information."
  2519. (let ((parent (org-export-get-parent-headline section)))
  2520. ;; Before first headline: no container, just return CONTENTS.
  2521. (if (not parent) contents
  2522. ;; Get div's class and id references.
  2523. (let* ((class-num (+ (org-export-get-relative-level parent info)
  2524. (1- org-html-toplevel-hlevel)))
  2525. (section-number
  2526. (mapconcat
  2527. 'number-to-string
  2528. (org-export-get-headline-number parent info) "-")))
  2529. ;; Build return value.
  2530. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2531. class-num
  2532. (or (org-element-property :CUSTOM_ID parent) section-number)
  2533. contents)))))
  2534. ;;;; Radio Target
  2535. (defun org-html-radio-target (radio-target text info)
  2536. "Transcode a RADIO-TARGET object from Org to HTML.
  2537. TEXT is the text of the target. INFO is a plist holding
  2538. contextual information."
  2539. (let ((id (org-export-solidify-link-text
  2540. (org-element-property :value radio-target))))
  2541. (org-html--anchor id text)))
  2542. ;;;; Special Block
  2543. (defun org-html-special-block (special-block contents info)
  2544. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2545. CONTENTS holds the contents of the block. INFO is a plist
  2546. holding contextual information."
  2547. (format "<div class=\"%s\">\n%s\n</div>"
  2548. (downcase (org-element-property :type special-block))
  2549. contents))
  2550. ;;;; Src Block
  2551. (defun org-html-src-block (src-block contents info)
  2552. "Transcode a SRC-BLOCK element from Org to HTML.
  2553. CONTENTS holds the contents of the item. INFO is a plist holding
  2554. contextual information."
  2555. (if (org-export-read-attribute :attr_html src-block :textarea)
  2556. (org-html--textarea-block src-block)
  2557. (let ((lang (org-element-property :language src-block))
  2558. (caption (org-export-get-caption src-block))
  2559. (code (org-html-format-code src-block info))
  2560. (label (let ((lbl (org-element-property :name src-block)))
  2561. (if (not lbl) ""
  2562. (format " id=\"%s\""
  2563. (org-export-solidify-link-text lbl))))))
  2564. (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
  2565. (format
  2566. "<div class=\"org-src-container\">\n%s%s\n</div>"
  2567. (if (not caption) ""
  2568. (format "<label class=\"org-src-name\">%s</label>"
  2569. (org-export-data caption info)))
  2570. (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
  2571. ;;;; Statistics Cookie
  2572. (defun org-html-statistics-cookie (statistics-cookie contents info)
  2573. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2574. CONTENTS is nil. INFO is a plist holding contextual information."
  2575. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2576. (format "<code>%s</code>" cookie-value)))
  2577. ;;;; Strike-Through
  2578. (defun org-html-strike-through (strike-through contents info)
  2579. "Transcode STRIKE-THROUGH from Org to HTML.
  2580. CONTENTS is the text with strike-through markup. INFO is a plist
  2581. holding contextual information."
  2582. (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
  2583. contents))
  2584. ;;;; Subscript
  2585. (defun org-html-subscript (subscript contents info)
  2586. "Transcode a SUBSCRIPT object from Org to HTML.
  2587. CONTENTS is the contents of the object. INFO is a plist holding
  2588. contextual information."
  2589. (format "<sub>%s</sub>" contents))
  2590. ;;;; Superscript
  2591. (defun org-html-superscript (superscript contents info)
  2592. "Transcode a SUPERSCRIPT object from Org to HTML.
  2593. CONTENTS is the contents of the object. INFO is a plist holding
  2594. contextual information."
  2595. (format "<sup>%s</sup>" contents))
  2596. ;;;; Tabel Cell
  2597. (defun org-html-table-cell (table-cell contents info)
  2598. "Transcode a TABLE-CELL element from Org to HTML.
  2599. CONTENTS is nil. INFO is a plist used as a communication
  2600. channel."
  2601. (let* ((table-row (org-export-get-parent table-cell))
  2602. (table (org-export-get-parent-table table-cell))
  2603. (cell-attrs
  2604. (if (not org-html-table-align-individual-fields) ""
  2605. (format (if (and (boundp 'org-html-format-table-no-css)
  2606. org-html-format-table-no-css)
  2607. " align=\"%s\"" " class=\"%s\"")
  2608. (org-export-table-cell-alignment table-cell info)))))
  2609. (when (or (not contents) (string= "" (org-trim contents)))
  2610. (setq contents "&#xa0;"))
  2611. (cond
  2612. ((and (org-export-table-has-header-p table info)
  2613. (= 1 (org-export-table-row-group table-row info)))
  2614. (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
  2615. contents (cdr org-html-table-header-tags)))
  2616. ((and org-html-table-use-header-tags-for-first-column
  2617. (zerop (cdr (org-export-table-cell-address table-cell info))))
  2618. (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
  2619. contents (cdr org-html-table-header-tags)))
  2620. (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
  2621. contents (cdr org-html-table-data-tags))))))
  2622. ;;;; Table Row
  2623. (defun org-html-table-row (table-row contents info)
  2624. "Transcode a TABLE-ROW element from Org to HTML.
  2625. CONTENTS is the contents of the row. INFO is a plist used as a
  2626. communication channel."
  2627. ;; Rules are ignored since table separators are deduced from
  2628. ;; borders of the current row.
  2629. (when (eq (org-element-property :type table-row) 'standard)
  2630. (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
  2631. (rowgroup-tags
  2632. (cond
  2633. ;; Case 1: Row belongs to second or subsequent rowgroups.
  2634. ((not (= 1 (org-export-table-row-group table-row info)))
  2635. '("<tbody>" . "\n</tbody>"))
  2636. ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
  2637. ((org-export-table-has-header-p
  2638. (org-export-get-parent-table table-row) info)
  2639. '("<thead>" . "\n</thead>"))
  2640. ;; Case 2: Row is from first and only row group.
  2641. (t '("<tbody>" . "\n</tbody>")))))
  2642. (concat
  2643. ;; Begin a rowgroup?
  2644. (when (org-export-table-row-starts-rowgroup-p table-row info)
  2645. (car rowgroup-tags))
  2646. ;; Actual table row
  2647. (concat "\n" (eval (car org-html-table-row-tags))
  2648. contents
  2649. "\n"
  2650. (eval (cdr org-html-table-row-tags)))
  2651. ;; End a rowgroup?
  2652. (when (org-export-table-row-ends-rowgroup-p table-row info)
  2653. (cdr rowgroup-tags))))))
  2654. ;;;; Table
  2655. (defun org-html-table-first-row-data-cells (table info)
  2656. "Transcode the first row of TABLE.
  2657. INFO is a plist used as a communication channel."
  2658. (let ((table-row
  2659. (org-element-map table 'table-row
  2660. (lambda (row)
  2661. (unless (eq (org-element-property :type row) 'rule) row))
  2662. info 'first-match))
  2663. (special-column-p (org-export-table-has-special-column-p table)))
  2664. (if (not special-column-p) (org-element-contents table-row)
  2665. (cdr (org-element-contents table-row)))))
  2666. (defun org-html-table--table.el-table (table info)
  2667. "Format table.el tables into HTML.
  2668. INFO is a plist used as a communication channel."
  2669. (when (eq (org-element-property :type table) 'table.el)
  2670. (require 'table)
  2671. (let ((outbuf (with-current-buffer
  2672. (get-buffer-create "*org-export-table*")
  2673. (erase-buffer) (current-buffer))))
  2674. (with-temp-buffer
  2675. (insert (org-element-property :value table))
  2676. (goto-char 1)
  2677. (re-search-forward "^[ \t]*|[^|]" nil t)
  2678. (table-generate-source 'html outbuf))
  2679. (with-current-buffer outbuf
  2680. (prog1 (org-trim (buffer-string))
  2681. (kill-buffer) )))))
  2682. (defun org-html-table (table contents info)
  2683. "Transcode a TABLE element from Org to HTML.
  2684. CONTENTS is the contents of the table. INFO is a plist holding
  2685. contextual information."
  2686. (case (org-element-property :type table)
  2687. ;; Case 1: table.el table. Convert it using appropriate tools.
  2688. (table.el (org-html-table--table.el-table table info))
  2689. ;; Case 2: Standard table.
  2690. (t
  2691. (let* ((label (org-element-property :name table))
  2692. (caption (org-export-get-caption table))
  2693. (attributes (mapconcat #'identity
  2694. (org-element-property :attr_html table)
  2695. " "))
  2696. (alignspec
  2697. (if (and (boundp 'org-html-format-table-no-css)
  2698. org-html-format-table-no-css)
  2699. "align=\"%s\"" "class=\"%s\""))
  2700. (table-column-specs
  2701. (function
  2702. (lambda (table info)
  2703. (mapconcat
  2704. (lambda (table-cell)
  2705. (let ((alignment (org-export-table-cell-alignment
  2706. table-cell info)))
  2707. (concat
  2708. ;; Begin a colgroup?
  2709. (when (org-export-table-cell-starts-colgroup-p
  2710. table-cell info)
  2711. "\n<colgroup>")
  2712. ;; Add a column. Also specify it's alignment.
  2713. (format "\n<col %s/>" (format alignspec alignment))
  2714. ;; End a colgroup?
  2715. (when (org-export-table-cell-ends-colgroup-p
  2716. table-cell info)
  2717. "\n</colgroup>"))))
  2718. (org-html-table-first-row-data-cells table info) "\n"))))
  2719. (table-attributes
  2720. (let ((table-tag (plist-get info :html-table-tag)))
  2721. (concat
  2722. (and (string-match "<table\\(.*\\)>" table-tag)
  2723. (match-string 1 table-tag))
  2724. (and label (format " id=\"%s\""
  2725. (org-export-solidify-link-text label)))
  2726. (unless (string= attributes "")
  2727. (concat " " attributes))))))
  2728. ;; Remove last blank line.
  2729. (setq contents (substring contents 0 -1))
  2730. (format "<table%s>\n%s\n%s\n%s\n</table>"
  2731. table-attributes
  2732. (if (not caption) ""
  2733. (format "<caption>%s</caption>"
  2734. (org-export-data caption info)))
  2735. (funcall table-column-specs table info)
  2736. contents)))))
  2737. ;;;; Target
  2738. (defun org-html-target (target contents info)
  2739. "Transcode a TARGET object from Org to HTML.
  2740. CONTENTS is nil. INFO is a plist holding contextual
  2741. information."
  2742. (let ((id (org-export-solidify-link-text
  2743. (org-element-property :value target))))
  2744. (org-html--anchor id)))
  2745. ;;;; Timestamp
  2746. (defun org-html-timestamp (timestamp contents info)
  2747. "Transcode a TIMESTAMP object from Org to HTML.
  2748. CONTENTS is nil. INFO is a plist holding contextual
  2749. information."
  2750. (let ((value (org-html-plain-text
  2751. (org-timestamp-translate timestamp) info)))
  2752. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  2753. (replace-regexp-in-string "--" "&#x2013;" value))))
  2754. ;;;; Underline
  2755. (defun org-html-underline (underline contents info)
  2756. "Transcode UNDERLINE from Org to HTML.
  2757. CONTENTS is the text with underline markup. INFO is a plist
  2758. holding contextual information."
  2759. (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
  2760. contents))
  2761. ;;;; Verbatim
  2762. (defun org-html-verbatim (verbatim contents info)
  2763. "Transcode VERBATIM from Org to HTML.
  2764. CONTENTS is nil. INFO is a plist holding contextual
  2765. information."
  2766. (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
  2767. (org-html-plain-text (org-element-property :value verbatim) info)))
  2768. ;;;; Verse Block
  2769. (defun org-html-verse-block (verse-block contents info)
  2770. "Transcode a VERSE-BLOCK element from Org to HTML.
  2771. CONTENTS is verse block contents. INFO is a plist holding
  2772. contextual information."
  2773. ;; Replace each newline character with line break. Also replace
  2774. ;; each blank line with a line break.
  2775. (setq contents (replace-regexp-in-string
  2776. "^ *\\\\\\\\$" "<br/>\n"
  2777. (replace-regexp-in-string
  2778. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
  2779. ;; Replace each white space at beginning of a line with a
  2780. ;; non-breaking space.
  2781. (while (string-match "^[ \t]+" contents)
  2782. (let* ((num-ws (length (match-string 0 contents)))
  2783. (ws (let (out) (dotimes (i num-ws out)
  2784. (setq out (concat out "&#xa0;"))))))
  2785. (setq contents (replace-match ws nil t contents))))
  2786. (format "<p class=\"verse\">\n%s</p>" contents))
  2787. ;;; Filter Functions
  2788. (defun org-html-final-function (contents backend info)
  2789. "Filter to indent the HTML and convert HTML entities."
  2790. (with-temp-buffer
  2791. (insert contents)
  2792. (set-auto-mode t)
  2793. (if org-html-indent
  2794. (indent-region (point-min) (point-max)))
  2795. (when org-html-use-unicode-chars
  2796. (require 'mm-url)
  2797. (mm-url-decode-entities))
  2798. (buffer-substring-no-properties (point-min) (point-max))))
  2799. ;;; End-user functions
  2800. ;;;###autoload
  2801. (defun org-html-export-as-html
  2802. (&optional async subtreep visible-only body-only ext-plist)
  2803. "Export current buffer to an HTML buffer.
  2804. If narrowing is active in the current buffer, only export its
  2805. narrowed part.
  2806. If a region is active, export that region.
  2807. A non-nil optional argument ASYNC means the process should happen
  2808. asynchronously. The resulting buffer should be accessible
  2809. through the `org-export-stack' interface.
  2810. When optional argument SUBTREEP is non-nil, export the sub-tree
  2811. at point, extracting information from the headline properties
  2812. first.
  2813. When optional argument VISIBLE-ONLY is non-nil, don't export
  2814. contents of hidden elements.
  2815. When optional argument BODY-ONLY is non-nil, only write code
  2816. between \"<body>\" and \"</body>\" tags.
  2817. EXT-PLIST, when provided, is a property list with external
  2818. parameters overriding Org default settings, but still inferior to
  2819. file-local settings.
  2820. Export is done in a buffer named \"*Org HTML Export*\", which
  2821. will be displayed when `org-export-show-temporary-export-buffer'
  2822. is non-nil."
  2823. (interactive)
  2824. (if async
  2825. (org-export-async-start
  2826. (lambda (output)
  2827. (with-current-buffer (get-buffer-create "*Org HTML Export*")
  2828. (erase-buffer)
  2829. (insert output)
  2830. (goto-char (point-min))
  2831. (set-auto-mode t)
  2832. (org-export-add-to-stack (current-buffer) 'html)))
  2833. `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
  2834. (let ((outbuf (org-export-to-buffer
  2835. 'html "*Org HTML Export*"
  2836. subtreep visible-only body-only ext-plist)))
  2837. ;; Set major mode.
  2838. (with-current-buffer outbuf (set-auto-mode t))
  2839. (when org-export-show-temporary-export-buffer
  2840. (switch-to-buffer-other-window outbuf)))))
  2841. ;;;###autoload
  2842. (defun org-html-export-to-html
  2843. (&optional async subtreep visible-only body-only ext-plist)
  2844. "Export current buffer to a HTML file.
  2845. If narrowing is active in the current buffer, only export its
  2846. narrowed part.
  2847. If a region is active, export that region.
  2848. A non-nil optional argument ASYNC means the process should happen
  2849. asynchronously. The resulting file should be accessible through
  2850. the `org-export-stack' interface.
  2851. When optional argument SUBTREEP is non-nil, export the sub-tree
  2852. at point, extracting information from the headline properties
  2853. first.
  2854. When optional argument VISIBLE-ONLY is non-nil, don't export
  2855. contents of hidden elements.
  2856. When optional argument BODY-ONLY is non-nil, only write code
  2857. between \"<body>\" and \"</body>\" tags.
  2858. EXT-PLIST, when provided, is a property list with external
  2859. parameters overriding Org default settings, but still inferior to
  2860. file-local settings.
  2861. Return output file's name."
  2862. (interactive)
  2863. (let* ((extension (concat "." org-html-extension))
  2864. (file (org-export-output-file-name extension subtreep))
  2865. (org-export-coding-system org-html-coding-system))
  2866. (if async
  2867. (org-export-async-start
  2868. (lambda (f) (org-export-add-to-stack f 'html))
  2869. (let ((org-export-coding-system org-html-coding-system))
  2870. `(expand-file-name
  2871. (org-export-to-file
  2872. 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
  2873. (let ((org-export-coding-system org-html-coding-system))
  2874. (org-export-to-file
  2875. 'html file subtreep visible-only body-only ext-plist)))))
  2876. ;;;###autoload
  2877. (defun org-html-publish-to-html (plist filename pub-dir)
  2878. "Publish an org file to HTML.
  2879. FILENAME is the filename of the Org file to be published. PLIST
  2880. is the property list for the given project. PUB-DIR is the
  2881. publishing directory.
  2882. Return output file name."
  2883. (org-publish-org-to 'html filename ".html" plist pub-dir))
  2884. ;;; FIXME
  2885. ;;;; org-format-table-html
  2886. ;;;; org-format-org-table-html
  2887. ;;;; org-format-table-table-html
  2888. ;;;; org-table-number-fraction
  2889. ;;;; org-table-number-regexp
  2890. ;;;; org-html-table-caption-above
  2891. ;;;; org-html-inline-image-extensions
  2892. ;;;; org-export-preferred-target-alist
  2893. ;;;; class for anchors
  2894. ;;;; org-export-with-section-numbers, body-only
  2895. ;;;; org-export-mark-todo-in-toc
  2896. ;;;; org-html-format-org-link
  2897. ;;;; (caption (and caption (org-xml-encode-org-text caption)))
  2898. ;;;; alt = (file-name-nondirectory path)
  2899. (provide 'ox-html)
  2900. ;; Local variables:
  2901. ;; generated-autoload-file: "org-loaddefs.el"
  2902. ;; End:
  2903. ;;; ox-html.el ends here