ox-html.el 114 KB

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