ox-html.el 145 KB

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