ox-html.el 124 KB

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