ox-html.el 142 KB

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