ox-html.el 143 KB

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