ox-html.el 132 KB

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