ox-html.el 144 KB

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