org-html.el 86 KB

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