ox-html.el 144 KB

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