ox-html.el 144 KB

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