ox-html.el 144 KB

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