ox-html.el 144 KB

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