ox-html.el 145 KB

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