org-html.el 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752
  1. ;;; org-html.el --- HTML export for Org-mode
  2. ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;;; Code:
  23. (require 'org-exp)
  24. (require 'format-spec)
  25. (eval-when-compile (require 'cl))
  26. (declare-function org-id-find-id-file "org-id" (id))
  27. (declare-function htmlize-region "ext:htmlize" (beg end))
  28. (declare-function org-pop-to-buffer-same-window
  29. "org-compat" (&optional buffer-or-name norecord label))
  30. (defgroup org-export-html nil
  31. "Options specific for HTML export of Org-mode files."
  32. :tag "Org Export HTML"
  33. :group 'org-export)
  34. (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
  35. <h2 class=\"footnotes\">%s: </h2>
  36. <div id=\"text-footnotes\">
  37. %s
  38. </div>
  39. </div>"
  40. "Format for the footnotes section.
  41. Should contain a two instances of %s. The first will be replaced with the
  42. language-specific word for \"Footnotes\", the second one will be replaced
  43. by the footnotes themselves."
  44. :group 'org-export-html
  45. :type 'string)
  46. (defcustom org-export-html-footnote-format "<sup>%s</sup>"
  47. "The format for the footnote reference.
  48. %s will be replaced by the footnote reference itself."
  49. :group 'org-export-html
  50. :type 'string)
  51. (defcustom org-export-html-footnote-separator "<sup>, </sup>"
  52. "Text used to separate footnotes."
  53. :group 'org-export-html
  54. :version "24.1"
  55. :type 'string)
  56. (defcustom org-export-html-coding-system nil
  57. "Coding system for HTML export, defaults to `buffer-file-coding-system'."
  58. :group 'org-export-html
  59. :type 'coding-system)
  60. (defcustom org-export-html-extension "html"
  61. "The extension for exported HTML files."
  62. :group 'org-export-html
  63. :type 'string)
  64. (defcustom org-export-html-xml-declaration
  65. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  66. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  67. "The extension for exported HTML files.
  68. %s will be replaced with the charset of the exported file.
  69. This may be a string, or an alist with export extensions
  70. and corresponding declarations."
  71. :group 'org-export-html
  72. :type '(choice
  73. (string :tag "Single declaration")
  74. (repeat :tag "Dependent on extension"
  75. (cons (string :tag "Extension")
  76. (string :tag "Declaration")))))
  77. (defcustom org-export-html-style-include-scripts t
  78. "Non-nil means include the JavaScript snippets in exported HTML files.
  79. The actual script is defined in `org-export-html-scripts' and should
  80. not be modified."
  81. :group 'org-export-html
  82. :type 'boolean)
  83. (defvar org-export-html-scripts
  84. "<script type=\"text/javascript\">
  85. /*
  86. @licstart The following is the entire license notice for the
  87. JavaScript code in this tag.
  88. Copyright (C) 2012 Free Software Foundation, Inc.
  89. The JavaScript code in this tag is free software: you can
  90. redistribute it and/or modify it under the terms of the GNU
  91. General Public License (GNU GPL) as published by the Free Software
  92. Foundation, either version 3 of the License, or (at your option)
  93. any later version. The code is distributed WITHOUT ANY WARRANTY;
  94. without even the implied warranty of MERCHANTABILITY or FITNESS
  95. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  96. As additional permission under GNU GPL version 3 section 7, you
  97. may distribute non-source (e.g., minimized or compacted) forms of
  98. that code without the copy of the GNU GPL normally required by
  99. section 4, provided you include this license notice and a URL
  100. through which recipients can access the Corresponding Source.
  101. @licend The above is the entire license notice
  102. for the JavaScript code in this tag.
  103. */
  104. <!--/*--><![CDATA[/*><!--*/
  105. function CodeHighlightOn(elem, id)
  106. {
  107. var target = document.getElementById(id);
  108. if(null != target) {
  109. elem.cacheClassElem = elem.className;
  110. elem.cacheClassTarget = target.className;
  111. target.className = \"code-highlighted\";
  112. elem.className = \"code-highlighted\";
  113. }
  114. }
  115. function CodeHighlightOff(elem, id)
  116. {
  117. var target = document.getElementById(id);
  118. if(elem.cacheClassElem)
  119. elem.className = elem.cacheClassElem;
  120. if(elem.cacheClassTarget)
  121. target.className = elem.cacheClassTarget;
  122. }
  123. /*]]>*///-->
  124. </script>"
  125. "Basic JavaScript that is needed by HTML files produced by Org-mode.")
  126. (defconst org-export-html-style-default
  127. "<style type=\"text/css\">
  128. <!--/*--><![CDATA[/*><!--*/
  129. html { font-family: Times, serif; font-size: 12pt; }
  130. .title { text-align: center; }
  131. .todo { color: red; }
  132. .done { color: green; }
  133. .tag { background-color: #add8e6; font-weight:normal }
  134. .target { }
  135. .timestamp { color: #bebebe; }
  136. .timestamp-kwd { color: #5f9ea0; }
  137. .right {margin-left:auto; margin-right:0px; text-align:right;}
  138. .left {margin-left:0px; margin-right:auto; text-align:left;}
  139. .center {margin-left:auto; margin-right:auto; text-align:center;}
  140. p.verse { margin-left: 3% }
  141. pre {
  142. border: 1pt solid #AEBDCC;
  143. background-color: #F3F5F7;
  144. padding: 5pt;
  145. font-family: courier, monospace;
  146. font-size: 90%;
  147. overflow:auto;
  148. }
  149. table { border-collapse: collapse; }
  150. td, th { vertical-align: top; }
  151. th.right { text-align:center; }
  152. th.left { text-align:center; }
  153. th.center { text-align:center; }
  154. td.right { text-align:right; }
  155. td.left { text-align:left; }
  156. td.center { text-align:center; }
  157. dt { font-weight: bold; }
  158. div.figure { padding: 0.5em; }
  159. div.figure p { text-align: center; }
  160. div.inlinetask {
  161. padding:10px;
  162. border:2px solid gray;
  163. margin:10px;
  164. background: #ffffcc;
  165. }
  166. textarea { overflow-x: auto; }
  167. .linenr { font-size:smaller }
  168. .code-highlighted {background-color:#ffff00;}
  169. .org-info-js_info-navigation { border-style:none; }
  170. #org-info-js_console-label { font-size:10px; font-weight:bold;
  171. white-space:nowrap; }
  172. .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
  173. font-weight:bold; }
  174. /*]]>*/-->
  175. </style>"
  176. "The default style specification for exported HTML files.
  177. Please use the variables `org-export-html-style' and
  178. `org-export-html-style-extra' to add to this style. If you wish to not
  179. have the default style included, customize the variable
  180. `org-export-html-style-include-default'.")
  181. (defcustom org-export-html-style-include-default t
  182. "Non-nil means include the default style in exported HTML files.
  183. The actual style is defined in `org-export-html-style-default' and should
  184. not be modified. Use the variables `org-export-html-style' to add
  185. your own style information."
  186. :group 'org-export-html
  187. :type 'boolean)
  188. ;;;###autoload
  189. (put 'org-export-html-style-include-default 'safe-local-variable 'booleanp)
  190. (defcustom org-export-html-style ""
  191. "Org-wide style definitions for exported HTML files.
  192. This variable needs to contain the full HTML structure to provide a style,
  193. including the surrounding HTML tags. If you set the value of this variable,
  194. you should consider to include definitions for the following classes:
  195. title, todo, done, timestamp, timestamp-kwd, tag, target.
  196. For example, a valid value would be:
  197. <style type=\"text/css\">
  198. <![CDATA[
  199. p { font-weight: normal; color: gray; }
  200. h1 { color: black; }
  201. .title { text-align: center; }
  202. .todo, .timestamp-kwd { color: red; }
  203. .done { color: green; }
  204. ]]>
  205. </style>
  206. If you'd like to refer to an external style file, use something like
  207. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  208. As the value of this option simply gets inserted into the HTML <head> header,
  209. you can \"misuse\" it to add arbitrary text to the header.
  210. See also the variable `org-export-html-style-extra'."
  211. :group 'org-export-html
  212. :type 'string)
  213. ;;;###autoload
  214. (put 'org-export-html-style 'safe-local-variable 'stringp)
  215. (defcustom org-export-html-style-extra ""
  216. "Additional style information for HTML export.
  217. The value of this variable is inserted into the HTML buffer right after
  218. the value of `org-export-html-style'. Use this variable for per-file
  219. settings of style information, and do not forget to surround the style
  220. settings with <style>...</style> tags."
  221. :group 'org-export-html
  222. :type 'string)
  223. ;;;###autoload
  224. (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
  225. (defcustom org-export-html-mathjax-options
  226. '((path "http://orgmode.org/mathjax/MathJax.js")
  227. (scale "100")
  228. (align "center")
  229. (indent "2em")
  230. (mathml nil))
  231. "Options for MathJax setup.
  232. path The path where to find MathJax
  233. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  234. align How to align display math: left, center, or right
  235. indent If align is not center, how far from the left/right side?
  236. mathml Should a MathML player be used if available?
  237. This is faster and reduces bandwidth use, but currently
  238. sometimes has lower spacing quality. Therefore, the default is
  239. nil. When browsers get better, this switch can be flipped.
  240. You can also customize this for each buffer, using something like
  241. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  242. :group 'org-export-html
  243. :version "24.1"
  244. :type '(list :greedy t
  245. (list :tag "path (the path from where to load MathJax.js)"
  246. (const :format " " path) (string))
  247. (list :tag "scale (scaling for the displayed math)"
  248. (const :format " " scale) (string))
  249. (list :tag "align (alignment of displayed equations)"
  250. (const :format " " align) (string))
  251. (list :tag "indent (indentation with left or right alignment)"
  252. (const :format " " indent) (string))
  253. (list :tag "mathml (should MathML display be used is possible)"
  254. (const :format " " mathml) (boolean))))
  255. (defun org-export-html-mathjax-config (template options in-buffer)
  256. "Insert the user setup into the matchjax template."
  257. (let (name val (yes " ") (no "// ") x)
  258. (mapc
  259. (lambda (e)
  260. (setq name (car e) val (nth 1 e))
  261. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  262. (setq val (car (read-from-string
  263. (substring in-buffer (match-end 0))))))
  264. (if (not (stringp val)) (setq val (format "%s" val)))
  265. (setq template
  266. (replace-regexp-in-string
  267. (concat "%" (upcase (symbol-name name))) val template t t)))
  268. options)
  269. (setq val (nth 1 (assq 'mathml options)))
  270. (if (string-match (concat "\\<mathml:") in-buffer)
  271. (setq val (car (read-from-string
  272. (substring in-buffer (match-end 0))))))
  273. ;; Exchange prefixes depending on mathml setting
  274. (if (not val) (setq x yes yes no no x))
  275. ;; Replace cookies to turn on or off the config/jax lines
  276. (if (string-match ":MMLYES:" template)
  277. (setq template (replace-match yes t t template)))
  278. (if (string-match ":MMLNO:" template)
  279. (setq template (replace-match no t t template)))
  280. ;; Return the modified template
  281. template))
  282. (defcustom org-export-html-mathjax-template
  283. "<script type=\"text/javascript\" src=\"%PATH\">
  284. /**
  285. *
  286. * @source: %PATH
  287. *
  288. * @licstart The following is the entire license notice for the
  289. * JavaScript code in %PATH.
  290. *
  291. * Copyright (C) 2012 MathJax
  292. *
  293. * Licensed under the Apache License, Version 2.0 (the \"License\");
  294. * you may not use this file except in compliance with the License.
  295. * You may obtain a copy of the License at
  296. *
  297. * http://www.apache.org/licenses/LICENSE-2.0
  298. *
  299. * Unless required by applicable law or agreed to in writing, software
  300. * distributed under the License is distributed on an \"AS IS\" BASIS,
  301. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  302. * See the License for the specific language governing permissions and
  303. * limitations under the License.
  304. *
  305. * @licend The above is the entire license notice
  306. * for the JavaScript code in %PATH.
  307. *
  308. */
  309. /*
  310. @licstart The following is the entire license notice for the
  311. JavaScript code below.
  312. Copyright (C) 2012 Free Software Foundation, Inc.
  313. The JavaScript code below is free software: you can
  314. redistribute it and/or modify it under the terms of the GNU
  315. General Public License (GNU GPL) as published by the Free Software
  316. Foundation, either version 3 of the License, or (at your option)
  317. any later version. The code is distributed WITHOUT ANY WARRANTY;
  318. without even the implied warranty of MERCHANTABILITY or FITNESS
  319. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  320. As additional permission under GNU GPL version 3 section 7, you
  321. may distribute non-source (e.g., minimized or compacted) forms of
  322. that code without the copy of the GNU GPL normally required by
  323. section 4, provided you include this license notice and a URL
  324. through which recipients can access the Corresponding Source.
  325. @licend The above is the entire license notice
  326. for the JavaScript code below.
  327. */
  328. <!--/*--><![CDATA[/*><!--*/
  329. MathJax.Hub.Config({
  330. // Only one of the two following lines, depending on user settings
  331. // First allows browser-native MathML display, second forces HTML/CSS
  332. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  333. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  334. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  335. \"TeX/noUndefined.js\"],
  336. tex2jax: {
  337. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  338. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  339. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  340. ignoreClass: \"tex2jax_ignore\",
  341. processEscapes: false,
  342. processEnvironments: true,
  343. preview: \"TeX\"
  344. },
  345. showProcessingMessages: true,
  346. displayAlign: \"%ALIGN\",
  347. displayIndent: \"%INDENT\",
  348. \"HTML-CSS\": {
  349. scale: %SCALE,
  350. availableFonts: [\"STIX\",\"TeX\"],
  351. preferredFont: \"TeX\",
  352. webFont: \"TeX\",
  353. imageFont: \"TeX\",
  354. showMathMenu: true,
  355. },
  356. MMLorHTML: {
  357. prefer: {
  358. MSIE: \"MML\",
  359. Firefox: \"MML\",
  360. Opera: \"HTML\",
  361. other: \"HTML\"
  362. }
  363. }
  364. });
  365. /*]]>*///-->
  366. </script>"
  367. "The MathJax setup for XHTML files."
  368. :group 'org-export-html
  369. :version "24.1"
  370. :type 'string)
  371. (defcustom org-export-html-tag-class-prefix ""
  372. "Prefix to class names for TODO keywords.
  373. Each tag gets a class given by the tag itself, with this prefix.
  374. The default prefix is empty because it is nice to just use the keyword
  375. as a class name. But if you get into conflicts with other, existing
  376. CSS classes, then this prefix can be very useful."
  377. :group 'org-export-html
  378. :type 'string)
  379. (defcustom org-export-html-todo-kwd-class-prefix ""
  380. "Prefix to class names for TODO keywords.
  381. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  382. The default prefix is empty because it is nice to just use the keyword
  383. as a class name. But if you get into conflicts with other, existing
  384. CSS classes, then this prefix can be very useful."
  385. :group 'org-export-html
  386. :type 'string)
  387. (defcustom org-export-html-headline-anchor-format "<a name=\"%s\" id=\"%s\"></a>"
  388. "Format for anchors in HTML headlines.
  389. It requires to %s: both will be replaced by the anchor referring
  390. to the headline (e.g. \"sec-2\"). When set to `nil', don't insert
  391. HTML anchors in headlines."
  392. :group 'org-export-html
  393. :version "24.1"
  394. :type 'string)
  395. (defcustom org-export-html-preamble t
  396. "Non-nil means insert a preamble in HTML export.
  397. When `t', insert a string as defined by one of the formatting
  398. strings in `org-export-html-preamble-format'. When set to a
  399. string, this string overrides `org-export-html-preamble-format'.
  400. When set to a function, apply this function and insert the
  401. returned string. The function takes no argument, but you can
  402. use `opt-plist' to access the current export options.
  403. Setting :html-preamble in publishing projects will take
  404. precedence over this variable."
  405. :group 'org-export-html
  406. :type '(choice (const :tag "No preamble" nil)
  407. (const :tag "Default preamble" t)
  408. (string :tag "Custom format string")
  409. (function :tag "Function (must return a string)")))
  410. (defcustom org-export-html-preamble-format '(("en" ""))
  411. "Alist of languages and format strings for the HTML preamble.
  412. The first element of each list is the language code, as used for
  413. the #+LANGUAGE keyword.
  414. The second element of each list is a format string to format the
  415. preamble itself. This format string can contain these elements:
  416. %t stands for the title.
  417. %a stands for the author's name.
  418. %e stands for the author's email.
  419. %d stands for the date.
  420. If you need to use a \"%\" character, you need to escape it
  421. like that: \"%%\"."
  422. :group 'org-export-html
  423. :version "24.1"
  424. :type 'string)
  425. (defcustom org-export-html-postamble 'auto
  426. "Non-nil means insert a postamble in HTML export.
  427. When `t', insert a string as defined by the format string in
  428. `org-export-html-postamble-format'. When set to a string, this
  429. string overrides `org-export-html-postamble-format'. When set to
  430. 'auto, discard `org-export-html-postamble-format' and honor
  431. `org-export-author/email/creator-info' variables. When set to a
  432. function, apply this function and insert the returned string.
  433. The function takes no argument, but you can use `opt-plist' to
  434. access the current export options.
  435. Setting :html-postamble in publishing projects will take
  436. precedence over this variable."
  437. :group 'org-export-html
  438. :type '(choice (const :tag "No postamble" nil)
  439. (const :tag "Auto preamble" 'auto)
  440. (const :tag "Default format string" t)
  441. (string :tag "Custom format string")
  442. (function :tag "Function (must return a string)")))
  443. (defcustom org-export-html-postamble-format
  444. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  445. <p class=\"date\">Date: %d</p>
  446. <p class=\"creator\">Generated by %c</p>
  447. <p class=\"xhtml-validation\">%v</p>
  448. "))
  449. "Alist of languages and format strings for the HTML postamble.
  450. The first element of each list is the language code, as used for
  451. the #+LANGUAGE keyword.
  452. The second element of each list is a format string to format the
  453. postamble itself. This format string can contain these elements:
  454. %a stands for the author's name.
  455. %e stands for the author's email.
  456. %d stands for the date.
  457. %c will be replaced by information about Org/Emacs versions.
  458. %v will be replaced by `org-export-html-validation-link'.
  459. If you need to use a \"%\" character, you need to escape it
  460. like that: \"%%\"."
  461. :group 'org-export-html
  462. :version "24.1"
  463. :type 'string)
  464. (defcustom org-export-html-home/up-format
  465. "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  466. <a accesskey=\"h\" href=\"%s\"> UP </a>
  467. |
  468. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  469. </div>"
  470. "Snippet used to insert the HOME and UP links.
  471. This is a format string, the first %s will receive the UP link,
  472. the second the HOME link. If both `org-export-html-link-up' and
  473. `org-export-html-link-home' are empty, the entire snippet will be
  474. ignored."
  475. :group 'org-export-html
  476. :type 'string)
  477. (defcustom org-export-html-toplevel-hlevel 2
  478. "The <H> level for level 1 headings in HTML export.
  479. This is also important for the classes that will be wrapped around headlines
  480. and outline structure. If this variable is 1, the top-level headlines will
  481. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  482. and outline-text-1. If this is 2, all of these will get a 2 instead.
  483. The default for this variable is 2, because we use <h1> for formatting the
  484. document title."
  485. :group 'org-export-html
  486. :type 'string)
  487. (defcustom org-export-html-link-org-files-as-html t
  488. "Non-nil means make file links to `file.org' point to `file.html'.
  489. When org-mode is exporting an org-mode file to HTML, links to
  490. non-html files are directly put into a href tag in HTML.
  491. However, links to other Org-mode files (recognized by the
  492. extension `.org.) should become links to the corresponding html
  493. file, assuming that the linked org-mode file will also be
  494. converted to HTML.
  495. When nil, the links still point to the plain `.org' file."
  496. :group 'org-export-html
  497. :type 'boolean)
  498. (defcustom org-export-html-inline-images 'maybe
  499. "Non-nil means inline images into exported HTML pages.
  500. This is done using an <img> tag. When nil, an anchor with href is used to
  501. link to the image. If this option is `maybe', then images in links with
  502. an empty description will be inlined, while images with a description will
  503. be linked only."
  504. :group 'org-export-html
  505. :type '(choice (const :tag "Never" nil)
  506. (const :tag "Always" t)
  507. (const :tag "When there is no description" maybe)))
  508. (defcustom org-export-html-inline-image-extensions
  509. '("png" "jpeg" "jpg" "gif" "svg")
  510. "Extensions of image files that can be inlined into HTML."
  511. :group 'org-export-html
  512. :type '(repeat (string :tag "Extension")))
  513. (defcustom org-export-html-table-tag
  514. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  515. "The HTML tag that is used to start a table.
  516. This must be a <table> tag, but you may change the options like
  517. borders and spacing."
  518. :group 'org-export-html
  519. :type 'string)
  520. (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  521. "The opening tag for table header fields.
  522. This is customizable so that alignment options can be specified.
  523. The first %s will be filled with the scope of the field, either row or col.
  524. The second %s will be replaced by a style entry to align the field.
  525. See also the variable `org-export-html-table-use-header-tags-for-first-column'.
  526. See also the variable `org-export-html-table-align-individual-fields'."
  527. :group 'org-export-tables
  528. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  529. (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
  530. "The opening tag for table data fields.
  531. This is customizable so that alignment options can be specified.
  532. The first %s will be filled with the scope of the field, either row or col.
  533. The second %s will be replaced by a style entry to align the field.
  534. See also the variable `org-export-html-table-align-individual-fields'."
  535. :group 'org-export-tables
  536. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  537. (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
  538. "The opening tag for table data fields.
  539. This is customizable so that alignment options can be specified.
  540. Instead of strings, these can be Lisp forms that will be evaluated
  541. for each row in order to construct the table row tags. During evaluation,
  542. the variable `head' will be true when this is a header line, nil when this
  543. is a body line. And the variable `nline' will contain the line number,
  544. starting from 1 in the first header line. For example
  545. (setq org-export-table-row-tags
  546. (cons '(if head
  547. \"<tr>\"
  548. (if (= (mod nline 2) 1)
  549. \"<tr class=\\\"tr-odd\\\">\"
  550. \"<tr class=\\\"tr-even\\\">\"))
  551. \"</tr>\"))
  552. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  553. :group 'org-export-tables
  554. :type '(cons
  555. (choice :tag "Opening tag"
  556. (string :tag "Specify")
  557. (sexp))
  558. (choice :tag "Closing tag"
  559. (string :tag "Specify")
  560. (sexp))))
  561. (defcustom org-export-html-table-align-individual-fields t
  562. "Non-nil means attach style attributes for alignment to each table field.
  563. When nil, alignment will only be specified in the column tags, but this
  564. is ignored by some browsers (like Firefox, Safari). Opera does it right
  565. though."
  566. :group 'org-export-tables
  567. :version "24.1"
  568. :type 'boolean)
  569. (defcustom org-export-html-table-use-header-tags-for-first-column nil
  570. "Non-nil means format column one in tables with header tags.
  571. When nil, also column one will use data tags."
  572. :group 'org-export-tables
  573. :type 'boolean)
  574. (defcustom org-export-html-validation-link
  575. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  576. "Link to HTML validation service."
  577. :group 'org-export-html
  578. :type 'string)
  579. ;; FIXME Obsolete since Org 7.7
  580. ;; Use the :timestamp option or `org-export-time-stamp-file' instead
  581. (defvar org-export-html-with-timestamp nil
  582. "If non-nil, write container for HTML-helper-mode timestamp.")
  583. ;; FIXME Obsolete since Org 7.7
  584. (defvar org-export-html-html-helper-timestamp
  585. "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
  586. "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
  587. (defcustom org-export-html-protect-char-alist
  588. '(("&" . "&amp;")
  589. ("<" . "&lt;")
  590. (">" . "&gt;"))
  591. "Alist of characters to be converted by `org-html-protect'."
  592. :group 'org-export-html
  593. :version "24.1"
  594. :type '(repeat (cons (string :tag "Character")
  595. (string :tag "HTML equivalent"))))
  596. (defgroup org-export-htmlize nil
  597. "Options for processing examples with htmlize.el."
  598. :tag "Org Export Htmlize"
  599. :group 'org-export-html)
  600. (defcustom org-export-htmlize-output-type 'inline-css
  601. "Output type to be used by htmlize when formatting code snippets.
  602. Choices are `css', to export the CSS selectors only, or `inline-css', to
  603. export the CSS attribute values inline in the HTML. We use as default
  604. `inline-css', in order to make the resulting HTML self-containing.
  605. However, this will fail when using Emacs in batch mode for export, because
  606. then no rich font definitions are in place. It will also not be good if
  607. people with different Emacs setup contribute HTML files to a website,
  608. because the fonts will represent the individual setups. In these cases,
  609. it is much better to let Org/Htmlize assign classes only, and to use
  610. a style file to define the look of these classes.
  611. To get a start for your css file, start Emacs session and make sure that
  612. all the faces you are interested in are defined, for example by loading files
  613. in all modes you want. Then, use the command
  614. \\[org-export-htmlize-generate-css] to extract class definitions."
  615. :group 'org-export-htmlize
  616. :type '(choice (const css) (const inline-css)))
  617. (defcustom org-export-htmlize-css-font-prefix "org-"
  618. "The prefix for CSS class names for htmlize font specifications."
  619. :group 'org-export-htmlize
  620. :type 'string)
  621. (defcustom org-export-htmlized-org-css-url nil
  622. "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
  623. Normally when creating an htmlized version of an Org buffer, htmlize will
  624. create CSS to define the font colors. However, this does not work when
  625. converting in batch mode, and it also can look bad if different people
  626. with different fontification setup work on the same website.
  627. When this variable is non-nil, creating an htmlized version of an Org buffer
  628. using `org-export-as-org' will remove the internal CSS section and replace it
  629. with a link to this URL."
  630. :group 'org-export-htmlize
  631. :type '(choice
  632. (const :tag "Keep internal css" nil)
  633. (string :tag "URL or local href")))
  634. ;; FIXME: The following variable is obsolete since Org 7.7 but is
  635. ;; still declared and checked within code for compatibility reasons.
  636. ;; Use the custom variables `org-export-html-divs' instead.
  637. (defvar org-export-html-content-div "content"
  638. "The name of the container DIV that holds all the page contents.
  639. This variable is obsolete since Org version 7.7.
  640. Please set `org-export-html-divs' instead.")
  641. (defcustom org-export-html-divs '("preamble" "content" "postamble")
  642. "The name of the main divs for HTML export.
  643. This is a list of three strings, the first one for the preamble
  644. DIV, the second one for the content DIV and the third one for the
  645. postamble DIV."
  646. :group 'org-export-html
  647. :version "24.1"
  648. :type '(list
  649. (string :tag " Div for the preamble:")
  650. (string :tag " Div for the content:")
  651. (string :tag "Div for the postamble:")))
  652. (defcustom org-export-html-date-format-string "%Y-%m-%dT%R%z"
  653. "Format string to format the date and time.
  654. The default is an extended format of the ISO 8601 specification."
  655. :group 'org-export-html
  656. :version "24.1"
  657. :type 'string)
  658. ;;; Hooks
  659. (defvar org-export-html-after-blockquotes-hook nil
  660. "Hook run during HTML export, after blockquote, verse, center are done.")
  661. (defvar org-export-html-final-hook nil
  662. "Hook run at the end of HTML export, in the new buffer.")
  663. ;;; HTML export
  664. (defun org-export-html-preprocess (parameters)
  665. "Convert LaTeX fragments to images."
  666. (when (and org-current-export-file
  667. (plist-get parameters :LaTeX-fragments))
  668. (org-format-latex
  669. (concat org-latex-preview-ltxpng-directory (file-name-sans-extension
  670. (file-name-nondirectory
  671. org-current-export-file)))
  672. org-current-export-dir nil "Creating LaTeX image %s"
  673. nil nil
  674. (cond
  675. ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
  676. ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
  677. ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
  678. ((eq (plist-get parameters :LaTeX-fragments) 'imagemagick) 'imagemagick)
  679. ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng))))
  680. (goto-char (point-min))
  681. (let (label l1)
  682. (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
  683. (org-if-unprotected-at (match-beginning 1)
  684. (setq label (match-string 1))
  685. (save-match-data
  686. (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  687. (setq l1 (substring label (match-beginning 1)))
  688. (setq l1 label)))
  689. (replace-match (format "[[#%s][%s]]" label l1) t t)))))
  690. ;;;###autoload
  691. (defun org-export-as-html-and-open (arg)
  692. "Export the outline as HTML and immediately open it with a browser.
  693. If there is an active region, export only the region.
  694. The prefix ARG specifies how many levels of the outline should become
  695. headlines. The default is 3. Lower levels will become bulleted lists."
  696. (interactive "P")
  697. (org-export-as-html arg)
  698. (org-open-file buffer-file-name)
  699. (when org-export-kill-product-buffer-when-displayed
  700. (kill-buffer (current-buffer))))
  701. ;;;###autoload
  702. (defun org-export-as-html-batch ()
  703. "Call the function `org-export-as-html'.
  704. This function can be used in batch processing as:
  705. emacs --batch
  706. --load=$HOME/lib/emacs/org.el
  707. --eval \"(setq org-export-headline-levels 2)\"
  708. --visit=MyFile --funcall org-export-as-html-batch"
  709. (org-export-as-html org-export-headline-levels))
  710. ;;;###autoload
  711. (defun org-export-as-html-to-buffer (arg)
  712. "Call `org-export-as-html` with output to a temporary buffer.
  713. No file is created. The prefix ARG is passed through to `org-export-as-html'."
  714. (interactive "P")
  715. (org-export-as-html arg nil "*Org HTML Export*")
  716. (when org-export-show-temporary-export-buffer
  717. (switch-to-buffer-other-window "*Org HTML Export*")))
  718. ;;;###autoload
  719. (defun org-replace-region-by-html (beg end)
  720. "Assume the current region has org-mode syntax, and convert it to HTML.
  721. This can be used in any buffer. For example, you could write an
  722. itemized list in org-mode syntax in an HTML buffer and then use this
  723. command to convert it."
  724. (interactive "r")
  725. (let (reg html buf pop-up-frames)
  726. (save-window-excursion
  727. (if (derived-mode-p 'org-mode)
  728. (setq html (org-export-region-as-html
  729. beg end t 'string))
  730. (setq reg (buffer-substring beg end)
  731. buf (get-buffer-create "*Org tmp*"))
  732. (with-current-buffer buf
  733. (erase-buffer)
  734. (insert reg)
  735. (org-mode)
  736. (setq html (org-export-region-as-html
  737. (point-min) (point-max) t 'string)))
  738. (kill-buffer buf)))
  739. (delete-region beg end)
  740. (insert html)))
  741. ;;;###autoload
  742. (defun org-export-region-as-html (beg end &optional body-only buffer)
  743. "Convert region from BEG to END in org-mode buffer to HTML.
  744. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  745. contents, and only produce the region of converted text, useful for
  746. cut-and-paste operations.
  747. If BUFFER is a buffer or a string, use/create that buffer as a target
  748. of the converted HTML. If BUFFER is the symbol `string', return the
  749. produced HTML as a string and leave not buffer behind. For example,
  750. a Lisp program could call this function in the following way:
  751. (setq html (org-export-region-as-html beg end t 'string))
  752. When called interactively, the output buffer is selected, and shown
  753. in a window. A non-interactive call will only return the buffer."
  754. (interactive "r\nP")
  755. (when (org-called-interactively-p 'any)
  756. (setq buffer "*Org HTML Export*"))
  757. (let ((transient-mark-mode t) (zmacs-regions t)
  758. ext-plist rtn)
  759. (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
  760. (goto-char end)
  761. (set-mark (point)) ;; to activate the region
  762. (goto-char beg)
  763. (setq rtn (org-export-as-html nil ext-plist buffer body-only))
  764. (if (fboundp 'deactivate-mark) (deactivate-mark))
  765. (if (and (org-called-interactively-p 'any) (bufferp rtn))
  766. (switch-to-buffer-other-window rtn)
  767. rtn)))
  768. (defvar html-table-tag nil) ; dynamically scoped into this.
  769. (defvar org-par-open nil)
  770. ;;; org-html-cvt-link-fn
  771. (defconst org-html-cvt-link-fn
  772. nil
  773. "Function to convert link URLs to exportable URLs.
  774. Takes two arguments, TYPE and PATH.
  775. Returns exportable url as (TYPE PATH), or nil to signal that it
  776. didn't handle this case.
  777. Intended to be locally bound around a call to `org-export-as-html'." )
  778. (defun org-html-cvt-org-as-html (opt-plist type path)
  779. "Convert an org filename to an equivalent html filename.
  780. If TYPE is not file, just return `nil'.
  781. See variable `org-export-html-link-org-files-as-html'"
  782. (save-match-data
  783. (and
  784. org-export-html-link-org-files-as-html
  785. (string= type "file")
  786. (string-match "\\.org$" path)
  787. (progn
  788. (list
  789. "file"
  790. (concat
  791. (substring path 0 (match-beginning 0))
  792. "."
  793. (plist-get opt-plist :html-extension)))))))
  794. ;;; org-html-should-inline-p
  795. (defun org-html-should-inline-p (filename descp)
  796. "Return non-nil if link FILENAME should be inlined.
  797. The decision to inline the FILENAME link is based on the current
  798. settings. DESCP is the boolean of whether there was a link
  799. description. See variables `org-export-html-inline-images' and
  800. `org-export-html-inline-image-extensions'."
  801. (declare (special
  802. org-export-html-inline-images
  803. org-export-html-inline-image-extensions))
  804. (and (or (eq t org-export-html-inline-images)
  805. (and org-export-html-inline-images (not descp)))
  806. (org-file-image-p
  807. filename org-export-html-inline-image-extensions)))
  808. ;;; org-html-make-link
  809. (defun org-html-make-link (opt-plist type path fragment desc attr
  810. may-inline-p)
  811. "Make an HTML link.
  812. OPT-PLIST is an options list.
  813. TYPE is the device-type of the link (THIS://foo.html).
  814. PATH is the path of the link (http://THIS#location).
  815. FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
  816. DESC is the link description, if any.
  817. ATTR is a string of other attributes of the \"a\" element.
  818. MAY-INLINE-P allows inlining it as an image."
  819. (declare (special org-par-open))
  820. (save-match-data
  821. (let* ((filename path)
  822. ;;First pass. Just sanity stuff.
  823. (components-1
  824. (cond
  825. ((string= type "file")
  826. (list
  827. type
  828. ;;Substitute just if original path was absolute.
  829. ;;(Otherwise path must remain relative)
  830. (if (file-name-absolute-p path)
  831. (concat "file://" (expand-file-name path))
  832. path)))
  833. ((string= type "")
  834. (list nil path))
  835. (t (list type path))))
  836. ;;Second pass. Components converted so they can refer
  837. ;;to a remote site.
  838. (components-2
  839. (or
  840. (and org-html-cvt-link-fn
  841. (apply org-html-cvt-link-fn
  842. opt-plist components-1))
  843. (apply #'org-html-cvt-org-as-html
  844. opt-plist components-1)
  845. components-1))
  846. (type (first components-2))
  847. (thefile (second components-2)))
  848. ;;Third pass. Build final link except for leading type
  849. ;;spec.
  850. (cond
  851. ((or
  852. (not type)
  853. (string= type "http")
  854. (string= type "https")
  855. (string= type "file")
  856. (string= type "coderef"))
  857. (if fragment
  858. (setq thefile (concat thefile "#" fragment))))
  859. (t))
  860. ;;Final URL-build, for all types.
  861. (setq thefile
  862. (let
  863. ((str (org-export-html-format-href thefile)))
  864. (if (and type (not (or (string= "file" type)
  865. (string= "coderef" type))))
  866. (concat type ":" str)
  867. str)))
  868. (if (and
  869. may-inline-p
  870. ;;Can't inline a URL with a fragment.
  871. (not fragment))
  872. (progn
  873. (message "image %s %s" thefile org-par-open)
  874. (org-export-html-format-image thefile org-par-open))
  875. (concat
  876. "<a href=\"" thefile "\"" (if attr (concat " " attr)) ">"
  877. (org-export-html-format-desc desc)
  878. "</a>")))))
  879. (defun org-html-handle-links (org-line opt-plist)
  880. "Return ORG-LINE with markup of Org mode links.
  881. OPT-PLIST is the export options list."
  882. (let ((start 0)
  883. (current-dir (if buffer-file-name
  884. (file-name-directory buffer-file-name)
  885. default-directory))
  886. (link-validate (plist-get opt-plist :link-validation-function))
  887. type id-file fnc
  888. rpl path attr desc descp desc1 desc2 link)
  889. (while (string-match org-bracket-link-analytic-regexp++ org-line start)
  890. (setq start (match-beginning 0))
  891. (setq path (save-match-data (org-link-unescape
  892. (match-string 3 org-line))))
  893. (setq type (cond
  894. ((match-end 2) (match-string 2 org-line))
  895. ((save-match-data
  896. (or (file-name-absolute-p path)
  897. (string-match "^\\.\\.?/" path)))
  898. "file")
  899. (t "internal")))
  900. (setq path (org-extract-attributes path))
  901. (setq attr (get-text-property 0 'org-attributes path))
  902. (setq desc1 (if (match-end 5) (match-string 5 org-line))
  903. desc2 (if (match-end 2) (concat type ":" path) path)
  904. descp (and desc1 (not (equal desc1 desc2)))
  905. desc (or desc1 desc2))
  906. ;; Make an image out of the description if that is so wanted
  907. (when (and descp (org-file-image-p
  908. desc org-export-html-inline-image-extensions))
  909. (save-match-data
  910. (if (string-match "^file:" desc)
  911. (setq desc (substring desc (match-end 0)))))
  912. (setq desc (org-add-props
  913. (concat "<img src=\"" desc "\" alt=\""
  914. (file-name-nondirectory desc) "\"/>")
  915. '(org-protected t))))
  916. (cond
  917. ((equal type "internal")
  918. (let
  919. ((frag-0
  920. (if (= (string-to-char path) ?#)
  921. (substring path 1)
  922. path)))
  923. (setq rpl
  924. (org-html-make-link
  925. opt-plist
  926. ""
  927. ""
  928. (org-solidify-link-text
  929. (save-match-data (org-link-unescape frag-0))
  930. nil)
  931. desc attr nil))))
  932. ((and (equal type "id")
  933. (setq id-file (org-id-find-id-file path)))
  934. ;; This is an id: link to another file (if it was the same file,
  935. ;; it would have become an internal link...)
  936. (save-match-data
  937. (setq id-file (file-relative-name
  938. id-file
  939. (file-name-directory org-current-export-file)))
  940. (setq rpl
  941. (org-html-make-link opt-plist
  942. "file" id-file
  943. (concat (if (org-uuidgen-p path) "ID-") path)
  944. desc
  945. attr
  946. nil))))
  947. ((member type '("http" "https"))
  948. ;; standard URL, can inline as image
  949. (setq rpl
  950. (org-html-make-link opt-plist
  951. type path nil
  952. desc
  953. attr
  954. (org-html-should-inline-p path descp))))
  955. ((member type '("ftp" "mailto" "news"))
  956. ;; standard URL, can't inline as image
  957. (setq rpl
  958. (org-html-make-link opt-plist
  959. type path nil
  960. desc
  961. attr
  962. nil)))
  963. ((string= type "coderef")
  964. (let*
  965. ((coderef-str (format "coderef-%s" path))
  966. (attr-1
  967. (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  968. coderef-str coderef-str)))
  969. (setq rpl
  970. (org-html-make-link opt-plist
  971. type "" coderef-str
  972. (format
  973. (org-export-get-coderef-format
  974. path
  975. (and descp desc))
  976. (cdr (assoc path org-export-code-refs)))
  977. attr-1
  978. nil))))
  979. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  980. ;; The link protocol has a function for format the link
  981. (setq rpl
  982. (save-match-data
  983. (funcall fnc (org-link-unescape path) desc1 'html))))
  984. ((string= type "file")
  985. ;; FILE link
  986. (save-match-data
  987. (let*
  988. ((components
  989. (if
  990. (string-match "::\\(.*\\)" path)
  991. (list
  992. (replace-match "" t nil path)
  993. (match-string 1 path))
  994. (list path nil)))
  995. ;;The proper path, without a fragment
  996. (path-1
  997. (first components))
  998. ;;The raw fragment
  999. (fragment-0
  1000. (second components))
  1001. ;;Check the fragment. If it can't be used as
  1002. ;;target fragment we'll pass nil instead.
  1003. (fragment-1
  1004. (if
  1005. (and fragment-0
  1006. (not (string-match "^[0-9]*$" fragment-0))
  1007. (not (string-match "^\\*" fragment-0))
  1008. (not (string-match "^/.*/$" fragment-0)))
  1009. (org-solidify-link-text
  1010. (org-link-unescape fragment-0))
  1011. nil))
  1012. (desc-2
  1013. ;;Description minus "file:" and ".org"
  1014. (if (string-match "^file:" desc)
  1015. (let
  1016. ((desc-1 (replace-match "" t t desc)))
  1017. (if (string-match "\\.org$" desc-1)
  1018. (replace-match "" t t desc-1)
  1019. desc-1))
  1020. desc)))
  1021. (setq rpl
  1022. (if
  1023. (and
  1024. (functionp link-validate)
  1025. (not (funcall link-validate path-1 current-dir)))
  1026. desc
  1027. (org-html-make-link opt-plist
  1028. "file" path-1 fragment-1 desc-2 attr
  1029. (org-html-should-inline-p path-1 descp)))))))
  1030. (t
  1031. ;; just publish the path, as default
  1032. (setq rpl (concat "<i>&lt;" type ":"
  1033. (save-match-data (org-link-unescape path))
  1034. "&gt;</i>"))))
  1035. (setq org-line (replace-match rpl t t org-line)
  1036. start (+ start (length rpl))))
  1037. org-line))
  1038. ;;; org-export-as-html
  1039. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  1040. ;;;###autoload
  1041. (defun org-export-as-html (arg &optional ext-plist to-buffer body-only pub-dir)
  1042. "Export the outline as a pretty HTML file.
  1043. If there is an active region, export only the region. The prefix
  1044. ARG specifies how many levels of the outline should become
  1045. headlines. The default is 3. Lower levels will become bulleted
  1046. lists. EXT-PLIST is a property list with external parameters overriding
  1047. org-mode's default settings, but still inferior to file-local
  1048. settings. When TO-BUFFER is non-nil, create a buffer with that
  1049. name and export to that buffer. If TO-BUFFER is the symbol
  1050. `string', don't leave any buffer behind but just return the
  1051. resulting HTML as a string. When BODY-ONLY is set, don't produce
  1052. the file header and footer, simply return the content of
  1053. <body>...</body>, without even the body tags themselves. When
  1054. PUB-DIR is set, use this as the publishing directory."
  1055. (interactive "P")
  1056. (run-hooks 'org-export-first-hook)
  1057. ;; Make sure we have a file name when we need it.
  1058. (when (and (not (or to-buffer body-only))
  1059. (not buffer-file-name))
  1060. (if (buffer-base-buffer)
  1061. (org-set-local 'buffer-file-name
  1062. (with-current-buffer (buffer-base-buffer)
  1063. buffer-file-name))
  1064. (error "Need a file name to be able to export")))
  1065. (message "Exporting...")
  1066. (setq-default org-todo-line-regexp org-todo-line-regexp)
  1067. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  1068. (setq-default org-done-keywords org-done-keywords)
  1069. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  1070. (let* ((opt-plist
  1071. (org-export-process-option-filters
  1072. (org-combine-plists (org-default-export-plist)
  1073. ext-plist
  1074. (org-infile-export-plist))))
  1075. (body-only (or body-only (plist-get opt-plist :body-only)))
  1076. (style (concat (if (plist-get opt-plist :style-include-default)
  1077. org-export-html-style-default)
  1078. (plist-get opt-plist :style)
  1079. (plist-get opt-plist :style-extra)
  1080. "\n"
  1081. (if (plist-get opt-plist :style-include-scripts)
  1082. org-export-html-scripts)))
  1083. (html-extension (plist-get opt-plist :html-extension))
  1084. valid thetoc have-headings first-heading-pos
  1085. (odd org-odd-levels-only)
  1086. (region-p (org-region-active-p))
  1087. (rbeg (and region-p (region-beginning)))
  1088. (rend (and region-p (region-end)))
  1089. (subtree-p
  1090. (if (plist-get opt-plist :ignore-subtree-p)
  1091. nil
  1092. (when region-p
  1093. (save-excursion
  1094. (goto-char rbeg)
  1095. (and (org-at-heading-p)
  1096. (>= (org-end-of-subtree t t) rend))))))
  1097. (level-offset (if subtree-p
  1098. (save-excursion
  1099. (goto-char rbeg)
  1100. (+ (funcall outline-level)
  1101. (if org-odd-levels-only 1 0)))
  1102. 0))
  1103. (opt-plist (setq org-export-opt-plist
  1104. (if subtree-p
  1105. (org-export-add-subtree-options opt-plist rbeg)
  1106. opt-plist)))
  1107. ;; The following two are dynamically scoped into other
  1108. ;; routines below.
  1109. (org-current-export-dir
  1110. (or pub-dir (org-export-directory :html opt-plist)))
  1111. (org-current-export-file buffer-file-name)
  1112. (level 0) (org-line "") (origline "") txt todo
  1113. (umax nil)
  1114. (umax-toc nil)
  1115. (filename (if to-buffer nil
  1116. (expand-file-name
  1117. (concat
  1118. (file-name-sans-extension
  1119. (or (and subtree-p
  1120. (org-entry-get (region-beginning)
  1121. "EXPORT_FILE_NAME" t))
  1122. (file-name-nondirectory buffer-file-name)))
  1123. "." html-extension)
  1124. (file-name-as-directory
  1125. (or pub-dir (org-export-directory :html opt-plist))))))
  1126. (current-dir (if buffer-file-name
  1127. (file-name-directory buffer-file-name)
  1128. default-directory))
  1129. (auto-insert nil); Avoid any auto-insert stuff for the new file
  1130. (buffer (if to-buffer
  1131. (cond
  1132. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  1133. (t (get-buffer-create to-buffer)))
  1134. (find-file-noselect filename)))
  1135. (org-levels-open (make-vector org-level-max nil))
  1136. (date (org-html-expand (plist-get opt-plist :date)))
  1137. (author (org-html-expand (plist-get opt-plist :author)))
  1138. (html-validation-link (or org-export-html-validation-link ""))
  1139. (title (org-html-expand
  1140. (or (and subtree-p (org-export-get-title-from-subtree))
  1141. (plist-get opt-plist :title)
  1142. (and (not body-only)
  1143. (not
  1144. (plist-get opt-plist :skip-before-1st-heading))
  1145. (org-export-grab-title-from-buffer))
  1146. (and buffer-file-name
  1147. (file-name-sans-extension
  1148. (file-name-nondirectory buffer-file-name)))
  1149. "UNTITLED")))
  1150. (link-up (and (plist-get opt-plist :link-up)
  1151. (string-match "\\S-" (plist-get opt-plist :link-up))
  1152. (plist-get opt-plist :link-up)))
  1153. (link-home (and (plist-get opt-plist :link-home)
  1154. (string-match "\\S-" (plist-get opt-plist :link-home))
  1155. (plist-get opt-plist :link-home)))
  1156. (dummy (setq opt-plist (plist-put opt-plist :title title)))
  1157. (html-table-tag (plist-get opt-plist :html-table-tag))
  1158. (quote-re0 (concat "^ *" org-quote-string "\\( +\\|[ \t]*$\\)"))
  1159. (quote-re (format org-heading-keyword-regexp-format
  1160. org-quote-string))
  1161. (inquote nil)
  1162. (infixed nil)
  1163. (inverse nil)
  1164. (email (plist-get opt-plist :email))
  1165. (language (plist-get opt-plist :language))
  1166. (keywords (org-html-expand (plist-get opt-plist :keywords)))
  1167. (description (org-html-expand (plist-get opt-plist :description)))
  1168. (num (plist-get opt-plist :section-numbers))
  1169. (lang-words nil)
  1170. (head-count 0) cnt
  1171. (start 0)
  1172. (coding-system (and (boundp 'buffer-file-coding-system)
  1173. buffer-file-coding-system))
  1174. (coding-system-for-write (or org-export-html-coding-system
  1175. coding-system))
  1176. (save-buffer-coding-system (or org-export-html-coding-system
  1177. coding-system))
  1178. (charset (and coding-system-for-write
  1179. (fboundp 'coding-system-get)
  1180. (coding-system-get coding-system-for-write
  1181. 'mime-charset)))
  1182. (region
  1183. (buffer-substring
  1184. (if region-p (region-beginning) (point-min))
  1185. (if region-p (region-end) (point-max))))
  1186. (org-export-have-math nil)
  1187. (org-export-footnotes-seen nil)
  1188. (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
  1189. (custom-id (or (org-entry-get nil "CUSTOM_ID" t) ""))
  1190. (footnote-def-prefix (format "fn-%s" custom-id))
  1191. (footnote-ref-prefix (format "fnr-%s" custom-id))
  1192. (lines
  1193. (org-split-string
  1194. (org-export-preprocess-string
  1195. region
  1196. :emph-multiline t
  1197. :for-backend 'html
  1198. :skip-before-1st-heading
  1199. (plist-get opt-plist :skip-before-1st-heading)
  1200. :drawers (plist-get opt-plist :drawers)
  1201. :todo-keywords (plist-get opt-plist :todo-keywords)
  1202. :tasks (plist-get opt-plist :tasks)
  1203. :tags (plist-get opt-plist :tags)
  1204. :priority (plist-get opt-plist :priority)
  1205. :footnotes (plist-get opt-plist :footnotes)
  1206. :timestamps (plist-get opt-plist :timestamps)
  1207. :archived-trees
  1208. (plist-get opt-plist :archived-trees)
  1209. :select-tags (plist-get opt-plist :select-tags)
  1210. :exclude-tags (plist-get opt-plist :exclude-tags)
  1211. :add-text
  1212. (plist-get opt-plist :text)
  1213. :LaTeX-fragments
  1214. (plist-get opt-plist :LaTeX-fragments))
  1215. "[\r\n]"))
  1216. (mathjax
  1217. (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
  1218. (and org-export-have-math
  1219. (eq (plist-get opt-plist :LaTeX-fragments) t)))
  1220. (org-export-html-mathjax-config
  1221. org-export-html-mathjax-template
  1222. org-export-html-mathjax-options
  1223. (or (plist-get opt-plist :mathjax) ""))
  1224. ""))
  1225. table-open
  1226. table-buffer table-orig-buffer
  1227. ind
  1228. rpl path attr desc descp desc1 desc2 link
  1229. snumber fnc
  1230. footnotes footref-seen
  1231. href)
  1232. (let ((inhibit-read-only t))
  1233. (org-unmodified
  1234. (remove-text-properties (point-min) (point-max)
  1235. '(:org-license-to-kill t))))
  1236. (message "Exporting...")
  1237. (setq org-min-level (org-get-min-level lines level-offset))
  1238. (setq org-last-level org-min-level)
  1239. (org-init-section-numbers)
  1240. (cond
  1241. ((and date (string-match "%" date))
  1242. (setq date (format-time-string date)))
  1243. (date)
  1244. (t (setq date (format-time-string org-export-html-date-format-string))))
  1245. ;; Get the language-dependent settings
  1246. (setq lang-words (or (assoc language org-export-language-setup)
  1247. (assoc "en" org-export-language-setup)))
  1248. ;; Switch to the output buffer
  1249. (set-buffer buffer)
  1250. (let ((inhibit-read-only t)) (erase-buffer))
  1251. (fundamental-mode)
  1252. (org-install-letbind)
  1253. (and (fboundp 'set-buffer-file-coding-system)
  1254. (set-buffer-file-coding-system coding-system-for-write))
  1255. (let ((case-fold-search nil)
  1256. (org-odd-levels-only odd))
  1257. ;; create local variables for all options, to make sure all called
  1258. ;; functions get the correct information
  1259. (mapc (lambda (x)
  1260. (set (make-local-variable (nth 2 x))
  1261. (plist-get opt-plist (car x))))
  1262. org-export-plist-vars)
  1263. (setq umax (if arg (prefix-numeric-value arg)
  1264. org-export-headline-levels))
  1265. (setq umax-toc (if (integerp org-export-with-toc)
  1266. (min org-export-with-toc umax)
  1267. umax))
  1268. (unless body-only
  1269. ;; File header
  1270. (insert (format
  1271. "%s
  1272. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1273. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  1274. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">
  1275. <head>
  1276. <title>%s</title>
  1277. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  1278. <meta name=\"title\" content=\"%s\"/>
  1279. <meta name=\"generator\" content=\"Org-mode\"/>
  1280. <meta name=\"generated\" content=\"%s\"/>
  1281. <meta name=\"author\" content=\"%s\"/>
  1282. <meta name=\"description\" content=\"%s\"/>
  1283. <meta name=\"keywords\" content=\"%s\"/>
  1284. %s
  1285. %s
  1286. </head>
  1287. <body>
  1288. %s
  1289. "
  1290. (format
  1291. (or (and (stringp org-export-html-xml-declaration)
  1292. org-export-html-xml-declaration)
  1293. (cdr (assoc html-extension org-export-html-xml-declaration))
  1294. (cdr (assoc "html" org-export-html-xml-declaration))
  1295. "")
  1296. (or charset "iso-8859-1"))
  1297. language language
  1298. title
  1299. (or charset "iso-8859-1")
  1300. title date author description keywords
  1301. style
  1302. mathjax
  1303. (if (or link-up link-home)
  1304. (concat
  1305. (format org-export-html-home/up-format
  1306. (or link-up link-home)
  1307. (or link-home link-up))
  1308. "\n")
  1309. "")))
  1310. ;; insert html preamble
  1311. (when (plist-get opt-plist :html-preamble)
  1312. (let ((html-pre (plist-get opt-plist :html-preamble))
  1313. (html-pre-real-contents ""))
  1314. (cond ((stringp html-pre)
  1315. (setq html-pre-real-contents
  1316. (format-spec html-pre `((?t . ,title) (?a . ,author)
  1317. (?d . ,date) (?e . ,email)))))
  1318. ((functionp html-pre)
  1319. (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
  1320. (if (stringp (funcall html-pre)) (insert (funcall html-pre)))
  1321. (insert "\n</div>\n"))
  1322. (t
  1323. (setq html-pre-real-contents
  1324. (format-spec
  1325. (or (cadr (assoc (nth 0 lang-words)
  1326. org-export-html-preamble-format))
  1327. (cadr (assoc "en" org-export-html-preamble-format)))
  1328. `((?t . ,title) (?a . ,author)
  1329. (?d . ,date) (?e . ,email))))))
  1330. ;; don't output an empty preamble DIV
  1331. (unless (and (functionp html-pre)
  1332. (equal html-pre-real-contents ""))
  1333. (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
  1334. (insert html-pre-real-contents)
  1335. (insert "\n</div>\n"))))
  1336. ;; begin wrap around body
  1337. (insert (format "\n<div id=\"%s\">"
  1338. ;; FIXME org-export-html-content-div is obsolete since 7.7
  1339. (or org-export-html-content-div
  1340. (nth 1 org-export-html-divs)))
  1341. ;; FIXME this should go in the preamble but is here so
  1342. ;; that org-infojs can still find it
  1343. "\n<h1 class=\"title\">" title "</h1>\n"))
  1344. ;; insert body
  1345. (if org-export-with-toc
  1346. (progn
  1347. (push (format "<h%d>%s</h%d>\n"
  1348. org-export-html-toplevel-hlevel
  1349. (nth 3 lang-words)
  1350. org-export-html-toplevel-hlevel)
  1351. thetoc)
  1352. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  1353. (push "<ul>\n<li>" thetoc)
  1354. (setq lines
  1355. (mapcar
  1356. #'(lambda (org-line)
  1357. (if (and (string-match org-todo-line-regexp org-line)
  1358. (not (get-text-property 0 'org-protected org-line)))
  1359. ;; This is a headline
  1360. (progn
  1361. (setq have-headings t)
  1362. (setq level (- (match-end 1) (match-beginning 1)
  1363. level-offset)
  1364. level (org-tr-level level)
  1365. txt (save-match-data
  1366. (org-html-expand
  1367. (org-export-cleanup-toc-line
  1368. (match-string 3 org-line))))
  1369. todo
  1370. (or (and org-export-mark-todo-in-toc
  1371. (match-beginning 2)
  1372. (not (member (match-string 2 org-line)
  1373. org-done-keywords)))
  1374. ; TODO, not DONE
  1375. (and org-export-mark-todo-in-toc
  1376. (= level umax-toc)
  1377. (org-search-todo-below
  1378. org-line lines level))))
  1379. (if (string-match
  1380. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  1381. (setq txt (replace-match
  1382. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">\\1</span>" t nil txt)))
  1383. (if (string-match quote-re0 txt)
  1384. (setq txt (replace-match "" t t txt)))
  1385. (setq snumber (org-section-number level))
  1386. (if (and num (if (integerp num)
  1387. (>= num level)
  1388. num))
  1389. (setq txt (concat snumber " " txt)))
  1390. (if (<= level (max umax umax-toc))
  1391. (setq head-count (+ head-count 1)))
  1392. (if (<= level umax-toc)
  1393. (progn
  1394. (if (> level org-last-level)
  1395. (progn
  1396. (setq cnt (- level org-last-level))
  1397. (while (>= (setq cnt (1- cnt)) 0)
  1398. (push "\n<ul>\n<li>" thetoc))
  1399. (push "\n" thetoc)))
  1400. (if (< level org-last-level)
  1401. (progn
  1402. (setq cnt (- org-last-level level))
  1403. (while (>= (setq cnt (1- cnt)) 0)
  1404. (push "</li>\n</ul>" thetoc))
  1405. (push "\n" thetoc)))
  1406. ;; Check for targets
  1407. (while (string-match org-any-target-regexp org-line)
  1408. (setq org-line (replace-match
  1409. (concat "@<span class=\"target\">"
  1410. (match-string 1 org-line) "@</span> ")
  1411. t t org-line)))
  1412. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  1413. (setq txt (replace-match "" t t txt)))
  1414. (setq href
  1415. (replace-regexp-in-string
  1416. "\\." "-" (format "sec-%s" snumber)))
  1417. (setq href (org-solidify-link-text
  1418. (or (cdr (assoc href
  1419. org-export-preferred-target-alist)) href)))
  1420. (push
  1421. (format
  1422. (if todo
  1423. "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
  1424. "</li>\n<li><a href=\"#%s\">%s</a>")
  1425. href txt) thetoc)
  1426. (setq org-last-level level)))))
  1427. org-line)
  1428. lines))
  1429. (while (> org-last-level (1- org-min-level))
  1430. (setq org-last-level (1- org-last-level))
  1431. (push "</li>\n</ul>\n" thetoc))
  1432. (push "</div>\n" thetoc)
  1433. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  1434. (setq head-count 0)
  1435. (org-init-section-numbers)
  1436. (org-open-par)
  1437. (while (setq org-line (pop lines) origline org-line)
  1438. (catch 'nextline
  1439. ;; end of quote section?
  1440. (when (and inquote (string-match org-outline-regexp-bol org-line))
  1441. (insert "</pre>\n")
  1442. (org-open-par)
  1443. (setq inquote nil))
  1444. ;; inside a quote section?
  1445. (when inquote
  1446. (insert (org-html-protect org-line) "\n")
  1447. (throw 'nextline nil))
  1448. ;; Fixed-width, verbatim lines (examples)
  1449. (when (and org-export-with-fixed-width
  1450. (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" org-line))
  1451. (when (not infixed)
  1452. (setq infixed t)
  1453. (org-close-par-maybe)
  1454. (insert "<pre class=\"example\">\n"))
  1455. (insert (org-html-protect (match-string 3 org-line)) "\n")
  1456. (when (or (not lines)
  1457. (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
  1458. (car lines))))
  1459. (setq infixed nil)
  1460. (insert "</pre>\n")
  1461. (org-open-par))
  1462. (throw 'nextline nil))
  1463. ;; Protected HTML
  1464. (when (and (get-text-property 0 'org-protected org-line)
  1465. ;; Make sure it is the entire line that is protected
  1466. (not (< (or (next-single-property-change
  1467. 0 'org-protected org-line) 10000)
  1468. (length org-line))))
  1469. (let (par (ind (get-text-property 0 'original-indentation org-line)))
  1470. (when (re-search-backward
  1471. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  1472. (setq par (match-string 1))
  1473. (replace-match "\\2\n"))
  1474. (insert org-line "\n")
  1475. (while (and lines
  1476. (or (= (length (car lines)) 0)
  1477. (not ind)
  1478. (equal ind (get-text-property 0 'original-indentation (car lines))))
  1479. (or (= (length (car lines)) 0)
  1480. (get-text-property 0 'org-protected (car lines))))
  1481. (insert (pop lines) "\n"))
  1482. (and par (insert "<p>\n")))
  1483. (throw 'nextline nil))
  1484. ;; Blockquotes, verse, and center
  1485. (when (equal "ORG-BLOCKQUOTE-START" org-line)
  1486. (org-close-par-maybe)
  1487. (insert "<blockquote>\n")
  1488. (org-open-par)
  1489. (throw 'nextline nil))
  1490. (when (equal "ORG-BLOCKQUOTE-END" org-line)
  1491. (org-close-par-maybe)
  1492. (insert "\n</blockquote>\n")
  1493. (org-open-par)
  1494. (throw 'nextline nil))
  1495. (when (equal "ORG-VERSE-START" org-line)
  1496. (org-close-par-maybe)
  1497. (insert "\n<p class=\"verse\">\n")
  1498. (setq org-par-open t)
  1499. (setq inverse t)
  1500. (throw 'nextline nil))
  1501. (when (equal "ORG-VERSE-END" org-line)
  1502. (insert "</p>\n")
  1503. (setq org-par-open nil)
  1504. (org-open-par)
  1505. (setq inverse nil)
  1506. (throw 'nextline nil))
  1507. (when (equal "ORG-CENTER-START" org-line)
  1508. (org-close-par-maybe)
  1509. (insert "\n<div style=\"text-align: center\">")
  1510. (org-open-par)
  1511. (throw 'nextline nil))
  1512. (when (equal "ORG-CENTER-END" org-line)
  1513. (org-close-par-maybe)
  1514. (insert "\n</div>")
  1515. (org-open-par)
  1516. (throw 'nextline nil))
  1517. (run-hooks 'org-export-html-after-blockquotes-hook)
  1518. (when inverse
  1519. (let ((i (org-get-string-indentation org-line)))
  1520. (if (> i 0)
  1521. (setq org-line (concat (mapconcat 'identity
  1522. (make-list (* 2 i) "\\nbsp") "")
  1523. " " (org-trim org-line))))
  1524. (unless (string-match "\\\\\\\\[ \t]*$" org-line)
  1525. (setq org-line (concat org-line "\\\\")))))
  1526. ;; make targets to anchors
  1527. (setq start 0)
  1528. (while (string-match
  1529. "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" org-line start)
  1530. (cond
  1531. ((get-text-property (match-beginning 1) 'org-protected org-line)
  1532. (setq start (match-end 1)))
  1533. ((match-end 2)
  1534. (setq org-line (replace-match
  1535. (format
  1536. "@<a name=\"%s\" id=\"%s\">@</a>"
  1537. (org-solidify-link-text (match-string 1 org-line))
  1538. (org-solidify-link-text (match-string 1 org-line)))
  1539. t t org-line)))
  1540. ((and org-export-with-toc (equal (string-to-char org-line) ?*))
  1541. ;; FIXME: NOT DEPENDENT on TOC?????????????????????
  1542. (setq org-line (replace-match
  1543. (concat "@<span class=\"target\">"
  1544. (match-string 1 org-line) "@</span> ")
  1545. ;; (concat "@<i>" (match-string 1 org-line) "@</i> ")
  1546. t t org-line)))
  1547. (t
  1548. (setq org-line (replace-match
  1549. (concat "@<a name=\""
  1550. (org-solidify-link-text (match-string 1 org-line))
  1551. "\" class=\"target\">" (match-string 1 org-line)
  1552. "@</a> ")
  1553. t t org-line)))))
  1554. (setq org-line (org-html-handle-time-stamps org-line))
  1555. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  1556. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  1557. ;; Also handle sub_superscripts and checkboxes
  1558. (or (string-match org-table-hline-regexp org-line)
  1559. (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" org-line)
  1560. (setq org-line (org-html-expand org-line)))
  1561. ;; Format the links
  1562. (setq org-line (org-html-handle-links org-line opt-plist))
  1563. ;; TODO items
  1564. (if (and org-todo-line-regexp
  1565. (string-match org-todo-line-regexp org-line)
  1566. (match-beginning 2))
  1567. (setq org-line
  1568. (concat (substring org-line 0 (match-beginning 2))
  1569. "<span class=\""
  1570. (if (member (match-string 2 org-line)
  1571. org-done-keywords)
  1572. "done" "todo")
  1573. " " (org-export-html-get-todo-kwd-class-name
  1574. (match-string 2 org-line))
  1575. "\">" (match-string 2 org-line)
  1576. "</span>" (substring org-line (match-end 2)))))
  1577. ;; Does this contain a reference to a footnote?
  1578. (when org-export-with-footnotes
  1579. (setq start 0)
  1580. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" org-line start)
  1581. ;; Discard protected matches not clearly identified as
  1582. ;; footnote markers.
  1583. (if (or (get-text-property (match-beginning 2) 'org-protected org-line)
  1584. (not (get-text-property (match-beginning 2) 'org-footnote org-line)))
  1585. (setq start (match-end 2))
  1586. (let ((n (match-string 2 org-line)) extra a)
  1587. (if (setq a (assoc n footref-seen))
  1588. (progn
  1589. (setcdr a (1+ (cdr a)))
  1590. (setq extra (format ".%d" (cdr a))))
  1591. (setq extra "")
  1592. (push (cons n 1) footref-seen))
  1593. (setq org-line
  1594. (replace-match
  1595. (concat
  1596. (format
  1597. (concat "%s"
  1598. (format org-export-html-footnote-format
  1599. (concat "<a class=\"footref\" name=\"" footnote-ref-prefix ".%s%s\" href=\"#" footnote-def-prefix ".%s\">%s</a>")))
  1600. (or (match-string 1 org-line) "") n extra n n)
  1601. ;; If another footnote is following the
  1602. ;; current one, add a separator.
  1603. (if (save-match-data
  1604. (string-match "\\`\\[[0-9]+\\]"
  1605. (substring org-line (match-end 0))))
  1606. org-export-html-footnote-separator
  1607. ""))
  1608. t t org-line))))))
  1609. (cond
  1610. ((string-match "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$" org-line)
  1611. ;; This is a headline
  1612. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
  1613. level-offset))
  1614. txt (or (match-string 2 org-line) ""))
  1615. (if (string-match quote-re0 txt)
  1616. (setq txt (replace-match "" t t txt)))
  1617. (if (<= level (max umax umax-toc))
  1618. (setq head-count (+ head-count 1)))
  1619. (setq first-heading-pos (or first-heading-pos (point)))
  1620. (org-html-level-start level txt umax
  1621. (and org-export-with-toc (<= level umax))
  1622. head-count opt-plist)
  1623. ;; QUOTES
  1624. (when (string-match quote-re org-line)
  1625. (org-close-par-maybe)
  1626. (insert "<pre>")
  1627. (setq inquote t)))
  1628. ((and org-export-with-tables
  1629. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" org-line))
  1630. (when (not table-open)
  1631. ;; New table starts
  1632. (setq table-open t table-buffer nil table-orig-buffer nil))
  1633. ;; Accumulate lines
  1634. (setq table-buffer (cons org-line table-buffer)
  1635. table-orig-buffer (cons origline table-orig-buffer))
  1636. (when (or (not lines)
  1637. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  1638. (car lines))))
  1639. (setq table-open nil
  1640. table-buffer (nreverse table-buffer)
  1641. table-orig-buffer (nreverse table-orig-buffer))
  1642. (org-close-par-maybe)
  1643. (insert (org-format-table-html table-buffer table-orig-buffer))))
  1644. ;; Normal lines
  1645. (t
  1646. ;; This line either is list item or end a list.
  1647. (when (get-text-property 0 'list-item org-line)
  1648. (setq org-line (org-html-export-list-line
  1649. org-line
  1650. (get-text-property 0 'list-item org-line)
  1651. (get-text-property 0 'list-struct org-line)
  1652. (get-text-property 0 'list-prevs org-line))))
  1653. ;; Horizontal line
  1654. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" org-line)
  1655. (if org-par-open
  1656. (insert "\n</p>\n<hr/>\n<p>\n")
  1657. (insert "\n<hr/>\n"))
  1658. (throw 'nextline nil))
  1659. ;; Empty lines start a new paragraph. If hand-formatted lists
  1660. ;; are not fully interpreted, lines starting with "-", "+", "*"
  1661. ;; also start a new paragraph.
  1662. (if (string-match "^ [-+*]-\\|^[ \t]*$" org-line) (org-open-par))
  1663. ;; Is this the start of a footnote?
  1664. (when org-export-with-footnotes
  1665. (when (and (boundp 'footnote-section-tag-regexp)
  1666. (string-match (concat "^" footnote-section-tag-regexp)
  1667. org-line))
  1668. ;; ignore this line
  1669. (throw 'nextline nil))
  1670. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" org-line)
  1671. (org-close-par-maybe)
  1672. (let ((n (match-string 1 org-line)))
  1673. (setq org-par-open t
  1674. org-line (replace-match
  1675. (format
  1676. (concat "<p class=\"footnote\">"
  1677. (format org-export-html-footnote-format
  1678. (concat
  1679. "<a class=\"footnum\" name=\"" footnote-def-prefix ".%s\" href=\"#" footnote-ref-prefix ".%s\">%s</a>")))
  1680. n n n) t t org-line)))))
  1681. ;; Check if the line break needs to be conserved
  1682. (cond
  1683. ((string-match "\\\\\\\\[ \t]*$" org-line)
  1684. (setq org-line (replace-match "<br/>" t t org-line)))
  1685. (org-export-preserve-breaks
  1686. (setq org-line (concat org-line "<br/>"))))
  1687. ;; Check if a paragraph should be started
  1688. (let ((start 0))
  1689. (while (and org-par-open
  1690. (string-match "\\\\par\\>" org-line start))
  1691. ;; Leave a space in the </p> so that the footnote matcher
  1692. ;; does not see this.
  1693. (if (not (get-text-property (match-beginning 0)
  1694. 'org-protected org-line))
  1695. (setq org-line (replace-match "</p ><p >" t t org-line)))
  1696. (setq start (match-end 0))))
  1697. (insert org-line "\n")))))
  1698. ;; Properly close all local lists and other lists
  1699. (when inquote
  1700. (insert "</pre>\n")
  1701. (org-open-par))
  1702. (org-html-level-start 1 nil umax
  1703. (and org-export-with-toc (<= level umax))
  1704. head-count opt-plist)
  1705. ;; the </div> to close the last text-... div.
  1706. (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
  1707. (save-excursion
  1708. (goto-char (point-min))
  1709. (while (re-search-forward
  1710. "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
  1711. nil t)
  1712. (push (match-string 1) footnotes)
  1713. (replace-match "\\4" t nil)
  1714. (goto-char (match-beginning 0))))
  1715. (when footnotes
  1716. (insert (format org-export-html-footnotes-section
  1717. (nth 4 lang-words)
  1718. (mapconcat 'identity (nreverse footnotes) "\n"))
  1719. "\n"))
  1720. (let ((bib (org-export-html-get-bibliography)))
  1721. (when bib
  1722. (insert "\n" bib "\n")))
  1723. (unless body-only
  1724. ;; end wrap around body
  1725. (insert "</div>\n")
  1726. ;; export html postamble
  1727. (let ((html-post (plist-get opt-plist :html-postamble))
  1728. (email
  1729. (mapconcat (lambda(e)
  1730. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1731. (split-string email ",+ *")
  1732. ", "))
  1733. (creator-info
  1734. (concat "<a href=\"http://orgmode.org\">Org</a> version "
  1735. (org-version) " with <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> version "
  1736. (number-to-string emacs-major-version))))
  1737. (when (plist-get opt-plist :html-postamble)
  1738. (insert "\n<div id=\"" (nth 2 org-export-html-divs) "\">\n")
  1739. (cond ((stringp html-post)
  1740. (insert (format-spec html-post
  1741. `((?a . ,author) (?e . ,email)
  1742. (?d . ,date) (?c . ,creator-info)
  1743. (?v . ,html-validation-link)))))
  1744. ((functionp html-post)
  1745. (if (stringp (funcall html-post)) (insert (funcall html-post))))
  1746. ((eq html-post 'auto)
  1747. ;; fall back on default postamble
  1748. (when (plist-get opt-plist :time-stamp-file)
  1749. (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
  1750. (when (and (plist-get opt-plist :author-info) author)
  1751. (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
  1752. (when (and (plist-get opt-plist :email-info) email)
  1753. (insert "<p class=\"email\">" email "</p>\n"))
  1754. (when (plist-get opt-plist :creator-info)
  1755. (insert "<p class=\"creator\">"
  1756. (concat "<a href=\"http://orgmode.org\">Org</a> version "
  1757. (org-version) " with <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> version "
  1758. (number-to-string emacs-major-version) "</p>\n")))
  1759. (insert html-validation-link "\n"))
  1760. (t
  1761. (insert (format-spec
  1762. (or (cadr (assoc (nth 0 lang-words)
  1763. org-export-html-postamble-format))
  1764. (cadr (assoc "en" org-export-html-postamble-format)))
  1765. `((?a . ,author) (?e . ,email)
  1766. (?d . ,date) (?c . ,creator-info)
  1767. (?v . ,html-validation-link))))))
  1768. (insert "\n</div>"))))
  1769. ;; FIXME `org-export-html-with-timestamp' has been declared
  1770. ;; obsolete since Org 7.7 -- don't forget to remove this.
  1771. (if org-export-html-with-timestamp
  1772. (insert org-export-html-html-helper-timestamp))
  1773. (unless body-only (insert "\n</body>\n</html>\n"))
  1774. (unless (plist-get opt-plist :buffer-will-be-killed)
  1775. (normal-mode)
  1776. (if (eq major-mode (default-value 'major-mode))
  1777. (html-mode)))
  1778. ;; insert the table of contents
  1779. (goto-char (point-min))
  1780. (when thetoc
  1781. (if (or (re-search-forward
  1782. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  1783. (re-search-forward
  1784. "\\[TABLE-OF-CONTENTS\\]" nil t))
  1785. (progn
  1786. (goto-char (match-beginning 0))
  1787. (replace-match ""))
  1788. (goto-char first-heading-pos)
  1789. (when (looking-at "\\s-*</p>")
  1790. (goto-char (match-end 0))
  1791. (insert "\n")))
  1792. (insert "<div id=\"table-of-contents\">\n")
  1793. (let ((beg (point)))
  1794. (mapc 'insert thetoc)
  1795. (insert "</div>\n")
  1796. (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t)
  1797. (replace-match ""))))
  1798. ;; remove empty paragraphs
  1799. (goto-char (point-min))
  1800. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  1801. (replace-match ""))
  1802. (goto-char (point-min))
  1803. ;; Convert whitespace place holders
  1804. (goto-char (point-min))
  1805. (let (beg end n)
  1806. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  1807. (setq n (get-text-property beg 'org-whitespace)
  1808. end (next-single-property-change beg 'org-whitespace))
  1809. (goto-char beg)
  1810. (delete-region beg end)
  1811. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  1812. (make-string n ?x)))))
  1813. ;; Remove empty lines at the beginning of the file.
  1814. (goto-char (point-min))
  1815. (when (looking-at "\\s-+\n") (replace-match ""))
  1816. ;; Remove display properties
  1817. (remove-text-properties (point-min) (point-max) '(display t))
  1818. ;; Run the hook
  1819. (run-hooks 'org-export-html-final-hook)
  1820. (or to-buffer (save-buffer))
  1821. (goto-char (point-min))
  1822. (or (org-export-push-to-kill-ring "HTML")
  1823. (message "Exporting... done"))
  1824. (if (eq to-buffer 'string)
  1825. (prog1 (buffer-substring (point-min) (point-max))
  1826. (kill-buffer (current-buffer)))
  1827. (current-buffer)))))
  1828. (defun org-export-html-format-href (s)
  1829. "Make sure the S is valid as a href reference in an XHTML document."
  1830. (save-match-data
  1831. (let ((start 0))
  1832. (while (string-match "&" s start)
  1833. (setq start (+ (match-beginning 0) 3)
  1834. s (replace-match "&amp;" t t s)))))
  1835. s)
  1836. (defun org-export-html-format-desc (s)
  1837. "Make sure the S is valid as a description in a link."
  1838. (if (and s (not (get-text-property 1 'org-protected s)))
  1839. (save-match-data
  1840. (org-html-do-expand s))
  1841. s))
  1842. (defun org-export-html-format-image (src par-open)
  1843. "Create image tag with source and attributes."
  1844. (save-match-data
  1845. (if (string-match (regexp-quote org-latex-preview-ltxpng-directory) src)
  1846. (format "<img src=\"%s\" alt=\"%s\"/>"
  1847. src (org-find-text-property-in-string 'org-latex-src src))
  1848. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  1849. (attr (org-find-text-property-in-string 'org-attributes src))
  1850. (label (org-find-text-property-in-string 'org-label src)))
  1851. (setq caption (and caption (org-html-do-expand caption)))
  1852. (concat
  1853. (if caption
  1854. (format "%s<div %sclass=\"figure\">
  1855. <p>"
  1856. (if org-par-open "</p>\n" "")
  1857. (if label (format "id=\"%s\" " (org-solidify-link-text label)) "")))
  1858. (format "<img src=\"%s\"%s />"
  1859. src
  1860. (if (string-match "\\<alt=" (or attr ""))
  1861. (concat " " attr )
  1862. (concat " " attr " alt=\"" src "\"")))
  1863. (if caption
  1864. (format "</p>%s
  1865. </div>%s"
  1866. (concat "\n<p>" caption "</p>")
  1867. (if org-par-open "\n<p>" ""))))))))
  1868. (defun org-export-html-get-bibliography ()
  1869. "Find bibliography, cut it out and return it."
  1870. (catch 'exit
  1871. (let (beg end (cnt 1) bib)
  1872. (save-excursion
  1873. (goto-char (point-min))
  1874. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  1875. (setq beg (match-beginning 0))
  1876. (while (re-search-forward "</?div\\>" nil t)
  1877. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  1878. (when (= cnt 0)
  1879. (and (looking-at ">") (forward-char 1))
  1880. (setq bib (buffer-substring beg (point)))
  1881. (delete-region beg (point))
  1882. (throw 'exit bib))))
  1883. nil))))
  1884. (defvar org-table-number-regexp) ; defined in org-table.el
  1885. (defun org-format-table-html (lines olines &optional no-css)
  1886. "Find out which HTML converter to use and return the HTML code.
  1887. NO-CSS is passed to the exporter."
  1888. (if (stringp lines)
  1889. (setq lines (org-split-string lines "\n")))
  1890. (if (string-match "^[ \t]*|" (car lines))
  1891. ;; A normal org table
  1892. (org-format-org-table-html lines nil no-css)
  1893. ;; Table made by table.el
  1894. (or (org-format-table-table-html-using-table-generate-source
  1895. olines (not org-export-prefer-native-exporter-for-tables))
  1896. ;; We are here only when table.el table has NO col or row
  1897. ;; spanning and the user prefers using org's own converter for
  1898. ;; exporting of such simple table.el tables.
  1899. (org-format-table-table-html lines))))
  1900. (defvar org-table-number-fraction) ; defined in org-table.el
  1901. (defun org-format-org-table-html (lines &optional splice no-css)
  1902. "Format a table into HTML.
  1903. LINES is a list of lines. Optional argument SPLICE means, do not
  1904. insert header and surrounding <table> tags, just format the lines.
  1905. Optional argument NO-CSS means use XHTML attributes instead of CSS
  1906. for formatting. This is required for the DocBook exporter."
  1907. (require 'org-table)
  1908. ;; Get rid of hlines at beginning and end
  1909. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1910. (setq lines (nreverse lines))
  1911. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1912. (setq lines (nreverse lines))
  1913. (when org-export-table-remove-special-lines
  1914. ;; Check if the table has a marking column. If yes remove the
  1915. ;; column and the special lines
  1916. (setq lines (org-table-clean-before-export lines)))
  1917. (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
  1918. (label (org-find-text-property-in-string 'org-label (car lines)))
  1919. (col-cookies (org-find-text-property-in-string 'org-col-cookies
  1920. (car lines)))
  1921. (attributes (org-find-text-property-in-string 'org-attributes
  1922. (car lines)))
  1923. (html-table-tag (org-export-splice-attributes
  1924. html-table-tag attributes))
  1925. (head (and org-export-highlight-first-table-line
  1926. (delq nil (mapcar
  1927. (lambda (x) (string-match "^[ \t]*|-" x))
  1928. (cdr lines)))))
  1929. (nline 0) fnum nfields i (cnt 0)
  1930. tbopen org-line fields html gr colgropen rowstart rowend
  1931. ali align aligns n)
  1932. (setq caption (and caption (org-html-do-expand caption)))
  1933. (when (and col-cookies org-table-clean-did-remove-column)
  1934. (setq col-cookies
  1935. (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies)))
  1936. (if splice (setq head nil))
  1937. (unless splice (push (if head "<thead>" "<tbody>") html))
  1938. (setq tbopen t)
  1939. (while (setq org-line (pop lines))
  1940. (catch 'next-line
  1941. (if (string-match "^[ \t]*|-" org-line)
  1942. (progn
  1943. (unless splice
  1944. (push (if head "</thead>" "</tbody>") html)
  1945. (if lines (push "<tbody>" html) (setq tbopen nil)))
  1946. (setq head nil) ;; head ends here, first time around
  1947. ;; ignore this line
  1948. (throw 'next-line t)))
  1949. ;; Break the line into fields
  1950. (setq fields (org-split-string org-line "[ \t]*|[ \t]*"))
  1951. (unless fnum (setq fnum (make-vector (length fields) 0)
  1952. nfields (length fnum)))
  1953. (setq nline (1+ nline) i -1
  1954. rowstart (eval (car org-export-table-row-tags))
  1955. rowend (eval (cdr org-export-table-row-tags)))
  1956. (push (concat rowstart
  1957. (mapconcat
  1958. (lambda (x)
  1959. (setq i (1+ i) ali (format "@@class%03d@@" i))
  1960. (if (and (< i nfields) ; make sure no rogue line causes an error here
  1961. (string-match org-table-number-regexp x))
  1962. (incf (aref fnum i)))
  1963. (cond
  1964. (head
  1965. (concat
  1966. (format (car org-export-table-header-tags)
  1967. "col" ali)
  1968. x
  1969. (cdr org-export-table-header-tags)))
  1970. ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
  1971. (concat
  1972. (format (car org-export-table-header-tags)
  1973. "row" ali)
  1974. x
  1975. (cdr org-export-table-header-tags)))
  1976. (t
  1977. (concat (format (car org-export-table-data-tags) ali)
  1978. x
  1979. (cdr org-export-table-data-tags)))))
  1980. fields "")
  1981. rowend)
  1982. html)))
  1983. (unless splice (if tbopen (push "</tbody>" html)))
  1984. (unless splice (push "</table>\n" html))
  1985. (setq html (nreverse html))
  1986. (unless splice
  1987. ;; Put in col tags with the alignment (unfortunately often ignored...)
  1988. (unless (car org-table-colgroup-info)
  1989. (setq org-table-colgroup-info
  1990. (cons :start (cdr org-table-colgroup-info))))
  1991. (setq i 0)
  1992. (push (mapconcat
  1993. (lambda (x)
  1994. (setq gr (pop org-table-colgroup-info)
  1995. i (1+ i)
  1996. align (if (nth 1 (assoc i col-cookies))
  1997. (cdr (assoc (nth 1 (assoc i col-cookies))
  1998. '(("l" . "left") ("r" . "right")
  1999. ("c" . "center"))))
  2000. (if (> (/ (float x) nline)
  2001. org-table-number-fraction)
  2002. "right" "left")))
  2003. (push align aligns)
  2004. (format (if no-css
  2005. "%s<col align=\"%s\" />%s"
  2006. "%s<col class=\"%s\" />%s")
  2007. (if (memq gr '(:start :startend))
  2008. (prog1
  2009. (if colgropen
  2010. "</colgroup>\n<colgroup>"
  2011. "<colgroup>")
  2012. (setq colgropen t))
  2013. "")
  2014. align
  2015. (if (memq gr '(:end :startend))
  2016. (progn (setq colgropen nil) "</colgroup>")
  2017. "")))
  2018. fnum "")
  2019. html)
  2020. (setq aligns (nreverse aligns))
  2021. (if colgropen (setq html (cons (car html)
  2022. (cons "</colgroup>" (cdr html)))))
  2023. ;; Since the output of HTML table formatter can also be used in
  2024. ;; DocBook document, include empty captions for the DocBook
  2025. ;; export only so that it produces valid XML.
  2026. (when (or caption (eq org-export-current-backend 'docbook))
  2027. (push (format "<caption>%s</caption>" (or caption "")) html))
  2028. (when label
  2029. (setq html-table-tag (org-export-splice-attributes html-table-tag (format "id=\"%s\"" (org-solidify-link-text label)))))
  2030. (push html-table-tag html))
  2031. (setq html (mapcar
  2032. (lambda (x)
  2033. (replace-regexp-in-string
  2034. "@@class\\([0-9]+\\)@@"
  2035. (lambda (txt)
  2036. (if (not org-export-html-table-align-individual-fields)
  2037. ""
  2038. (setq n (string-to-number (match-string 1 txt)))
  2039. (format (if no-css " align=\"%s\"" " class=\"%s\"")
  2040. (or (nth n aligns) "left"))))
  2041. x))
  2042. html))
  2043. (concat (mapconcat 'identity html "\n") "\n")))
  2044. (defun org-export-splice-attributes (tag attributes)
  2045. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  2046. (if (not attributes)
  2047. tag
  2048. (let (oldatt newatt)
  2049. (setq oldatt (org-extract-attributes-from-string tag)
  2050. tag (pop oldatt)
  2051. newatt (cdr (org-extract-attributes-from-string attributes)))
  2052. (while newatt
  2053. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  2054. (if (string-match ">" tag)
  2055. (setq tag
  2056. (replace-match (concat (org-attributes-to-string oldatt) ">")
  2057. t t tag)))
  2058. tag)))
  2059. (defun org-format-table-table-html (lines)
  2060. "Format a table generated by table.el into HTML.
  2061. This conversion does *not* use `table-generate-source' from table.el.
  2062. This has the advantage that Org-mode's HTML conversions can be used.
  2063. But it has the disadvantage, that no cell- or row-spanning is allowed."
  2064. (let (org-line field-buffer
  2065. (head org-export-highlight-first-table-line)
  2066. fields html empty i)
  2067. (setq html (concat html-table-tag "\n"))
  2068. (while (setq org-line (pop lines))
  2069. (setq empty "&nbsp;")
  2070. (catch 'next-line
  2071. (if (string-match "^[ \t]*\\+-" org-line)
  2072. (progn
  2073. (if field-buffer
  2074. (progn
  2075. (setq
  2076. html
  2077. (concat
  2078. html
  2079. "<tr>"
  2080. (mapconcat
  2081. (lambda (x)
  2082. (if (equal x "") (setq x empty))
  2083. (if head
  2084. (concat
  2085. (format (car org-export-table-header-tags) "col" "")
  2086. x
  2087. (cdr org-export-table-header-tags))
  2088. (concat (format (car org-export-table-data-tags) "") x
  2089. (cdr org-export-table-data-tags))))
  2090. field-buffer "\n")
  2091. "</tr>\n"))
  2092. (setq head nil)
  2093. (setq field-buffer nil)))
  2094. ;; Ignore this line
  2095. (throw 'next-line t)))
  2096. ;; Break the line into fields and store the fields
  2097. (setq fields (org-split-string org-line "[ \t]*|[ \t]*"))
  2098. (if field-buffer
  2099. (setq field-buffer (mapcar
  2100. (lambda (x)
  2101. (concat x "<br/>" (pop fields)))
  2102. field-buffer))
  2103. (setq field-buffer fields))))
  2104. (setq html (concat html "</table>\n"))
  2105. html))
  2106. (defun org-format-table-table-html-using-table-generate-source (lines
  2107. &optional
  2108. spanned-only)
  2109. "Format a table into html, using `table-generate-source' from table.el.
  2110. Use SPANNED-ONLY to suppress exporting of simple table.el tables.
  2111. When SPANNED-ONLY is nil, all table.el tables are exported. When
  2112. SPANNED-ONLY is non-nil, only tables with either row or column
  2113. spans are exported.
  2114. This routine returns the generated source or nil as appropriate.
  2115. Refer docstring of `org-export-prefer-native-exporter-for-tables'
  2116. for further information."
  2117. (require 'table)
  2118. (with-current-buffer (get-buffer-create " org-tmp1 ")
  2119. (erase-buffer)
  2120. (insert (mapconcat 'identity lines "\n"))
  2121. (goto-char (point-min))
  2122. (if (not (re-search-forward "|[^+]" nil t))
  2123. (error "Error processing table"))
  2124. (table-recognize-table)
  2125. (when (or (not spanned-only)
  2126. (let* ((dim (table-query-dimension))
  2127. (c (nth 4 dim)) (r (nth 5 dim)) (cells (nth 6 dim)))
  2128. (not (= (* c r) cells))))
  2129. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  2130. (table-generate-source 'html " org-tmp2 ")
  2131. (set-buffer " org-tmp2 ")
  2132. (buffer-substring (point-min) (point-max)))))
  2133. (defun org-export-splice-style (style extra)
  2134. "Splice EXTRA into STYLE, just before \"</style>\"."
  2135. (if (and (stringp extra)
  2136. (string-match "\\S-" extra)
  2137. (string-match "</style>" style))
  2138. (concat (substring style 0 (match-beginning 0))
  2139. "\n" extra "\n"
  2140. (substring style (match-beginning 0)))
  2141. style))
  2142. (defun org-html-handle-time-stamps (s)
  2143. "Format time stamps in string S, or remove them."
  2144. (catch 'exit
  2145. (let (r b)
  2146. (when org-maybe-keyword-time-regexp
  2147. (while (string-match org-maybe-keyword-time-regexp s)
  2148. (or b (setq b (substring s 0 (match-beginning 0))))
  2149. (setq r (concat
  2150. r (substring s 0 (match-beginning 0))
  2151. " @<span class=\"timestamp-wrapper\">"
  2152. (if (match-end 1)
  2153. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  2154. (match-string 1 s)))
  2155. (format " @<span class=\"timestamp\">%s@</span>"
  2156. (substring
  2157. (org-translate-time (match-string 3 s)) 1 -1))
  2158. "@</span>")
  2159. s (substring s (match-end 0)))))
  2160. ;; Line break if line started and ended with time stamp stuff
  2161. (if (not r)
  2162. s
  2163. (setq r (concat r s))
  2164. (unless (string-match "\\S-" (concat b s))
  2165. (setq r (concat r "@<br/>")))
  2166. r))))
  2167. (defvar htmlize-buffer-places) ; from htmlize.el
  2168. (defun org-export-htmlize-region-for-paste (beg end)
  2169. "Convert the region to HTML, using htmlize.el.
  2170. This is much like `htmlize-region-for-paste', only that it uses
  2171. the settings define in the org-... variables."
  2172. (let* ((htmlize-output-type org-export-htmlize-output-type)
  2173. (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
  2174. (htmlbuf (htmlize-region beg end)))
  2175. (unwind-protect
  2176. (with-current-buffer htmlbuf
  2177. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  2178. (plist-get htmlize-buffer-places 'content-end)))
  2179. (kill-buffer htmlbuf))))
  2180. (defun org-export-htmlize-generate-css ()
  2181. "Create the CSS for all font definitions in the current Emacs session.
  2182. Use this to create face definitions in your CSS style file that can then
  2183. be used by code snippets transformed by htmlize.
  2184. This command just produces a buffer that contains class definitions for all
  2185. faces used in the current Emacs session. You can copy and paste the ones you
  2186. need into your CSS file.
  2187. If you then set `org-export-htmlize-output-type' to `css', calls to
  2188. the function `org-export-htmlize-region-for-paste' will produce code
  2189. that uses these same face definitions."
  2190. (interactive)
  2191. (require 'htmlize)
  2192. (and (get-buffer "*html*") (kill-buffer "*html*"))
  2193. (with-temp-buffer
  2194. (let ((fl (face-list))
  2195. (htmlize-css-name-prefix "org-")
  2196. (htmlize-output-type 'css)
  2197. f i)
  2198. (while (setq f (pop fl)
  2199. i (and f (face-attribute f :inherit)))
  2200. (when (and (symbolp f) (or (not i) (not (listp i))))
  2201. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  2202. (htmlize-region (point-min) (point-max))))
  2203. (org-pop-to-buffer-same-window "*html*")
  2204. (goto-char (point-min))
  2205. (if (re-search-forward "<style" nil t)
  2206. (delete-region (point-min) (match-beginning 0)))
  2207. (if (re-search-forward "</style>" nil t)
  2208. (delete-region (1+ (match-end 0)) (point-max)))
  2209. (beginning-of-line 1)
  2210. (if (looking-at " +") (replace-match ""))
  2211. (goto-char (point-min)))
  2212. (defun org-html-protect (s)
  2213. "Convert characters to HTML equivalent.
  2214. Possible conversions are set in `org-export-html-protect-char-alist'."
  2215. (let ((cl org-export-html-protect-char-alist) c)
  2216. (while (setq c (pop cl))
  2217. (let ((start 0))
  2218. (while (string-match (car c) s start)
  2219. (setq s (replace-match (cdr c) t t s)
  2220. start (1+ (match-beginning 0))))))
  2221. s))
  2222. (defun org-html-expand (string)
  2223. "Prepare STRING for HTML export. Apply all active conversions.
  2224. If there are links in the string, don't modify these. If STRING
  2225. is nil, return nil."
  2226. (when string
  2227. (let* ((re (concat org-bracket-link-regexp "\\|"
  2228. (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
  2229. m s l res)
  2230. (while (setq m (string-match re string))
  2231. (setq s (substring string 0 m)
  2232. l (match-string 0 string)
  2233. string (substring string (match-end 0)))
  2234. (push (org-html-do-expand s) res)
  2235. (push l res))
  2236. (push (org-html-do-expand string) res)
  2237. (apply 'concat (nreverse res)))))
  2238. (defun org-html-do-expand (s)
  2239. "Apply all active conversions to translate special ASCII to HTML."
  2240. (setq s (org-html-protect s))
  2241. (if org-export-html-expand
  2242. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  2243. (setq s (replace-match "<\\1>" t nil s))))
  2244. (if org-export-with-emphasize
  2245. (setq s (org-export-html-convert-emphasize s)))
  2246. (if org-export-with-special-strings
  2247. (setq s (org-export-html-convert-special-strings s)))
  2248. (if org-export-with-sub-superscripts
  2249. (setq s (org-export-html-convert-sub-super s)))
  2250. (if org-export-with-TeX-macros
  2251. (let ((start 0) wd rep)
  2252. (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
  2253. s start))
  2254. (if (get-text-property (match-beginning 0) 'org-protected s)
  2255. (setq start (match-end 0))
  2256. (setq wd (match-string 1 s))
  2257. (if (setq rep (org-entity-get-representation wd 'html))
  2258. (setq s (replace-match rep t t s))
  2259. (setq start (+ start (length wd))))))))
  2260. s)
  2261. (defun org-export-html-convert-special-strings (string)
  2262. "Convert special characters in STRING to HTML."
  2263. (let ((all org-export-html-special-string-regexps)
  2264. e a re rpl start)
  2265. (while (setq a (pop all))
  2266. (setq re (car a) rpl (cdr a) start 0)
  2267. (while (string-match re string start)
  2268. (if (get-text-property (match-beginning 0) 'org-protected string)
  2269. (setq start (match-end 0))
  2270. (setq string (replace-match rpl t nil string)))))
  2271. string))
  2272. (defun org-export-html-convert-sub-super (string)
  2273. "Convert sub- and superscripts in STRING to HTML."
  2274. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  2275. (while (string-match org-match-substring-regexp string s)
  2276. (cond
  2277. ((and requireb (match-end 8)) (setq s (match-end 2)))
  2278. ((get-text-property (match-beginning 2) 'org-protected string)
  2279. (setq s (match-end 2)))
  2280. (t
  2281. (setq s (match-end 1)
  2282. key (if (string= (match-string 2 string) "_") "sub" "sup")
  2283. c (or (match-string 8 string)
  2284. (match-string 6 string)
  2285. (match-string 5 string))
  2286. string (replace-match
  2287. (concat (match-string 1 string)
  2288. "<" key ">" c "</" key ">")
  2289. t t string)))))
  2290. (while (string-match "\\\\\\([_^]\\)" string)
  2291. (setq string (replace-match (match-string 1 string) t t string)))
  2292. string))
  2293. (defun org-export-html-convert-emphasize (string)
  2294. "Apply emphasis."
  2295. (let ((s 0) rpl)
  2296. (while (string-match org-emph-re string s)
  2297. (if (not (equal
  2298. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  2299. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  2300. (setq s (match-beginning 0)
  2301. rpl
  2302. (concat
  2303. (match-string 1 string)
  2304. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  2305. (match-string 4 string)
  2306. (nth 3 (assoc (match-string 3 string)
  2307. org-emphasis-alist))
  2308. (match-string 5 string))
  2309. string (replace-match rpl t t string)
  2310. s (+ s (- (length rpl) 2)))
  2311. (setq s (1+ s))))
  2312. string))
  2313. (defun org-open-par ()
  2314. "Insert <p>, but first close previous paragraph if any."
  2315. (org-close-par-maybe)
  2316. (insert "\n<p>")
  2317. (setq org-par-open t))
  2318. (defun org-close-par-maybe ()
  2319. "Close paragraph if there is one open."
  2320. (when org-par-open
  2321. (insert "</p>")
  2322. (setq org-par-open nil)))
  2323. (defun org-close-li (&optional type)
  2324. "Close <li> if necessary."
  2325. (org-close-par-maybe)
  2326. (insert (if (equal type "d") "</dd>\n" "</li>\n")))
  2327. (defvar body-only) ; dynamically scoped into this.
  2328. (defun org-html-level-start (level title umax with-toc head-count &optional opt-plist)
  2329. "Insert a new level in HTML export.
  2330. When TITLE is nil, just close all open levels."
  2331. (org-close-par-maybe)
  2332. (let* ((target (and title (org-get-text-property-any 0 'target title)))
  2333. (extra-targets (and target
  2334. (assoc target org-export-target-aliases)))
  2335. (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
  2336. (preferred (and target
  2337. (cdr (assoc target org-export-preferred-target-alist))))
  2338. (l org-level-max)
  2339. (num (plist-get opt-plist :section-numbers))
  2340. snumber snu href suffix)
  2341. (setq extra-targets (remove (or preferred target) extra-targets))
  2342. (setq extra-targets
  2343. (mapconcat (lambda (x)
  2344. (setq x (org-solidify-link-text
  2345. (if (org-uuidgen-p x) (concat "ID-" x) x)))
  2346. (if (stringp org-export-html-headline-anchor-format)
  2347. (format org-export-html-headline-anchor-format x x)
  2348. ""))
  2349. extra-targets
  2350. ""))
  2351. (while (>= l level)
  2352. (if (aref org-levels-open (1- l))
  2353. (progn
  2354. (org-html-level-close l umax)
  2355. (aset org-levels-open (1- l) nil)))
  2356. (setq l (1- l)))
  2357. (when title
  2358. ;; If title is nil, this means this function is called to close
  2359. ;; all levels, so the rest is done only if title is given
  2360. (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
  2361. (setq title (replace-match
  2362. (if org-export-with-tags
  2363. (save-match-data
  2364. (concat
  2365. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  2366. (mapconcat
  2367. (lambda (x)
  2368. (format "<span class=\"%s\">%s</span>"
  2369. (org-export-html-get-tag-class-name x)
  2370. x))
  2371. (org-split-string (match-string 1 title) ":")
  2372. "&nbsp;")
  2373. "</span>"))
  2374. "")
  2375. t t title)))
  2376. (if (> level umax)
  2377. (progn
  2378. (if (aref org-levels-open (1- level))
  2379. (progn
  2380. (org-close-li)
  2381. (if target
  2382. (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
  2383. extra-targets title "<br/>\n")
  2384. (insert "<li>" title "<br/>\n")))
  2385. (aset org-levels-open (1- level) t)
  2386. (org-close-par-maybe)
  2387. (if target
  2388. (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
  2389. extra-targets title "<br/>\n")
  2390. (insert "<ul>\n<li>" title "<br/>\n"))))
  2391. (aset org-levels-open (1- level) t)
  2392. (setq snumber (org-section-number level)
  2393. snu (replace-regexp-in-string "\\." "-" snumber))
  2394. (setq level (+ level org-export-html-toplevel-hlevel -1))
  2395. (if (and num (not body-only))
  2396. (setq title (concat
  2397. (format "<span class=\"section-number-%d\">%s</span>"
  2398. level
  2399. (if (and num
  2400. (if (integerp num)
  2401. ;; fix up num to take into
  2402. ;; account the top-level
  2403. ;; heading value
  2404. (>= (+ num org-export-html-toplevel-hlevel -1)
  2405. level)
  2406. num))
  2407. snumber
  2408. ""))
  2409. " " title)))
  2410. (unless (= head-count 1) (insert "\n</div>\n"))
  2411. (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
  2412. (setq suffix (org-solidify-link-text (or href snu)))
  2413. (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
  2414. (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d%s\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
  2415. suffix level (if extra-class (concat " " extra-class) "")
  2416. level href
  2417. extra-targets
  2418. title level level suffix))
  2419. (org-open-par)))))
  2420. (defun org-export-html-get-tag-class-name (tag)
  2421. "Turn tag into a valid class name.
  2422. Replaces invalid characters with \"_\" and then prepends a prefix."
  2423. (save-match-data
  2424. (while (string-match "[^a-zA-Z0-9_]" tag)
  2425. (setq tag (replace-match "_" t t tag))))
  2426. (concat org-export-html-tag-class-prefix tag))
  2427. (defun org-export-html-get-todo-kwd-class-name (kwd)
  2428. "Turn todo keyword into a valid class name.
  2429. Replaces invalid characters with \"_\" and then prepends a prefix."
  2430. (save-match-data
  2431. (while (string-match "[^a-zA-Z0-9_]" kwd)
  2432. (setq kwd (replace-match "_" t t kwd))))
  2433. (concat org-export-html-todo-kwd-class-prefix kwd))
  2434. (defun org-html-level-close (level max-outline-level)
  2435. "Terminate one level in HTML export."
  2436. (if (<= level max-outline-level)
  2437. (insert "</div>\n")
  2438. (org-close-li)
  2439. (insert "</ul>\n")))
  2440. (defun org-html-export-list-line (org-line pos struct prevs)
  2441. "Insert list syntax in export buffer. Return ORG-LINE, maybe modified.
  2442. POS is the item position or org-line position the org-line had before
  2443. modifications to buffer. STRUCT is the list structure. PREVS is
  2444. the alist of previous items."
  2445. (let* ((get-type
  2446. (function
  2447. ;; Translate type of list containing POS to "d", "o" or
  2448. ;; "u".
  2449. (lambda (pos struct prevs)
  2450. (let ((type (org-list-get-list-type pos struct prevs)))
  2451. (cond
  2452. ((eq 'ordered type) "o")
  2453. ((eq 'descriptive type) "d")
  2454. (t "u"))))))
  2455. (get-closings
  2456. (function
  2457. ;; Return list of all items and sublists ending at POS, in
  2458. ;; reverse order.
  2459. (lambda (pos)
  2460. (let (out)
  2461. (catch 'exit
  2462. (mapc (lambda (e)
  2463. (let ((end (nth 6 e))
  2464. (item (car e)))
  2465. (cond
  2466. ((= end pos) (push item out))
  2467. ((>= item pos) (throw 'exit nil)))))
  2468. struct))
  2469. out)))))
  2470. ;; First close any previous item, or list, ending at POS.
  2471. (mapc (lambda (e)
  2472. (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
  2473. (first-item (org-list-get-list-begin e struct prevs))
  2474. (type (funcall get-type first-item struct prevs)))
  2475. (org-close-par-maybe)
  2476. ;; Ending for every item
  2477. (org-close-li type)
  2478. ;; We're ending last item of the list: end list.
  2479. (when lastp
  2480. (insert (format "</%sl>\n" type))
  2481. (org-open-par))))
  2482. (funcall get-closings pos))
  2483. (cond
  2484. ;; At an item: insert appropriate tags in export buffer.
  2485. ((assq pos struct)
  2486. (string-match
  2487. (concat "[ \t]*\\(\\S-+[ \t]*\\)"
  2488. "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
  2489. "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
  2490. "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
  2491. "\\(.*\\)") org-line)
  2492. (let* ((checkbox (match-string 3 org-line))
  2493. (desc-tag (or (match-string 4 org-line) "???"))
  2494. (body (or (match-string 5 org-line) ""))
  2495. (list-beg (org-list-get-list-begin pos struct prevs))
  2496. (firstp (= list-beg pos))
  2497. ;; Always refer to first item to determine list type, in
  2498. ;; case list is ill-formed.
  2499. (type (funcall get-type list-beg struct prevs))
  2500. (counter (let ((count-tmp (org-list-get-counter pos struct)))
  2501. (cond
  2502. ((not count-tmp) nil)
  2503. ((string-match "[A-Za-z]" count-tmp)
  2504. (- (string-to-char (upcase count-tmp)) 64))
  2505. ((string-match "[0-9]+" count-tmp)
  2506. count-tmp)))))
  2507. (when firstp
  2508. (org-close-par-maybe)
  2509. (insert (format "<%sl>\n" type)))
  2510. (insert (cond
  2511. ((equal type "d")
  2512. (format "<dt>%s</dt><dd>" desc-tag))
  2513. ((and (equal type "o") counter)
  2514. (format "<li value=\"%s\">" counter))
  2515. (t "<li>")))
  2516. ;; If line had a checkbox, some additional modification is required.
  2517. (when checkbox
  2518. (setq body
  2519. (concat
  2520. (cond
  2521. ((string-match "X" checkbox) "<code>[X]</code> ")
  2522. ((string-match " " checkbox) "<code>[&nbsp;]</code> ")
  2523. (t "<code>[-]</code> "))
  2524. body)))
  2525. ;; Return modified line
  2526. body))
  2527. ;; At a list ender: go to next line (side-effects only).
  2528. ((equal "ORG-LIST-END-MARKER" org-line) (throw 'nextline nil))
  2529. ;; Not at an item: return line unchanged (side-effects only).
  2530. (t org-line))))
  2531. (provide 'org-html)
  2532. ;; Local variables:
  2533. ;; generated-autoload-file: "org-loaddefs.el"
  2534. ;; End:
  2535. ;;; org-html.el ends here