ox-html.el 126 KB

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