ox-html.el 144 KB

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