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