ox-html.el 132 KB

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