ox-html.el 145 KB

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