ox-html.el 127 KB

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