ox-html.el 124 KB

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