ox-html.el 145 KB

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