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