ox-html.el 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497
  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 nil
  578. "When nil, do not set \"name\" attribute in anchors.
  579. By default, when appropriate, anchors are formatted with \"id\"
  580. but without \"name\" attribute."
  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. (defconst org-html-checkbox-types
  856. '((unicode .
  857. ((on . "&#x2611;") (off . "&#x2610;") (trans . "&#x2610;")))
  858. (ascii .
  859. ((on . "<code>[X]</code>")
  860. (off . "<code>[&#xa0;]</code>")
  861. (trans . "<code>[-]</code>")))
  862. (html .
  863. ((on . "<input type='checkbox' checked='checked' />")
  864. (off . "<input type='checkbox' />")
  865. (trans . "<input type='checkbox' />"))))
  866. "Alist of checkbox types.
  867. The cdr of each entry is an alist list three checkbox types for
  868. HTML export: `on', `off' and `trans'.
  869. The choices are:
  870. `unicode' Unicode characters (HTML entities)
  871. `ascii' ASCII characters
  872. `html' HTML checkboxes
  873. Note that only the ascii characters implement tri-state
  874. checkboxes. The other two use the `off' checkbox for `trans'.")
  875. (defcustom org-html-checkbox-type 'ascii
  876. "The type of checkboxes to use for HTML export.
  877. See `org-html-checkbox-types' for for the values used for each
  878. option."
  879. :group 'org-export-html
  880. :version "24.4"
  881. :package-version '(Org . "8.0")
  882. :type '(choice
  883. (const :tag "ASCII characters" ascii)
  884. (const :tag "Unicode characters" unicode)
  885. (const :tag "HTML checkboxes" html)))
  886. (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
  887. "Format used for timestamps in preamble, postamble and metadata.
  888. See `format-time-string' for more information on its components."
  889. :group 'org-export-html
  890. :version "24.4"
  891. :package-version '(Org . "8.0")
  892. :type 'string)
  893. ;;;; Template :: Mathjax
  894. (defcustom org-html-mathjax-options
  895. '((path "http://orgmode.org/mathjax/MathJax.js")
  896. (scale "100")
  897. (align "center")
  898. (indent "2em")
  899. (mathml nil))
  900. "Options for MathJax setup.
  901. path The path where to find MathJax
  902. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  903. align How to align display math: left, center, or right
  904. indent If align is not center, how far from the left/right side?
  905. mathml Should a MathML player be used if available?
  906. This is faster and reduces bandwidth use, but currently
  907. sometimes has lower spacing quality. Therefore, the default is
  908. nil. When browsers get better, this switch can be flipped.
  909. You can also customize this for each buffer, using something like
  910. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  911. :group 'org-export-html
  912. :type '(list :greedy t
  913. (list :tag "path (the path from where to load MathJax.js)"
  914. (const :format " " path) (string))
  915. (list :tag "scale (scaling for the displayed math)"
  916. (const :format " " scale) (string))
  917. (list :tag "align (alignment of displayed equations)"
  918. (const :format " " align) (string))
  919. (list :tag "indent (indentation with left or right alignment)"
  920. (const :format " " indent) (string))
  921. (list :tag "mathml (should MathML display be used is possible)"
  922. (const :format " " mathml) (boolean))))
  923. (defcustom org-html-mathjax-template
  924. "<script type=\"text/javascript\" src=\"%PATH\"></script>
  925. <script type=\"text/javascript\">
  926. <!--/*--><![CDATA[/*><!--*/
  927. MathJax.Hub.Config({
  928. // Only one of the two following lines, depending on user settings
  929. // First allows browser-native MathML display, second forces HTML/CSS
  930. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  931. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  932. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  933. \"TeX/noUndefined.js\"],
  934. tex2jax: {
  935. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  936. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  937. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  938. ignoreClass: \"tex2jax_ignore\",
  939. processEscapes: false,
  940. processEnvironments: true,
  941. preview: \"TeX\"
  942. },
  943. showProcessingMessages: true,
  944. displayAlign: \"%ALIGN\",
  945. displayIndent: \"%INDENT\",
  946. \"HTML-CSS\": {
  947. scale: %SCALE,
  948. availableFonts: [\"STIX\",\"TeX\"],
  949. preferredFont: \"TeX\",
  950. webFont: \"TeX\",
  951. imageFont: \"TeX\",
  952. showMathMenu: true,
  953. },
  954. MMLorHTML: {
  955. prefer: {
  956. MSIE: \"MML\",
  957. Firefox: \"MML\",
  958. Opera: \"HTML\",
  959. other: \"HTML\"
  960. }
  961. }
  962. });
  963. /*]]>*///-->
  964. </script>"
  965. "The MathJax setup for XHTML files."
  966. :group 'org-export-html
  967. :type 'string)
  968. ;;;; Template :: Postamble
  969. (defcustom org-html-postamble 'auto
  970. "Non-nil means insert a postamble in HTML export.
  971. When set to 'auto, check against the
  972. `org-export-with-author/email/creator/date' variables to set the
  973. content of the postamble. When set to a string, use this string
  974. as the postamble. When t, insert a string as defined by the
  975. formatting string in `org-html-postamble-format'.
  976. When set to a function, apply this function and insert the
  977. returned string. The function takes the property list of export
  978. options as its only argument.
  979. Setting :html-postamble in publishing projects will take
  980. precedence over this variable."
  981. :group 'org-export-html
  982. :type '(choice (const :tag "No postamble" nil)
  983. (const :tag "Auto postamble" auto)
  984. (const :tag "Default formatting string" t)
  985. (string :tag "Custom formatting string")
  986. (function :tag "Function (must return a string)")))
  987. (defcustom org-html-postamble-format
  988. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  989. <p class=\"date\">Date: %d</p>
  990. <p class=\"creator\">%c</p>
  991. <p class=\"validation\">%v</p>"))
  992. "Alist of languages and format strings for the HTML postamble.
  993. The first element of each list is the language code, as used for
  994. the LANGUAGE keyword. See `org-export-default-language'.
  995. The second element of each list is a format string to format the
  996. postamble itself. This format string can contain these elements:
  997. %t stands for the title.
  998. %a stands for the author's name.
  999. %e stands for the author's email.
  1000. %d stands for the date.
  1001. %c will be replaced by `org-html-creator-string'.
  1002. %v will be replaced by `org-html-validation-link'.
  1003. %T will be replaced by the export time.
  1004. %C will be replaced by the last modification time.
  1005. If you need to use a \"%\" character, you need to escape it
  1006. like that: \"%%\"."
  1007. :group 'org-export-html
  1008. :type '(repeat
  1009. (list (string :tag "Language")
  1010. (string :tag "Format string"))))
  1011. (defcustom org-html-validation-link
  1012. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
  1013. "Link to HTML validation service."
  1014. :group 'org-export-html
  1015. :type 'string)
  1016. (defcustom org-html-creator-string
  1017. (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
  1018. emacs-version
  1019. (if (fboundp 'org-version) (org-version) "unknown version"))
  1020. "Information about the creator of the HTML document.
  1021. This option can also be set on with the CREATOR keyword."
  1022. :group 'org-export-html
  1023. :version "24.4"
  1024. :package-version '(Org . "8.0")
  1025. :type '(string :tag "Creator string"))
  1026. ;;;; Template :: Preamble
  1027. (defcustom org-html-preamble t
  1028. "Non-nil means insert a preamble in HTML export.
  1029. When t, insert a string as defined by the formatting string in
  1030. `org-html-preamble-format'. When set to a string, use this
  1031. formatting string instead (see `org-html-postamble-format' for an
  1032. example of such a formatting string).
  1033. When set to a function, apply this function and insert the
  1034. returned string. The function takes the property list of export
  1035. options as its only argument.
  1036. Setting :html-preamble in publishing projects will take
  1037. precedence over this variable."
  1038. :group 'org-export-html
  1039. :type '(choice (const :tag "No preamble" nil)
  1040. (const :tag "Default preamble" t)
  1041. (string :tag "Custom formatting string")
  1042. (function :tag "Function (must return a string)")))
  1043. (defcustom org-html-preamble-format '(("en" ""))
  1044. "Alist of languages and format strings for the HTML preamble.
  1045. The first element of each list is the language code, as used for
  1046. the LANGUAGE keyword. See `org-export-default-language'.
  1047. The second element of each list is a format string to format the
  1048. preamble itself. This format string can contain these elements:
  1049. %t stands for the title.
  1050. %a stands for the author's name.
  1051. %e stands for the author's email.
  1052. %d stands for the date.
  1053. %c will be replaced by `org-html-creator-string'.
  1054. %v will be replaced by `org-html-validation-link'.
  1055. %T will be replaced by the export time.
  1056. %C will be replaced by the last modification time.
  1057. If you need to use a \"%\" character, you need to escape it
  1058. like that: \"%%\".
  1059. See the default value of `org-html-postamble-format' for an
  1060. example."
  1061. :group 'org-export-html
  1062. :type '(repeat
  1063. (list (string :tag "Language")
  1064. (string :tag "Format string"))))
  1065. (defcustom org-html-link-up ""
  1066. "Where should the \"UP\" link of exported HTML pages lead?"
  1067. :group 'org-export-html
  1068. :type '(string :tag "File or URL"))
  1069. (defcustom org-html-link-home ""
  1070. "Where should the \"HOME\" link of exported HTML pages lead?"
  1071. :group 'org-export-html
  1072. :type '(string :tag "File or URL"))
  1073. (defcustom org-html-link-use-abs-url nil
  1074. "Should we prepend relative links with HTML_LINK_HOME?"
  1075. :group 'org-export-html
  1076. :version "24.4"
  1077. :package-version '(Org . "8.1")
  1078. :type 'boolean)
  1079. (defcustom org-html-home/up-format
  1080. "<div id=\"org-div-home-and-up\">
  1081. <a accesskey=\"h\" href=\"%s\"> UP </a>
  1082. |
  1083. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  1084. </div>"
  1085. "Snippet used to insert the HOME and UP links.
  1086. This is a format string, the first %s will receive the UP link,
  1087. the second the HOME link. If both `org-html-link-up' and
  1088. `org-html-link-home' are empty, the entire snippet will be
  1089. ignored."
  1090. :group 'org-export-html
  1091. :type 'string)
  1092. ;;;; Template :: Scripts
  1093. (define-obsolete-variable-alias
  1094. 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
  1095. (defcustom org-html-head-include-scripts t
  1096. "Non-nil means include the JavaScript snippets in exported HTML files.
  1097. The actual script is defined in `org-html-scripts' and should
  1098. not be modified."
  1099. :group 'org-export-html
  1100. :version "24.4"
  1101. :package-version '(Org . "8.0")
  1102. :type 'boolean)
  1103. ;;;; Template :: Styles
  1104. (define-obsolete-variable-alias
  1105. 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
  1106. (defcustom org-html-head-include-default-style t
  1107. "Non-nil means include the default style in exported HTML files.
  1108. The actual style is defined in `org-html-style-default' and
  1109. should not be modified. Use `org-html-head' to use your own
  1110. style information."
  1111. :group 'org-export-html
  1112. :version "24.4"
  1113. :package-version '(Org . "8.0")
  1114. :type 'boolean)
  1115. ;;;###autoload
  1116. (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
  1117. (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
  1118. (defcustom org-html-head ""
  1119. "Org-wide head definitions for exported HTML files.
  1120. This variable can contain the full HTML structure to provide a
  1121. style, including the surrounding HTML tags. You can consider
  1122. including definitions for the following classes: title, todo,
  1123. done, timestamp, timestamp-kwd, tag, target.
  1124. For example, a valid value would be:
  1125. <style type=\"text/css\">
  1126. <![CDATA[
  1127. p { font-weight: normal; color: gray; }
  1128. h1 { color: black; }
  1129. .title { text-align: center; }
  1130. .todo, .timestamp-kwd { color: red; }
  1131. .done { color: green; }
  1132. ]]>
  1133. </style>
  1134. If you want to refer to an external style, use something like
  1135. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
  1136. As the value of this option simply gets inserted into the HTML
  1137. <head> header, you can use it to add any arbitrary text to the
  1138. header.
  1139. You can set this on a per-file basis using #+HTML_HEAD:,
  1140. or for publication projects using the :html-head property."
  1141. :group 'org-export-html
  1142. :version "24.4"
  1143. :package-version '(Org . "8.0")
  1144. :type 'string)
  1145. ;;;###autoload
  1146. (put 'org-html-head 'safe-local-variable 'stringp)
  1147. (defcustom org-html-head-extra ""
  1148. "More head information to add in the HTML output.
  1149. You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
  1150. or for publication projects using the :html-head-extra property."
  1151. :group 'org-export-html
  1152. :version "24.4"
  1153. :package-version '(Org . "8.0")
  1154. :type 'string)
  1155. ;;;###autoload
  1156. (put 'org-html-head-extra 'safe-local-variable 'stringp)
  1157. ;;;; Todos
  1158. (defcustom org-html-todo-kwd-class-prefix ""
  1159. "Prefix to class names for TODO keywords.
  1160. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  1161. The default prefix is empty because it is nice to just use the keyword
  1162. as a class name. But if you get into conflicts with other, existing
  1163. CSS classes, then this prefix can be very useful."
  1164. :group 'org-export-html
  1165. :type 'string)
  1166. ;;; Internal Functions
  1167. (defun org-html-xhtml-p (info)
  1168. (let ((dt (downcase (plist-get info :html-doctype))))
  1169. (string-match-p "xhtml" dt)))
  1170. (defun org-html-html5-p (info)
  1171. (let ((dt (downcase (plist-get info :html-doctype))))
  1172. (member dt '("html5" "xhtml5" "<!doctype html>"))))
  1173. (defun org-html-close-tag (tag attr info)
  1174. (concat "<" tag " " attr
  1175. (if (org-html-xhtml-p info) " />" ">")))
  1176. (defun org-html-doctype (info)
  1177. "Return correct html doctype tag from `org-html-doctype-alist',
  1178. or the literal value of :html-doctype from INFO if :html-doctype
  1179. is not found in the alist.
  1180. INFO is a plist used as a communication channel."
  1181. (let ((dt (plist-get info :html-doctype)))
  1182. (or (cdr (assoc dt org-html-doctype-alist)) dt)))
  1183. (defun org-html--make-attribute-string (attributes)
  1184. "Return a list of attributes, as a string.
  1185. ATTRIBUTES is a plist where values are either strings or nil. An
  1186. attributes with a nil value will be omitted from the result."
  1187. (let (output)
  1188. (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
  1189. (cond ((null item) (pop output))
  1190. ((symbolp item) (push (substring (symbol-name item) 1) output))
  1191. (t (let ((key (car output))
  1192. (value (replace-regexp-in-string
  1193. "\"" "&quot;" (org-html-encode-plain-text item))))
  1194. (setcar output (format "%s=\"%s\"" key value))))))))
  1195. (defun org-html--wrap-image (contents info &optional caption label)
  1196. "Wrap CONTENTS string within an appropriate environment for images.
  1197. INFO is a plist used as a communication channel. When optional
  1198. arguments CAPTION and LABEL are given, use them for caption and
  1199. \"id\" attribute."
  1200. (let ((html5-fancy (and (org-html-html5-p info)
  1201. (plist-get info :html-html5-fancy))))
  1202. (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
  1203. "\n<div%s class=\"figure\">%s%s\n</div>")
  1204. ;; ID.
  1205. (if (not (org-string-nw-p label)) ""
  1206. (format " id=\"%s\"" (org-export-solidify-link-text label)))
  1207. ;; Contents.
  1208. (format "\n<p>%s</p>" contents)
  1209. ;; Caption.
  1210. (if (not (org-string-nw-p caption)) ""
  1211. (format (if html5-fancy "\n<figcaption>%s</figcaption>"
  1212. "\n<p>%s</p>")
  1213. caption)))))
  1214. (defun org-html--format-image (source attributes info)
  1215. "Return \"img\" tag with given SOURCE and ATTRIBUTES.
  1216. SOURCE is a string specifying the location of the image.
  1217. ATTRIBUTES is a plist, as returned by
  1218. `org-export-read-attribute'. INFO is a plist used as
  1219. a communication channel."
  1220. (org-html-close-tag
  1221. "img"
  1222. (org-html--make-attribute-string
  1223. (org-combine-plists
  1224. (list :src source
  1225. :alt (if (string-match-p "^ltxpng/" source)
  1226. (org-html-encode-plain-text
  1227. (org-find-text-property-in-string 'org-latex-src source))
  1228. (file-name-nondirectory source)))
  1229. attributes))
  1230. info))
  1231. (defun org-html--textarea-block (element)
  1232. "Transcode ELEMENT into a textarea block.
  1233. ELEMENT is either a src block or an example block."
  1234. (let* ((code (car (org-export-unravel-code element)))
  1235. (attr (org-export-read-attribute :attr_html element)))
  1236. (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
  1237. (or (plist-get attr :width) 80)
  1238. (or (plist-get attr :height) (org-count-lines code))
  1239. code)))
  1240. (defun org-html--has-caption-p (element &optional info)
  1241. "Non-nil when ELEMENT has a caption affiliated keyword.
  1242. INFO is a plist used as a communication channel. This function
  1243. is meant to be used as a predicate for `org-export-get-ordinal' or
  1244. a value to `org-html-standalone-image-predicate'."
  1245. (org-element-property :caption element))
  1246. ;;;; Table
  1247. (defun org-html-htmlize-region-for-paste (beg end)
  1248. "Convert the region between BEG and END to HTML, using htmlize.el.
  1249. This is much like `htmlize-region-for-paste', only that it uses
  1250. the settings define in the org-... variables."
  1251. (let* ((htmlize-output-type org-html-htmlize-output-type)
  1252. (htmlize-css-name-prefix org-html-htmlize-font-prefix)
  1253. (htmlbuf (htmlize-region beg end)))
  1254. (unwind-protect
  1255. (with-current-buffer htmlbuf
  1256. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  1257. (plist-get htmlize-buffer-places 'content-end)))
  1258. (kill-buffer htmlbuf))))
  1259. ;;;###autoload
  1260. (defun org-html-htmlize-generate-css ()
  1261. "Create the CSS for all font definitions in the current Emacs session.
  1262. Use this to create face definitions in your CSS style file that can then
  1263. be used by code snippets transformed by htmlize.
  1264. This command just produces a buffer that contains class definitions for all
  1265. faces used in the current Emacs session. You can copy and paste the ones you
  1266. need into your CSS file.
  1267. If you then set `org-html-htmlize-output-type' to `css', calls
  1268. to the function `org-html-htmlize-region-for-paste' will
  1269. produce code that uses these same face definitions."
  1270. (interactive)
  1271. (require 'htmlize)
  1272. (and (get-buffer "*html*") (kill-buffer "*html*"))
  1273. (with-temp-buffer
  1274. (let ((fl (face-list))
  1275. (htmlize-css-name-prefix "org-")
  1276. (htmlize-output-type 'css)
  1277. f i)
  1278. (while (setq f (pop fl)
  1279. i (and f (face-attribute f :inherit)))
  1280. (when (and (symbolp f) (or (not i) (not (listp i))))
  1281. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  1282. (htmlize-region (point-min) (point-max))))
  1283. (org-pop-to-buffer-same-window "*html*")
  1284. (goto-char (point-min))
  1285. (if (re-search-forward "<style" nil t)
  1286. (delete-region (point-min) (match-beginning 0)))
  1287. (if (re-search-forward "</style>" nil t)
  1288. (delete-region (1+ (match-end 0)) (point-max)))
  1289. (beginning-of-line 1)
  1290. (if (looking-at " +") (replace-match ""))
  1291. (goto-char (point-min)))
  1292. (defun org-html--make-string (n string)
  1293. "Build a string by concatenating N times STRING."
  1294. (let (out) (dotimes (i n out) (setq out (concat string out)))))
  1295. (defun org-html-fix-class-name (kwd) ; audit callers of this function
  1296. "Turn todo keyword KWD into a valid class name.
  1297. Replaces invalid characters with \"_\"."
  1298. (save-match-data
  1299. (while (string-match "[^a-zA-Z0-9_]" kwd)
  1300. (setq kwd (replace-match "_" t t kwd))))
  1301. kwd)
  1302. (defun org-html-format-footnote-reference (n def refcnt)
  1303. "Format footnote reference N with definition DEF into HTML."
  1304. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  1305. (format org-html-footnote-format
  1306. (let* ((id (format "fnr.%s%s" n extra))
  1307. (href (format " href=\"#fn.%s\"" n))
  1308. (attributes (concat " class=\"footref\"" href)))
  1309. (org-html--anchor id n attributes)))))
  1310. (defun org-html-format-footnotes-section (section-name definitions)
  1311. "Format footnotes section SECTION-NAME."
  1312. (if (not definitions) ""
  1313. (format org-html-footnotes-section section-name definitions)))
  1314. (defun org-html-format-footnote-definition (fn)
  1315. "Format the footnote definition FN."
  1316. (let ((n (car fn)) (def (cdr fn)))
  1317. (format
  1318. "<div class=\"footdef\">%s %s</div>\n"
  1319. (format org-html-footnote-format
  1320. (let* ((id (format "fn.%s" n))
  1321. (href (format " href=\"#fnr.%s\"" n))
  1322. (attributes (concat " class=\"footnum\"" href)))
  1323. (org-html--anchor id n attributes)))
  1324. def)))
  1325. (defun org-html-footnote-section (info)
  1326. "Format the footnote section.
  1327. INFO is a plist used as a communication channel."
  1328. (let* ((fn-alist (org-export-collect-footnote-definitions
  1329. (plist-get info :parse-tree) info))
  1330. (fn-alist
  1331. (loop for (n type raw) in fn-alist collect
  1332. (cons n (if (eq (org-element-type raw) 'org-data)
  1333. (org-trim (org-export-data raw info))
  1334. (format "<p>%s</p>"
  1335. (org-trim (org-export-data raw info))))))))
  1336. (when fn-alist
  1337. (org-html-format-footnotes-section
  1338. (org-html--translate "Footnotes" info)
  1339. (format
  1340. "\n%s\n"
  1341. (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
  1342. ;;; Template
  1343. (defun org-html--build-meta-info (info)
  1344. "Return meta tags for exported document.
  1345. INFO is a plist used as a communication channel."
  1346. (let ((protect-string
  1347. (lambda (str)
  1348. (replace-regexp-in-string
  1349. "\"" "&quot;" (org-html-encode-plain-text str))))
  1350. (title (org-export-data (plist-get info :title) info))
  1351. (author (and (plist-get info :with-author)
  1352. (let ((auth (plist-get info :author)))
  1353. (and auth
  1354. ;; Return raw Org syntax, skipping non
  1355. ;; exportable objects.
  1356. (org-element-interpret-data
  1357. (org-element-map auth
  1358. (cons 'plain-text org-element-all-objects)
  1359. 'identity info))))))
  1360. (description (plist-get info :description))
  1361. (keywords (plist-get info :keywords))
  1362. (charset (or (and org-html-coding-system
  1363. (fboundp 'coding-system-get)
  1364. (coding-system-get org-html-coding-system
  1365. 'mime-charset))
  1366. "iso-8859-1")))
  1367. (concat
  1368. (format "<title>%s</title>\n" title)
  1369. (when (plist-get info :time-stamp-file)
  1370. (format-time-string
  1371. (concat "<!-- " org-html-metadata-timestamp-format " -->\n")))
  1372. (format
  1373. (if (org-html-html5-p info)
  1374. (org-html-close-tag "meta" " charset=\"%s\"" info)
  1375. (org-html-close-tag
  1376. "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
  1377. info))
  1378. charset) "\n"
  1379. (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
  1380. "\n"
  1381. (and (org-string-nw-p author)
  1382. (concat
  1383. (org-html-close-tag "meta"
  1384. (format " name=\"author\" content=\"%s\""
  1385. (funcall protect-string author))
  1386. info)
  1387. "\n"))
  1388. (and (org-string-nw-p description)
  1389. (concat
  1390. (org-html-close-tag "meta"
  1391. (format " name=\"description\" content=\"%s\"\n"
  1392. (funcall protect-string description))
  1393. info)
  1394. "\n"))
  1395. (and (org-string-nw-p keywords)
  1396. (concat
  1397. (org-html-close-tag "meta"
  1398. (format " name=\"keywords\" content=\"%s\""
  1399. (funcall protect-string keywords))
  1400. info)
  1401. "\n")))))
  1402. (defun org-html--build-head (info)
  1403. "Return information for the <head>..</head> of the HTML output.
  1404. INFO is a plist used as a communication channel."
  1405. (org-element-normalize-string
  1406. (concat
  1407. (when (plist-get info :html-head-include-default-style)
  1408. (org-element-normalize-string org-html-style-default))
  1409. (org-element-normalize-string (plist-get info :html-head))
  1410. (org-element-normalize-string (plist-get info :html-head-extra))
  1411. (when (and (plist-get info :html-htmlized-css-url)
  1412. (eq org-html-htmlize-output-type 'css))
  1413. (org-html-close-tag "link"
  1414. (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
  1415. (plist-get info :html-htmlized-css-url))
  1416. info))
  1417. (when (plist-get info :html-head-include-scripts) org-html-scripts))))
  1418. (defun org-html--build-mathjax-config (info)
  1419. "Insert the user setup into the mathjax template.
  1420. INFO is a plist used as a communication channel."
  1421. (when (and (memq (plist-get info :with-latex) '(mathjax t))
  1422. (org-element-map (plist-get info :parse-tree)
  1423. '(latex-fragment latex-environment) 'identity info t))
  1424. (let ((template org-html-mathjax-template)
  1425. (options org-html-mathjax-options)
  1426. (in-buffer (or (plist-get info :html-mathjax) ""))
  1427. name val (yes " ") (no "// ") x)
  1428. (mapc
  1429. (lambda (e)
  1430. (setq name (car e) val (nth 1 e))
  1431. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  1432. (setq val (car (read-from-string
  1433. (substring in-buffer (match-end 0))))))
  1434. (if (not (stringp val)) (setq val (format "%s" val)))
  1435. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  1436. (setq template (replace-match val t t template))))
  1437. options)
  1438. (setq val (nth 1 (assq 'mathml options)))
  1439. (if (string-match (concat "\\<mathml:") in-buffer)
  1440. (setq val (car (read-from-string
  1441. (substring in-buffer (match-end 0))))))
  1442. ;; Exchange prefixes depending on mathml setting.
  1443. (if (not val) (setq x yes yes no no x))
  1444. ;; Replace cookies to turn on or off the config/jax lines.
  1445. (if (string-match ":MMLYES:" template)
  1446. (setq template (replace-match yes t t template)))
  1447. (if (string-match ":MMLNO:" template)
  1448. (setq template (replace-match no t t template)))
  1449. ;; Return the modified template.
  1450. (org-element-normalize-string template))))
  1451. (defun org-html-format-spec (info)
  1452. "Return format specification for elements that can be
  1453. used in the preamble or postamble."
  1454. `((?t . ,(org-export-data (plist-get info :title) info))
  1455. (?d . ,(org-export-data (org-export-get-date info) info))
  1456. (?T . ,(format-time-string org-html-metadata-timestamp-format))
  1457. (?a . ,(org-export-data (plist-get info :author) info))
  1458. (?e . ,(mapconcat
  1459. (lambda (e)
  1460. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1461. (split-string (plist-get info :email) ",+ *")
  1462. ", "))
  1463. (?c . ,(plist-get info :creator))
  1464. (?C . ,(let ((file (plist-get info :input-file)))
  1465. (format-time-string org-html-metadata-timestamp-format
  1466. (if file (nth 5 (file-attributes file))
  1467. (current-time)))))
  1468. (?v . ,(or org-html-validation-link ""))))
  1469. (defun org-html--build-pre/postamble (type info)
  1470. "Return document preamble or postamble as a string, or nil.
  1471. TYPE is either 'preamble or 'postamble, INFO is a plist used as a
  1472. communication channel."
  1473. (let ((section (plist-get info (intern (format ":html-%s" type))))
  1474. (spec (org-html-format-spec info)))
  1475. (when section
  1476. (let ((section-contents
  1477. (if (functionp section) (funcall section info)
  1478. (cond
  1479. ((stringp section) (format-spec section spec))
  1480. ((eq section 'auto)
  1481. (let ((date (cdr (assq ?d spec)))
  1482. (author (cdr (assq ?a spec)))
  1483. (email (cdr (assq ?e spec)))
  1484. (creator (cdr (assq ?c spec)))
  1485. (timestamp (cdr (assq ?T spec)))
  1486. (validation-link (cdr (assq ?v spec))))
  1487. (concat
  1488. (when (and (plist-get info :with-date)
  1489. (org-string-nw-p date))
  1490. (format "<p class=\"date\">%s: %s</p>\n"
  1491. (org-html--translate "Date" info)
  1492. date))
  1493. (when (and (plist-get info :with-author)
  1494. (org-string-nw-p author))
  1495. (format "<p class=\"author\">%s: %s</p>\n"
  1496. (org-html--translate "Author" info)
  1497. author))
  1498. (when (and (plist-get info :with-email)
  1499. (org-string-nw-p email))
  1500. (format "<p class=\"email\">%s: %s</p>\n"
  1501. (org-html--translate "Email" info)
  1502. email))
  1503. (when (plist-get info :time-stamp-file)
  1504. (format
  1505. "<p class=\"date\">%s: %s</p>\n"
  1506. (org-html--translate "Created" info)
  1507. (format-time-string org-html-metadata-timestamp-format)))
  1508. (when (plist-get info :with-creator)
  1509. (format "<p class=\"creator\">%s</p>\n" creator))
  1510. (format "<p class=\"validation\">%s</p>\n"
  1511. validation-link))))
  1512. (t (format-spec
  1513. (or (cadr (assoc
  1514. (plist-get info :language)
  1515. (eval (intern
  1516. (format "org-html-%s-format" type)))))
  1517. (cadr
  1518. (assoc
  1519. "en"
  1520. (eval
  1521. (intern (format "org-html-%s-format" type))))))
  1522. spec))))))
  1523. (when (org-string-nw-p section-contents)
  1524. (concat
  1525. (format "<%s id=\"%s\" class=\"%s\">\n"
  1526. (nth 1 (assq type org-html-divs))
  1527. (nth 2 (assq type org-html-divs))
  1528. org-html--pre/postamble-class)
  1529. (org-element-normalize-string section-contents)
  1530. (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
  1531. (defun org-html-inner-template (contents info)
  1532. "Return body of document string after HTML conversion.
  1533. CONTENTS is the transcoded contents string. INFO is a plist
  1534. holding export options."
  1535. (concat
  1536. ;; Table of contents.
  1537. (let ((depth (plist-get info :with-toc)))
  1538. (when depth (org-html-toc depth info)))
  1539. ;; Document contents.
  1540. contents
  1541. ;; Footnotes section.
  1542. (org-html-footnote-section info)))
  1543. (defun org-html-template (contents info)
  1544. "Return complete document string after HTML conversion.
  1545. CONTENTS is the transcoded contents string. INFO is a plist
  1546. holding export options."
  1547. (concat
  1548. (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
  1549. (let ((decl (or (and (stringp org-html-xml-declaration)
  1550. org-html-xml-declaration)
  1551. (cdr (assoc (plist-get info :html-extension)
  1552. org-html-xml-declaration))
  1553. (cdr (assoc "html" org-html-xml-declaration))
  1554. "")))
  1555. (when (not (or (eq nil decl) (string= "" decl)))
  1556. (format "%s\n"
  1557. (format decl
  1558. (or (and org-html-coding-system
  1559. (fboundp 'coding-system-get)
  1560. (coding-system-get org-html-coding-system 'mime-charset))
  1561. "iso-8859-1"))))))
  1562. (org-html-doctype info)
  1563. "\n"
  1564. (concat "<html"
  1565. (when (org-html-xhtml-p info)
  1566. (format
  1567. " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
  1568. (plist-get info :language) (plist-get info :language)))
  1569. ">\n")
  1570. "<head>\n"
  1571. (org-html--build-meta-info info)
  1572. (org-html--build-head info)
  1573. (org-html--build-mathjax-config info)
  1574. "</head>\n"
  1575. "<body>\n"
  1576. (let ((link-up (org-trim (plist-get info :html-link-up)))
  1577. (link-home (org-trim (plist-get info :html-link-home))))
  1578. (unless (and (string= link-up "") (string= link-home ""))
  1579. (format org-html-home/up-format
  1580. (or link-up link-home)
  1581. (or link-home link-up))))
  1582. ;; Preamble.
  1583. (org-html--build-pre/postamble 'preamble info)
  1584. ;; Document contents.
  1585. (format "<%s id=\"%s\">\n"
  1586. (nth 1 (assq 'content org-html-divs))
  1587. (nth 2 (assq 'content org-html-divs)))
  1588. ;; Document title.
  1589. (let ((title (plist-get info :title)))
  1590. (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
  1591. contents
  1592. (format "</%s>\n"
  1593. (nth 1 (assq 'content org-html-divs)))
  1594. ;; Postamble.
  1595. (org-html--build-pre/postamble 'postamble info)
  1596. ;; Closing document.
  1597. "</body>\n</html>"))
  1598. (defun org-html--translate (s info)
  1599. "Translate string S according to specified language.
  1600. INFO is a plist used as a communication channel."
  1601. (org-export-translate s :html info))
  1602. ;;;; Anchor
  1603. (defun org-html--anchor (&optional id desc attributes)
  1604. "Format a HTML anchor."
  1605. (let* ((name (and org-html-allow-name-attribute-in-anchors id))
  1606. (attributes (concat (and id (format " id=\"%s\"" id))
  1607. (and name (format " name=\"%s\"" name))
  1608. attributes)))
  1609. (format "<a%s>%s</a>" attributes (or desc ""))))
  1610. ;;;; Todo
  1611. (defun org-html--todo (todo)
  1612. "Format TODO keywords into HTML."
  1613. (when todo
  1614. (format "<span class=\"%s %s%s\">%s</span>"
  1615. (if (member todo org-done-keywords) "done" "todo")
  1616. org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
  1617. todo)))
  1618. ;;;; Tags
  1619. (defun org-html--tags (tags)
  1620. "Format TAGS into HTML."
  1621. (when tags
  1622. (format "<span class=\"tag\">%s</span>"
  1623. (mapconcat
  1624. (lambda (tag)
  1625. (format "<span class=\"%s\">%s</span>"
  1626. (concat org-html-tag-class-prefix
  1627. (org-html-fix-class-name tag))
  1628. tag))
  1629. tags "&#xa0;"))))
  1630. ;;;; Headline
  1631. (defun* org-html-format-headline
  1632. (todo todo-type priority text tags
  1633. &key level section-number headline-label &allow-other-keys)
  1634. "Format a headline in HTML."
  1635. (let ((section-number
  1636. (when section-number
  1637. (format "<span class=\"section-number-%d\">%s</span> "
  1638. level section-number)))
  1639. (todo (org-html--todo todo))
  1640. (tags (org-html--tags tags)))
  1641. (concat section-number todo (and todo " ") text
  1642. (and tags "&#xa0;&#xa0;&#xa0;") tags)))
  1643. ;;;; Src Code
  1644. (defun org-html-fontify-code (code lang)
  1645. "Color CODE with htmlize library.
  1646. CODE is a string representing the source code to colorize. LANG
  1647. is the language used for CODE, as a string, or nil."
  1648. (when code
  1649. (cond
  1650. ;; Case 1: No lang. Possibly an example block.
  1651. ((not lang)
  1652. ;; Simple transcoding.
  1653. (org-html-encode-plain-text code))
  1654. ;; Case 2: No htmlize or an inferior version of htmlize
  1655. ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
  1656. ;; Emit a warning.
  1657. (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
  1658. ;; Simple transcoding.
  1659. (org-html-encode-plain-text code))
  1660. (t
  1661. ;; Map language
  1662. (setq lang (or (assoc-default lang org-src-lang-modes) lang))
  1663. (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
  1664. (cond
  1665. ;; Case 1: Language is not associated with any Emacs mode
  1666. ((not (functionp lang-mode))
  1667. ;; Simple transcoding.
  1668. (org-html-encode-plain-text code))
  1669. ;; Case 2: Default. Fontify code.
  1670. (t
  1671. ;; htmlize
  1672. (setq code (with-temp-buffer
  1673. ;; Switch to language-specific mode.
  1674. (funcall lang-mode)
  1675. (insert code)
  1676. ;; Fontify buffer.
  1677. (font-lock-fontify-buffer)
  1678. ;; Remove formatting on newline characters.
  1679. (save-excursion
  1680. (let ((beg (point-min))
  1681. (end (point-max)))
  1682. (goto-char beg)
  1683. (while (progn (end-of-line) (< (point) end))
  1684. (put-text-property (point) (1+ (point)) 'face nil)
  1685. (forward-char 1))))
  1686. (org-src-mode)
  1687. (set-buffer-modified-p nil)
  1688. ;; Htmlize region.
  1689. (org-html-htmlize-region-for-paste
  1690. (point-min) (point-max))))
  1691. ;; Strip any enclosing <pre></pre> tags.
  1692. (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
  1693. (end (and beg (string-match "</pre>\\'" code))))
  1694. (if (and beg end) (substring code beg end) code)))))))))
  1695. (defun org-html-do-format-code
  1696. (code &optional lang refs retain-labels num-start)
  1697. "Format CODE string as source code.
  1698. Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
  1699. respectively, the language of the source code, as a string, an
  1700. alist between line numbers and references (as returned by
  1701. `org-export-unravel-code'), a boolean specifying if labels should
  1702. appear in the source code, and the number associated to the first
  1703. line of code."
  1704. (let* ((code-lines (org-split-string code "\n"))
  1705. (code-length (length code-lines))
  1706. (num-fmt
  1707. (and num-start
  1708. (format "%%%ds: "
  1709. (length (number-to-string (+ code-length num-start))))))
  1710. (code (org-html-fontify-code code lang)))
  1711. (org-export-format-code
  1712. code
  1713. (lambda (loc line-num ref)
  1714. (setq loc
  1715. (concat
  1716. ;; Add line number, if needed.
  1717. (when num-start
  1718. (format "<span class=\"linenr\">%s</span>"
  1719. (format num-fmt line-num)))
  1720. ;; Transcoded src line.
  1721. loc
  1722. ;; Add label, if needed.
  1723. (when (and ref retain-labels) (format " (%s)" ref))))
  1724. ;; Mark transcoded line as an anchor, if needed.
  1725. (if (not ref) loc
  1726. (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
  1727. ref loc)))
  1728. num-start refs)))
  1729. (defun org-html-format-code (element info)
  1730. "Format contents of ELEMENT as source code.
  1731. ELEMENT is either an example block or a src block. INFO is
  1732. a plist used as a communication channel."
  1733. (let* ((lang (org-element-property :language element))
  1734. ;; Extract code and references.
  1735. (code-info (org-export-unravel-code element))
  1736. (code (car code-info))
  1737. (refs (cdr code-info))
  1738. ;; Does the src block contain labels?
  1739. (retain-labels (org-element-property :retain-labels element))
  1740. ;; Does it have line numbers?
  1741. (num-start (case (org-element-property :number-lines element)
  1742. (continued (org-export-get-loc element info))
  1743. (new 0))))
  1744. (org-html-do-format-code code lang refs retain-labels num-start)))
  1745. ;;; Tables of Contents
  1746. (defun org-html-toc (depth info)
  1747. "Build a table of contents.
  1748. DEPTH is an integer specifying the depth of the table. INFO is a
  1749. plist used as a communication channel. Return the table of
  1750. contents as a string, or nil if it is empty."
  1751. (let ((toc-entries
  1752. (mapcar (lambda (headline)
  1753. (cons (org-html--format-toc-headline headline info)
  1754. (org-export-get-relative-level headline info)))
  1755. (org-export-collect-headlines info depth)))
  1756. (outer-tag (if (and (org-html-html5-p info)
  1757. (plist-get info :html-html5-fancy))
  1758. "nav"
  1759. "div")))
  1760. (when toc-entries
  1761. (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
  1762. (format "<h%d>%s</h%d>\n"
  1763. org-html-toplevel-hlevel
  1764. (org-html--translate "Table of Contents" info)
  1765. org-html-toplevel-hlevel)
  1766. "<div id=\"text-table-of-contents\">"
  1767. (org-html--toc-text toc-entries)
  1768. "</div>\n"
  1769. (format "</%s>\n" outer-tag)))))
  1770. (defun org-html--toc-text (toc-entries)
  1771. "Return innards of a table of contents, as a string.
  1772. TOC-ENTRIES is an alist where key is an entry title, as a string,
  1773. and value is its relative level, as an integer."
  1774. (let* ((prev-level (1- (cdar toc-entries)))
  1775. (start-level prev-level))
  1776. (concat
  1777. (mapconcat
  1778. (lambda (entry)
  1779. (let ((headline (car entry))
  1780. (level (cdr entry)))
  1781. (concat
  1782. (let* ((cnt (- level prev-level))
  1783. (times (if (> cnt 0) (1- cnt) (- cnt)))
  1784. rtn)
  1785. (setq prev-level level)
  1786. (concat
  1787. (org-html--make-string
  1788. times (cond ((> cnt 0) "\n<ul>\n<li>")
  1789. ((< cnt 0) "</li>\n</ul>\n")))
  1790. (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
  1791. headline)))
  1792. toc-entries "")
  1793. (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
  1794. (defun org-html--format-toc-headline (headline info)
  1795. "Return an appropriate table of contents entry for HEADLINE.
  1796. INFO is a plist used as a communication channel."
  1797. (let* ((headline-number (org-export-get-headline-number headline info))
  1798. (todo (and (plist-get info :with-todo-keywords)
  1799. (let ((todo (org-element-property :todo-keyword headline)))
  1800. (and todo (org-export-data todo info)))))
  1801. (todo-type (and todo (org-element-property :todo-type headline)))
  1802. (priority (and (plist-get info :with-priority)
  1803. (org-element-property :priority headline)))
  1804. (text (org-export-data-with-backend
  1805. (org-export-get-alt-title headline info)
  1806. ;; Create an anonymous back-end that will ignore any
  1807. ;; footnote-reference, link, radio-target and target
  1808. ;; in table of contents.
  1809. (org-export-create-backend
  1810. :parent 'html
  1811. :transcoders '((footnote-reference . ignore)
  1812. (link . (lambda (object c i) c))
  1813. (radio-target . (lambda (object c i) c))
  1814. (target . ignore)))
  1815. info))
  1816. (tags (and (eq (plist-get info :with-tags) t)
  1817. (org-export-get-tags headline info))))
  1818. (format "<a href=\"#%s\">%s</a>"
  1819. ;; Label.
  1820. (org-export-solidify-link-text
  1821. (or (org-element-property :CUSTOM_ID headline)
  1822. (concat "sec-"
  1823. (mapconcat #'number-to-string headline-number "-"))))
  1824. ;; Body.
  1825. (concat
  1826. (and (not (org-export-low-level-p headline info))
  1827. (org-export-numbered-headline-p headline info)
  1828. (concat (mapconcat #'number-to-string headline-number ".")
  1829. ". "))
  1830. (apply (if (not (eq org-html-format-headline-function 'ignore))
  1831. (lambda (todo todo-type priority text tags &rest ignore)
  1832. (funcall org-html-format-headline-function
  1833. todo todo-type priority text tags))
  1834. #'org-html-format-headline)
  1835. todo todo-type priority text tags :section-number nil)))))
  1836. (defun org-html-list-of-listings (info)
  1837. "Build a list of listings.
  1838. INFO is a plist used as a communication channel. Return the list
  1839. of listings as a string, or nil if it is empty."
  1840. (let ((lol-entries (org-export-collect-listings info)))
  1841. (when lol-entries
  1842. (concat "<div id=\"list-of-listings\">\n"
  1843. (format "<h%d>%s</h%d>\n"
  1844. org-html-toplevel-hlevel
  1845. (org-html--translate "List of Listings" info)
  1846. org-html-toplevel-hlevel)
  1847. "<div id=\"text-list-of-listings\">\n<ul>\n"
  1848. (let ((count 0)
  1849. (initial-fmt (format "<span class=\"listing-number\">%s</span>"
  1850. (org-html--translate "Listing %d:" info))))
  1851. (mapconcat
  1852. (lambda (entry)
  1853. (let ((label (org-element-property :name entry))
  1854. (title (org-trim
  1855. (org-export-data
  1856. (or (org-export-get-caption entry t)
  1857. (org-export-get-caption entry))
  1858. info))))
  1859. (concat
  1860. "<li>"
  1861. (if (not label)
  1862. (concat (format initial-fmt (incf count)) " " title)
  1863. (format "<a href=\"#%s\">%s %s</a>"
  1864. (org-export-solidify-link-text label)
  1865. (format initial-fmt (incf count))
  1866. title))
  1867. "</li>")))
  1868. lol-entries "\n"))
  1869. "\n</ul>\n</div>\n</div>"))))
  1870. (defun org-html-list-of-tables (info)
  1871. "Build a list of tables.
  1872. INFO is a plist used as a communication channel. Return the list
  1873. of tables as a string, or nil if it is empty."
  1874. (let ((lol-entries (org-export-collect-tables info)))
  1875. (when lol-entries
  1876. (concat "<div id=\"list-of-tables\">\n"
  1877. (format "<h%d>%s</h%d>\n"
  1878. org-html-toplevel-hlevel
  1879. (org-html--translate "List of Tables" info)
  1880. org-html-toplevel-hlevel)
  1881. "<div id=\"text-list-of-tables\">\n<ul>\n"
  1882. (let ((count 0)
  1883. (initial-fmt (format "<span class=\"table-number\">%s</span>"
  1884. (org-html--translate "Table %d:" info))))
  1885. (mapconcat
  1886. (lambda (entry)
  1887. (let ((label (org-element-property :name entry))
  1888. (title (org-trim
  1889. (org-export-data
  1890. (or (org-export-get-caption entry t)
  1891. (org-export-get-caption entry))
  1892. info))))
  1893. (concat
  1894. "<li>"
  1895. (if (not label)
  1896. (concat (format initial-fmt (incf count)) " " title)
  1897. (format "<a href=\"#%s\">%s %s</a>"
  1898. (org-export-solidify-link-text label)
  1899. (format initial-fmt (incf count))
  1900. title))
  1901. "</li>")))
  1902. lol-entries "\n"))
  1903. "\n</ul>\n</div>\n</div>"))))
  1904. ;;; Transcode Functions
  1905. ;;;; Bold
  1906. (defun org-html-bold (bold contents info)
  1907. "Transcode BOLD from Org to HTML.
  1908. CONTENTS is the text with bold markup. INFO is a plist holding
  1909. contextual information."
  1910. (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
  1911. contents))
  1912. ;;;; Center Block
  1913. (defun org-html-center-block (center-block contents info)
  1914. "Transcode a CENTER-BLOCK element from Org to HTML.
  1915. CONTENTS holds the contents of the block. INFO is a plist
  1916. holding contextual information."
  1917. (format "<div class=\"center\">\n%s</div>" contents))
  1918. ;;;; Clock
  1919. (defun org-html-clock (clock contents info)
  1920. "Transcode a CLOCK element from Org to HTML.
  1921. CONTENTS is nil. INFO is a plist used as a communication
  1922. channel."
  1923. (format "<p>
  1924. <span class=\"timestamp-wrapper\">
  1925. <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
  1926. </span>
  1927. </p>"
  1928. org-clock-string
  1929. (org-translate-time
  1930. (org-element-property :raw-value
  1931. (org-element-property :value clock)))
  1932. (let ((time (org-element-property :duration clock)))
  1933. (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
  1934. ;;;; Code
  1935. (defun org-html-code (code contents info)
  1936. "Transcode CODE from Org to HTML.
  1937. CONTENTS is nil. INFO is a plist holding contextual
  1938. information."
  1939. (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
  1940. (org-html-encode-plain-text (org-element-property :value code))))
  1941. ;;;; Drawer
  1942. (defun org-html-drawer (drawer contents info)
  1943. "Transcode a DRAWER element from Org to HTML.
  1944. CONTENTS holds the contents of the block. INFO is a plist
  1945. holding contextual information."
  1946. (if (functionp org-html-format-drawer-function)
  1947. (funcall org-html-format-drawer-function
  1948. (org-element-property :drawer-name drawer)
  1949. contents)
  1950. ;; If there's no user defined function: simply
  1951. ;; display contents of the drawer.
  1952. contents))
  1953. ;;;; Dynamic Block
  1954. (defun org-html-dynamic-block (dynamic-block contents info)
  1955. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1956. CONTENTS holds the contents of the block. INFO is a plist
  1957. holding contextual information. See `org-export-data'."
  1958. contents)
  1959. ;;;; Entity
  1960. (defun org-html-entity (entity contents info)
  1961. "Transcode an ENTITY object from Org to HTML.
  1962. CONTENTS are the definition itself. INFO is a plist holding
  1963. contextual information."
  1964. (org-element-property :html entity))
  1965. ;;;; Example Block
  1966. (defun org-html-example-block (example-block contents info)
  1967. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  1968. CONTENTS is nil. INFO is a plist holding contextual
  1969. information."
  1970. (if (org-export-read-attribute :attr_html example-block :textarea)
  1971. (org-html--textarea-block example-block)
  1972. (format "<pre class=\"example\">\n%s</pre>"
  1973. (org-html-format-code example-block info))))
  1974. ;;;; Export Snippet
  1975. (defun org-html-export-snippet (export-snippet contents info)
  1976. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  1977. CONTENTS is nil. INFO is a plist holding contextual
  1978. information."
  1979. (when (eq (org-export-snippet-backend export-snippet) 'html)
  1980. (org-element-property :value export-snippet)))
  1981. ;;;; Export Block
  1982. (defun org-html-export-block (export-block contents info)
  1983. "Transcode a EXPORT-BLOCK element from Org to HTML.
  1984. CONTENTS is nil. INFO is a plist holding contextual information."
  1985. (when (string= (org-element-property :type export-block) "HTML")
  1986. (org-remove-indentation (org-element-property :value export-block))))
  1987. ;;;; Fixed Width
  1988. (defun org-html-fixed-width (fixed-width contents info)
  1989. "Transcode a FIXED-WIDTH element from Org to HTML.
  1990. CONTENTS is nil. INFO is a plist holding contextual information."
  1991. (format "<pre class=\"example\">\n%s</pre>"
  1992. (org-html-do-format-code
  1993. (org-remove-indentation
  1994. (org-element-property :value fixed-width)))))
  1995. ;;;; Footnote Reference
  1996. (defun org-html-footnote-reference (footnote-reference contents info)
  1997. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  1998. CONTENTS is nil. INFO is a plist holding contextual information."
  1999. (concat
  2000. ;; Insert separator between two footnotes in a row.
  2001. (let ((prev (org-export-get-previous-element footnote-reference info)))
  2002. (when (eq (org-element-type prev) 'footnote-reference)
  2003. org-html-footnote-separator))
  2004. (cond
  2005. ((not (org-export-footnote-first-reference-p footnote-reference info))
  2006. (org-html-format-footnote-reference
  2007. (org-export-get-footnote-number footnote-reference info)
  2008. "IGNORED" 100))
  2009. ;; Inline definitions are secondary strings.
  2010. ((eq (org-element-property :type footnote-reference) 'inline)
  2011. (org-html-format-footnote-reference
  2012. (org-export-get-footnote-number footnote-reference info)
  2013. "IGNORED" 1))
  2014. ;; Non-inline footnotes definitions are full Org data.
  2015. (t (org-html-format-footnote-reference
  2016. (org-export-get-footnote-number footnote-reference info)
  2017. "IGNORED" 1)))))
  2018. ;;;; Headline
  2019. (defun org-html-format-headline--wrap
  2020. (headline info &optional format-function &rest extra-keys)
  2021. "Transcode a HEADLINE element from Org to HTML.
  2022. CONTENTS holds the contents of the headline. INFO is a plist
  2023. holding contextual information."
  2024. (let* ((level (+ (org-export-get-relative-level headline info)
  2025. (1- org-html-toplevel-hlevel)))
  2026. (headline-number (org-export-get-headline-number headline info))
  2027. (section-number (and (not (org-export-low-level-p headline info))
  2028. (org-export-numbered-headline-p headline info)
  2029. (mapconcat 'number-to-string
  2030. headline-number ".")))
  2031. (todo (and (plist-get info :with-todo-keywords)
  2032. (let ((todo (org-element-property :todo-keyword headline)))
  2033. (and todo (org-export-data todo info)))))
  2034. (todo-type (and todo (org-element-property :todo-type headline)))
  2035. (priority (and (plist-get info :with-priority)
  2036. (org-element-property :priority headline)))
  2037. (text (org-export-data (org-element-property :title headline) info))
  2038. (tags (and (plist-get info :with-tags)
  2039. (org-export-get-tags headline info)))
  2040. (headline-label (or (org-element-property :CUSTOM_ID headline)
  2041. (concat "sec-" (mapconcat 'number-to-string
  2042. headline-number "-"))))
  2043. (format-function
  2044. (cond ((functionp format-function) format-function)
  2045. ((not (eq org-html-format-headline-function 'ignore))
  2046. (lambda (todo todo-type priority text tags &rest ignore)
  2047. (funcall org-html-format-headline-function
  2048. todo todo-type priority text tags)))
  2049. (t 'org-html-format-headline))))
  2050. (apply format-function
  2051. todo todo-type priority text tags
  2052. :headline-label headline-label :level level
  2053. :section-number section-number extra-keys)))
  2054. (defun org-html-headline (headline contents info)
  2055. "Transcode a HEADLINE element from Org to HTML.
  2056. CONTENTS holds the contents of the headline. INFO is a plist
  2057. holding contextual information."
  2058. ;; Empty contents?
  2059. (setq contents (or contents ""))
  2060. (let* ((numberedp (org-export-numbered-headline-p headline info))
  2061. (level (org-export-get-relative-level headline info))
  2062. (text (org-export-data (org-element-property :title headline) info))
  2063. (todo (and (plist-get info :with-todo-keywords)
  2064. (let ((todo (org-element-property :todo-keyword headline)))
  2065. (and todo (org-export-data todo info)))))
  2066. (todo-type (and todo (org-element-property :todo-type headline)))
  2067. (tags (and (plist-get info :with-tags)
  2068. (org-export-get-tags headline info)))
  2069. (priority (and (plist-get info :with-priority)
  2070. (org-element-property :priority headline)))
  2071. (section-number (and (org-export-numbered-headline-p headline info)
  2072. (mapconcat 'number-to-string
  2073. (org-export-get-headline-number
  2074. headline info) ".")))
  2075. ;; Create the headline text.
  2076. (full-text (org-html-format-headline--wrap headline info)))
  2077. (cond
  2078. ;; Case 1: This is a footnote section: ignore it.
  2079. ((org-element-property :footnote-section-p headline) nil)
  2080. ;; Case 2. This is a deep sub-tree: export it as a list item.
  2081. ;; Also export as items headlines for which no section
  2082. ;; format has been found.
  2083. ((org-export-low-level-p headline info)
  2084. ;; Build the real contents of the sub-tree.
  2085. (let* ((type (if numberedp 'ordered 'unordered))
  2086. (itemized-body (org-html-format-list-item
  2087. contents type nil info nil full-text)))
  2088. (concat
  2089. (and (org-export-first-sibling-p headline info)
  2090. (org-html-begin-plain-list type))
  2091. itemized-body
  2092. (and (org-export-last-sibling-p headline info)
  2093. (org-html-end-plain-list type)))))
  2094. ;; Case 3. Standard headline. Export it as a section.
  2095. (t
  2096. (let* ((section-number (mapconcat 'number-to-string
  2097. (org-export-get-headline-number
  2098. headline info) "-"))
  2099. (ids (remove 'nil
  2100. (list (org-element-property :CUSTOM_ID headline)
  2101. (concat "sec-" section-number)
  2102. (org-element-property :ID headline))))
  2103. (preferred-id (car ids))
  2104. (extra-ids (cdr ids))
  2105. (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
  2106. (level1 (+ level (1- org-html-toplevel-hlevel)))
  2107. (first-content (car (org-element-contents headline))))
  2108. (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
  2109. (org-html--container headline info)
  2110. (format "outline-container-%s"
  2111. (or (org-element-property :CUSTOM_ID headline)
  2112. (concat "sec-" section-number)))
  2113. (concat (format "outline-%d" level1) (and extra-class " ")
  2114. extra-class)
  2115. (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
  2116. level1
  2117. preferred-id
  2118. (mapconcat
  2119. (lambda (x)
  2120. (let ((id (org-export-solidify-link-text
  2121. (if (org-uuidgen-p x) (concat "ID-" x)
  2122. x))))
  2123. (org-html--anchor id)))
  2124. extra-ids "")
  2125. full-text
  2126. level1)
  2127. ;; When there is no section, pretend there is an empty
  2128. ;; one to get the correct <div class="outline- ...>
  2129. ;; which is needed by `org-info.js'.
  2130. (if (not (eq (org-element-type first-content) 'section))
  2131. (concat (org-html-section first-content "" info)
  2132. contents)
  2133. contents)
  2134. (org-html--container headline info)))))))
  2135. (defun org-html--container (headline info)
  2136. (or (org-element-property :HTML_CONTAINER headline)
  2137. (if (= 1 (org-export-get-relative-level headline info))
  2138. (plist-get info :html-container)
  2139. "div")))
  2140. ;;;; Horizontal Rule
  2141. (defun org-html-horizontal-rule (horizontal-rule contents info)
  2142. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  2143. CONTENTS is nil. INFO is a plist holding contextual information."
  2144. (org-html-close-tag "hr" nil info))
  2145. ;;;; Inline Src Block
  2146. (defun org-html-inline-src-block (inline-src-block contents info)
  2147. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  2148. CONTENTS holds the contents of the item. INFO is a plist holding
  2149. contextual information."
  2150. (let* ((org-lang (org-element-property :language inline-src-block))
  2151. (code (org-element-property :value inline-src-block)))
  2152. (error "Cannot export inline src block")))
  2153. ;;;; Inlinetask
  2154. (defun org-html-format-section (text class &optional id)
  2155. "Format a section with TEXT into a HTML div with CLASS and ID."
  2156. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  2157. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  2158. (defun org-html-inlinetask (inlinetask contents info)
  2159. "Transcode an INLINETASK element from Org to HTML.
  2160. CONTENTS holds the contents of the block. INFO is a plist
  2161. holding contextual information."
  2162. (cond
  2163. ;; If `org-html-format-inlinetask-function' is not 'ignore, call it
  2164. ;; with appropriate arguments.
  2165. ((not (eq org-html-format-inlinetask-function 'ignore))
  2166. (let ((format-function
  2167. (function*
  2168. (lambda (todo todo-type priority text tags
  2169. &key contents &allow-other-keys)
  2170. (funcall org-html-format-inlinetask-function
  2171. todo todo-type priority text tags contents)))))
  2172. (org-html-format-headline--wrap
  2173. inlinetask info format-function :contents contents)))
  2174. ;; Otherwise, use a default template.
  2175. (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
  2176. (org-html-format-headline--wrap inlinetask info)
  2177. (org-html-close-tag "br" nil info)
  2178. contents))))
  2179. ;;;; Italic
  2180. (defun org-html-italic (italic contents info)
  2181. "Transcode ITALIC from Org to HTML.
  2182. CONTENTS is the text with italic markup. INFO is a plist holding
  2183. contextual information."
  2184. (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
  2185. ;;;; Item
  2186. (defun org-html-checkbox (checkbox info)
  2187. "Format CHECKBOX into HTML.
  2188. INFO is a plist holding contextual information. See
  2189. `org-html-checkbox-type' for customization options."
  2190. (cdr (assq checkbox
  2191. (cdr (assq org-html-checkbox-type org-html-checkbox-types)))))
  2192. (defun org-html-format-list-item (contents type checkbox info
  2193. &optional term-counter-id
  2194. headline)
  2195. "Format a list item into HTML."
  2196. (let ((checkbox (concat (org-html-checkbox checkbox info)
  2197. (and checkbox " ")))
  2198. (br (org-html-close-tag "br" nil info)))
  2199. (concat
  2200. (case type
  2201. (ordered
  2202. (let* ((counter term-counter-id)
  2203. (extra (if counter (format " value=\"%s\"" counter) "")))
  2204. (concat
  2205. (format "<li%s>" extra)
  2206. (when headline (concat headline br)))))
  2207. (unordered
  2208. (let* ((id term-counter-id)
  2209. (extra (if id (format " id=\"%s\"" id) "")))
  2210. (concat
  2211. (format "<li%s>" extra)
  2212. (when headline (concat headline br)))))
  2213. (descriptive
  2214. (let* ((term term-counter-id))
  2215. (setq term (or term "(no term)"))
  2216. ;; Check-boxes in descriptive lists are associated to tag.
  2217. (concat (format "<dt> %s </dt>"
  2218. (concat checkbox term))
  2219. "<dd>"))))
  2220. (unless (eq type 'descriptive) checkbox)
  2221. contents
  2222. (case type
  2223. (ordered "</li>")
  2224. (unordered "</li>")
  2225. (descriptive "</dd>")))))
  2226. (defun org-html-item (item contents info)
  2227. "Transcode an ITEM element from Org to HTML.
  2228. CONTENTS holds the contents of the item. INFO is a plist holding
  2229. contextual information."
  2230. (let* ((plain-list (org-export-get-parent item))
  2231. (type (org-element-property :type plain-list))
  2232. (counter (org-element-property :counter item))
  2233. (checkbox (org-element-property :checkbox item))
  2234. (tag (let ((tag (org-element-property :tag item)))
  2235. (and tag (org-export-data tag info)))))
  2236. (org-html-format-list-item
  2237. contents type checkbox info (or tag counter))))
  2238. ;;;; Keyword
  2239. (defun org-html-keyword (keyword contents info)
  2240. "Transcode a KEYWORD element from Org to HTML.
  2241. CONTENTS is nil. INFO is a plist holding contextual information."
  2242. (let ((key (org-element-property :key keyword))
  2243. (value (org-element-property :value keyword)))
  2244. (cond
  2245. ((string= key "HTML") value)
  2246. ((string= key "TOC")
  2247. (let ((value (downcase value)))
  2248. (cond
  2249. ((string-match "\\<headlines\\>" value)
  2250. (let ((depth (or (and (string-match "[0-9]+" value)
  2251. (string-to-number (match-string 0 value)))
  2252. (plist-get info :with-toc))))
  2253. (org-html-toc depth info)))
  2254. ((string= "listings" value) (org-html-list-of-listings info))
  2255. ((string= "tables" value) (org-html-list-of-tables info))))))))
  2256. ;;;; Latex Environment
  2257. (defun org-html-format-latex (latex-frag processing-type info)
  2258. "Format a LaTeX fragment LATEX-FRAG into HTML.
  2259. PROCESSING-TYPE designates the tool used for conversion. It is
  2260. a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
  2261. and t. See `org-html-with-latex' for more information. INFO is
  2262. a plist containing export properties."
  2263. (let ((cache-relpath "") (cache-dir ""))
  2264. (unless (eq processing-type 'mathjax)
  2265. (let ((bfn (or (buffer-file-name)
  2266. (make-temp-name
  2267. (expand-file-name "latex" temporary-file-directory))))
  2268. (latex-header
  2269. (let ((header (plist-get info :latex-header)))
  2270. (and header
  2271. (concat (mapconcat
  2272. (lambda (line) (concat "#+LATEX_HEADER: " line))
  2273. (org-split-string header "\n")
  2274. "\n")
  2275. "\n")))))
  2276. (setq cache-relpath
  2277. (concat "ltxpng/"
  2278. (file-name-sans-extension
  2279. (file-name-nondirectory bfn)))
  2280. cache-dir (file-name-directory bfn))
  2281. ;; Re-create LaTeX environment from original buffer in
  2282. ;; temporary buffer so that dvipng/imagemagick can properly
  2283. ;; turn the fragment into an image.
  2284. (setq latex-frag (concat latex-header latex-frag))))
  2285. (with-temp-buffer
  2286. (insert latex-frag)
  2287. (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
  2288. nil nil processing-type)
  2289. (buffer-string))))
  2290. (defun org-html-latex-environment (latex-environment contents info)
  2291. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  2292. CONTENTS is nil. INFO is a plist holding contextual information."
  2293. (let ((processing-type (plist-get info :with-latex))
  2294. (latex-frag (org-remove-indentation
  2295. (org-element-property :value latex-environment)))
  2296. (attributes (org-export-read-attribute :attr_html latex-environment)))
  2297. (case processing-type
  2298. ((t mathjax)
  2299. (org-html-format-latex latex-frag 'mathjax info))
  2300. ((dvipng imagemagick)
  2301. (let ((formula-link
  2302. (org-html-format-latex latex-frag processing-type info)))
  2303. (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
  2304. ;; Do not provide a caption or a name to be consistent with
  2305. ;; `mathjax' handling.
  2306. (org-html--wrap-image
  2307. (org-html--format-image
  2308. (match-string 1 formula-link) attributes info) info))))
  2309. (t latex-frag))))
  2310. ;;;; Latex Fragment
  2311. (defun org-html-latex-fragment (latex-fragment contents info)
  2312. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2313. CONTENTS is nil. INFO is a plist holding contextual information."
  2314. (let ((latex-frag (org-element-property :value latex-fragment))
  2315. (processing-type (plist-get info :with-latex)))
  2316. (case processing-type
  2317. ((t mathjax)
  2318. (org-html-format-latex latex-frag 'mathjax info))
  2319. ((dvipng imagemagick)
  2320. (let ((formula-link
  2321. (org-html-format-latex latex-frag processing-type info)))
  2322. (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
  2323. (org-html--format-image (match-string 1 formula-link) nil info))))
  2324. (t latex-frag))))
  2325. ;;;; Line Break
  2326. (defun org-html-line-break (line-break contents info)
  2327. "Transcode a LINE-BREAK object from Org to HTML.
  2328. CONTENTS is nil. INFO is a plist holding contextual information."
  2329. (concat (org-html-close-tag "br" nil info) "\n"))
  2330. ;;;; Link
  2331. (defun org-html-inline-image-p (link info)
  2332. "Non-nil when LINK is meant to appear as an image.
  2333. INFO is a plist used as a communication channel. LINK is an
  2334. inline image when it has no description and targets an image
  2335. file (see `org-html-inline-image-rules' for more information), or
  2336. if its description is a single link targeting an image file."
  2337. (if (not (org-element-contents link))
  2338. (org-export-inline-image-p link org-html-inline-image-rules)
  2339. (not
  2340. (let ((link-count 0))
  2341. (org-element-map (org-element-contents link)
  2342. (cons 'plain-text org-element-all-objects)
  2343. (lambda (obj)
  2344. (case (org-element-type obj)
  2345. (plain-text (org-string-nw-p obj))
  2346. (link (if (= link-count 1) t
  2347. (incf link-count)
  2348. (not (org-export-inline-image-p
  2349. obj org-html-inline-image-rules))))
  2350. (otherwise t)))
  2351. info t)))))
  2352. (defvar org-html-standalone-image-predicate)
  2353. (defun org-html-standalone-image-p (element info)
  2354. "Test if ELEMENT is a standalone image.
  2355. INFO is a plist holding contextual information.
  2356. Return non-nil, if ELEMENT is of type paragraph and its sole
  2357. content, save for white spaces, is a link that qualifies as an
  2358. inline image.
  2359. Return non-nil, if ELEMENT is of type link and its containing
  2360. paragraph has no other content save white spaces.
  2361. Return nil, otherwise.
  2362. Bind `org-html-standalone-image-predicate' to constrain paragraph
  2363. further. For example, to check for only captioned standalone
  2364. images, set it to:
  2365. \(lambda (paragraph) (org-element-property :caption paragraph))"
  2366. (let ((paragraph (case (org-element-type element)
  2367. (paragraph element)
  2368. (link (org-export-get-parent element)))))
  2369. (and (eq (org-element-type paragraph) 'paragraph)
  2370. (or (not (and (boundp 'org-html-standalone-image-predicate)
  2371. (functionp org-html-standalone-image-predicate)))
  2372. (funcall org-html-standalone-image-predicate paragraph))
  2373. (not (let ((link-count 0))
  2374. (org-element-map (org-element-contents paragraph)
  2375. (cons 'plain-text org-element-all-objects)
  2376. (lambda (obj) (case (org-element-type obj)
  2377. (plain-text (org-string-nw-p obj))
  2378. (link
  2379. (or (> (incf link-count) 1)
  2380. (not (org-html-inline-image-p obj info))))
  2381. (otherwise t)))
  2382. info 'first-match 'link))))))
  2383. (defun org-html-link (link desc info)
  2384. "Transcode a LINK object from Org to HTML.
  2385. DESC is the description part of the link, or the empty string.
  2386. INFO is a plist holding contextual information. See
  2387. `org-export-data'."
  2388. (let* ((home (when (plist-get info :html-link-home)
  2389. (org-trim (plist-get info :html-link-home))))
  2390. (use-abs-url (plist-get info :html-link-use-abs-url))
  2391. (link-org-files-as-html-maybe
  2392. (function
  2393. (lambda (raw-path info)
  2394. "Treat links to `file.org' as links to `file.html', if needed.
  2395. See `org-html-link-org-files-as-html'."
  2396. (cond
  2397. ((and org-html-link-org-files-as-html
  2398. (string= ".org"
  2399. (downcase (file-name-extension raw-path "."))))
  2400. (concat (file-name-sans-extension raw-path) "."
  2401. (plist-get info :html-extension)))
  2402. (t raw-path)))))
  2403. (type (org-element-property :type link))
  2404. (raw-path (org-element-property :path link))
  2405. ;; Ensure DESC really exists, or set it to nil.
  2406. (desc (org-string-nw-p desc))
  2407. (path
  2408. (cond
  2409. ((member type '("http" "https" "ftp" "mailto"))
  2410. (org-link-escape
  2411. (org-link-unescape
  2412. (concat type ":" raw-path)) org-link-escape-chars-browser))
  2413. ((string= type "file")
  2414. ;; Treat links to ".org" files as ".html", if needed.
  2415. (setq raw-path
  2416. (funcall link-org-files-as-html-maybe raw-path info))
  2417. ;; If file path is absolute, prepend it with protocol
  2418. ;; component - "file://".
  2419. (cond ((file-name-absolute-p raw-path)
  2420. (setq raw-path
  2421. (concat "file://" (expand-file-name
  2422. raw-path))))
  2423. ((and home use-abs-url)
  2424. (setq raw-path (concat (file-name-as-directory home) raw-path))))
  2425. ;; Add search option, if any. A search option can be
  2426. ;; relative to a custom-id or a headline title. Append
  2427. ;; a hash sign to any unresolved option, as it might point
  2428. ;; to a target.
  2429. (let ((option (org-element-property :search-option link)))
  2430. (cond ((not option) raw-path)
  2431. ((eq (aref option 0) ?#) (concat raw-path option))
  2432. (t
  2433. (let ((destination
  2434. (org-publish-resolve-external-fuzzy-link
  2435. (org-element-property :path link) option)))
  2436. (concat raw-path
  2437. (if (not destination) (concat "#" option)
  2438. (concat "#sec-"
  2439. (mapconcat #'number-to-string
  2440. destination "-")))))))))
  2441. (t raw-path)))
  2442. ;; Extract attributes from parent's paragraph. HACK: Only do
  2443. ;; this for the first link in parent (inner image link for
  2444. ;; inline images). This is needed as long as attributes
  2445. ;; cannot be set on a per link basis.
  2446. (attributes-plist
  2447. (let* ((parent (org-export-get-parent-element link))
  2448. (link (let ((container (org-export-get-parent link)))
  2449. (if (and (eq (org-element-type container) 'link)
  2450. (org-html-inline-image-p link info))
  2451. container
  2452. link))))
  2453. (and (eq (org-element-map parent 'link 'identity info t) link)
  2454. (org-export-read-attribute :attr_html parent))))
  2455. (attributes
  2456. (let ((attr (org-html--make-attribute-string attributes-plist)))
  2457. (if (org-string-nw-p attr) (concat " " attr) "")))
  2458. protocol)
  2459. (cond
  2460. ;; Image file.
  2461. ((and org-html-inline-images
  2462. (org-export-inline-image-p link org-html-inline-image-rules))
  2463. (org-html--format-image path attributes-plist info))
  2464. ;; Radio target: Transcode target's contents and use them as
  2465. ;; link's description.
  2466. ((string= type "radio")
  2467. (let ((destination (org-export-resolve-radio-link link info)))
  2468. (when destination
  2469. (format "<a href=\"#%s\"%s>%s</a>"
  2470. (org-export-solidify-link-text path)
  2471. attributes
  2472. (org-export-data (org-element-contents destination) info)))))
  2473. ;; Links pointing to a headline: Find destination and build
  2474. ;; appropriate referencing command.
  2475. ((member type '("custom-id" "fuzzy" "id"))
  2476. (let ((destination (if (string= type "fuzzy")
  2477. (org-export-resolve-fuzzy-link link info)
  2478. (org-export-resolve-id-link link info))))
  2479. (case (org-element-type destination)
  2480. ;; ID link points to an external file.
  2481. (plain-text
  2482. (let ((fragment (concat "ID-" path))
  2483. ;; Treat links to ".org" files as ".html", if needed.
  2484. (path (funcall link-org-files-as-html-maybe
  2485. destination info)))
  2486. (format "<a href=\"%s#%s\"%s>%s</a>"
  2487. path fragment attributes (or desc destination))))
  2488. ;; Fuzzy link points nowhere.
  2489. ((nil)
  2490. (format "<i>%s</i>"
  2491. (or desc
  2492. (org-export-data
  2493. (org-element-property :raw-link link) info))))
  2494. ;; Link points to a headline.
  2495. (headline
  2496. (let ((href
  2497. ;; What href to use?
  2498. (cond
  2499. ;; Case 1: Headline is linked via it's CUSTOM_ID
  2500. ;; property. Use CUSTOM_ID.
  2501. ((string= type "custom-id")
  2502. (org-element-property :CUSTOM_ID destination))
  2503. ;; Case 2: Headline is linked via it's ID property
  2504. ;; or through other means. Use the default href.
  2505. ((member type '("id" "fuzzy"))
  2506. (format "sec-%s"
  2507. (mapconcat 'number-to-string
  2508. (org-export-get-headline-number
  2509. destination info) "-")))
  2510. (t (error "Shouldn't reach here"))))
  2511. ;; What description to use?
  2512. (desc
  2513. ;; Case 1: Headline is numbered and LINK has no
  2514. ;; description. Display section number.
  2515. (if (and (org-export-numbered-headline-p destination info)
  2516. (not desc))
  2517. (mapconcat 'number-to-string
  2518. (org-export-get-headline-number
  2519. destination info) ".")
  2520. ;; Case 2: Either the headline is un-numbered or
  2521. ;; LINK has a custom description. Display LINK's
  2522. ;; description or headline's title.
  2523. (or desc (org-export-data (org-element-property
  2524. :title destination) info)))))
  2525. (format "<a href=\"#%s\"%s>%s</a>"
  2526. (org-export-solidify-link-text href) attributes desc)))
  2527. ;; Fuzzy link points to a target or an element.
  2528. (t
  2529. (let* ((path (org-export-solidify-link-text path))
  2530. (org-html-standalone-image-predicate 'org-html--has-caption-p)
  2531. (number (cond
  2532. (desc nil)
  2533. ((org-html-standalone-image-p destination info)
  2534. (org-export-get-ordinal
  2535. (org-element-map destination 'link
  2536. 'identity info t)
  2537. info 'link 'org-html-standalone-image-p))
  2538. (t (org-export-get-ordinal
  2539. destination info nil 'org-html--has-caption-p))))
  2540. (desc (cond (desc)
  2541. ((not number) "No description for this link")
  2542. ((numberp number) (number-to-string number))
  2543. (t (mapconcat 'number-to-string number ".")))))
  2544. (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
  2545. ;; Coderef: replace link with the reference name or the
  2546. ;; equivalent line number.
  2547. ((string= type "coderef")
  2548. (let ((fragment (concat "coderef-" path)))
  2549. (format "<a href=\"#%s\"%s%s>%s</a>"
  2550. fragment
  2551. (org-trim
  2552. (format (concat "class=\"coderef\""
  2553. " onmouseover=\"CodeHighlightOn(this, '%s');\""
  2554. " onmouseout=\"CodeHighlightOff(this, '%s');\"")
  2555. fragment fragment))
  2556. attributes
  2557. (format (org-export-get-coderef-format path desc)
  2558. (org-export-resolve-coderef path info)))))
  2559. ;; Link type is handled by a special function.
  2560. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2561. (funcall protocol (org-link-unescape path) desc 'html))
  2562. ;; External link with a description part.
  2563. ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
  2564. ;; External link without a description part.
  2565. (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
  2566. ;; No path, only description. Try to do something useful.
  2567. (t (format "<i>%s</i>" desc)))))
  2568. ;;;; Node Property
  2569. (defun org-html-node-property (node-property contents info)
  2570. "Transcode a NODE-PROPERTY element from Org to HTML.
  2571. CONTENTS is nil. INFO is a plist holding contextual
  2572. information."
  2573. (format "%s:%s"
  2574. (org-element-property :key node-property)
  2575. (let ((value (org-element-property :value node-property)))
  2576. (if value (concat " " value) ""))))
  2577. ;;;; Paragraph
  2578. (defun org-html-paragraph (paragraph contents info)
  2579. "Transcode a PARAGRAPH element from Org to HTML.
  2580. CONTENTS is the contents of the paragraph, as a string. INFO is
  2581. the plist used as a communication channel."
  2582. (let* ((parent (org-export-get-parent paragraph))
  2583. (parent-type (org-element-type parent))
  2584. (style '((footnote-definition " class=\"footpara\"")))
  2585. (extra (or (cadr (assoc parent-type style)) "")))
  2586. (cond
  2587. ((and (eq (org-element-type parent) 'item)
  2588. (= (org-element-property :begin paragraph)
  2589. (org-element-property :contents-begin parent)))
  2590. ;; Leading paragraph in a list item have no tags.
  2591. contents)
  2592. ((org-html-standalone-image-p paragraph info)
  2593. ;; Standalone image.
  2594. (let ((caption
  2595. (let ((raw (org-export-data
  2596. (org-export-get-caption paragraph) info))
  2597. (org-html-standalone-image-predicate
  2598. 'org-html--has-caption-p))
  2599. (if (not (org-string-nw-p raw)) raw
  2600. (concat
  2601. "<span class=\"figure-number\">"
  2602. (format (org-html--translate "Figure %d:" info)
  2603. (org-export-get-ordinal
  2604. (org-element-map paragraph 'link
  2605. 'identity info t)
  2606. info nil 'org-html-standalone-image-p))
  2607. "</span> " raw))))
  2608. (label (org-element-property :name paragraph)))
  2609. (org-html--wrap-image contents info caption label)))
  2610. ;; Regular paragraph.
  2611. (t (format "<p%s>\n%s</p>" extra contents)))))
  2612. ;;;; Plain List
  2613. ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
  2614. ;; the correct value for the item counter
  2615. (defun org-html-begin-plain-list (type &optional arg1)
  2616. "Insert the beginning of the HTML list depending on TYPE.
  2617. When ARG1 is a string, use it as the start parameter for ordered
  2618. lists."
  2619. (case type
  2620. (ordered
  2621. (format "<ol class=\"org-ol\"%s>"
  2622. (if arg1 (format " start=\"%d\"" arg1) "")))
  2623. (unordered "<ul class=\"org-ul\">")
  2624. (descriptive "<dl class=\"org-dl\">")))
  2625. (defun org-html-end-plain-list (type)
  2626. "Insert the end of the HTML list depending on TYPE."
  2627. (case type
  2628. (ordered "</ol>")
  2629. (unordered "</ul>")
  2630. (descriptive "</dl>")))
  2631. (defun org-html-plain-list (plain-list contents info)
  2632. "Transcode a PLAIN-LIST element from Org to HTML.
  2633. CONTENTS is the contents of the list. INFO is a plist holding
  2634. contextual information."
  2635. (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
  2636. (type (org-element-property :type plain-list)))
  2637. (format "%s\n%s%s"
  2638. (org-html-begin-plain-list type)
  2639. contents (org-html-end-plain-list type))))
  2640. ;;;; Plain Text
  2641. (defun org-html-convert-special-strings (string)
  2642. "Convert special characters in STRING to HTML."
  2643. (let ((all org-html-special-string-regexps)
  2644. e a re rpl start)
  2645. (while (setq a (pop all))
  2646. (setq re (car a) rpl (cdr a) start 0)
  2647. (while (string-match re string start)
  2648. (setq string (replace-match rpl t nil string))))
  2649. string))
  2650. (defun org-html-encode-plain-text (text)
  2651. "Convert plain text characters from TEXT to HTML equivalent.
  2652. Possible conversions are set in `org-html-protect-char-alist'."
  2653. (mapc
  2654. (lambda (pair)
  2655. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
  2656. org-html-protect-char-alist)
  2657. text)
  2658. (defun org-html-plain-text (text info)
  2659. "Transcode a TEXT string from Org to HTML.
  2660. TEXT is the string to transcode. INFO is a plist holding
  2661. contextual information."
  2662. (let ((output text))
  2663. ;; Protect following characters: <, >, &.
  2664. (setq output (org-html-encode-plain-text output))
  2665. ;; Handle smart quotes. Be sure to provide original string since
  2666. ;; OUTPUT may have been modified.
  2667. (when (plist-get info :with-smart-quotes)
  2668. (setq output (org-export-activate-smart-quotes output :html info text)))
  2669. ;; Handle special strings.
  2670. (when (plist-get info :with-special-strings)
  2671. (setq output (org-html-convert-special-strings output)))
  2672. ;; Handle break preservation if required.
  2673. (when (plist-get info :preserve-breaks)
  2674. (setq output
  2675. (replace-regexp-in-string
  2676. "\\(\\\\\\\\\\)?[ \t]*\n"
  2677. (concat (org-html-close-tag "br" nil info) "\n") output)))
  2678. ;; Return value.
  2679. output))
  2680. ;; Planning
  2681. (defun org-html-planning (planning contents info)
  2682. "Transcode a PLANNING element from Org to HTML.
  2683. CONTENTS is nil. INFO is a plist used as a communication
  2684. channel."
  2685. (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
  2686. (format
  2687. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  2688. (mapconcat
  2689. 'identity
  2690. (delq nil
  2691. (list
  2692. (let ((closed (org-element-property :closed planning)))
  2693. (when closed
  2694. (format span-fmt org-closed-string
  2695. (org-translate-time
  2696. (org-element-property :raw-value closed)))))
  2697. (let ((deadline (org-element-property :deadline planning)))
  2698. (when deadline
  2699. (format span-fmt org-deadline-string
  2700. (org-translate-time
  2701. (org-element-property :raw-value deadline)))))
  2702. (let ((scheduled (org-element-property :scheduled planning)))
  2703. (when scheduled
  2704. (format span-fmt org-scheduled-string
  2705. (org-translate-time
  2706. (org-element-property :raw-value scheduled)))))))
  2707. " "))))
  2708. ;;;; Property Drawer
  2709. (defun org-html-property-drawer (property-drawer contents info)
  2710. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2711. CONTENTS holds the contents of the drawer. INFO is a plist
  2712. holding contextual information."
  2713. (and (org-string-nw-p contents)
  2714. (format "<pre class=\"example\">\n%s</pre>" contents)))
  2715. ;;;; Quote Block
  2716. (defun org-html-quote-block (quote-block contents info)
  2717. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2718. CONTENTS holds the contents of the block. INFO is a plist
  2719. holding contextual information."
  2720. (format "<blockquote>\n%s</blockquote>" contents))
  2721. ;;;; Quote Section
  2722. (defun org-html-quote-section (quote-section contents info)
  2723. "Transcode a QUOTE-SECTION element from Org to HTML.
  2724. CONTENTS is nil. INFO is a plist holding contextual information."
  2725. (let ((value (org-remove-indentation
  2726. (org-element-property :value quote-section))))
  2727. (when value (format "<pre>\n%s</pre>" value))))
  2728. ;;;; Section
  2729. (defun org-html-section (section contents info)
  2730. "Transcode a SECTION element from Org to HTML.
  2731. CONTENTS holds the contents of the section. INFO is a plist
  2732. holding contextual information."
  2733. (let ((parent (org-export-get-parent-headline section)))
  2734. ;; Before first headline: no container, just return CONTENTS.
  2735. (if (not parent) contents
  2736. ;; Get div's class and id references.
  2737. (let* ((class-num (+ (org-export-get-relative-level parent info)
  2738. (1- org-html-toplevel-hlevel)))
  2739. (section-number
  2740. (mapconcat
  2741. 'number-to-string
  2742. (org-export-get-headline-number parent info) "-")))
  2743. ;; Build return value.
  2744. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2745. class-num
  2746. (or (org-element-property :CUSTOM_ID parent) section-number)
  2747. contents)))))
  2748. ;;;; Radio Target
  2749. (defun org-html-radio-target (radio-target text info)
  2750. "Transcode a RADIO-TARGET object from Org to HTML.
  2751. TEXT is the text of the target. INFO is a plist holding
  2752. contextual information."
  2753. (let ((id (org-export-solidify-link-text
  2754. (org-element-property :value radio-target))))
  2755. (org-html--anchor id text)))
  2756. ;;;; Special Block
  2757. (defun org-html-special-block (special-block contents info)
  2758. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2759. CONTENTS holds the contents of the block. INFO is a plist
  2760. holding contextual information."
  2761. (let* ((block-type (downcase
  2762. (org-element-property :type special-block)))
  2763. (contents (or contents ""))
  2764. (html5-fancy (and (org-html-html5-p info)
  2765. (plist-get info :html-html5-fancy)
  2766. (member block-type org-html-html5-elements)))
  2767. (attributes (org-export-read-attribute :attr_html special-block)))
  2768. (unless html5-fancy
  2769. (let ((class (plist-get attributes :class)))
  2770. (setq attributes (plist-put attributes :class
  2771. (if class (concat class " " block-type)
  2772. block-type)))))
  2773. (setq attributes (org-html--make-attribute-string attributes))
  2774. (when (not (equal attributes ""))
  2775. (setq attributes (concat " " attributes)))
  2776. (if html5-fancy
  2777. (format "<%s%s>\n%s</%s>" block-type attributes
  2778. contents block-type)
  2779. (format "<div%s>\n%s\n</div>" attributes contents))))
  2780. ;;;; Src Block
  2781. (defun org-html-src-block (src-block contents info)
  2782. "Transcode a SRC-BLOCK element from Org to HTML.
  2783. CONTENTS holds the contents of the item. INFO is a plist holding
  2784. contextual information."
  2785. (if (org-export-read-attribute :attr_html src-block :textarea)
  2786. (org-html--textarea-block src-block)
  2787. (let ((lang (org-element-property :language src-block))
  2788. (caption (org-export-get-caption src-block))
  2789. (code (org-html-format-code src-block info))
  2790. (label (let ((lbl (org-element-property :name src-block)))
  2791. (if (not lbl) ""
  2792. (format " id=\"%s\""
  2793. (org-export-solidify-link-text lbl))))))
  2794. (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
  2795. (format
  2796. "<div class=\"org-src-container\">\n%s%s\n</div>"
  2797. (if (not caption) ""
  2798. (format "<label class=\"org-src-name\">%s</label>"
  2799. (org-export-data caption info)))
  2800. (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
  2801. ;;;; Statistics Cookie
  2802. (defun org-html-statistics-cookie (statistics-cookie contents info)
  2803. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2804. CONTENTS is nil. INFO is a plist holding contextual information."
  2805. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2806. (format "<code>%s</code>" cookie-value)))
  2807. ;;;; Strike-Through
  2808. (defun org-html-strike-through (strike-through contents info)
  2809. "Transcode STRIKE-THROUGH from Org to HTML.
  2810. CONTENTS is the text with strike-through markup. INFO is a plist
  2811. holding contextual information."
  2812. (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
  2813. contents))
  2814. ;;;; Subscript
  2815. (defun org-html-subscript (subscript contents info)
  2816. "Transcode a SUBSCRIPT object from Org to HTML.
  2817. CONTENTS is the contents of the object. INFO is a plist holding
  2818. contextual information."
  2819. (format "<sub>%s</sub>" contents))
  2820. ;;;; Superscript
  2821. (defun org-html-superscript (superscript contents info)
  2822. "Transcode a SUPERSCRIPT object from Org to HTML.
  2823. CONTENTS is the contents of the object. INFO is a plist holding
  2824. contextual information."
  2825. (format "<sup>%s</sup>" contents))
  2826. ;;;; Table Cell
  2827. (defun org-html-table-cell (table-cell contents info)
  2828. "Transcode a TABLE-CELL element from Org to HTML.
  2829. CONTENTS is nil. INFO is a plist used as a communication
  2830. channel."
  2831. (let* ((table-row (org-export-get-parent table-cell))
  2832. (table (org-export-get-parent-table table-cell))
  2833. (cell-attrs
  2834. (if (not org-html-table-align-individual-fields) ""
  2835. (format (if (and (boundp 'org-html-format-table-no-css)
  2836. org-html-format-table-no-css)
  2837. " align=\"%s\"" " class=\"%s\"")
  2838. (org-export-table-cell-alignment table-cell info)))))
  2839. (when (or (not contents) (string= "" (org-trim contents)))
  2840. (setq contents "&#xa0;"))
  2841. (cond
  2842. ((and (org-export-table-has-header-p table info)
  2843. (= 1 (org-export-table-row-group table-row info)))
  2844. (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
  2845. contents (cdr org-html-table-header-tags)))
  2846. ((and org-html-table-use-header-tags-for-first-column
  2847. (zerop (cdr (org-export-table-cell-address table-cell info))))
  2848. (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
  2849. contents (cdr org-html-table-header-tags)))
  2850. (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
  2851. contents (cdr org-html-table-data-tags))))))
  2852. ;;;; Table Row
  2853. (defun org-html-table-row (table-row contents info)
  2854. "Transcode a TABLE-ROW element from Org to HTML.
  2855. CONTENTS is the contents of the row. INFO is a plist used as a
  2856. communication channel."
  2857. ;; Rules are ignored since table separators are deduced from
  2858. ;; borders of the current row.
  2859. (when (eq (org-element-property :type table-row) 'standard)
  2860. (let* ((rowgroup-number (org-export-table-row-group table-row info))
  2861. (row-number (org-export-table-row-number table-row info))
  2862. (start-rowgroup-p
  2863. (org-export-table-row-starts-rowgroup-p table-row info))
  2864. (end-rowgroup-p
  2865. (org-export-table-row-ends-rowgroup-p table-row info))
  2866. ;; `top-row-p' and `end-rowgroup-p' are not used directly
  2867. ;; but should be set so that `org-html-table-row-tags' can
  2868. ;; use them (see the docstring of this variable.)
  2869. (top-row-p (and (equal start-rowgroup-p '(top))
  2870. (equal end-rowgroup-p '(below top))))
  2871. (bottom-row-p (and (equal start-rowgroup-p '(above))
  2872. (equal end-rowgroup-p '(bottom above))))
  2873. (rowgroup-tags
  2874. (cond
  2875. ;; Case 1: Row belongs to second or subsequent rowgroups.
  2876. ((not (= 1 rowgroup-number))
  2877. '("<tbody>" . "\n</tbody>"))
  2878. ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
  2879. ((org-export-table-has-header-p
  2880. (org-export-get-parent-table table-row) info)
  2881. '("<thead>" . "\n</thead>"))
  2882. ;; Case 2: Row is from first and only row group.
  2883. (t '("<tbody>" . "\n</tbody>")))))
  2884. (concat
  2885. ;; Begin a rowgroup?
  2886. (when start-rowgroup-p (car rowgroup-tags))
  2887. ;; Actual table row
  2888. (concat "\n" (eval (car org-html-table-row-tags))
  2889. contents
  2890. "\n"
  2891. (eval (cdr org-html-table-row-tags)))
  2892. ;; End a rowgroup?
  2893. (when end-rowgroup-p (cdr rowgroup-tags))))))
  2894. ;;;; Table
  2895. (defun org-html-table-first-row-data-cells (table info)
  2896. "Transcode the first row of TABLE.
  2897. INFO is a plist used as a communication channel."
  2898. (let ((table-row
  2899. (org-element-map table 'table-row
  2900. (lambda (row)
  2901. (unless (eq (org-element-property :type row) 'rule) row))
  2902. info 'first-match))
  2903. (special-column-p (org-export-table-has-special-column-p table)))
  2904. (if (not special-column-p) (org-element-contents table-row)
  2905. (cdr (org-element-contents table-row)))))
  2906. (defun org-html-table--table.el-table (table info)
  2907. "Format table.el tables into HTML.
  2908. INFO is a plist used as a communication channel."
  2909. (when (eq (org-element-property :type table) 'table.el)
  2910. (require 'table)
  2911. (let ((outbuf (with-current-buffer
  2912. (get-buffer-create "*org-export-table*")
  2913. (erase-buffer) (current-buffer))))
  2914. (with-temp-buffer
  2915. (insert (org-element-property :value table))
  2916. (goto-char 1)
  2917. (re-search-forward "^[ \t]*|[^|]" nil t)
  2918. (table-generate-source 'html outbuf))
  2919. (with-current-buffer outbuf
  2920. (prog1 (org-trim (buffer-string))
  2921. (kill-buffer) )))))
  2922. (defun org-html-table (table contents info)
  2923. "Transcode a TABLE element from Org to HTML.
  2924. CONTENTS is the contents of the table. INFO is a plist holding
  2925. contextual information."
  2926. (case (org-element-property :type table)
  2927. ;; Case 1: table.el table. Convert it using appropriate tools.
  2928. (table.el (org-html-table--table.el-table table info))
  2929. ;; Case 2: Standard table.
  2930. (t
  2931. (let* ((label (org-element-property :name table))
  2932. (caption (org-export-get-caption table))
  2933. (number (org-export-get-ordinal
  2934. table info nil 'org-html--has-caption-p))
  2935. (attributes
  2936. (org-html--make-attribute-string
  2937. (org-combine-plists
  2938. (and label (list :id (org-export-solidify-link-text label)))
  2939. (and (not (org-html-html5-p info))
  2940. (plist-get info :html-table-attributes))
  2941. (org-export-read-attribute :attr_html table))))
  2942. (alignspec
  2943. (if (and (boundp 'org-html-format-table-no-css)
  2944. org-html-format-table-no-css)
  2945. "align=\"%s\"" "class=\"%s\""))
  2946. (table-column-specs
  2947. (function
  2948. (lambda (table info)
  2949. (mapconcat
  2950. (lambda (table-cell)
  2951. (let ((alignment (org-export-table-cell-alignment
  2952. table-cell info)))
  2953. (concat
  2954. ;; Begin a colgroup?
  2955. (when (org-export-table-cell-starts-colgroup-p
  2956. table-cell info)
  2957. "\n<colgroup>")
  2958. ;; Add a column. Also specify it's alignment.
  2959. (format "\n%s"
  2960. (org-html-close-tag
  2961. "col" (concat " " (format alignspec alignment)) info))
  2962. ;; End a colgroup?
  2963. (when (org-export-table-cell-ends-colgroup-p
  2964. table-cell info)
  2965. "\n</colgroup>"))))
  2966. (org-html-table-first-row-data-cells table info) "\n")))))
  2967. (format "<table%s>\n%s\n%s\n%s</table>"
  2968. (if (equal attributes "") "" (concat " " attributes))
  2969. (if (not caption) ""
  2970. (format (if org-html-table-caption-above
  2971. "<caption class=\"t-above\">%s</caption>"
  2972. "<caption class=\"t-bottom\">%s</caption>")
  2973. (concat
  2974. "<span class=\"table-number\">"
  2975. (format (org-html--translate "Table %d:" info) number)
  2976. "</span> " (org-export-data caption info))))
  2977. (funcall table-column-specs table info)
  2978. contents)))))
  2979. ;;;; Target
  2980. (defun org-html-target (target contents info)
  2981. "Transcode a TARGET object from Org to HTML.
  2982. CONTENTS is nil. INFO is a plist holding contextual
  2983. information."
  2984. (let ((id (org-export-solidify-link-text
  2985. (org-element-property :value target))))
  2986. (org-html--anchor id)))
  2987. ;;;; Timestamp
  2988. (defun org-html-timestamp (timestamp contents info)
  2989. "Transcode a TIMESTAMP object from Org to HTML.
  2990. CONTENTS is nil. INFO is a plist holding contextual
  2991. information."
  2992. (let ((value (org-html-plain-text
  2993. (org-timestamp-translate timestamp) info)))
  2994. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  2995. (replace-regexp-in-string "--" "&#x2013;" value))))
  2996. ;;;; Underline
  2997. (defun org-html-underline (underline contents info)
  2998. "Transcode UNDERLINE from Org to HTML.
  2999. CONTENTS is the text with underline markup. INFO is a plist
  3000. holding contextual information."
  3001. (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
  3002. contents))
  3003. ;;;; Verbatim
  3004. (defun org-html-verbatim (verbatim contents info)
  3005. "Transcode VERBATIM from Org to HTML.
  3006. CONTENTS is nil. INFO is a plist holding contextual
  3007. information."
  3008. (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
  3009. (org-html-encode-plain-text (org-element-property :value verbatim))))
  3010. ;;;; Verse Block
  3011. (defun org-html-verse-block (verse-block contents info)
  3012. "Transcode a VERSE-BLOCK element from Org to HTML.
  3013. CONTENTS is verse block contents. INFO is a plist holding
  3014. contextual information."
  3015. ;; Replace each newline character with line break. Also replace
  3016. ;; each blank line with a line break.
  3017. (setq contents (replace-regexp-in-string
  3018. "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
  3019. (replace-regexp-in-string
  3020. "\\(\\\\\\\\\\)?[ \t]*\n"
  3021. (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
  3022. ;; Replace each white space at beginning of a line with a
  3023. ;; non-breaking space.
  3024. (while (string-match "^[ \t]+" contents)
  3025. (let* ((num-ws (length (match-string 0 contents)))
  3026. (ws (let (out) (dotimes (i num-ws out)
  3027. (setq out (concat out "&#xa0;"))))))
  3028. (setq contents (replace-match ws nil t contents))))
  3029. (format "<p class=\"verse\">\n%s</p>" contents))
  3030. ;;; Filter Functions
  3031. (defun org-html-final-function (contents backend info)
  3032. "Filter to indent the HTML and convert HTML entities."
  3033. (with-temp-buffer
  3034. (insert contents)
  3035. (set-auto-mode t)
  3036. (if org-html-indent
  3037. (indent-region (point-min) (point-max)))
  3038. (when org-html-use-unicode-chars
  3039. (require 'mm-url)
  3040. (mm-url-decode-entities))
  3041. (buffer-substring-no-properties (point-min) (point-max))))
  3042. ;;; End-user functions
  3043. ;;;###autoload
  3044. (defun org-html-export-as-html
  3045. (&optional async subtreep visible-only body-only ext-plist)
  3046. "Export current buffer to an HTML buffer.
  3047. If narrowing is active in the current buffer, only export its
  3048. narrowed part.
  3049. If a region is active, export that region.
  3050. A non-nil optional argument ASYNC means the process should happen
  3051. asynchronously. The resulting buffer should be accessible
  3052. through the `org-export-stack' interface.
  3053. When optional argument SUBTREEP is non-nil, export the sub-tree
  3054. at point, extracting information from the headline properties
  3055. first.
  3056. When optional argument VISIBLE-ONLY is non-nil, don't export
  3057. contents of hidden elements.
  3058. When optional argument BODY-ONLY is non-nil, only write code
  3059. between \"<body>\" and \"</body>\" tags.
  3060. EXT-PLIST, when provided, is a property list with external
  3061. parameters overriding Org default settings, but still inferior to
  3062. file-local settings.
  3063. Export is done in a buffer named \"*Org HTML Export*\", which
  3064. will be displayed when `org-export-show-temporary-export-buffer'
  3065. is non-nil."
  3066. (interactive)
  3067. (org-export-to-buffer 'html "*Org HTML Export*"
  3068. async subtreep visible-only body-only ext-plist
  3069. (lambda () (set-auto-mode t))))
  3070. ;;;###autoload
  3071. (defun org-html-convert-region-to-html ()
  3072. "Assume the current region has org-mode syntax, and convert it to HTML.
  3073. This can be used in any buffer. For example, you can write an
  3074. itemized list in org-mode syntax in an HTML buffer and use this
  3075. command to convert it."
  3076. (interactive)
  3077. (org-export-replace-region-by 'html))
  3078. ;;;###autoload
  3079. (defun org-html-export-to-html
  3080. (&optional async subtreep visible-only body-only ext-plist)
  3081. "Export current buffer to a HTML file.
  3082. If narrowing is active in the current buffer, only export its
  3083. narrowed part.
  3084. If a region is active, export that region.
  3085. A non-nil optional argument ASYNC means the process should happen
  3086. asynchronously. The resulting file should be accessible through
  3087. the `org-export-stack' interface.
  3088. When optional argument SUBTREEP is non-nil, export the sub-tree
  3089. at point, extracting information from the headline properties
  3090. first.
  3091. When optional argument VISIBLE-ONLY is non-nil, don't export
  3092. contents of hidden elements.
  3093. When optional argument BODY-ONLY is non-nil, only write code
  3094. between \"<body>\" and \"</body>\" tags.
  3095. EXT-PLIST, when provided, is a property list with external
  3096. parameters overriding Org default settings, but still inferior to
  3097. file-local settings.
  3098. Return output file's name."
  3099. (interactive)
  3100. (let* ((extension (concat "." org-html-extension))
  3101. (file (org-export-output-file-name extension subtreep))
  3102. (org-export-coding-system org-html-coding-system))
  3103. (org-export-to-file 'html file
  3104. async subtreep visible-only body-only ext-plist)))
  3105. ;;;###autoload
  3106. (defun org-html-publish-to-html (plist filename pub-dir)
  3107. "Publish an org file to HTML.
  3108. FILENAME is the filename of the Org file to be published. PLIST
  3109. is the property list for the given project. PUB-DIR is the
  3110. publishing directory.
  3111. Return output file name."
  3112. (org-publish-org-to 'html filename
  3113. (concat "." (or (plist-get plist :html-extension)
  3114. org-html-extension "html"))
  3115. plist pub-dir))
  3116. (provide 'ox-html)
  3117. ;; Local variables:
  3118. ;; generated-autoload-file: "org-loaddefs.el"
  3119. ;; End:
  3120. ;;; ox-html.el ends here