ox-html.el 130 KB

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