org-html.el 98 KB

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