ox-html.el 144 KB

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