ox-html.el 119 KB

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