ox-html.el 144 KB

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