ox-html.el 127 KB

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