ox-html.el 142 KB

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