ox-html.el 117 KB

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