ox-html.el 125 KB

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