ox-html.el 128 KB

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