ox-html.el 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865
  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. (and (plist-get info :with-date)
  1764. (org-string-nw-p date)
  1765. (format "<p class=\"date\">%s: %s</p>\n"
  1766. (org-html--translate "Date" info)
  1767. date))
  1768. (and (plist-get info :with-author)
  1769. (org-string-nw-p author)
  1770. (format "<p class=\"author\">%s: %s</p>\n"
  1771. (org-html--translate "Author" info)
  1772. author))
  1773. (and (plist-get info :with-email)
  1774. (org-string-nw-p email)
  1775. (format "<p class=\"email\">%s: %s</p>\n"
  1776. (org-html--translate "Email" info)
  1777. email))
  1778. (and (plist-get info :time-stamp-file)
  1779. (format
  1780. "<p class=\"date\">%s: %s</p>\n"
  1781. (org-html--translate "Created" info)
  1782. (format-time-string
  1783. (plist-get info :html-metadata-timestamp-format))))
  1784. (and (plist-get info :with-creator)
  1785. (org-string-nw-p creator)
  1786. (format "<p class=\"creator\">%s</p>\n" creator))
  1787. (and (org-string-nw-p validation-link)
  1788. (format "<p class=\"validation\">%s</p>\n"
  1789. validation-link)))))
  1790. (t
  1791. (let ((formats (plist-get info (if (eq type 'preamble)
  1792. :html-preamble-format
  1793. :html-postamble-format)))
  1794. (language (plist-get info :language)))
  1795. (format-spec
  1796. (cadr (or (assoc-string language formats t)
  1797. (assoc-string "en" formats t)))
  1798. spec)))))))
  1799. (let ((div (assq type (plist-get info :html-divs))))
  1800. (when (org-string-nw-p section-contents)
  1801. (concat
  1802. (format "<%s id=\"%s\" class=\"%s\">\n"
  1803. (nth 1 div)
  1804. (nth 2 div)
  1805. org-html--pre/postamble-class)
  1806. (org-element-normalize-string section-contents)
  1807. (format "</%s>\n" (nth 1 div)))))))))
  1808. (defun org-html-inner-template (contents info)
  1809. "Return body of document string after HTML conversion.
  1810. CONTENTS is the transcoded contents string. INFO is a plist
  1811. holding export options."
  1812. (concat
  1813. ;; Table of contents.
  1814. (let ((depth (plist-get info :with-toc)))
  1815. (when depth (org-html-toc depth info)))
  1816. ;; Document contents.
  1817. contents
  1818. ;; Footnotes section.
  1819. (org-html-footnote-section info)))
  1820. (defun org-html-template (contents info)
  1821. "Return complete document string after HTML conversion.
  1822. CONTENTS is the transcoded contents string. INFO is a plist
  1823. holding export options."
  1824. (concat
  1825. (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
  1826. (let* ((xml-declaration (plist-get info :html-xml-declaration))
  1827. (decl (or (and (stringp xml-declaration) xml-declaration)
  1828. (cdr (assoc (plist-get info :html-extension)
  1829. xml-declaration))
  1830. (cdr (assoc "html" xml-declaration))
  1831. "")))
  1832. (when (not (or (not decl) (string= "" decl)))
  1833. (format "%s\n"
  1834. (format decl
  1835. (or (and org-html-coding-system
  1836. (fboundp 'coding-system-get)
  1837. (coding-system-get org-html-coding-system 'mime-charset))
  1838. "iso-8859-1"))))))
  1839. (org-html-doctype info)
  1840. "\n"
  1841. (concat "<html"
  1842. (cond ((org-html-xhtml-p info)
  1843. (format
  1844. " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
  1845. (plist-get info :language) (plist-get info :language)))
  1846. ((org-html-html5-p info)
  1847. (format " lang=\"%s\"" (plist-get info :language))))
  1848. ">\n")
  1849. "<head>\n"
  1850. (org-html--build-meta-info info)
  1851. (org-html--build-head info)
  1852. (org-html--build-mathjax-config info)
  1853. "</head>\n"
  1854. "<body>\n"
  1855. (let ((link-up (org-trim (plist-get info :html-link-up)))
  1856. (link-home (org-trim (plist-get info :html-link-home))))
  1857. (unless (and (string= link-up "") (string= link-home ""))
  1858. (format (plist-get info :html-home/up-format)
  1859. (or link-up link-home)
  1860. (or link-home link-up))))
  1861. ;; Preamble.
  1862. (org-html--build-pre/postamble 'preamble info)
  1863. ;; Document contents.
  1864. (let ((div (assq 'content (plist-get info :html-divs))))
  1865. (format "<%s id=\"%s\">\n" (nth 1 div) (nth 2 div)))
  1866. ;; Document title.
  1867. (when (plist-get info :with-title)
  1868. (let ((title (and (plist-get info :with-title)
  1869. (plist-get info :title)))
  1870. (subtitle (plist-get info :subtitle))
  1871. (html5-fancy (org-html--html5-fancy-p info)))
  1872. (when title
  1873. (format
  1874. (if html5-fancy
  1875. "<header>\n<h1 class=\"title\">%s</h1>\n%s</header>"
  1876. "<h1 class=\"title\">%s%s</h1>\n")
  1877. (org-export-data title info)
  1878. (if subtitle
  1879. (format
  1880. (if html5-fancy
  1881. "<p class=\"subtitle\">%s</p>\n"
  1882. (concat "\n" (org-html-close-tag "br" nil info) "\n"
  1883. "<span class=\"subtitle\">%s</span>\n"))
  1884. (org-export-data subtitle info))
  1885. "")))))
  1886. contents
  1887. (format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
  1888. ;; Postamble.
  1889. (org-html--build-pre/postamble 'postamble info)
  1890. ;; Possibly use the Klipse library live code blocks.
  1891. (when (plist-get info :html-klipsify-src)
  1892. (concat "<script>" (plist-get info :html-klipse-selection-script)
  1893. "</script><script src=\""
  1894. org-html-klipse-js
  1895. "\"></script><link rel=\"stylesheet\" type=\"text/css\" href=\""
  1896. org-html-klipse-css "\"/>"))
  1897. ;; Closing document.
  1898. "</body>\n</html>"))
  1899. (defun org-html--translate (s info)
  1900. "Translate string S according to specified language.
  1901. INFO is a plist used as a communication channel."
  1902. (org-export-translate s :html info))
  1903. ;;;; Anchor
  1904. (defun org-html--anchor (id desc attributes info)
  1905. "Format a HTML anchor."
  1906. (let* ((name (and (plist-get info :html-allow-name-attribute-in-anchors) id))
  1907. (attributes (concat (and id (format " id=\"%s\"" id))
  1908. (and name (format " name=\"%s\"" name))
  1909. attributes)))
  1910. (format "<a%s>%s</a>" attributes (or desc ""))))
  1911. ;;;; Todo
  1912. (defun org-html--todo (todo info)
  1913. "Format TODO keywords into HTML."
  1914. (when todo
  1915. (format "<span class=\"%s %s%s\">%s</span>"
  1916. (if (member todo org-done-keywords) "done" "todo")
  1917. (or (plist-get info :html-todo-kwd-class-prefix) "")
  1918. (org-html-fix-class-name todo)
  1919. todo)))
  1920. ;;;; Priority
  1921. (defun org-html--priority (priority _info)
  1922. "Format a priority into HTML.
  1923. PRIORITY is the character code of the priority or nil. INFO is
  1924. a plist containing export options."
  1925. (and priority (format "<span class=\"priority\">[%c]</span>" priority)))
  1926. ;;;; Tags
  1927. (defun org-html--tags (tags info)
  1928. "Format TAGS into HTML.
  1929. INFO is a plist containing export options."
  1930. (when tags
  1931. (format "<span class=\"tag\">%s</span>"
  1932. (mapconcat
  1933. (lambda (tag)
  1934. (format "<span class=\"%s\">%s</span>"
  1935. (concat (plist-get info :html-tag-class-prefix)
  1936. (org-html-fix-class-name tag))
  1937. tag))
  1938. tags "&#xa0;"))))
  1939. ;;;; Src Code
  1940. (defun org-html-fontify-code (code lang)
  1941. "Color CODE with htmlize library.
  1942. CODE is a string representing the source code to colorize. LANG
  1943. is the language used for CODE, as a string, or nil."
  1944. (when code
  1945. (cond
  1946. ;; No language. Possibly an example block.
  1947. ((not lang) (org-html-encode-plain-text code))
  1948. ;; Plain text explicitly set.
  1949. ((not org-html-htmlize-output-type) (org-html-encode-plain-text code))
  1950. ;; No htmlize library or an inferior version of htmlize.
  1951. ((not (progn (require 'htmlize nil t)
  1952. (fboundp 'htmlize-region-for-paste)))
  1953. ;; Emit a warning.
  1954. (message "Cannot fontify source block (htmlize.el >= 1.34 required)")
  1955. (org-html-encode-plain-text code))
  1956. (t
  1957. ;; Map language
  1958. (setq lang (or (assoc-default lang org-src-lang-modes) lang))
  1959. (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
  1960. (cond
  1961. ;; Case 1: Language is not associated with any Emacs mode
  1962. ((not (functionp lang-mode))
  1963. (org-html-encode-plain-text code))
  1964. ;; Case 2: Default. Fontify code.
  1965. (t
  1966. ;; htmlize
  1967. (setq code
  1968. (let ((output-type org-html-htmlize-output-type)
  1969. (font-prefix org-html-htmlize-font-prefix))
  1970. (with-temp-buffer
  1971. ;; Switch to language-specific mode.
  1972. (funcall lang-mode)
  1973. (insert code)
  1974. ;; Fontify buffer.
  1975. (org-font-lock-ensure)
  1976. ;; Remove formatting on newline characters.
  1977. (save-excursion
  1978. (let ((beg (point-min))
  1979. (end (point-max)))
  1980. (goto-char beg)
  1981. (while (progn (end-of-line) (< (point) end))
  1982. (put-text-property (point) (1+ (point)) 'face nil)
  1983. (forward-char 1))))
  1984. (org-src-mode)
  1985. (set-buffer-modified-p nil)
  1986. ;; Htmlize region.
  1987. (let ((org-html-htmlize-output-type output-type)
  1988. (org-html-htmlize-font-prefix font-prefix))
  1989. (org-html-htmlize-region-for-paste
  1990. (point-min) (point-max))))))
  1991. ;; Strip any enclosing <pre></pre> tags.
  1992. (let* ((beg (and (string-match "\\`<pre[^>]*>\n?" code) (match-end 0)))
  1993. (end (and beg (string-match "</pre>\\'" code))))
  1994. (if (and beg end) (substring code beg end) code)))))))))
  1995. (defun org-html-do-format-code
  1996. (code &optional lang refs retain-labels num-start)
  1997. "Format CODE string as source code.
  1998. Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
  1999. respectively, the language of the source code, as a string, an
  2000. alist between line numbers and references (as returned by
  2001. `org-export-unravel-code'), a boolean specifying if labels should
  2002. appear in the source code, and the number associated to the first
  2003. line of code."
  2004. (let* ((code-lines (split-string code "\n"))
  2005. (code-length (length code-lines))
  2006. (num-fmt
  2007. (and num-start
  2008. (format "%%%ds: "
  2009. (length (number-to-string (+ code-length num-start))))))
  2010. (code (org-html-fontify-code code lang)))
  2011. (org-export-format-code
  2012. code
  2013. (lambda (loc line-num ref)
  2014. (setq loc
  2015. (concat
  2016. ;; Add line number, if needed.
  2017. (when num-start
  2018. (format "<span class=\"linenr\">%s</span>"
  2019. (format num-fmt line-num)))
  2020. ;; Transcoded src line.
  2021. loc
  2022. ;; Add label, if needed.
  2023. (when (and ref retain-labels) (format " (%s)" ref))))
  2024. ;; Mark transcoded line as an anchor, if needed.
  2025. (if (not ref) loc
  2026. (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
  2027. ref loc)))
  2028. num-start refs)))
  2029. (defun org-html-format-code (element info)
  2030. "Format contents of ELEMENT as source code.
  2031. ELEMENT is either an example or a source block. INFO is a plist
  2032. used as a communication channel."
  2033. (let* ((lang (org-element-property :language element))
  2034. ;; Extract code and references.
  2035. (code-info (org-export-unravel-code element))
  2036. (code (car code-info))
  2037. (refs (cdr code-info))
  2038. ;; Does the source block contain labels?
  2039. (retain-labels (org-element-property :retain-labels element))
  2040. ;; Does it have line numbers?
  2041. (num-start (org-export-get-loc element info)))
  2042. (org-html-do-format-code code lang refs retain-labels num-start)))
  2043. ;;; Tables of Contents
  2044. (defun org-html-toc (depth info &optional scope)
  2045. "Build a table of contents.
  2046. DEPTH is an integer specifying the depth of the table. INFO is
  2047. a plist used as a communication channel. Optional argument SCOPE
  2048. is an element defining the scope of the table. Return the table
  2049. of contents as a string, or nil if it is empty."
  2050. (let ((toc-entries
  2051. (mapcar (lambda (headline)
  2052. (cons (org-html--format-toc-headline headline info)
  2053. (org-export-get-relative-level headline info)))
  2054. (org-export-collect-headlines info depth scope))))
  2055. (when toc-entries
  2056. (let ((toc (concat "<div id=\"text-table-of-contents\">"
  2057. (org-html--toc-text toc-entries)
  2058. "</div>\n")))
  2059. (if scope toc
  2060. (let ((outer-tag (if (org-html--html5-fancy-p info)
  2061. "nav"
  2062. "div")))
  2063. (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
  2064. (let ((top-level (plist-get info :html-toplevel-hlevel)))
  2065. (format "<h%d>%s</h%d>\n"
  2066. top-level
  2067. (org-html--translate "Table of Contents" info)
  2068. top-level))
  2069. toc
  2070. (format "</%s>\n" outer-tag))))))))
  2071. (defun org-html--toc-text (toc-entries)
  2072. "Return innards of a table of contents, as a string.
  2073. TOC-ENTRIES is an alist where key is an entry title, as a string,
  2074. and value is its relative level, as an integer."
  2075. (let* ((prev-level (1- (cdar toc-entries)))
  2076. (start-level prev-level))
  2077. (concat
  2078. (mapconcat
  2079. (lambda (entry)
  2080. (let ((headline (car entry))
  2081. (level (cdr entry)))
  2082. (concat
  2083. (let* ((cnt (- level prev-level))
  2084. (times (if (> cnt 0) (1- cnt) (- cnt))))
  2085. (setq prev-level level)
  2086. (concat
  2087. (org-html--make-string
  2088. times (cond ((> cnt 0) "\n<ul>\n<li>")
  2089. ((< cnt 0) "</li>\n</ul>\n")))
  2090. (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
  2091. headline)))
  2092. toc-entries "")
  2093. (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
  2094. (defun org-html--format-toc-headline (headline info)
  2095. "Return an appropriate table of contents entry for HEADLINE.
  2096. INFO is a plist used as a communication channel."
  2097. (let* ((headline-number (org-export-get-headline-number headline info))
  2098. (todo (and (plist-get info :with-todo-keywords)
  2099. (let ((todo (org-element-property :todo-keyword headline)))
  2100. (and todo (org-export-data todo info)))))
  2101. (todo-type (and todo (org-element-property :todo-type headline)))
  2102. (priority (and (plist-get info :with-priority)
  2103. (org-element-property :priority headline)))
  2104. (text (org-export-data-with-backend
  2105. (org-export-get-alt-title headline info)
  2106. (org-export-toc-entry-backend 'html)
  2107. info))
  2108. (tags (and (eq (plist-get info :with-tags) t)
  2109. (org-export-get-tags headline info))))
  2110. (format "<a href=\"#%s\">%s</a>"
  2111. ;; Label.
  2112. (or (org-element-property :CUSTOM_ID headline)
  2113. (org-export-get-reference headline info))
  2114. ;; Body.
  2115. (concat
  2116. (and (not (org-export-low-level-p headline info))
  2117. (org-export-numbered-headline-p headline info)
  2118. (concat (mapconcat #'number-to-string headline-number ".")
  2119. ". "))
  2120. (apply (plist-get info :html-format-headline-function)
  2121. todo todo-type priority text tags :section-number nil)))))
  2122. (defun org-html-list-of-listings (info)
  2123. "Build a list of listings.
  2124. INFO is a plist used as a communication channel. Return the list
  2125. of listings as a string, or nil if it is empty."
  2126. (let ((lol-entries (org-export-collect-listings info)))
  2127. (when lol-entries
  2128. (concat "<div id=\"list-of-listings\">\n"
  2129. (let ((top-level (plist-get info :html-toplevel-hlevel)))
  2130. (format "<h%d>%s</h%d>\n"
  2131. top-level
  2132. (org-html--translate "List of Listings" info)
  2133. top-level))
  2134. "<div id=\"text-list-of-listings\">\n<ul>\n"
  2135. (let ((count 0)
  2136. (initial-fmt (format "<span class=\"listing-number\">%s</span>"
  2137. (org-html--translate "Listing %d:" info))))
  2138. (mapconcat
  2139. (lambda (entry)
  2140. (let ((label (and (org-element-property :name entry)
  2141. (org-export-get-reference entry info)))
  2142. (title (org-trim
  2143. (org-export-data
  2144. (or (org-export-get-caption entry t)
  2145. (org-export-get-caption entry))
  2146. info))))
  2147. (concat
  2148. "<li>"
  2149. (if (not label)
  2150. (concat (format initial-fmt (cl-incf count))
  2151. " "
  2152. title)
  2153. (format "<a href=\"#%s\">%s %s</a>"
  2154. label
  2155. (format initial-fmt (cl-incf count))
  2156. title))
  2157. "</li>")))
  2158. lol-entries "\n"))
  2159. "\n</ul>\n</div>\n</div>"))))
  2160. (defun org-html-list-of-tables (info)
  2161. "Build a list of tables.
  2162. INFO is a plist used as a communication channel. Return the list
  2163. of tables as a string, or nil if it is empty."
  2164. (let ((lol-entries (org-export-collect-tables info)))
  2165. (when lol-entries
  2166. (concat "<div id=\"list-of-tables\">\n"
  2167. (let ((top-level (plist-get info :html-toplevel-hlevel)))
  2168. (format "<h%d>%s</h%d>\n"
  2169. top-level
  2170. (org-html--translate "List of Tables" info)
  2171. top-level))
  2172. "<div id=\"text-list-of-tables\">\n<ul>\n"
  2173. (let ((count 0)
  2174. (initial-fmt (format "<span class=\"table-number\">%s</span>"
  2175. (org-html--translate "Table %d:" info))))
  2176. (mapconcat
  2177. (lambda (entry)
  2178. (let ((label (and (org-element-property :name entry)
  2179. (org-export-get-reference entry info)))
  2180. (title (org-trim
  2181. (org-export-data
  2182. (or (org-export-get-caption entry t)
  2183. (org-export-get-caption entry))
  2184. info))))
  2185. (concat
  2186. "<li>"
  2187. (if (not label)
  2188. (concat (format initial-fmt (cl-incf count))
  2189. " "
  2190. title)
  2191. (format "<a href=\"#%s\">%s %s</a>"
  2192. label
  2193. (format initial-fmt (cl-incf count))
  2194. title))
  2195. "</li>")))
  2196. lol-entries "\n"))
  2197. "\n</ul>\n</div>\n</div>"))))
  2198. ;;; Transcode Functions
  2199. ;;;; Bold
  2200. (defun org-html-bold (_bold contents info)
  2201. "Transcode BOLD from Org to HTML.
  2202. CONTENTS is the text with bold markup. INFO is a plist holding
  2203. contextual information."
  2204. (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
  2205. contents))
  2206. ;;;; Center Block
  2207. (defun org-html-center-block (_center-block contents _info)
  2208. "Transcode a CENTER-BLOCK element from Org to HTML.
  2209. CONTENTS holds the contents of the block. INFO is a plist
  2210. holding contextual information."
  2211. (format "<div class=\"org-center\">\n%s</div>" contents))
  2212. ;;;; Clock
  2213. (defun org-html-clock (clock _contents _info)
  2214. "Transcode a CLOCK element from Org to HTML.
  2215. CONTENTS is nil. INFO is a plist used as a communication
  2216. channel."
  2217. (format "<p>
  2218. <span class=\"timestamp-wrapper\">
  2219. <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
  2220. </span>
  2221. </p>"
  2222. org-clock-string
  2223. (org-timestamp-translate (org-element-property :value clock))
  2224. (let ((time (org-element-property :duration clock)))
  2225. (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
  2226. ;;;; Code
  2227. (defun org-html-code (code _contents info)
  2228. "Transcode CODE from Org to HTML.
  2229. CONTENTS is nil. INFO is a plist holding contextual
  2230. information."
  2231. (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
  2232. (org-html-encode-plain-text (org-element-property :value code))))
  2233. ;;;; Drawer
  2234. (defun org-html-drawer (drawer contents info)
  2235. "Transcode a DRAWER element from Org to HTML.
  2236. CONTENTS holds the contents of the block. INFO is a plist
  2237. holding contextual information."
  2238. (funcall (plist-get info :html-format-drawer-function)
  2239. (org-element-property :drawer-name drawer)
  2240. contents))
  2241. ;;;; Dynamic Block
  2242. (defun org-html-dynamic-block (_dynamic-block contents _info)
  2243. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  2244. CONTENTS holds the contents of the block. INFO is a plist
  2245. holding contextual information. See `org-export-data'."
  2246. contents)
  2247. ;;;; Entity
  2248. (defun org-html-entity (entity _contents _info)
  2249. "Transcode an ENTITY object from Org to HTML.
  2250. CONTENTS are the definition itself. INFO is a plist holding
  2251. contextual information."
  2252. (org-element-property :html entity))
  2253. ;;;; Example Block
  2254. (defun org-html-example-block (example-block _contents info)
  2255. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  2256. CONTENTS is nil. INFO is a plist holding contextual
  2257. information."
  2258. (let ((attributes (org-export-read-attribute :attr_html example-block)))
  2259. (if (plist-get attributes :textarea)
  2260. (org-html--textarea-block example-block)
  2261. (format "<pre class=\"example\"%s>\n%s</pre>"
  2262. (let* ((name (org-element-property :name example-block))
  2263. (a (org-html--make-attribute-string
  2264. (if (or (not name) (plist-member attributes :id))
  2265. attributes
  2266. (plist-put attributes :id name)))))
  2267. (if (org-string-nw-p a) (concat " " a) ""))
  2268. (org-html-format-code example-block info)))))
  2269. ;;;; Export Snippet
  2270. (defun org-html-export-snippet (export-snippet _contents _info)
  2271. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  2272. CONTENTS is nil. INFO is a plist holding contextual
  2273. information."
  2274. (when (eq (org-export-snippet-backend export-snippet) 'html)
  2275. (org-element-property :value export-snippet)))
  2276. ;;;; Export Block
  2277. (defun org-html-export-block (export-block _contents _info)
  2278. "Transcode a EXPORT-BLOCK element from Org to HTML.
  2279. CONTENTS is nil. INFO is a plist holding contextual information."
  2280. (when (string= (org-element-property :type export-block) "HTML")
  2281. (org-remove-indentation (org-element-property :value export-block))))
  2282. ;;;; Fixed Width
  2283. (defun org-html-fixed-width (fixed-width _contents _info)
  2284. "Transcode a FIXED-WIDTH element from Org to HTML.
  2285. CONTENTS is nil. INFO is a plist holding contextual information."
  2286. (format "<pre class=\"example\">\n%s</pre>"
  2287. (org-html-do-format-code
  2288. (org-remove-indentation
  2289. (org-element-property :value fixed-width)))))
  2290. ;;;; Footnote Reference
  2291. (defun org-html-footnote-reference (footnote-reference _contents info)
  2292. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  2293. CONTENTS is nil. INFO is a plist holding contextual information."
  2294. (concat
  2295. ;; Insert separator between two footnotes in a row.
  2296. (let ((prev (org-export-get-previous-element footnote-reference info)))
  2297. (when (eq (org-element-type prev) 'footnote-reference)
  2298. (plist-get info :html-footnote-separator)))
  2299. (let* ((n (org-export-get-footnote-number footnote-reference info))
  2300. (id (format "fnr.%d%s"
  2301. n
  2302. (if (org-export-footnote-first-reference-p
  2303. footnote-reference info)
  2304. ""
  2305. ".100"))))
  2306. (format
  2307. (plist-get info :html-footnote-format)
  2308. (org-html--anchor
  2309. id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
  2310. ;;;; Headline
  2311. (defun org-html-headline (headline contents info)
  2312. "Transcode a HEADLINE element from Org to HTML.
  2313. CONTENTS holds the contents of the headline. INFO is a plist
  2314. holding contextual information."
  2315. (unless (org-element-property :footnote-section-p headline)
  2316. (let* ((numberedp (org-export-numbered-headline-p headline info))
  2317. (numbers (org-export-get-headline-number headline info))
  2318. (level (+ (org-export-get-relative-level headline info)
  2319. (1- (plist-get info :html-toplevel-hlevel))))
  2320. (todo (and (plist-get info :with-todo-keywords)
  2321. (let ((todo (org-element-property :todo-keyword headline)))
  2322. (and todo (org-export-data todo info)))))
  2323. (todo-type (and todo (org-element-property :todo-type headline)))
  2324. (priority (and (plist-get info :with-priority)
  2325. (org-element-property :priority headline)))
  2326. (text (org-export-data (org-element-property :title headline) info))
  2327. (tags (and (plist-get info :with-tags)
  2328. (org-export-get-tags headline info)))
  2329. (full-text (funcall (plist-get info :html-format-headline-function)
  2330. todo todo-type priority text tags info))
  2331. (contents (or contents ""))
  2332. (id (or (org-element-property :CUSTOM_ID headline)
  2333. (org-export-get-reference headline info)))
  2334. (formatted-text
  2335. (if (plist-get info :html-self-link-headlines)
  2336. (format "<a href=\"#%s\">%s</a>" id full-text)
  2337. full-text)))
  2338. (if (org-export-low-level-p headline info)
  2339. ;; This is a deep sub-tree: export it as a list item.
  2340. (let* ((html-type (if numberedp "ol" "ul")))
  2341. (concat
  2342. (and (org-export-first-sibling-p headline info)
  2343. (apply #'format "<%s class=\"org-%s\">\n"
  2344. (make-list 2 html-type)))
  2345. (org-html-format-list-item
  2346. contents (if numberedp 'ordered 'unordered)
  2347. nil info nil
  2348. (concat (org-html--anchor id nil nil info) formatted-text)) "\n"
  2349. (and (org-export-last-sibling-p headline info)
  2350. (format "</%s>\n" html-type))))
  2351. ;; Standard headline. Export it as a section.
  2352. (let ((extra-class
  2353. (org-element-property :HTML_CONTAINER_CLASS headline))
  2354. (headline-class
  2355. (org-element-property :HTML_HEADLINE_CLASS headline))
  2356. (first-content (car (org-element-contents headline))))
  2357. (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
  2358. (org-html--container headline info)
  2359. (concat "outline-container-"
  2360. (org-export-get-reference headline info))
  2361. (concat (format "outline-%d" level)
  2362. (and extra-class " ")
  2363. extra-class)
  2364. (format "\n<h%d id=\"%s\"%s>%s</h%d>\n"
  2365. level
  2366. id
  2367. (if (not headline-class) ""
  2368. (format " class=\"%s\"" headline-class))
  2369. (concat
  2370. (and numberedp
  2371. (format
  2372. "<span class=\"section-number-%d\">%s</span> "
  2373. level
  2374. (mapconcat #'number-to-string numbers ".")))
  2375. formatted-text)
  2376. level)
  2377. ;; When there is no section, pretend there is an
  2378. ;; empty one to get the correct <div
  2379. ;; class="outline-...> which is needed by
  2380. ;; `org-info.js'.
  2381. (if (eq (org-element-type first-content) 'section) contents
  2382. (concat (org-html-section first-content "" info) contents))
  2383. (org-html--container headline info)))))))
  2384. (defun org-html-format-headline-default-function
  2385. (todo _todo-type priority text tags info)
  2386. "Default format function for a headline.
  2387. See `org-html-format-headline-function' for details."
  2388. (let ((todo (org-html--todo todo info))
  2389. (priority (org-html--priority priority info))
  2390. (tags (org-html--tags tags info)))
  2391. (concat todo (and todo " ")
  2392. priority (and priority " ")
  2393. text
  2394. (and tags "&#xa0;&#xa0;&#xa0;") tags)))
  2395. (defun org-html--container (headline info)
  2396. (or (org-element-property :HTML_CONTAINER headline)
  2397. (if (= 1 (org-export-get-relative-level headline info))
  2398. (plist-get info :html-container)
  2399. "div")))
  2400. ;;;; Horizontal Rule
  2401. (defun org-html-horizontal-rule (_horizontal-rule _contents info)
  2402. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  2403. CONTENTS is nil. INFO is a plist holding contextual information."
  2404. (org-html-close-tag "hr" nil info))
  2405. ;;;; Inline Src Block
  2406. (defun org-html-inline-src-block (inline-src-block _contents info)
  2407. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  2408. CONTENTS holds the contents of the item. INFO is a plist holding
  2409. contextual information."
  2410. (let* ((lang (org-element-property :language inline-src-block))
  2411. (code (org-html-fontify-code
  2412. (org-element-property :value inline-src-block)
  2413. lang))
  2414. (label
  2415. (let ((lbl (and (org-element-property :name inline-src-block)
  2416. (org-export-get-reference inline-src-block info))))
  2417. (if (not lbl) "" (format " id=\"%s\"" lbl)))))
  2418. (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)))
  2419. ;;;; Inlinetask
  2420. (defun org-html-inlinetask (inlinetask contents info)
  2421. "Transcode an INLINETASK element from Org to HTML.
  2422. CONTENTS holds the contents of the block. INFO is a plist
  2423. holding contextual information."
  2424. (let* ((todo (and (plist-get info :with-todo-keywords)
  2425. (let ((todo (org-element-property :todo-keyword inlinetask)))
  2426. (and todo (org-export-data todo info)))))
  2427. (todo-type (and todo (org-element-property :todo-type inlinetask)))
  2428. (priority (and (plist-get info :with-priority)
  2429. (org-element-property :priority inlinetask)))
  2430. (text (org-export-data (org-element-property :title inlinetask) info))
  2431. (tags (and (plist-get info :with-tags)
  2432. (org-export-get-tags inlinetask info))))
  2433. (funcall (plist-get info :html-format-inlinetask-function)
  2434. todo todo-type priority text tags contents info)))
  2435. (defun org-html-format-inlinetask-default-function
  2436. (todo todo-type priority text tags contents info)
  2437. "Default format function for inlinetasks.
  2438. See `org-html-format-inlinetask-function' for details."
  2439. (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
  2440. (org-html-format-headline-default-function
  2441. todo todo-type priority text tags info)
  2442. (org-html-close-tag "br" nil info)
  2443. contents))
  2444. ;;;; Italic
  2445. (defun org-html-italic (_italic contents info)
  2446. "Transcode ITALIC from Org to HTML.
  2447. CONTENTS is the text with italic markup. INFO is a plist holding
  2448. contextual information."
  2449. (format
  2450. (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
  2451. contents))
  2452. ;;;; Item
  2453. (defun org-html-checkbox (checkbox info)
  2454. "Format CHECKBOX into HTML.
  2455. INFO is a plist holding contextual information. See
  2456. `org-html-checkbox-type' for customization options."
  2457. (cdr (assq checkbox
  2458. (cdr (assq (plist-get info :html-checkbox-type)
  2459. org-html-checkbox-types)))))
  2460. (defun org-html-format-list-item (contents type checkbox info
  2461. &optional term-counter-id
  2462. headline)
  2463. "Format a list item into HTML."
  2464. (let ((class (if checkbox
  2465. (format " class=\"%s\""
  2466. (symbol-name checkbox)) ""))
  2467. (checkbox (concat (org-html-checkbox checkbox info)
  2468. (and checkbox " ")))
  2469. (br (org-html-close-tag "br" nil info))
  2470. (extra-newline (if (and (org-string-nw-p contents) headline) "\n" "")))
  2471. (concat
  2472. (pcase type
  2473. (`ordered
  2474. (let* ((counter term-counter-id)
  2475. (extra (if counter (format " value=\"%s\"" counter) "")))
  2476. (concat
  2477. (format "<li%s%s>" class extra)
  2478. (when headline (concat headline br)))))
  2479. (`unordered
  2480. (let* ((id term-counter-id)
  2481. (extra (if id (format " id=\"%s\"" id) "")))
  2482. (concat
  2483. (format "<li%s%s>" class extra)
  2484. (when headline (concat headline br)))))
  2485. (`descriptive
  2486. (let* ((term term-counter-id))
  2487. (setq term (or term "(no term)"))
  2488. ;; Check-boxes in descriptive lists are associated to tag.
  2489. (concat (format "<dt%s>%s</dt>"
  2490. class (concat checkbox term))
  2491. "<dd>"))))
  2492. (unless (eq type 'descriptive) checkbox)
  2493. extra-newline
  2494. (and (org-string-nw-p contents) (org-trim contents))
  2495. extra-newline
  2496. (pcase type
  2497. (`ordered "</li>")
  2498. (`unordered "</li>")
  2499. (`descriptive "</dd>")))))
  2500. (defun org-html-item (item contents info)
  2501. "Transcode an ITEM element from Org to HTML.
  2502. CONTENTS holds the contents of the item. INFO is a plist holding
  2503. contextual information."
  2504. (let* ((plain-list (org-export-get-parent item))
  2505. (type (org-element-property :type plain-list))
  2506. (counter (org-element-property :counter item))
  2507. (checkbox (org-element-property :checkbox item))
  2508. (tag (let ((tag (org-element-property :tag item)))
  2509. (and tag (org-export-data tag info)))))
  2510. (org-html-format-list-item
  2511. contents type checkbox info (or tag counter))))
  2512. ;;;; Keyword
  2513. (defun org-html-keyword (keyword _contents info)
  2514. "Transcode a KEYWORD element from Org to HTML.
  2515. CONTENTS is nil. INFO is a plist holding contextual information."
  2516. (let ((key (org-element-property :key keyword))
  2517. (value (org-element-property :value keyword)))
  2518. (cond
  2519. ((string= key "HTML") value)
  2520. ((string= key "TOC")
  2521. (let ((case-fold-search t))
  2522. (cond
  2523. ((string-match "\\<headlines\\>" value)
  2524. (let ((depth (and (string-match "\\<[0-9]+\\>" value)
  2525. (string-to-number (match-string 0 value))))
  2526. (scope
  2527. (cond
  2528. ((string-match ":target +\\(\".+?\"\\|\\S-+\\)" value) ;link
  2529. (org-export-resolve-link
  2530. (org-strip-quotes (match-string 1 value)) info))
  2531. ((string-match-p "\\<local\\>" value) keyword)))) ;local
  2532. (org-html-toc depth info scope)))
  2533. ((string= "listings" value) (org-html-list-of-listings info))
  2534. ((string= "tables" value) (org-html-list-of-tables info))))))))
  2535. ;;;; Latex Environment
  2536. (defun org-html-format-latex (latex-frag processing-type info)
  2537. "Format a LaTeX fragment LATEX-FRAG into HTML.
  2538. PROCESSING-TYPE designates the tool used for conversion. It can
  2539. be `mathjax', `verbatim', nil, t or symbols in
  2540. `org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
  2541. `imagemagick'. See `org-html-with-latex' for more information.
  2542. INFO is a plist containing export properties."
  2543. (let ((cache-relpath "") (cache-dir ""))
  2544. (unless (eq processing-type 'mathjax)
  2545. (let ((bfn (or (buffer-file-name)
  2546. (make-temp-name
  2547. (expand-file-name "latex" temporary-file-directory))))
  2548. (latex-header
  2549. (let ((header (plist-get info :latex-header)))
  2550. (and header
  2551. (concat (mapconcat
  2552. (lambda (line) (concat "#+LATEX_HEADER: " line))
  2553. (org-split-string header "\n")
  2554. "\n")
  2555. "\n")))))
  2556. (setq cache-relpath
  2557. (concat (file-name-as-directory org-preview-latex-image-directory)
  2558. (file-name-sans-extension
  2559. (file-name-nondirectory bfn)))
  2560. cache-dir (file-name-directory bfn))
  2561. ;; Re-create LaTeX environment from original buffer in
  2562. ;; temporary buffer so that dvipng/imagemagick can properly
  2563. ;; turn the fragment into an image.
  2564. (setq latex-frag (concat latex-header latex-frag))))
  2565. (with-temp-buffer
  2566. (insert latex-frag)
  2567. (org-format-latex cache-relpath nil nil cache-dir nil
  2568. "Creating LaTeX Image..." nil processing-type)
  2569. (buffer-string))))
  2570. (defun org-html--wrap-latex-environment (contents _ &optional caption label)
  2571. "Wrap CONTENTS string within appropriate environment for equations.
  2572. When optional arguments CAPTION and LABEL are given, use them for
  2573. caption and \"id\" attribute."
  2574. (format "\n<div%s class=\"equation-container\">\n%s%s\n</div>"
  2575. ;; ID.
  2576. (if (org-string-nw-p label) (format " id=\"%s\"" label) "")
  2577. ;; Contents.
  2578. (format "<span class=\"equation\">\n%s\n</span>" contents)
  2579. ;; Caption.
  2580. (if (not (org-string-nw-p caption)) ""
  2581. (format "\n<span class=\"equation-label\">\n%s\n</span>"
  2582. caption))))
  2583. (defun org-html--math-environment-p (element &optional _)
  2584. "Non-nil when ELEMENT is a LaTeX math environment.
  2585. Math environments match the regular expression defined in
  2586. `org-latex-math-environments-re'. This function is meant to be
  2587. used as a predicate for `org-export-get-ordinal' or a value to
  2588. `org-html-standalone-image-predicate'."
  2589. (string-match-p org-latex-math-environments-re
  2590. (org-element-property :value element)))
  2591. (defun org-html--unlabel-latex-environment (latex-frag)
  2592. "Change environment in LATEX-FRAG string to an unnumbered one.
  2593. For instance, change an 'equation' environment to 'equation*'."
  2594. (replace-regexp-in-string
  2595. "\\`[ \t]*\\\\begin{\\([^*]+?\\)}"
  2596. "\\1*"
  2597. (replace-regexp-in-string "^[ \t]*\\\\end{\\([^*]+?\\)}[ \r\t\n]*\\'"
  2598. "\\1*"
  2599. latex-frag nil nil 1)
  2600. nil nil 1))
  2601. (defun org-html-latex-environment (latex-environment _contents info)
  2602. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  2603. CONTENTS is nil. INFO is a plist holding contextual information."
  2604. (let ((processing-type (plist-get info :with-latex))
  2605. (latex-frag (org-remove-indentation
  2606. (org-element-property :value latex-environment)))
  2607. (attributes (org-export-read-attribute :attr_html latex-environment))
  2608. (label (and (org-element-property :name latex-environment)
  2609. (org-export-get-reference latex-environment info)))
  2610. (caption (number-to-string
  2611. (org-export-get-ordinal
  2612. latex-environment info nil
  2613. #'org-html--math-environment-p))))
  2614. (cond
  2615. ((memq processing-type '(t mathjax))
  2616. (org-html-format-latex
  2617. (if (org-string-nw-p label)
  2618. (replace-regexp-in-string "\\`.*"
  2619. (format "\\&\n\\\\label{%s}" label)
  2620. latex-frag)
  2621. latex-frag)
  2622. 'mathjax info))
  2623. ((assq processing-type org-preview-latex-process-alist)
  2624. (let ((formula-link
  2625. (org-html-format-latex
  2626. (org-html--unlabel-latex-environment latex-frag)
  2627. processing-type info)))
  2628. (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
  2629. (org-html--wrap-latex-environment
  2630. (org-html--format-image
  2631. (match-string 1 formula-link) attributes info)
  2632. info caption label))))
  2633. (t (org-html--wrap-latex-environment latex-frag info caption label)))))
  2634. ;;;; Latex Fragment
  2635. (defun org-html-latex-fragment (latex-fragment _contents info)
  2636. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2637. CONTENTS is nil. INFO is a plist holding contextual information."
  2638. (let ((latex-frag (org-element-property :value latex-fragment))
  2639. (processing-type (plist-get info :with-latex)))
  2640. (cond
  2641. ((memq processing-type '(t mathjax))
  2642. (org-html-format-latex latex-frag 'mathjax info))
  2643. ((assq processing-type org-preview-latex-process-alist)
  2644. (let ((formula-link
  2645. (org-html-format-latex latex-frag processing-type info)))
  2646. (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
  2647. (org-html--format-image (match-string 1 formula-link) nil info))))
  2648. (t latex-frag))))
  2649. ;;;; Line Break
  2650. (defun org-html-line-break (_line-break _contents info)
  2651. "Transcode a LINE-BREAK object from Org to HTML.
  2652. CONTENTS is nil. INFO is a plist holding contextual information."
  2653. (concat (org-html-close-tag "br" nil info) "\n"))
  2654. ;;;; Link
  2655. (defun org-html-image-link-filter (data _backend info)
  2656. (org-export-insert-image-links data info org-html-inline-image-rules))
  2657. (defun org-html-inline-image-p (link info)
  2658. "Non-nil when LINK is meant to appear as an image.
  2659. INFO is a plist used as a communication channel. LINK is an
  2660. inline image when it has no description and targets an image
  2661. file (see `org-html-inline-image-rules' for more information), or
  2662. if its description is a single link targeting an image file."
  2663. (if (not (org-element-contents link))
  2664. (org-export-inline-image-p
  2665. link (plist-get info :html-inline-image-rules))
  2666. (not
  2667. (let ((link-count 0))
  2668. (org-element-map (org-element-contents link)
  2669. (cons 'plain-text org-element-all-objects)
  2670. (lambda (obj)
  2671. (pcase (org-element-type obj)
  2672. (`plain-text (org-string-nw-p obj))
  2673. (`link (if (= link-count 1) t
  2674. (cl-incf link-count)
  2675. (not (org-export-inline-image-p
  2676. obj (plist-get info :html-inline-image-rules)))))
  2677. (_ t)))
  2678. info t)))))
  2679. (defvar org-html-standalone-image-predicate)
  2680. (defun org-html-standalone-image-p (element info)
  2681. "Non-nil if ELEMENT is a standalone image.
  2682. INFO is a plist holding contextual information.
  2683. An element or object is a standalone image when
  2684. - its type is `paragraph' and its sole content, save for white
  2685. spaces, is a link that qualifies as an inline image;
  2686. - its type is `link' and its containing paragraph has no other
  2687. content save white spaces.
  2688. Bind `org-html-standalone-image-predicate' to constrain paragraph
  2689. further. For example, to check for only captioned standalone
  2690. images, set it to:
  2691. (lambda (paragraph) (org-element-property :caption paragraph))"
  2692. (let ((paragraph (pcase (org-element-type element)
  2693. (`paragraph element)
  2694. (`link (org-export-get-parent element)))))
  2695. (and (eq (org-element-type paragraph) 'paragraph)
  2696. (or (not (fboundp 'org-html-standalone-image-predicate))
  2697. (funcall org-html-standalone-image-predicate paragraph))
  2698. (catch 'exit
  2699. (let ((link-count 0))
  2700. (org-element-map (org-element-contents paragraph)
  2701. (cons 'plain-text org-element-all-objects)
  2702. (lambda (obj)
  2703. (when (pcase (org-element-type obj)
  2704. (`plain-text (org-string-nw-p obj))
  2705. (`link (or (> (cl-incf link-count) 1)
  2706. (not (org-html-inline-image-p obj info))))
  2707. (_ t))
  2708. (throw 'exit nil)))
  2709. info nil 'link)
  2710. (= link-count 1))))))
  2711. (defun org-html-link (link desc info)
  2712. "Transcode a LINK object from Org to HTML.
  2713. DESC is the description part of the link, or the empty string.
  2714. INFO is a plist holding contextual information. See
  2715. `org-export-data'."
  2716. (let* ((link-org-files-as-html-maybe
  2717. (lambda (raw-path info)
  2718. ;; Treat links to `file.org' as links to `file.html', if
  2719. ;; needed. See `org-html-link-org-files-as-html'.
  2720. (cond
  2721. ((and (plist-get info :html-link-org-files-as-html)
  2722. (string= ".org"
  2723. (downcase (file-name-extension raw-path "."))))
  2724. (concat (file-name-sans-extension raw-path) "."
  2725. (plist-get info :html-extension)))
  2726. (t raw-path))))
  2727. (type (org-element-property :type link))
  2728. (raw-path (org-element-property :path link))
  2729. ;; Ensure DESC really exists, or set it to nil.
  2730. (desc (org-string-nw-p desc))
  2731. (path
  2732. (cond
  2733. ((member type '("http" "https" "ftp" "mailto" "news"))
  2734. (url-encode-url (concat type ":" raw-path)))
  2735. ((string= type "file")
  2736. ;; During publishing, turn absolute file names belonging
  2737. ;; to base directory into relative file names. Otherwise,
  2738. ;; append "file" protocol to absolute file name.
  2739. (setq raw-path
  2740. (org-export-file-uri
  2741. (org-publish-file-relative-name raw-path info)))
  2742. ;; Possibly append `:html-link-home' to relative file
  2743. ;; name.
  2744. (let ((home (and (plist-get info :html-link-home)
  2745. (org-trim (plist-get info :html-link-home)))))
  2746. (when (and home
  2747. (plist-get info :html-link-use-abs-url)
  2748. (file-name-absolute-p raw-path))
  2749. (setq raw-path (concat (file-name-as-directory home) raw-path))))
  2750. ;; Maybe turn ".org" into ".html".
  2751. (setq raw-path (funcall link-org-files-as-html-maybe raw-path info))
  2752. ;; Add search option, if any. A search option can be
  2753. ;; relative to a custom-id, a headline title, a name or
  2754. ;; a target.
  2755. (let ((option (org-element-property :search-option link)))
  2756. (if (not option) raw-path
  2757. (let ((path (org-element-property :path link)))
  2758. (concat raw-path
  2759. "#"
  2760. (org-publish-resolve-external-link option path t))))))
  2761. (t raw-path)))
  2762. (attributes-plist
  2763. (org-combine-plists
  2764. ;; Extract attributes from parent's paragraph. HACK: Only
  2765. ;; do this for the first link in parent (inner image link
  2766. ;; for inline images). This is needed as long as
  2767. ;; attributes cannot be set on a per link basis.
  2768. (let* ((parent (org-export-get-parent-element link))
  2769. (link (let ((container (org-export-get-parent link)))
  2770. (if (and (eq 'link (org-element-type container))
  2771. (org-html-inline-image-p link info))
  2772. container
  2773. link))))
  2774. (and (eq link (org-element-map parent 'link #'identity info t))
  2775. (org-export-read-attribute :attr_html parent)))
  2776. ;; Also add attributes from link itself. Currently, those
  2777. ;; need to be added programmatically before `org-html-link'
  2778. ;; is invoked, for example, by backends building upon HTML
  2779. ;; export.
  2780. (org-export-read-attribute :attr_html link)))
  2781. (attributes
  2782. (let ((attr (org-html--make-attribute-string attributes-plist)))
  2783. (if (org-string-nw-p attr) (concat " " attr) ""))))
  2784. (cond
  2785. ;; Link type is handled by a special function.
  2786. ((org-export-custom-protocol-maybe link desc 'html))
  2787. ;; Image file.
  2788. ((and (plist-get info :html-inline-images)
  2789. (org-export-inline-image-p
  2790. link (plist-get info :html-inline-image-rules)))
  2791. (org-html--format-image path attributes-plist info))
  2792. ;; Radio target: Transcode target's contents and use them as
  2793. ;; link's description.
  2794. ((string= type "radio")
  2795. (let ((destination (org-export-resolve-radio-link link info)))
  2796. (if (not destination) desc
  2797. (format "<a href=\"#%s\"%s>%s</a>"
  2798. (org-export-get-reference destination info)
  2799. attributes
  2800. desc))))
  2801. ;; Links pointing to a headline: Find destination and build
  2802. ;; appropriate referencing command.
  2803. ((member type '("custom-id" "fuzzy" "id"))
  2804. (let ((destination (if (string= type "fuzzy")
  2805. (org-export-resolve-fuzzy-link link info)
  2806. (org-export-resolve-id-link link info))))
  2807. (pcase (org-element-type destination)
  2808. ;; ID link points to an external file.
  2809. (`plain-text
  2810. (let ((fragment (concat "ID-" path))
  2811. ;; Treat links to ".org" files as ".html", if needed.
  2812. (path (funcall link-org-files-as-html-maybe
  2813. destination info)))
  2814. (format "<a href=\"%s#%s\"%s>%s</a>"
  2815. path fragment attributes (or desc destination))))
  2816. ;; Fuzzy link points nowhere.
  2817. (`nil
  2818. (format "<i>%s</i>"
  2819. (or desc
  2820. (org-export-data
  2821. (org-element-property :raw-link link) info))))
  2822. ;; Link points to a headline.
  2823. (`headline
  2824. (let ((href (or (org-element-property :CUSTOM_ID destination)
  2825. (org-export-get-reference destination info)))
  2826. ;; What description to use?
  2827. (desc
  2828. ;; Case 1: Headline is numbered and LINK has no
  2829. ;; description. Display section number.
  2830. (if (and (org-export-numbered-headline-p destination info)
  2831. (not desc))
  2832. (mapconcat #'number-to-string
  2833. (org-export-get-headline-number
  2834. destination info) ".")
  2835. ;; Case 2: Either the headline is un-numbered or
  2836. ;; LINK has a custom description. Display LINK's
  2837. ;; description or headline's title.
  2838. (or desc
  2839. (org-export-data
  2840. (org-element-property :title destination) info)))))
  2841. (format "<a href=\"#%s\"%s>%s</a>" href attributes desc)))
  2842. ;; Fuzzy link points to a target or an element.
  2843. (_
  2844. (if (and destination
  2845. (memq (plist-get info :with-latex) '(mathjax t))
  2846. (eq 'latex-environment (org-element-type destination))
  2847. (eq 'math (org-latex--environment-type destination)))
  2848. ;; Caption and labels are introduced within LaTeX
  2849. ;; environment. Use "eqref" macro to refer to those in
  2850. ;; the document.
  2851. (format "\\eqref{%s}"
  2852. (org-export-get-reference destination info))
  2853. (let* ((ref (org-export-get-reference destination info))
  2854. (org-html-standalone-image-predicate
  2855. #'org-html--has-caption-p)
  2856. (counter-predicate
  2857. (if (eq 'latex-environment (org-element-type destination))
  2858. #'org-html--math-environment-p
  2859. #'org-html--has-caption-p))
  2860. (number
  2861. (cond
  2862. (desc nil)
  2863. ((org-html-standalone-image-p destination info)
  2864. (org-export-get-ordinal
  2865. (org-element-map destination 'link #'identity info t)
  2866. info 'link 'org-html-standalone-image-p))
  2867. (t (org-export-get-ordinal
  2868. destination info nil counter-predicate))))
  2869. (desc
  2870. (cond (desc)
  2871. ((not number) "No description for this link")
  2872. ((numberp number) (number-to-string number))
  2873. (t (mapconcat #'number-to-string number ".")))))
  2874. (format "<a href=\"#%s\"%s>%s</a>" ref attributes desc)))))))
  2875. ;; Coderef: replace link with the reference name or the
  2876. ;; equivalent line number.
  2877. ((string= type "coderef")
  2878. (let ((fragment (concat "coderef-" (org-html-encode-plain-text path))))
  2879. (format "<a href=\"#%s\" %s%s>%s</a>"
  2880. fragment
  2881. (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, \
  2882. '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  2883. fragment fragment)
  2884. attributes
  2885. (format (org-export-get-coderef-format path desc)
  2886. (org-export-resolve-coderef path info)))))
  2887. ;; External link with a description part.
  2888. ((and path desc)
  2889. (format "<a href=\"%s\"%s>%s</a>"
  2890. (org-html-encode-plain-text path)
  2891. attributes
  2892. desc))
  2893. ;; External link without a description part.
  2894. (path
  2895. (let ((path (org-html-encode-plain-text path)))
  2896. (format "<a href=\"%s\"%s>%s</a>" path attributes path)))
  2897. ;; No path, only description. Try to do something useful.
  2898. (t
  2899. (format "<i>%s</i>" desc)))))
  2900. ;;;; Node Property
  2901. (defun org-html-node-property (node-property _contents _info)
  2902. "Transcode a NODE-PROPERTY element from Org to HTML.
  2903. CONTENTS is nil. INFO is a plist holding contextual
  2904. information."
  2905. (format "%s:%s"
  2906. (org-element-property :key node-property)
  2907. (let ((value (org-element-property :value node-property)))
  2908. (if value (concat " " value) ""))))
  2909. ;;;; Paragraph
  2910. (defun org-html-paragraph (paragraph contents info)
  2911. "Transcode a PARAGRAPH element from Org to HTML.
  2912. CONTENTS is the contents of the paragraph, as a string. INFO is
  2913. the plist used as a communication channel."
  2914. (let* ((parent (org-export-get-parent paragraph))
  2915. (parent-type (org-element-type parent))
  2916. (style '((footnote-definition " class=\"footpara\"")
  2917. (org-data " class=\"footpara\"")))
  2918. (attributes (org-html--make-attribute-string
  2919. (org-export-read-attribute :attr_html paragraph)))
  2920. (extra (or (cadr (assq parent-type style)) "")))
  2921. (cond
  2922. ((and (eq parent-type 'item)
  2923. (not (org-export-get-previous-element paragraph info))
  2924. (let ((followers (org-export-get-next-element paragraph info 2)))
  2925. (and (not (cdr followers))
  2926. (memq (org-element-type (car followers)) '(nil plain-list)))))
  2927. ;; First paragraph in an item has no tag if it is alone or
  2928. ;; followed, at most, by a sub-list.
  2929. contents)
  2930. ((org-html-standalone-image-p paragraph info)
  2931. ;; Standalone image.
  2932. (let ((caption
  2933. (let ((raw (org-export-data
  2934. (org-export-get-caption paragraph) info))
  2935. (org-html-standalone-image-predicate
  2936. #'org-html--has-caption-p))
  2937. (if (not (org-string-nw-p raw)) raw
  2938. (concat "<span class=\"figure-number\">"
  2939. (format (org-html--translate "Figure %d:" info)
  2940. (org-export-get-ordinal
  2941. (org-element-map paragraph 'link
  2942. #'identity info t)
  2943. info nil #'org-html-standalone-image-p))
  2944. " </span>"
  2945. raw))))
  2946. (label (and (org-element-property :name paragraph)
  2947. (org-export-get-reference paragraph info))))
  2948. (org-html--wrap-image contents info caption label)))
  2949. ;; Regular paragraph.
  2950. (t (format "<p%s%s>\n%s</p>"
  2951. (if (org-string-nw-p attributes)
  2952. (concat " " attributes) "")
  2953. extra contents)))))
  2954. ;;;; Plain List
  2955. (defun org-html-plain-list (plain-list contents _info)
  2956. "Transcode a PLAIN-LIST element from Org to HTML.
  2957. CONTENTS is the contents of the list. INFO is a plist holding
  2958. contextual information."
  2959. (let* ((type (pcase (org-element-property :type plain-list)
  2960. (`ordered "ol")
  2961. (`unordered "ul")
  2962. (`descriptive "dl")
  2963. (other (error "Unknown HTML list type: %s" other))))
  2964. (class (format "org-%s" type))
  2965. (attributes (org-export-read-attribute :attr_html plain-list)))
  2966. (format "<%s %s>\n%s</%s>"
  2967. type
  2968. (org-html--make-attribute-string
  2969. (plist-put attributes :class
  2970. (org-trim
  2971. (mapconcat #'identity
  2972. (list class (plist-get attributes :class))
  2973. " "))))
  2974. contents
  2975. type)))
  2976. ;;;; Plain Text
  2977. (defun org-html-convert-special-strings (string)
  2978. "Convert special characters in STRING to HTML."
  2979. (dolist (a org-html-special-string-regexps string)
  2980. (let ((re (car a))
  2981. (rpl (cdr a)))
  2982. (setq string (replace-regexp-in-string re rpl string t)))))
  2983. (defun org-html-encode-plain-text (text)
  2984. "Convert plain text characters from TEXT to HTML equivalent.
  2985. Possible conversions are set in `org-html-protect-char-alist'."
  2986. (dolist (pair org-html-protect-char-alist text)
  2987. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t))))
  2988. (defun org-html-plain-text (text info)
  2989. "Transcode a TEXT string from Org to HTML.
  2990. TEXT is the string to transcode. INFO is a plist holding
  2991. contextual information."
  2992. (let ((output text))
  2993. ;; Protect following characters: <, >, &.
  2994. (setq output (org-html-encode-plain-text output))
  2995. ;; Handle smart quotes. Be sure to provide original string since
  2996. ;; OUTPUT may have been modified.
  2997. (when (plist-get info :with-smart-quotes)
  2998. (setq output (org-export-activate-smart-quotes output :html info text)))
  2999. ;; Handle special strings.
  3000. (when (plist-get info :with-special-strings)
  3001. (setq output (org-html-convert-special-strings output)))
  3002. ;; Handle break preservation if required.
  3003. (when (plist-get info :preserve-breaks)
  3004. (setq output
  3005. (replace-regexp-in-string
  3006. "\\(\\\\\\\\\\)?[ \t]*\n"
  3007. (concat (org-html-close-tag "br" nil info) "\n") output)))
  3008. ;; Return value.
  3009. output))
  3010. ;; Planning
  3011. (defun org-html-planning (planning _contents info)
  3012. "Transcode a PLANNING element from Org to HTML.
  3013. CONTENTS is nil. INFO is a plist used as a communication
  3014. channel."
  3015. (format
  3016. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  3017. (org-trim
  3018. (mapconcat
  3019. (lambda (pair)
  3020. (let ((timestamp (cdr pair)))
  3021. (when timestamp
  3022. (let ((string (car pair)))
  3023. (format "<span class=\"timestamp-kwd\">%s</span> \
  3024. <span class=\"timestamp\">%s</span> "
  3025. string
  3026. (org-html-plain-text (org-timestamp-translate timestamp)
  3027. info))))))
  3028. `((,org-closed-string . ,(org-element-property :closed planning))
  3029. (,org-deadline-string . ,(org-element-property :deadline planning))
  3030. (,org-scheduled-string . ,(org-element-property :scheduled planning)))
  3031. ""))))
  3032. ;;;; Property Drawer
  3033. (defun org-html-property-drawer (_property-drawer contents _info)
  3034. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  3035. CONTENTS holds the contents of the drawer. INFO is a plist
  3036. holding contextual information."
  3037. (and (org-string-nw-p contents)
  3038. (format "<pre class=\"example\">\n%s</pre>" contents)))
  3039. ;;;; Quote Block
  3040. (defun org-html-quote-block (quote-block contents _info)
  3041. "Transcode a QUOTE-BLOCK element from Org to HTML.
  3042. CONTENTS holds the contents of the block. INFO is a plist
  3043. holding contextual information."
  3044. (format "<blockquote%s>\n%s</blockquote>"
  3045. (let* ((name (org-element-property :name quote-block))
  3046. (attributes (org-export-read-attribute :attr_html quote-block))
  3047. (a (org-html--make-attribute-string
  3048. (if (or (not name) (plist-member attributes :id))
  3049. attributes
  3050. (plist-put attributes :id name)))))
  3051. (if (org-string-nw-p a) (concat " " a) ""))
  3052. contents))
  3053. ;;;; Section
  3054. (defun org-html-section (section contents info)
  3055. "Transcode a SECTION element from Org to HTML.
  3056. CONTENTS holds the contents of the section. INFO is a plist
  3057. holding contextual information."
  3058. (let ((parent (org-export-get-parent-headline section)))
  3059. ;; Before first headline: no container, just return CONTENTS.
  3060. (if (not parent) contents
  3061. ;; Get div's class and id references.
  3062. (let* ((class-num (+ (org-export-get-relative-level parent info)
  3063. (1- (plist-get info :html-toplevel-hlevel))))
  3064. (section-number
  3065. (and (org-export-numbered-headline-p parent info)
  3066. (mapconcat
  3067. #'number-to-string
  3068. (org-export-get-headline-number parent info) "-"))))
  3069. ;; Build return value.
  3070. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>\n"
  3071. class-num
  3072. (or (org-element-property :CUSTOM_ID parent)
  3073. section-number
  3074. (org-export-get-reference parent info))
  3075. (or contents ""))))))
  3076. ;;;; Radio Target
  3077. (defun org-html-radio-target (radio-target text info)
  3078. "Transcode a RADIO-TARGET object from Org to HTML.
  3079. TEXT is the text of the target. INFO is a plist holding
  3080. contextual information."
  3081. (let ((ref (org-export-get-reference radio-target info)))
  3082. (org-html--anchor ref text nil info)))
  3083. ;;;; Special Block
  3084. (defun org-html-special-block (special-block contents info)
  3085. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  3086. CONTENTS holds the contents of the block. INFO is a plist
  3087. holding contextual information."
  3088. (let* ((block-type (org-element-property :type special-block))
  3089. (html5-fancy (and (org-html--html5-fancy-p info)
  3090. (member block-type org-html-html5-elements)))
  3091. (attributes (org-export-read-attribute :attr_html special-block)))
  3092. (unless html5-fancy
  3093. (let ((class (plist-get attributes :class)))
  3094. (setq attributes (plist-put attributes :class
  3095. (if class (concat class " " block-type)
  3096. block-type)))))
  3097. (let* ((contents (or contents ""))
  3098. (name (org-element-property :name special-block))
  3099. (a (org-html--make-attribute-string
  3100. (if (or (not name) (plist-member attributes :id))
  3101. attributes
  3102. (plist-put attributes :id name))))
  3103. (str (if (org-string-nw-p a) (concat " " a) "")))
  3104. (if html5-fancy
  3105. (format "<%s%s>\n%s</%s>" block-type str contents block-type)
  3106. (format "<div%s>\n%s\n</div>" str contents)))))
  3107. ;;;; Src Block
  3108. (defun org-html-src-block (src-block _contents info)
  3109. "Transcode a SRC-BLOCK element from Org to HTML.
  3110. CONTENTS holds the contents of the item. INFO is a plist holding
  3111. contextual information."
  3112. (if (org-export-read-attribute :attr_html src-block :textarea)
  3113. (org-html--textarea-block src-block)
  3114. (let* ((lang (org-element-property :language src-block))
  3115. (code (org-html-format-code src-block info))
  3116. (label (let ((lbl (and (org-element-property :name src-block)
  3117. (org-export-get-reference src-block info))))
  3118. (if lbl (format " id=\"%s\"" lbl) "")))
  3119. (klipsify (and (plist-get info :html-klipsify-src)
  3120. (member lang '("javascript" "js"
  3121. "ruby" "scheme" "clojure" "php" "html")))))
  3122. (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
  3123. (format "<div class=\"org-src-container\">\n%s%s\n</div>"
  3124. ;; Build caption.
  3125. (let ((caption (org-export-get-caption src-block)))
  3126. (if (not caption) ""
  3127. (let ((listing-number
  3128. (format
  3129. "<span class=\"listing-number\">%s </span>"
  3130. (format
  3131. (org-html--translate "Listing %d:" info)
  3132. (org-export-get-ordinal
  3133. src-block info nil #'org-html--has-caption-p)))))
  3134. (format "<label class=\"org-src-name\">%s%s</label>"
  3135. listing-number
  3136. (org-trim (org-export-data caption info))))))
  3137. ;; Contents.
  3138. (if klipsify
  3139. (format "<pre><code class=\"src src-%s\"%s%s>%s</code></pre>"
  3140. lang
  3141. label
  3142. (if (string= lang "html")
  3143. " data-editor-type=\"html\""
  3144. "")
  3145. code)
  3146. (format "<pre class=\"src src-%s\"%s>%s</pre>"
  3147. lang label code)))))))
  3148. ;;;; Statistics Cookie
  3149. (defun org-html-statistics-cookie (statistics-cookie _contents _info)
  3150. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  3151. CONTENTS is nil. INFO is a plist holding contextual information."
  3152. (let ((cookie-value (org-element-property :value statistics-cookie)))
  3153. (format "<code>%s</code>" cookie-value)))
  3154. ;;;; Strike-Through
  3155. (defun org-html-strike-through (_strike-through contents info)
  3156. "Transcode STRIKE-THROUGH from Org to HTML.
  3157. CONTENTS is the text with strike-through markup. INFO is a plist
  3158. holding contextual information."
  3159. (format
  3160. (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
  3161. "%s")
  3162. contents))
  3163. ;;;; Subscript
  3164. (defun org-html-subscript (_subscript contents _info)
  3165. "Transcode a SUBSCRIPT object from Org to HTML.
  3166. CONTENTS is the contents of the object. INFO is a plist holding
  3167. contextual information."
  3168. (format "<sub>%s</sub>" contents))
  3169. ;;;; Superscript
  3170. (defun org-html-superscript (_superscript contents _info)
  3171. "Transcode a SUPERSCRIPT object from Org to HTML.
  3172. CONTENTS is the contents of the object. INFO is a plist holding
  3173. contextual information."
  3174. (format "<sup>%s</sup>" contents))
  3175. ;;;; Table Cell
  3176. (defun org-html-table-cell (table-cell contents info)
  3177. "Transcode a TABLE-CELL element from Org to HTML.
  3178. CONTENTS is nil. INFO is a plist used as a communication
  3179. channel."
  3180. (let* ((table-row (org-export-get-parent table-cell))
  3181. (table (org-export-get-parent-table table-cell))
  3182. (cell-attrs
  3183. (if (not (plist-get info :html-table-align-individual-fields)) ""
  3184. (format (if (and (boundp 'org-html-format-table-no-css)
  3185. org-html-format-table-no-css)
  3186. " align=\"%s\"" " class=\"org-%s\"")
  3187. (org-export-table-cell-alignment table-cell info)))))
  3188. (when (or (not contents) (string= "" (org-trim contents)))
  3189. (setq contents "&#xa0;"))
  3190. (cond
  3191. ((and (org-export-table-has-header-p table info)
  3192. (= 1 (org-export-table-row-group table-row info)))
  3193. (let ((header-tags (plist-get info :html-table-header-tags)))
  3194. (concat "\n" (format (car header-tags) "col" cell-attrs)
  3195. contents
  3196. (cdr header-tags))))
  3197. ((and (plist-get info :html-table-use-header-tags-for-first-column)
  3198. (zerop (cdr (org-export-table-cell-address table-cell info))))
  3199. (let ((header-tags (plist-get info :html-table-header-tags)))
  3200. (concat "\n" (format (car header-tags) "row" cell-attrs)
  3201. contents
  3202. (cdr header-tags))))
  3203. (t (let ((data-tags (plist-get info :html-table-data-tags)))
  3204. (concat "\n" (format (car data-tags) cell-attrs)
  3205. contents
  3206. (cdr data-tags)))))))
  3207. ;;;; Table Row
  3208. (defun org-html-table-row (table-row contents info)
  3209. "Transcode a TABLE-ROW element from Org to HTML.
  3210. CONTENTS is the contents of the row. INFO is a plist used as a
  3211. communication channel."
  3212. ;; Rules are ignored since table separators are deduced from
  3213. ;; borders of the current row.
  3214. (when (eq (org-element-property :type table-row) 'standard)
  3215. (let* ((group (org-export-table-row-group table-row info))
  3216. (number (org-export-table-row-number table-row info))
  3217. (start-group-p
  3218. (org-export-table-row-starts-rowgroup-p table-row info))
  3219. (end-group-p
  3220. (org-export-table-row-ends-rowgroup-p table-row info))
  3221. (topp (and (equal start-group-p '(top))
  3222. (equal end-group-p '(below top))))
  3223. (bottomp (and (equal start-group-p '(above))
  3224. (equal end-group-p '(bottom above))))
  3225. (row-open-tag
  3226. (pcase (plist-get info :html-table-row-open-tag)
  3227. ((and accessor (pred functionp))
  3228. (funcall accessor
  3229. number group start-group-p end-group-p topp bottomp))
  3230. (accessor accessor)))
  3231. (row-close-tag
  3232. (pcase (plist-get info :html-table-row-close-tag)
  3233. ((and accessor (pred functionp))
  3234. (funcall accessor
  3235. number group start-group-p end-group-p topp bottomp))
  3236. (accessor accessor)))
  3237. (group-tags
  3238. (cond
  3239. ;; Row belongs to second or subsequent groups.
  3240. ((not (= 1 group)) '("<tbody>" . "\n</tbody>"))
  3241. ;; Row is from first group. Table has >=1 groups.
  3242. ((org-export-table-has-header-p
  3243. (org-export-get-parent-table table-row) info)
  3244. '("<thead>" . "\n</thead>"))
  3245. ;; Row is from first and only group.
  3246. (t '("<tbody>" . "\n</tbody>")))))
  3247. (concat (and start-group-p (car group-tags))
  3248. (concat "\n"
  3249. row-open-tag
  3250. contents
  3251. "\n"
  3252. row-close-tag)
  3253. (and end-group-p (cdr group-tags))))))
  3254. ;;;; Table
  3255. (defun org-html-table-first-row-data-cells (table info)
  3256. "Transcode the first row of TABLE.
  3257. INFO is a plist used as a communication channel."
  3258. (let ((table-row
  3259. (org-element-map table 'table-row
  3260. (lambda (row)
  3261. (unless (eq (org-element-property :type row) 'rule) row))
  3262. info 'first-match))
  3263. (special-column-p (org-export-table-has-special-column-p table)))
  3264. (if (not special-column-p) (org-element-contents table-row)
  3265. (cdr (org-element-contents table-row)))))
  3266. (defun org-html-table--table.el-table (table _info)
  3267. "Format table.el tables into HTML.
  3268. INFO is a plist used as a communication channel."
  3269. (when (eq (org-element-property :type table) 'table.el)
  3270. (require 'table)
  3271. (let ((outbuf (with-current-buffer
  3272. (get-buffer-create "*org-export-table*")
  3273. (erase-buffer) (current-buffer))))
  3274. (with-temp-buffer
  3275. (insert (org-element-property :value table))
  3276. (goto-char 1)
  3277. (re-search-forward "^[ \t]*|[^|]" nil t)
  3278. (table-generate-source 'html outbuf))
  3279. (with-current-buffer outbuf
  3280. (prog1 (org-trim (buffer-string))
  3281. (kill-buffer) )))))
  3282. (defun org-html-table (table contents info)
  3283. "Transcode a TABLE element from Org to HTML.
  3284. CONTENTS is the contents of the table. INFO is a plist holding
  3285. contextual information."
  3286. (if (eq (org-element-property :type table) 'table.el)
  3287. ;; "table.el" table. Convert it using appropriate tools.
  3288. (org-html-table--table.el-table table info)
  3289. ;; Standard table.
  3290. (let* ((caption (org-export-get-caption table))
  3291. (number (org-export-get-ordinal
  3292. table info nil #'org-html--has-caption-p))
  3293. (attributes
  3294. (org-html--make-attribute-string
  3295. (org-combine-plists
  3296. (and (org-element-property :name table)
  3297. (list :id (org-export-get-reference table info)))
  3298. (and (not (org-html-html5-p info))
  3299. (plist-get info :html-table-attributes))
  3300. (org-export-read-attribute :attr_html table))))
  3301. (alignspec
  3302. (if (bound-and-true-p org-html-format-table-no-css)
  3303. "align=\"%s\""
  3304. "class=\"org-%s\""))
  3305. (table-column-specs
  3306. (lambda (table info)
  3307. (mapconcat
  3308. (lambda (table-cell)
  3309. (let ((alignment (org-export-table-cell-alignment
  3310. table-cell info)))
  3311. (concat
  3312. ;; Begin a colgroup?
  3313. (when (org-export-table-cell-starts-colgroup-p
  3314. table-cell info)
  3315. "\n<colgroup>")
  3316. ;; Add a column. Also specify its alignment.
  3317. (format "\n%s"
  3318. (org-html-close-tag
  3319. "col" (concat " " (format alignspec alignment)) info))
  3320. ;; End a colgroup?
  3321. (when (org-export-table-cell-ends-colgroup-p
  3322. table-cell info)
  3323. "\n</colgroup>"))))
  3324. (org-html-table-first-row-data-cells table info) "\n"))))
  3325. (format "<table%s>\n%s\n%s\n%s</table>"
  3326. (if (equal attributes "") "" (concat " " attributes))
  3327. (if (not caption) ""
  3328. (format (if (plist-get info :html-table-caption-above)
  3329. "<caption class=\"t-above\">%s</caption>"
  3330. "<caption class=\"t-bottom\">%s</caption>")
  3331. (concat
  3332. "<span class=\"table-number\">"
  3333. (format (org-html--translate "Table %d:" info) number)
  3334. "</span> " (org-export-data caption info))))
  3335. (funcall table-column-specs table info)
  3336. contents))))
  3337. ;;;; Target
  3338. (defun org-html-target (target _contents info)
  3339. "Transcode a TARGET object from Org to HTML.
  3340. CONTENTS is nil. INFO is a plist holding contextual
  3341. information."
  3342. (let ((ref (org-export-get-reference target info)))
  3343. (org-html--anchor ref nil nil info)))
  3344. ;;;; Timestamp
  3345. (defun org-html-timestamp (timestamp _contents info)
  3346. "Transcode a TIMESTAMP object from Org to HTML.
  3347. CONTENTS is nil. INFO is a plist holding contextual
  3348. information."
  3349. (let ((value (org-html-plain-text (org-timestamp-translate timestamp) info)))
  3350. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  3351. (replace-regexp-in-string "--" "&#x2013;" value))))
  3352. ;;;; Underline
  3353. (defun org-html-underline (_underline contents info)
  3354. "Transcode UNDERLINE from Org to HTML.
  3355. CONTENTS is the text with underline markup. INFO is a plist
  3356. holding contextual information."
  3357. (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
  3358. "%s")
  3359. contents))
  3360. ;;;; Verbatim
  3361. (defun org-html-verbatim (verbatim _contents info)
  3362. "Transcode VERBATIM from Org to HTML.
  3363. CONTENTS is nil. INFO is a plist holding contextual
  3364. information."
  3365. (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
  3366. (org-html-encode-plain-text (org-element-property :value verbatim))))
  3367. ;;;; Verse Block
  3368. (defun org-html-verse-block (_verse-block contents info)
  3369. "Transcode a VERSE-BLOCK element from Org to HTML.
  3370. CONTENTS is verse block contents. INFO is a plist holding
  3371. contextual information."
  3372. (format "<p class=\"verse\">\n%s</p>"
  3373. ;; Replace leading white spaces with non-breaking spaces.
  3374. (replace-regexp-in-string
  3375. "^[ \t]+" (lambda (m) (org-html--make-string (length m) "&#xa0;"))
  3376. ;; Replace each newline character with line break. Also
  3377. ;; remove any trailing "br" close-tag so as to avoid
  3378. ;; duplicates.
  3379. (let* ((br (org-html-close-tag "br" nil info))
  3380. (re (format "\\(?:%s\\)?[ \t]*\n" (regexp-quote br))))
  3381. (replace-regexp-in-string re (concat br "\n") contents)))))
  3382. ;;; Filter Functions
  3383. (defun org-html-final-function (contents _backend info)
  3384. "Filter to indent the HTML and convert HTML entities."
  3385. (with-temp-buffer
  3386. (insert contents)
  3387. (set-auto-mode t)
  3388. (when (plist-get info :html-indent)
  3389. (indent-region (point-min) (point-max)))
  3390. (buffer-substring-no-properties (point-min) (point-max))))
  3391. ;;; End-user functions
  3392. ;;;###autoload
  3393. (defun org-html-export-as-html
  3394. (&optional async subtreep visible-only body-only ext-plist)
  3395. "Export current buffer to an HTML buffer.
  3396. If narrowing is active in the current buffer, only export its
  3397. narrowed part.
  3398. If a region is active, export that region.
  3399. A non-nil optional argument ASYNC means the process should happen
  3400. asynchronously. The resulting buffer should be accessible
  3401. through the `org-export-stack' interface.
  3402. When optional argument SUBTREEP is non-nil, export the sub-tree
  3403. at point, extracting information from the headline properties
  3404. first.
  3405. When optional argument VISIBLE-ONLY is non-nil, don't export
  3406. contents of hidden elements.
  3407. When optional argument BODY-ONLY is non-nil, only write code
  3408. between \"<body>\" and \"</body>\" tags.
  3409. EXT-PLIST, when provided, is a property list with external
  3410. parameters overriding Org default settings, but still inferior to
  3411. file-local settings.
  3412. Export is done in a buffer named \"*Org HTML Export*\", which
  3413. will be displayed when `org-export-show-temporary-export-buffer'
  3414. is non-nil."
  3415. (interactive)
  3416. (org-export-to-buffer 'html "*Org HTML Export*"
  3417. async subtreep visible-only body-only ext-plist
  3418. (lambda () (set-auto-mode t))))
  3419. ;;;###autoload
  3420. (defun org-html-convert-region-to-html ()
  3421. "Assume the current region has Org syntax, and convert it to HTML.
  3422. This can be used in any buffer. For example, you can write an
  3423. itemized list in Org syntax in an HTML buffer and use this command
  3424. to convert it."
  3425. (interactive)
  3426. (org-export-replace-region-by 'html))
  3427. ;;;###autoload
  3428. (defun org-html-export-to-html
  3429. (&optional async subtreep visible-only body-only ext-plist)
  3430. "Export current buffer to a HTML file.
  3431. If narrowing is active in the current buffer, only export its
  3432. narrowed part.
  3433. If a region is active, export that region.
  3434. A non-nil optional argument ASYNC means the process should happen
  3435. asynchronously. The resulting file should be accessible through
  3436. the `org-export-stack' interface.
  3437. When optional argument SUBTREEP is non-nil, export the sub-tree
  3438. at point, extracting information from the headline properties
  3439. first.
  3440. When optional argument VISIBLE-ONLY is non-nil, don't export
  3441. contents of hidden elements.
  3442. When optional argument BODY-ONLY is non-nil, only write code
  3443. between \"<body>\" and \"</body>\" tags.
  3444. EXT-PLIST, when provided, is a property list with external
  3445. parameters overriding Org default settings, but still inferior to
  3446. file-local settings.
  3447. Return output file's name."
  3448. (interactive)
  3449. (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
  3450. org-html-extension
  3451. "html")))
  3452. (file (org-export-output-file-name extension subtreep))
  3453. (org-export-coding-system org-html-coding-system))
  3454. (org-export-to-file 'html file
  3455. async subtreep visible-only body-only ext-plist)))
  3456. ;;;###autoload
  3457. (defun org-html-publish-to-html (plist filename pub-dir)
  3458. "Publish an org file to HTML.
  3459. FILENAME is the filename of the Org file to be published. PLIST
  3460. is the property list for the given project. PUB-DIR is the
  3461. publishing directory.
  3462. Return output file name."
  3463. (org-publish-org-to 'html filename
  3464. (concat "." (or (plist-get plist :html-extension)
  3465. org-html-extension
  3466. "html"))
  3467. plist pub-dir))
  3468. (provide 'ox-html)
  3469. ;; Local variables:
  3470. ;; generated-autoload-file: "org-loaddefs.el"
  3471. ;; End:
  3472. ;;; ox-html.el ends here