ox-html.el 142 KB

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