ox-html.el 124 KB

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