ox-html.el 115 KB

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