ox-html.el 125 KB

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