org-html.el 92 KB

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