org-xhtml.el 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  1. ;;; org-xhtml.el --- XHTML export for Org-mode (uses org-lparse)
  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. ;; Version: 0.8
  7. ;; This file is not (yet) part of GNU Emacs.
  8. ;; However, it is distributed under the same license.
  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. (require 'org-lparse)
  26. (eval-when-compile (require 'cl) (require 'table) (require 'browse-url))
  27. (declare-function org-id-find-id-file "org-id" (id))
  28. (declare-function htmlize-region "ext:htmlize" (beg end))
  29. (defgroup org-export-xhtml nil
  30. "Options specific for HTML export of Org-mode files."
  31. :tag "Org Export HTML"
  32. :group 'org-export)
  33. (defconst org-export-xhtml-special-string-regexps
  34. '(("\\\\-" . "&shy;")
  35. ("---\\([^-]\\)" . "&mdash;\\1")
  36. ("--\\([^-]\\)" . "&ndash;\\1")
  37. ("\\.\\.\\." . "&hellip;"))
  38. "Regular expressions for special string conversion.")
  39. (defcustom org-export-xhtml-footnotes-section "<div id=\"footnotes\">
  40. <h2 class=\"footnotes\">%s: </h2>
  41. <div id=\"text-footnotes\">
  42. %s
  43. </div>
  44. </div>"
  45. "Format for the footnotes section.
  46. Should contain a two instances of %s. The first will be replaced with the
  47. language-specific word for \"Footnotes\", the second one will be replaced
  48. by the footnotes themselves."
  49. :group 'org-export-xhtml
  50. :type 'string)
  51. (defcustom org-export-xhtml-footnote-format "<sup>%s</sup>"
  52. "The format for the footnote reference.
  53. %s will be replaced by the footnote reference itself."
  54. :group 'org-export-xhtml
  55. :type 'string)
  56. (defcustom org-export-xhtml-footnote-separator "<sup>, </sup>"
  57. "Text used to separate footnotes."
  58. :group 'org-export-xhtml
  59. :type 'string)
  60. (defcustom org-export-xhtml-coding-system nil
  61. "Coding system for HTML export, defaults to `buffer-file-coding-system'."
  62. :group 'org-export-xhtml
  63. :type 'coding-system)
  64. (defcustom org-export-xhtml-extension "html"
  65. "The extension for exported HTML files."
  66. :group 'org-export-xhtml
  67. :type 'string)
  68. (defcustom org-export-xhtml-xml-declaration
  69. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  70. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  71. "The extension for exported HTML files.
  72. %s will be replaced with the charset of the exported file.
  73. This may be a string, or an alist with export extensions
  74. and corresponding declarations."
  75. :group 'org-export-xhtml
  76. :type '(choice
  77. (string :tag "Single declaration")
  78. (repeat :tag "Dependent on extension"
  79. (cons (string :tag "Extension")
  80. (string :tag "Declaration")))))
  81. (defcustom org-export-xhtml-style-include-scripts t
  82. "Non-nil means include the JavaScript snippets in exported HTML files.
  83. The actual script is defined in `org-export-xhtml-scripts' and should
  84. not be modified."
  85. :group 'org-export-xhtml
  86. :type 'boolean)
  87. (defconst org-export-xhtml-scripts
  88. "<script type=\"text/javascript\">
  89. <!--/*--><![CDATA[/*><!--*/
  90. function CodeHighlightOn(elem, id)
  91. {
  92. var target = document.getElementById(id);
  93. if(null != target) {
  94. elem.cacheClassElem = elem.className;
  95. elem.cacheClassTarget = target.className;
  96. target.className = \"code-highlighted\";
  97. elem.className = \"code-highlighted\";
  98. }
  99. }
  100. function CodeHighlightOff(elem, id)
  101. {
  102. var target = document.getElementById(id);
  103. if(elem.cacheClassElem)
  104. elem.className = elem.cacheClassElem;
  105. if(elem.cacheClassTarget)
  106. target.className = elem.cacheClassTarget;
  107. }
  108. /*]]>*///-->
  109. </script>"
  110. "Basic JavaScript that is needed by HTML files produced by Org-mode.")
  111. (defconst org-export-xhtml-style-default
  112. "<style type=\"text/css\">
  113. <!--/*--><![CDATA[/*><!--*/
  114. html { font-family: Times, serif; font-size: 12pt; }
  115. .title { text-align: center; }
  116. .todo { color: red; }
  117. .done { color: green; }
  118. .tag { background-color: #add8e6; font-weight:normal }
  119. .target { }
  120. .timestamp { color: #bebebe; }
  121. .timestamp-kwd { color: #5f9ea0; }
  122. .right {margin-left:auto; margin-right:0px; text-align:right;}
  123. .left {margin-left:0px; margin-right:auto; text-align:left;}
  124. .center {margin-left:auto; margin-right:auto; text-align:center;}
  125. p.verse { margin-left: 3% }
  126. pre {
  127. border: 1pt solid #AEBDCC;
  128. background-color: #F3F5F7;
  129. padding: 5pt;
  130. font-family: courier, monospace;
  131. font-size: 90%;
  132. overflow:auto;
  133. }
  134. table { border-collapse: collapse; }
  135. td, th { vertical-align: top; }
  136. th.right { text-align:center; }
  137. th.left { text-align:center; }
  138. th.center { text-align:center; }
  139. td.right { text-align:right; }
  140. td.left { text-align:left; }
  141. td.center { text-align:center; }
  142. dt { font-weight: bold; }
  143. div.figure { padding: 0.5em; }
  144. div.figure p { text-align: center; }
  145. textarea { overflow-x: auto; }
  146. .linenr { font-size:smaller }
  147. .code-highlighted {background-color:#ffff00;}
  148. .org-info-js_info-navigation { border-style:none; }
  149. #org-info-js_console-label { font-size:10px; font-weight:bold;
  150. white-space:nowrap; }
  151. .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
  152. font-weight:bold; }
  153. /*]]>*/-->
  154. </style>"
  155. "The default style specification for exported HTML files.
  156. Please use the variables `org-export-xhtml-style' and
  157. `org-export-xhtml-style-extra' to add to this style. If you wish to not
  158. have the default style included, customize the variable
  159. `org-export-xhtml-style-include-default'.")
  160. (defcustom org-export-xhtml-style-include-default t
  161. "Non-nil means include the default style in exported HTML files.
  162. The actual style is defined in `org-export-xhtml-style-default' and should
  163. not be modified. Use the variables `org-export-xhtml-style' to add
  164. your own style information."
  165. :group 'org-export-xhtml
  166. :type 'boolean)
  167. ;;;###autoload
  168. (put 'org-export-xhtml-style-include-default 'safe-local-variable 'booleanp)
  169. (defcustom org-export-xhtml-style ""
  170. "Org-wide style definitions for exported HTML files.
  171. This variable needs to contain the full HTML structure to provide a style,
  172. including the surrounding HTML tags. If you set the value of this variable,
  173. you should consider to include definitions for the following classes:
  174. title, todo, done, timestamp, timestamp-kwd, tag, target.
  175. For example, a valid value would be:
  176. <style type=\"text/css\">
  177. <![CDATA[
  178. p { font-weight: normal; color: gray; }
  179. h1 { color: black; }
  180. .title { text-align: center; }
  181. .todo, .timestamp-kwd { color: red; }
  182. .done { color: green; }
  183. ]]>
  184. </style>
  185. If you'd like to refer to an external style file, use something like
  186. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  187. As the value of this option simply gets inserted into the HTML <head> header,
  188. you can \"misuse\" it to add arbitrary text to the header.
  189. See also the variable `org-export-xhtml-style-extra'."
  190. :group 'org-export-xhtml
  191. :type 'string)
  192. ;;;###autoload
  193. (put 'org-export-xhtml-style 'safe-local-variable 'stringp)
  194. (defcustom org-export-xhtml-style-extra ""
  195. "Additional style information for HTML export.
  196. The value of this variable is inserted into the HTML buffer right after
  197. the value of `org-export-xhtml-style'. Use this variable for per-file
  198. settings of style information, and do not forget to surround the style
  199. settings with <style>...</style> tags."
  200. :group 'org-export-xhtml
  201. :type 'string)
  202. ;;;###autoload
  203. (put 'org-export-xhtml-style-extra 'safe-local-variable 'stringp)
  204. (defcustom org-export-xhtml-mathjax-options
  205. '((path "http://orgmode.org/mathjax/MathJax.js")
  206. (scale "100")
  207. (align "center")
  208. (indent "2em")
  209. (mathml nil))
  210. "Options for MathJax setup.
  211. path The path where to find MathJax
  212. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  213. align How to align display math: left, center, or right
  214. indent If align is not center, how far from the left/right side?
  215. mathml Should a MathML player be used if available?
  216. This is faster and reduces bandwidth use, but currently
  217. sometimes has lower spacing quality. Therefore, the default is
  218. nil. When browsers get better, this switch can be flipped.
  219. You can also customize this for each buffer, using something like
  220. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  221. :group 'org-export-xhtml
  222. :type '(list :greedy t
  223. (list :tag "path (the path from where to load MathJax.js)"
  224. (const :format " " path) (string))
  225. (list :tag "scale (scaling for the displayed math)"
  226. (const :format " " scale) (string))
  227. (list :tag "align (alignment of displayed equations)"
  228. (const :format " " align) (string))
  229. (list :tag "indent (indentation with left or right alignment)"
  230. (const :format " " indent) (string))
  231. (list :tag "mathml (should MathML display be used is possible)"
  232. (const :format " " mathml) (boolean))))
  233. (defun org-export-xhtml-mathjax-config (template options in-buffer)
  234. "Insert the user setup into the matchjax template."
  235. (let (name val (yes " ") (no "// ") x)
  236. (mapc
  237. (lambda (e)
  238. (setq name (car e) val (nth 1 e))
  239. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  240. (setq val (car (read-from-string
  241. (substring in-buffer (match-end 0))))))
  242. (if (not (stringp val)) (setq val (format "%s" val)))
  243. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  244. (setq template (replace-match val t t template))))
  245. options)
  246. (setq val (nth 1 (assq 'mathml options)))
  247. (if (string-match (concat "\\<mathml:") in-buffer)
  248. (setq val (car (read-from-string
  249. (substring in-buffer (match-end 0))))))
  250. ;; Exchange prefixes depending on mathml setting
  251. (if (not val) (setq x yes yes no no x))
  252. ;; Replace cookies to turn on or off the config/jax lines
  253. (if (string-match ":MMLYES:" template)
  254. (setq template (replace-match yes t t template)))
  255. (if (string-match ":MMLNO:" template)
  256. (setq template (replace-match no t t template)))
  257. ;; Return the modified template
  258. template))
  259. (defcustom org-export-xhtml-mathjax-template
  260. "<script type=\"text/javascript\" src=\"%PATH\">
  261. <!--/*--><![CDATA[/*><!--*/
  262. MathJax.Hub.Config({
  263. // Only one of the two following lines, depending on user settings
  264. // First allows browser-native MathML display, second forces HTML/CSS
  265. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  266. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  267. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  268. \"TeX/noUndefined.js\"],
  269. tex2jax: {
  270. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  271. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  272. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  273. ignoreClass: \"tex2jax_ignore\",
  274. processEscapes: false,
  275. processEnvironments: true,
  276. preview: \"TeX\"
  277. },
  278. showProcessingMessages: true,
  279. displayAlign: \"%ALIGN\",
  280. displayIndent: \"%INDENT\",
  281. \"HTML-CSS\": {
  282. scale: %SCALE,
  283. availableFonts: [\"STIX\",\"TeX\"],
  284. preferredFont: \"TeX\",
  285. webFont: \"TeX\",
  286. imageFont: \"TeX\",
  287. showMathMenu: true,
  288. },
  289. MMLorHTML: {
  290. prefer: {
  291. MSIE: \"MML\",
  292. Firefox: \"MML\",
  293. Opera: \"HTML\",
  294. other: \"HTML\"
  295. }
  296. }
  297. });
  298. /*]]>*///-->
  299. </script>"
  300. "The MathJax setup for XHTML files."
  301. :group 'org-export-xhtml
  302. :type 'string)
  303. (defcustom org-export-xhtml-tag-class-prefix ""
  304. "Prefix to class names for TODO keywords.
  305. Each tag gets a class given by the tag itself, with this prefix.
  306. The default prefix is empty because it is nice to just use the keyword
  307. as a class name. But if you get into conflicts with other, existing
  308. CSS classes, then this prefix can be very useful."
  309. :group 'org-export-xhtml
  310. :type 'string)
  311. (defcustom org-export-xhtml-todo-kwd-class-prefix ""
  312. "Prefix to class names for TODO keywords.
  313. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  314. The default prefix is empty because it is nice to just use the keyword
  315. as a class name. But if you get into conflicts with other, existing
  316. CSS classes, then this prefix can be very useful."
  317. :group 'org-export-xhtml
  318. :type 'string)
  319. (defcustom org-export-xhtml-preamble t
  320. "Non-nil means insert a preamble in HTML export.
  321. When `t', insert a string as defined by one of the formatting
  322. strings in `org-export-xhtml-preamble-format'. When set to a
  323. string, this string overrides `org-export-xhtml-preamble-format'.
  324. When set to a function, apply this function and insert the
  325. returned string. The function takes the property list of export
  326. options as its only argument.
  327. Setting :html-preamble in publishing projects will take
  328. precedence over this variable."
  329. :group 'org-export-xhtml
  330. :type '(choice (const :tag "No preamble" nil)
  331. (const :tag "Default preamble" t)
  332. (string :tag "Custom formatting string")
  333. (function :tag "Function (must return a string)")))
  334. (defcustom org-export-xhtml-preamble-format
  335. '(("en" "<h1 class=\"title\">%t</h1>"))
  336. "The format for the HTML preamble.
  337. %t stands for the title.
  338. If you need to use a \"%\" character, you need to escape it
  339. like that: \"%%\"."
  340. :group 'org-export-xhtml
  341. :type 'string)
  342. (defcustom org-export-xhtml-postamble 'auto
  343. "Non-nil means insert a postamble in HTML export.
  344. When `t', insert a string as defined by the formatting string in
  345. `org-export-xhtml-postamble-format'. When set to a string, this
  346. string overrides `org-export-xhtml-postamble-format'. When set to
  347. 'auto, discard `org-export-xhtml-postamble-format' and honor
  348. `org-export-author/email/creator-info' variables. When set to a
  349. function, apply this function and insert the returned string.
  350. The function takes the property list of export options as its
  351. only argument.
  352. Setting :html-postamble in publishing projects will take
  353. precedence over this variable."
  354. :group 'org-export-xhtml
  355. :type '(choice (const :tag "No postamble" nil)
  356. (const :tag "Auto preamble" 'auto)
  357. (const :tag "Default formatting string" t)
  358. (string :tag "Custom formatting string")
  359. (function :tag "Function (must return a string)")))
  360. (defcustom org-export-xhtml-postamble-format
  361. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  362. <p class=\"date\">Date: %d</p>
  363. <p class=\"creator\">Generated by %c</p>
  364. <p class=\"xhtml-validation\">%v</p>
  365. "))
  366. "The format for the HTML postamble.
  367. %a stands for the author.
  368. %e stands for the email(s).
  369. %d stands for the date.
  370. %c will be replaced by information about Org/Emacs.
  371. %v will be replaced by `org-export-xhtml-validation-link'.
  372. If you need to use a \"%\" character, you need to escape it
  373. like that: \"%%\"."
  374. :group 'org-export-xhtml
  375. :type 'string)
  376. (defcustom org-export-xhtml-home/up-format
  377. "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  378. <a accesskey=\"h\" href=\"%s\"> UP </a>
  379. |
  380. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  381. </div>"
  382. "Snippet used to insert the HOME and UP links.
  383. This is a format string, the first %s will receive the UP link,
  384. the second the HOME link. If both `org-export-xhtml-link-up' and
  385. `org-export-xhtml-link-home' are empty, the entire snippet will be
  386. ignored."
  387. :group 'org-export-xhtml
  388. :type 'string)
  389. (defcustom org-export-xhtml-toplevel-hlevel 2
  390. "The <H> level for level 1 headings in HTML export.
  391. This is also important for the classes that will be wrapped around headlines
  392. and outline structure. If this variable is 1, the top-level headlines will
  393. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  394. and outline-text-1. If this is 2, all of these will get a 2 instead.
  395. The default for this variable is 2, because we use <h1> for formatting the
  396. document title."
  397. :group 'org-export-xhtml
  398. :type 'string)
  399. (defcustom org-export-xhtml-link-org-files-as-html t
  400. "Non-nil means make file links to `file.org' point to `file.html'.
  401. When org-mode is exporting an org-mode file to HTML, links to
  402. non-html files are directly put into a href tag in HTML.
  403. However, links to other Org-mode files (recognized by the
  404. extension `.org.) should become links to the corresponding html
  405. file, assuming that the linked org-mode file will also be
  406. converted to HTML.
  407. When nil, the links still point to the plain `.org' file."
  408. :group 'org-export-xhtml
  409. :type 'boolean)
  410. (defcustom org-export-xhtml-inline-images 'maybe
  411. "Non-nil means inline images into exported HTML pages.
  412. This is done using an <img> tag. When nil, an anchor with href is used to
  413. link to the image. If this option is `maybe', then images in links with
  414. an empty description will be inlined, while images with a description will
  415. be linked only."
  416. :group 'org-export-xhtml
  417. :type '(choice (const :tag "Never" nil)
  418. (const :tag "Always" t)
  419. (const :tag "When there is no description" maybe)))
  420. (defcustom org-export-xhtml-inline-image-extensions
  421. '("png" "jpeg" "jpg" "gif" "svg")
  422. "Extensions of image files that can be inlined into HTML."
  423. :group 'org-export-xhtml
  424. :type '(repeat (string :tag "Extension")))
  425. (defcustom org-export-xhtml-table-tag
  426. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  427. "The HTML tag that is used to start a table.
  428. This must be a <table> tag, but you may change the options like
  429. borders and spacing."
  430. :group 'org-export-xhtml
  431. :type 'string)
  432. (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  433. "The opening tag for table header fields.
  434. This is customizable so that alignment options can be specified.
  435. The first %s will be filled with the scope of the field, either row or col.
  436. The second %s will be replaced by a style entry to align the field.
  437. See also the variable `org-export-xhtml-table-use-header-tags-for-first-column'.
  438. See also the variable `org-export-xhtml-table-align-individual-fields'."
  439. :group 'org-export-tables
  440. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  441. (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
  442. "The opening tag for table data fields.
  443. This is customizable so that alignment options can be specified.
  444. The first %s will be filled with the scope of the field, either row or col.
  445. The second %s will be replaced by a style entry to align the field.
  446. See also the variable `org-export-xhtml-table-align-individual-fields'."
  447. :group 'org-export-tables
  448. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  449. (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
  450. "The opening tag for table data fields.
  451. This is customizable so that alignment options can be specified.
  452. Instead of strings, these can be Lisp forms that will be evaluated
  453. for each row in order to construct the table row tags. During evaluation,
  454. the variable `head' will be true when this is a header line, nil when this
  455. is a body line. And the variable `nline' will contain the line number,
  456. starting from 1 in the first header line. For example
  457. (setq org-export-table-row-tags
  458. (cons '(if head
  459. \"<tr>\"
  460. (if (= (mod nline 2) 1)
  461. \"<tr class=\\\"tr-odd\\\">\"
  462. \"<tr class=\\\"tr-even\\\">\"))
  463. \"</tr>\"))
  464. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  465. :group 'org-export-tables
  466. :type '(cons
  467. (choice :tag "Opening tag"
  468. (string :tag "Specify")
  469. (sexp))
  470. (choice :tag "Closing tag"
  471. (string :tag "Specify")
  472. (sexp))))
  473. (defcustom org-export-xhtml-table-align-individual-fields t
  474. "Non-nil means attach style attributes for alignment to each table field.
  475. When nil, alignment will only be specified in the column tags, but this
  476. is ignored by some browsers (like Firefox, Safari). Opera does it right
  477. though."
  478. :group 'org-export-tables
  479. :type 'boolean)
  480. (defcustom org-export-xhtml-table-use-header-tags-for-first-column nil
  481. "Non-nil means format column one in tables with header tags.
  482. When nil, also column one will use data tags."
  483. :group 'org-export-tables
  484. :type 'boolean)
  485. (defcustom org-export-xhtml-validation-link
  486. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  487. "Link to HTML validation service."
  488. :group 'org-export-xhtml
  489. :type 'string)
  490. (defcustom org-export-xhtml-with-timestamp nil
  491. "If non-nil, write timestamp into the exported HTML text.
  492. If non-nil, write `org-export-xhtml-html-helper-timestamp' into the
  493. exported HTML text. Otherwise, the buffer will just be saved to
  494. a file."
  495. :group 'org-export-xhtml
  496. :type 'boolean)
  497. (defcustom org-export-xhtml-html-helper-timestamp
  498. "<br/><br/><hr/><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
  499. "The HTML tag used as timestamp delimiter for HTML-helper-mode."
  500. :group 'org-export-xhtml
  501. :type 'string)
  502. (defcustom org-export-xhtml-protect-char-alist
  503. '(("&" . "&amp;")
  504. ("<" . "&lt;")
  505. (">" . "&gt;"))
  506. "Alist of characters to be converted by `org-html-protect'."
  507. :type '(repeat (cons (string :tag "Character")
  508. (string :tag "HTML equivalent"))))
  509. (defgroup org-export-xhtmlize nil
  510. "Options for processing examples with htmlize.el."
  511. :tag "Org Export Htmlize"
  512. :group 'org-export-xhtml)
  513. (defcustom org-export-xhtmlize-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-xhtmlize-generate-css] to extract class definitions."
  528. :group 'org-export-xhtmlize
  529. :type '(choice (const css) (const inline-css)))
  530. (defcustom org-export-xhtmlize-css-font-prefix "org-"
  531. "The prefix for CSS class names for htmlize font specifications."
  532. :group 'org-export-xhtmlize
  533. :type 'string)
  534. (defcustom org-export-xhtmlized-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-xhtmlize
  544. :type '(choice
  545. (const :tag "Keep internal css" nil)
  546. (string :tag "URL or local href")))
  547. ;;; Hooks
  548. (defvar org-export-xhtml-after-blockquotes-hook nil
  549. "Hook run during HTML export, after blockquote, verse, center are done.")
  550. (defvar org-export-xhtml-final-hook nil
  551. "Hook run at the end of HTML export, in the new buffer.")
  552. ;;; HTML export
  553. (defun org-export-xhtml-preprocess (parameters)
  554. "Convert LaTeX fragments to images."
  555. (when (and org-current-export-file
  556. (plist-get parameters :LaTeX-fragments))
  557. (org-format-latex
  558. (concat "ltxpng/" (file-name-sans-extension
  559. (file-name-nondirectory
  560. org-current-export-file)))
  561. org-current-export-dir nil "Creating LaTeX image %s"
  562. nil nil
  563. (cond
  564. ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
  565. ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
  566. ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
  567. ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
  568. (t nil))))
  569. (goto-char (point-min))
  570. (let (label l1)
  571. (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
  572. (org-if-unprotected-at (match-beginning 1)
  573. (setq label (match-string 1))
  574. (save-match-data
  575. (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  576. (setq l1 (substring label (match-beginning 1)))
  577. (setq l1 label)))
  578. (replace-match (format "[[#%s][%s]]" label l1) t t)))))
  579. (defvar html-table-tag nil) ; dynamically scoped into this.
  580. ;; FIXME: it already exists in org-html.el
  581. (defconst org-html-cvt-link-fn
  582. nil
  583. "Function to convert link URLs to exportable URLs.
  584. Takes two arguments, TYPE and PATH.
  585. Returns exportable url as (TYPE PATH), or nil to signal that it
  586. didn't handle this case.
  587. Intended to be locally bound around a call to `org-export-as-html'." )
  588. ;; FIXME: it already exists in org-html.el
  589. (defun org-html-cvt-org-as-html (opt-plist type path)
  590. "Convert an org filename to an equivalent html filename.
  591. If TYPE is not file, just return `nil'.
  592. See variable `org-export-xhtml-link-org-files-as-html'"
  593. (save-match-data
  594. (and
  595. org-export-xhtml-link-org-files-as-html
  596. (string= type "file")
  597. (string-match "\\.org$" path)
  598. (progn
  599. (list
  600. "file"
  601. (concat
  602. (substring path 0 (match-beginning 0))
  603. "."
  604. (plist-get opt-plist :html-extension)))))))
  605. ;;; org-xhtml-format-org-link
  606. (defun org-xhtml-format-org-link (opt-plist type-1 path fragment desc attr
  607. descp)
  608. "Make an HTML link.
  609. OPT-PLIST is an options list.
  610. TYPE is the device-type of the link (THIS://foo.html)
  611. PATH is the path of the link (http://THIS#locationx)
  612. FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
  613. DESC is the link description, if any.
  614. ATTR is a string of other attributes of the a element.
  615. MAY-INLINE-P allows inlining it as an image."
  616. (declare (special org-lparse-par-open))
  617. (when (string= type-1 "coderef")
  618. (setq attr
  619. (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  620. fragment fragment)))
  621. (save-match-data
  622. (let* ((may-inline-p
  623. (and (member type-1 '("http" "https" "file"))
  624. (org-lparse-should-inline-p path descp)
  625. (not fragment)))
  626. (type (if (equal type-1 "id") "file" type-1))
  627. (filename path)
  628. ;;First pass. Just sanity stuff.
  629. (components-1
  630. (cond
  631. ((string= type "file")
  632. (list
  633. type
  634. ;;Substitute just if original path was absolute.
  635. ;;(Otherwise path must remain relative)
  636. (if (file-name-absolute-p path)
  637. (concat "file://" (expand-file-name path))
  638. path)))
  639. ((string= type "")
  640. (list nil path))
  641. (t (list type path))))
  642. ;;Second pass. Components converted so they can refer
  643. ;;to a remote site.
  644. (components-2
  645. (or
  646. (and org-html-cvt-link-fn
  647. (apply org-html-cvt-link-fn
  648. opt-plist components-1))
  649. (apply #'org-html-cvt-org-as-html
  650. opt-plist components-1)
  651. components-1))
  652. (type (first components-2))
  653. (thefile (second components-2)))
  654. ;;Third pass. Build final link except for leading type
  655. ;;spec.
  656. (cond
  657. ((or
  658. (not type)
  659. (string= type "http")
  660. (string= type "https")
  661. (string= type "file")
  662. (string= type "coderef"))
  663. (if fragment
  664. (setq thefile (concat thefile "#" fragment))))
  665. (t))
  666. ;;Final URL-build, for all types.
  667. (setq thefile
  668. (let
  669. ((str (org-xml-format-href thefile)))
  670. (if (and type (not (or (string= "file" type)
  671. (string= "coderef" type))))
  672. (concat type ":" str)
  673. str)))
  674. (if may-inline-p
  675. (org-xhtml-format-image thefile)
  676. (org-lparse-format
  677. 'LINK (org-xml-format-desc desc) thefile attr)))))
  678. (defun org-xhtml-format-inline-image (desc)
  679. ;; FIXME: alt text missing here?
  680. (org-xhtml-format-tags "<img src=\"%s\" alt=\"\"/>" "" desc))
  681. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  682. (defvar org-lparse-link-description-is-image)
  683. (defun org-xhtml-format-image (src)
  684. "Create image tag with source and attributes."
  685. (save-match-data
  686. (if (string-match "^ltxpng/" src)
  687. (format "<img src=\"%s\" alt=\"%s\"/>"
  688. src (org-find-text-property-in-string 'org-latex-src src))
  689. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  690. (attr (org-find-text-property-in-string 'org-attributes src))
  691. (label (org-find-text-property-in-string 'org-label src))
  692. (caption (and caption (org-xml-encode-org-text caption)))
  693. (img (format "<img src=\"%s\"%s />"
  694. src
  695. (if (string-match "\\<alt=" (or attr ""))
  696. (concat " " attr )
  697. (concat " " attr " alt=\"" src "\""))))
  698. (extra (concat
  699. (and label
  700. (format "id=\"%s\" " (org-solidify-link-text label)))
  701. "class=\"figure\"")))
  702. (if caption
  703. (with-temp-buffer
  704. (with-org-lparse-preserve-paragraph-state
  705. (insert
  706. (org-lparse-format
  707. '("<div %s>" . "\n</div>")
  708. (concat
  709. (org-lparse-format '("\n<p>" . "</p>") img)
  710. (org-lparse-format '("\n<p>" . "</p>") caption))
  711. extra)))
  712. (buffer-string))
  713. img)))))
  714. (defun org-export-xhtml-get-bibliography ()
  715. "Find bibliography, cut it out and return it."
  716. (catch 'exit
  717. (let (beg end (cnt 1) bib)
  718. (save-excursion
  719. (goto-char (point-min))
  720. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  721. (setq beg (match-beginning 0))
  722. (while (re-search-forward "</?div\\>" nil t)
  723. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  724. (when (= cnt 0)
  725. (and (looking-at ">") (forward-char 1))
  726. (setq bib (buffer-substring beg (point)))
  727. (delete-region beg (point))
  728. (throw 'exit bib))))
  729. nil))))
  730. (defun org-xhtml-format-table (lines olines)
  731. (let ((org-xhtml-format-table-no-css nil))
  732. (org-lparse-format-table lines olines)))
  733. ;; Following variable is defined for native tables i.e., when
  734. ;; `org-lparse-table-is-styled' evals to t.
  735. (defvar org-xhtml-format-table-no-css)
  736. (defvar org-table-number-regexp) ; defined in org-table.el
  737. ;; FIXME: This function is called from other modules. Use xhtml suffix
  738. ;; to avoid conflict
  739. (defun org-format-table-xhtml (lines olines &optional no-css)
  740. "Find out which HTML converter to use and return the HTML code.
  741. NO-CSS is passed to the exporter."
  742. (let* ((org-lparse-backend 'xhtml)
  743. (org-lparse-entity-control-callbacks-alist
  744. (org-lparse-get 'ENTITY-CONTROL))
  745. (org-lparse-entity-format-callbacks-alist
  746. (org-lparse-get 'ENTITY-FORMAT))
  747. (org-xhtml-format-table-no-css no-css))
  748. (org-lparse-format-table lines olines)))
  749. ;; FIXME: This function is called from other modules. Use xhtml suffix
  750. ;; to avoid conflict
  751. (defun org-format-org-table-xhtml (lines &optional splice no-css)
  752. ;; This routine might get called outside of org-export-as-html. For
  753. ;; example, this could happen as part of org-table-export or as part
  754. ;; of org-export-as-docbook. Explicitly bind the parser callback to
  755. ;; the html ones for the duration of the call.
  756. (let* ((org-lparse-backend 'xhtml)
  757. (org-lparse-entity-control-callbacks-alist
  758. (org-lparse-get 'ENTITY-CONTROL))
  759. (org-lparse-entity-format-callbacks-alist
  760. (org-lparse-get 'ENTITY-FORMAT))
  761. (org-xhtml-format-table-no-css no-css))
  762. (org-lparse-format-org-table lines splice)))
  763. ;; FIXME: it already exists in org-html.el
  764. (defun org-export-splice-attributes (tag attributes)
  765. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  766. (if (not attributes)
  767. tag
  768. (let (oldatt newatt)
  769. (setq oldatt (org-extract-attributes-from-string tag)
  770. tag (pop oldatt)
  771. newatt (cdr (org-extract-attributes-from-string attributes)))
  772. (while newatt
  773. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  774. (if (string-match ">" tag)
  775. (setq tag
  776. (replace-match (concat (org-attributes-to-string oldatt) ">")
  777. t t tag)))
  778. tag)))
  779. ;; FIXME: This function is called from other modules. Use xhtml suffix
  780. ;; to avoid conflict
  781. (defun org-format-table-table-xhtml (lines)
  782. (let* ((org-lparse-get 'html)
  783. (org-lparse-entity-control-callbacks-alist
  784. (org-lparse-get 'ENTITY-CONTROL))
  785. (org-lparse-entity-format-callbacks-alist
  786. (org-lparse-get 'ENTITY-FORMAT)))
  787. (org-lparse-format-table-table lines)))
  788. ;; FIXME: it already exists in org-html.el
  789. (defun org-export-splice-style (style extra)
  790. "Splice EXTRA into STYLE, just before \"</style>\"."
  791. (if (and (stringp extra)
  792. (string-match "\\S-" extra)
  793. (string-match "</style>" style))
  794. (concat (substring style 0 (match-beginning 0))
  795. "\n" extra "\n"
  796. (substring style (match-beginning 0)))
  797. style))
  798. (defvar htmlize-buffer-places) ; from htmlize.el
  799. (defun org-export-xhtmlize-region-for-paste (beg end)
  800. "Convert the region to HTML, using htmlize.el.
  801. This is much like `htmlize-region-for-paste', only that it uses
  802. the settings define in the org-... variables."
  803. (let* ((htmlize-output-type org-export-xhtmlize-output-type)
  804. (htmlize-css-name-prefix org-export-xhtmlize-css-font-prefix)
  805. (htmlbuf (htmlize-region beg end)))
  806. (unwind-protect
  807. (with-current-buffer htmlbuf
  808. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  809. (plist-get htmlize-buffer-places 'content-end)))
  810. (kill-buffer htmlbuf))))
  811. ;;;###autoload
  812. (defun org-export-xhtmlize-generate-css ()
  813. "Create the CSS for all font definitions in the current Emacs session.
  814. Use this to create face definitions in your CSS style file that can then
  815. be used by code snippets transformed by htmlize.
  816. This command just produces a buffer that contains class definitions for all
  817. faces used in the current Emacs session. You can copy and paste the ones you
  818. need into your CSS file.
  819. If you then set `org-export-xhtmlize-output-type' to `css', calls to
  820. the function `org-export-xhtmlize-region-for-paste' will produce code
  821. that uses these same face definitions."
  822. (interactive)
  823. (require 'htmlize)
  824. (and (get-buffer "*html*") (kill-buffer "*html*"))
  825. (with-temp-buffer
  826. (let ((fl (face-list))
  827. (htmlize-css-name-prefix "org-")
  828. (htmlize-output-type 'css)
  829. f i)
  830. (while (setq f (pop fl)
  831. i (and f (face-attribute f :inherit)))
  832. (when (and (symbolp f) (or (not i) (not (listp i))))
  833. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  834. (htmlize-region (point-min) (point-max))))
  835. (org-pop-to-buffer-same-window "*html*")
  836. (goto-char (point-min))
  837. (if (re-search-forward "<style" nil t)
  838. (delete-region (point-min) (match-beginning 0)))
  839. (if (re-search-forward "</style>" nil t)
  840. (delete-region (1+ (match-end 0)) (point-max)))
  841. (beginning-of-line 1)
  842. (if (looking-at " +") (replace-match ""))
  843. (goto-char (point-min)))
  844. (defvar body-only) ; dynamically scoped into this.
  845. ;; Following variable is let bound when `org-do-lparse' is in
  846. ;; progress. See org-lparse.el.
  847. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  848. (defvar org-lparse-toc)
  849. (defvar org-lparse-footnote-buffer)
  850. (defvar org-lparse-footnote-definitions)
  851. (defvar org-lparse-dyn-first-heading-pos)
  852. (defun org-xhtml-end-export ()
  853. ;; insert the table of contents
  854. (when (and org-export-with-toc (not body-only) org-lparse-toc)
  855. (org-xhtml-insert-toc org-lparse-toc))
  856. ;; remove empty paragraphs
  857. (goto-char (point-min))
  858. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  859. (replace-match ""))
  860. ;; Convert whitespace place holders
  861. (goto-char (point-min))
  862. (let (beg end n)
  863. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  864. (setq n (get-text-property beg 'org-whitespace)
  865. end (next-single-property-change beg 'org-whitespace))
  866. (goto-char beg)
  867. (delete-region beg end)
  868. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  869. (make-string n ?x)))))
  870. ;; Remove empty lines at the beginning of the file.
  871. (goto-char (point-min))
  872. (when (looking-at "\\s-+\n") (replace-match ""))
  873. ;; Remove display properties
  874. (remove-text-properties (point-min) (point-max) '(display t))
  875. ;; kill temporary buffers
  876. (when org-lparse-footnote-buffer
  877. (kill-buffer org-lparse-footnote-buffer))
  878. ;; Run the hook
  879. (run-hooks 'org-export-xhtml-final-hook))
  880. (defun org-xhtml-format-toc-entry (snumber todo headline tags href)
  881. (setq headline (concat
  882. (and org-export-with-section-numbers
  883. (concat snumber " "))
  884. headline
  885. (and tags
  886. (concat
  887. (org-lparse-format 'SPACES 3)
  888. (org-lparse-format 'FONTIFY tags "tag")))))
  889. (when todo
  890. (setq headline (org-lparse-format 'FONTIFY headline "todo")))
  891. (org-lparse-format 'LINK headline (concat "#" href)))
  892. (defun org-xhtml-format-toc-item (toc-entry level org-last-level)
  893. (when (> level org-last-level)
  894. (let ((cnt (- level org-last-level)))
  895. (while (>= (setq cnt (1- cnt)) 0)
  896. (org-lparse-begin-list 'unordered)
  897. (org-lparse-begin 'LIST-ITEM 'unordered))))
  898. (when (< level org-last-level)
  899. (let ((cnt (- org-last-level level)))
  900. (while (>= (setq cnt (1- cnt)) 0)
  901. (org-lparse-end-list-item)
  902. (org-lparse-end-list 'unordered))))
  903. (org-lparse-end-list-item)
  904. (org-lparse-begin 'LIST-ITEM 'unordered)
  905. (insert toc-entry))
  906. (defun org-xhtml-begin-toc (lang-specific-heading)
  907. (org-lparse-insert-tag "<div id=\"table-of-contents\">")
  908. (insert
  909. (org-lparse-format 'HEADING lang-specific-heading
  910. (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1)))
  911. (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
  912. (org-lparse-begin-list 'unordered)
  913. (org-lparse-begin 'LIST-ITEM 'unordered))
  914. (defun org-xhtml-end-toc ()
  915. (while (> org-last-level (1- org-min-level))
  916. (setq org-last-level (1- org-last-level))
  917. (org-lparse-end-list-item)
  918. (org-lparse-end-list 'unordered))
  919. (org-lparse-insert-tag "</div>")
  920. (org-lparse-insert-tag "</div>")
  921. ;; cleanup empty list items in toc
  922. (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
  923. (replace-match "")))
  924. ;;;###autoload
  925. (defun org-export-as-xhtml-and-open (arg)
  926. "Export the outline as HTML and immediately open it with a browser.
  927. If there is an active region, export only the region.
  928. The prefix ARG specifies how many levels of the outline should become
  929. headlines. The default is 3. Lower levels will become bulleted lists."
  930. (interactive "P")
  931. (org-lparse-and-open "xhtml" "xhtml" arg))
  932. ;;;###autoload
  933. (defun org-export-as-xhtml-batch ()
  934. "Call the function `org-lparse-batch'.
  935. This function can be used in batch processing as:
  936. emacs --batch
  937. --load=$HOME/lib/emacs/org.el
  938. --eval \"(setq org-export-headline-levels 2)\"
  939. --visit=MyFile --funcall org-export-as-html-batch"
  940. (org-lparse-batch "xhtml"))
  941. ;;;###autoload
  942. (defun org-export-as-xhtml-to-buffer (arg)
  943. "Call `org-lparse-to-buffer` with output to a temporary buffer.
  944. No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
  945. (interactive "P")
  946. (org-lparse-to-buffer "xhtml" arg))
  947. ;;;###autoload
  948. (defun org-replace-region-by-xhtml (beg end)
  949. "Assume the current region has org-mode syntax, and convert it to HTML.
  950. This can be used in any buffer. For example, you could write an
  951. itemized list in org-mode syntax in an HTML buffer and then use this
  952. command to convert it."
  953. (interactive "r")
  954. (org-replace-region-by "xhtml" beg end))
  955. ;;;###autoload
  956. (defun org-export-region-as-xhtml (beg end &optional body-only buffer)
  957. "Convert region from BEG to END in `org-mode' buffer to HTML.
  958. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  959. contents, and only produce the region of converted text, useful for
  960. cut-and-paste operations.
  961. If BUFFER is a buffer or a string, use/create that buffer as a target
  962. of the converted HTML. If BUFFER is the symbol `string', return the
  963. produced HTML as a string and leave not buffer behind. For example,
  964. a Lisp program could call this function in the following way:
  965. (setq html (org-export-region-as-html beg end t 'string))
  966. When called interactively, the output buffer is selected, and shown
  967. in a window. A non-interactive call will only return the buffer."
  968. (interactive "r\nP")
  969. (org-lparse-region "xhtml" beg end body-only buffer))
  970. ;;; org-export-as-xhtml
  971. ;;;###autoload
  972. (defun org-export-as-xhtml (arg &optional hidden ext-plist
  973. to-buffer body-only pub-dir)
  974. "Export the outline as a pretty HTML file.
  975. Use `org-lparse' internally to perform the actual export. This
  976. routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
  977. of `org-lparse' to \"html\"."
  978. (interactive "P")
  979. (org-lparse "xhtml" "xhtml" arg hidden ext-plist to-buffer body-only pub-dir))
  980. (defvar org-xhtml-entity-control-callbacks-alist
  981. `((EXPORT
  982. . (org-xhtml-begin-export org-xhtml-end-export))
  983. (DOCUMENT-CONTENT
  984. . (org-xhtml-begin-document-content org-xhtml-end-document-content))
  985. (DOCUMENT-BODY
  986. . (org-xhtml-begin-document-body org-xhtml-end-document-body))
  987. (TOC
  988. . (org-xhtml-begin-toc org-xhtml-end-toc))
  989. (ENVIRONMENT
  990. . (org-xhtml-begin-environment org-xhtml-end-environment))
  991. (FOOTNOTE-DEFINITION
  992. . (org-xhtml-begin-footnote-definition org-xhtml-end-footnote-definition))
  993. (TABLE
  994. . (org-xhtml-begin-table org-xhtml-end-table))
  995. (TABLE-ROWGROUP
  996. . (org-xhtml-begin-table-rowgroup org-xhtml-end-table-rowgroup))
  997. (LIST
  998. . (org-xhtml-begin-list org-xhtml-end-list))
  999. (LIST-ITEM
  1000. . (org-xhtml-begin-list-item org-xhtml-end-list-item))
  1001. (OUTLINE
  1002. . (org-xhtml-begin-outline org-xhtml-end-outline))
  1003. (OUTLINE-TEXT
  1004. . (org-xhtml-begin-outline-text org-xhtml-end-outline-text))
  1005. (PARAGRAPH
  1006. . (org-xhtml-begin-paragraph org-xhtml-end-paragraph)))
  1007. "Alist of control callbacks registered with the exporter.
  1008. Each element is of the form (ENTITY . (BEGIN-ENTITY-FUNCTION
  1009. END-ENTITY-FUNCTION)). ENTITY is one of PARAGRAPH, LIST etc as
  1010. seen above. BEGIN-ENTITY-FUNCTION and END-ENTITY-FUNCTION are
  1011. functions that get called when the exporter needs to begin or end
  1012. an entity in the currently exported file. The signatures of
  1013. these callbacks are specific to the ENTITY being emitted. These
  1014. callbacks always get called with exported file as the current
  1015. buffer and need to insert the appropriate tags into the current
  1016. buffer. For example, `org-xhtml-begin-paragraph' inserts <p> and
  1017. `org-xhtml-end-paragraph' inserts </p> in to the current buffer.
  1018. These callbacks are invoked via `org-lparse-begin' and
  1019. `org-lparse-end'.")
  1020. (defvar org-xhtml-entity-format-callbacks-alist
  1021. `((EXTRA-TARGETS . org-lparse-format-extra-targets)
  1022. (ORG-TAGS . org-lparse-format-org-tags)
  1023. (SECTION-NUMBER . org-lparse-format-section-number)
  1024. (HEADLINE . org-xhtml-format-headline)
  1025. (TOC-ENTRY . org-xhtml-format-toc-entry)
  1026. (TOC-ITEM . org-xhtml-format-toc-item)
  1027. (TAGS . org-xhtml-format-tags)
  1028. (SPACES . org-xhtml-format-spaces)
  1029. (TABS . org-xhtml-format-tabs)
  1030. (LINE-BREAK . org-xhtml-format-line-break)
  1031. (FONTIFY . org-xhtml-format-fontify)
  1032. (TODO . org-lparse-format-todo)
  1033. (ORG-LINK . org-xhtml-format-org-link)
  1034. (LINK . org-xhtml-format-link)
  1035. (INLINE-IMAGE . org-xhtml-format-inline-image)
  1036. (HEADING . org-xhtml-format-heading)
  1037. (ANCHOR . org-xhtml-format-anchor)
  1038. (TABLE . org-xhtml-format-table)
  1039. (TABLE-ROW . org-xhtml-format-table-row)
  1040. (TABLE-CELL . org-xhtml-format-table-cell)
  1041. (FOOTNOTES-SECTION . org-xhtml-format-footnotes-section)
  1042. (FOOTNOTE-REFERENCE . org-xhtml-format-footnote-reference)
  1043. (HORIZONTAL-LINE . org-xhtml-format-horizontal-line)
  1044. (LINE . org-xhtml-format-line)
  1045. (COMMENT . org-xhtml-format-comment)
  1046. (ORG-ENTITY . org-xhtml-format-org-entity))
  1047. "Alist of format callbacks registered with the exporter.
  1048. Each element is of the form (ENTITY . ENTITY-FORMAT-FUNCTION).
  1049. ENTITY is one of LINE, HEADING, COMMENT, LINK, TABLE-ROW etc as
  1050. seen above. ENTITY-FORMAT-FUNCTION is a functions that gets
  1051. called when the exporter needs to format a string in `org-mode'
  1052. buffer in a backend specific way. The signatures of the
  1053. formatting callback is specific to the ENTITY being passed in.
  1054. These callbacks always need to encode the incoming entity in
  1055. backend specific way and return the same. These callbacks do not
  1056. make any modifications to the exporter file. For example,
  1057. `org-xhtml-format-table-row' encloses incoming entity in <tr>
  1058. </tr> tags and returns it. See also `org-lparse-format'.")
  1059. ;; register the xhtml exporter with org-lparse library
  1060. (org-lparse-register-backend 'xhtml)
  1061. (defun org-xhtml-unload-function ()
  1062. ;; notify org-lparse library on unload
  1063. (org-lparse-unregister-backend 'xhtml)
  1064. nil)
  1065. (defun org-xhtml-begin-document-body (opt-plist)
  1066. (let ((link-up (and (plist-get opt-plist :link-up)
  1067. (string-match "\\S-" (plist-get opt-plist :link-up))
  1068. (plist-get opt-plist :link-up)))
  1069. (link-home (and (plist-get opt-plist :link-home)
  1070. (string-match "\\S-" (plist-get opt-plist :link-home))
  1071. (plist-get opt-plist :link-home))))
  1072. (insert "\n<body>")
  1073. (org-lparse-insert-tag "<div id=\"content\">")
  1074. (insert "\n"
  1075. (or (and (or link-up link-home)
  1076. (format org-export-xhtml-home/up-format
  1077. (or link-up link-home)
  1078. (or link-home link-up))) "")
  1079. "\n"))
  1080. (org-xhtml-insert-preamble opt-plist))
  1081. (defun org-xhtml-end-document-body (opt-plist)
  1082. (org-xhtml-insert-postamble opt-plist)
  1083. (unless body-only
  1084. (org-lparse-insert-tag "</div>")
  1085. (insert "\n</body>")))
  1086. (defun org-xhtml-begin-document-content (opt-plist)
  1087. (let* ((language (plist-get opt-plist :language))
  1088. (charset (or (and coding-system-for-write
  1089. (fboundp 'coding-system-get)
  1090. (coding-system-get coding-system-for-write
  1091. 'mime-charset))
  1092. "iso-8859-1"))
  1093. (style (concat (if (plist-get opt-plist :style-include-default)
  1094. org-export-xhtml-style-default)
  1095. (plist-get opt-plist :style)
  1096. (plist-get opt-plist :style-extra)
  1097. "\n"
  1098. (if (plist-get opt-plist :style-include-scripts)
  1099. org-export-xhtml-scripts)))
  1100. (mathjax
  1101. (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
  1102. (and org-export-have-math
  1103. (eq (plist-get opt-plist :LaTeX-fragments) t)))
  1104. (org-export-xhtml-mathjax-config
  1105. org-export-xhtml-mathjax-template
  1106. org-export-xhtml-mathjax-options
  1107. (or (plist-get opt-plist :mathjax) "")) "")))
  1108. (insert (format
  1109. "%s
  1110. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1111. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  1112. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  1113. lang=\"%s\" xml:lang=\"%s\">
  1114. <head>
  1115. <title>%s</title>
  1116. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  1117. <meta name=\"generator\" content=\"Org-mode\"/>
  1118. <meta name=\"generated\" content=\"%s\"/>
  1119. <meta name=\"author\" content=\"%s\"/>
  1120. <meta name=\"description\" content=\"%s\"/>
  1121. <meta name=\"keywords\" content=\"%s\"/>
  1122. %s
  1123. %s
  1124. </head>
  1125. "
  1126. (format
  1127. (or (and (stringp org-export-xhtml-xml-declaration)
  1128. org-export-xhtml-xml-declaration)
  1129. (cdr (assoc (plist-get opt-plist :html-extension)
  1130. org-export-xhtml-xml-declaration))
  1131. (cdr (assoc "html" org-export-xhtml-xml-declaration))
  1132. "")
  1133. charset)
  1134. language language
  1135. (plist-get opt-plist :title)
  1136. charset
  1137. (plist-get opt-plist :effective-date)
  1138. (plist-get opt-plist :author)
  1139. (plist-get opt-plist :description)
  1140. (plist-get opt-plist :keywords)
  1141. style
  1142. mathjax))))
  1143. (defun org-xhtml-end-document-content ()
  1144. (insert "\n</html>\n"))
  1145. (defun org-xhtml-begin-outline (level1 snumber title tags
  1146. target extra-targets extra-class)
  1147. (let* ((class (format "outline-%d" level1))
  1148. (class (if extra-class (concat class " " extra-class) class))
  1149. (id (format "outline-container-%s"
  1150. (org-lparse-suffix-from-snumber snumber)))
  1151. (extra (concat (when id (format " id=\"%s\"" id))
  1152. (when class (format " class=\"%s\"" class)))))
  1153. (org-lparse-insert-tag "<div%s>" extra)
  1154. (insert
  1155. (org-lparse-format 'HEADING
  1156. (org-lparse-format
  1157. 'HEADLINE title extra-targets tags snumber level1)
  1158. level1 target))))
  1159. (defun org-xhtml-end-outline ()
  1160. (org-lparse-insert-tag "</div>"))
  1161. (defun org-xhtml-begin-outline-text (level1 snumber extra-class)
  1162. (let* ((class (format "outline-text-%d" level1))
  1163. (class (if extra-class (concat class " " extra-class) class))
  1164. (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
  1165. (extra (concat (when id (format " id=\"%s\"" id))
  1166. (when class (format " class=\"%s\"" class)))))
  1167. (org-lparse-insert-tag "<div%s>" extra)))
  1168. (defun org-xhtml-end-outline-text ()
  1169. (org-lparse-insert-tag "</div>"))
  1170. (defun org-xhtml-begin-paragraph (&optional style)
  1171. (let* ((class (cdr (assoc style '((footnote . "footnote")
  1172. (verse . nil)))))
  1173. (extra (if class (format " class=\"%s\"" class) "")))
  1174. (org-lparse-insert-tag "<p%s>" extra)))
  1175. (defun org-xhtml-end-paragraph ()
  1176. (insert "</p>"))
  1177. (defun org-xhtml-format-environment (style beg-end)
  1178. (assert (memq style '(blockquote center verse fixedwidth quote native)) t)
  1179. (case style
  1180. (blockquote
  1181. (case beg-end
  1182. (BEGIN
  1183. (org-lparse-end-paragraph)
  1184. (insert "<blockquote>\n")
  1185. (org-lparse-begin-paragraph))
  1186. (END
  1187. (org-lparse-end-paragraph)
  1188. (insert "\n</blockquote>\n")
  1189. (org-lparse-begin-paragraph))))
  1190. (verse
  1191. (case beg-end
  1192. (BEGIN
  1193. (org-lparse-end-paragraph)
  1194. (insert "\n<p class=\"verse\">\n")
  1195. (setq org-lparse-par-open t))
  1196. (END
  1197. (insert "</p>\n")
  1198. (setq org-lparse-par-open nil)
  1199. (org-lparse-begin-paragraph))))
  1200. (center
  1201. (case beg-end
  1202. (BEGIN
  1203. (org-lparse-end-paragraph)
  1204. (insert "\n<div style=\"text-align: center\">")
  1205. (org-lparse-begin-paragraph))
  1206. (END
  1207. (org-lparse-end-paragraph)
  1208. (insert "\n</div>")
  1209. (org-lparse-begin-paragraph))))
  1210. (fixedwidth
  1211. (case beg-end
  1212. (BEGIN
  1213. (org-lparse-end-paragraph)
  1214. (insert "<pre class=\"example\">\n"))
  1215. (END
  1216. (insert "</pre>\n")
  1217. (org-lparse-begin-paragraph))))
  1218. (quote
  1219. (case beg-end
  1220. (BEGIN
  1221. (org-lparse-end-paragraph)
  1222. (insert "<pre>"))
  1223. (END
  1224. (insert "</pre>\n")
  1225. (org-lparse-begin-paragraph))))
  1226. (native
  1227. (case beg-end
  1228. (BEGIN (org-lparse-end-paragraph))
  1229. (END (org-lparse-begin-paragraph))))
  1230. (t (error "Unknown environment %s" style))))
  1231. (defun org-xhtml-begin-environment (style)
  1232. (org-xhtml-format-environment style 'BEGIN))
  1233. (defun org-xhtml-end-environment (style)
  1234. (org-xhtml-format-environment style 'END))
  1235. (defun org-xhtml-begin-list (ltype)
  1236. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1237. ltype))
  1238. (case ltype
  1239. (ordered (let* ((arg1 nil)
  1240. (extra (if arg1 (format " start=\"%d\"" arg1) "")))
  1241. (org-lparse-insert-tag "<ol%s>" extra)))
  1242. (unordered (org-lparse-insert-tag "<ul>"))
  1243. (description (org-lparse-insert-tag "<dl>"))
  1244. (t (error "Unknown list type: %s" ltype))))
  1245. (defun org-xhtml-end-list (ltype)
  1246. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1247. ltype))
  1248. (org-lparse-insert-tag
  1249. (case ltype
  1250. (ordered "</ol>")
  1251. (unordered "</ul>")
  1252. (description "</dl>")
  1253. (t (error "Unknown list type: %s" ltype)))))
  1254. (defun org-xhtml-begin-list-item (ltype &optional arg headline)
  1255. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1256. ltype))
  1257. (case ltype
  1258. (ordered
  1259. (assert (not headline) t)
  1260. (let* ((counter arg)
  1261. (extra (if counter (format " value=\"%s\"" counter) "")))
  1262. (org-lparse-insert-tag "<li%s>" extra)))
  1263. (unordered
  1264. (let* ((id arg)
  1265. (extra (if id (format " id=\"%s\"" id) "")))
  1266. (org-lparse-insert-tag "<li%s>" extra)
  1267. (when headline
  1268. (insert headline (org-lparse-format 'LINE-BREAK) "\n"))))
  1269. (description
  1270. (assert (not headline) t)
  1271. (let* ((desc-tag (or arg "(no term)")))
  1272. (insert
  1273. (org-xhtml-format-tags '("<dt>" . "</dt>") desc-tag))
  1274. (org-lparse-insert-tag "<dd>")))
  1275. (t (error "Unknown list type"))))
  1276. (defun org-xhtml-end-list-item (ltype)
  1277. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1278. ltype))
  1279. (case ltype
  1280. (ordered (org-lparse-insert-tag "</li>"))
  1281. (unordered (org-lparse-insert-tag "</li>"))
  1282. (description (org-lparse-insert-tag "</dd>"))
  1283. (t (error "Unknown list type"))))
  1284. ;; Following variables are let bound when table emission is in
  1285. ;; progress. See org-lparse.el.
  1286. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  1287. (defvar org-lparse-table-begin-marker)
  1288. (defvar org-lparse-table-ncols)
  1289. (defvar org-lparse-table-rowgrp-open)
  1290. (defvar org-lparse-table-rownum)
  1291. (defvar org-lparse-table-cur-rowgrp-is-hdr)
  1292. (defvar org-lparse-table-is-styled)
  1293. (defvar org-lparse-table-rowgrp-info)
  1294. (defvar org-lparse-table-colalign-vector)
  1295. (defvar org-lparse-table-num-numeric-items-per-column)
  1296. (defun org-xhtml-begin-table-rowgroup (&optional is-header-row)
  1297. (when org-lparse-table-rowgrp-open
  1298. (org-lparse-end 'TABLE-ROWGROUP))
  1299. (org-lparse-insert-tag (if is-header-row "<thead>" "<tbody>"))
  1300. (setq org-lparse-table-rowgrp-open t)
  1301. (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row))
  1302. (defun org-xhtml-end-table-rowgroup ()
  1303. (when org-lparse-table-rowgrp-open
  1304. (setq org-lparse-table-rowgrp-open nil)
  1305. (org-lparse-insert-tag
  1306. (if org-lparse-table-cur-rowgrp-is-hdr "</thead>" "</tbody>"))))
  1307. (defun org-xhtml-begin-table (caption label attributes)
  1308. (let ((html-table-tag
  1309. (org-export-splice-attributes html-table-tag attributes)))
  1310. (when label
  1311. (setq html-table-tag
  1312. (org-export-splice-attributes
  1313. html-table-tag
  1314. (format "id=\"%s\"" (org-solidify-link-text label)))))
  1315. (org-lparse-insert-tag html-table-tag))
  1316. ;; Since the output of HTML table formatter can also be used in
  1317. ;; DocBook document, we want to always include the caption to make
  1318. ;; DocBook XML file valid.
  1319. (insert (format "<caption>%s</caption>" (or caption "")) "\n"))
  1320. (defun org-xhtml-end-table ()
  1321. (when org-lparse-table-is-styled
  1322. (goto-char org-lparse-table-begin-marker)
  1323. (setq org-lparse-table-begin-marker nil)
  1324. (let ((c -1) gr colgropen)
  1325. (insert
  1326. (mapconcat
  1327. (lambda (x)
  1328. (incf c)
  1329. (setq gr (pop org-table-colgroup-info))
  1330. (concat
  1331. (if (memq gr '(:start :startend))
  1332. (prog1
  1333. (if colgropen
  1334. "</colgroup>\n<colgroup>"
  1335. "<colgroup>")
  1336. (setq colgropen t))
  1337. "")
  1338. (let* ((align (aref org-lparse-table-colalign-vector c))
  1339. (alignspec (if org-xhtml-format-table-no-css
  1340. " align=\"%s\"" " class=\"%s\""))
  1341. (extra (format alignspec align)))
  1342. (format "<col%s />" extra))
  1343. (if (memq gr '(:end :startend))
  1344. (progn (setq colgropen nil) "</colgroup>")
  1345. "")))
  1346. org-lparse-table-num-numeric-items-per-column ""))
  1347. (if colgropen (insert "</colgroup>")))
  1348. ;; fill style attributes for table cells
  1349. (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t)
  1350. (let ((c (string-to-number (match-string 1))))
  1351. (replace-match
  1352. (if org-export-xhtml-table-align-individual-fields
  1353. (format (if org-xhtml-format-table-no-css " align=\"%s\""
  1354. " class=\"%s\"")
  1355. (or (aref org-lparse-table-colalign-vector c) "left")) "")
  1356. t t)))
  1357. (goto-char (point-max)))
  1358. (org-lparse-insert-tag "</table>\n"))
  1359. (defun org-xhtml-format-table-row (row)
  1360. (org-xhtml-format-tags
  1361. (cons (eval (car org-export-table-row-tags))
  1362. (eval (cdr org-export-table-row-tags))) row))
  1363. (defun org-xhtml-format-table-cell (text r c)
  1364. (let ((cell-style-cookie (or (and org-lparse-table-is-styled
  1365. (format "@@class%03d@@" c)) "")))
  1366. (cond
  1367. (org-lparse-table-cur-rowgrp-is-hdr
  1368. (org-xhtml-format-tags
  1369. org-export-table-header-tags text "col" cell-style-cookie))
  1370. ((and (= c 0) org-export-xhtml-table-use-header-tags-for-first-column)
  1371. (org-xhtml-format-tags
  1372. org-export-table-header-tags text "row" cell-style-cookie))
  1373. (t
  1374. (org-xhtml-format-tags
  1375. org-export-table-data-tags text cell-style-cookie)))))
  1376. (defun org-xhtml-begin-footnote-definition (n)
  1377. (org-lparse-begin-paragraph 'footnote)
  1378. (insert
  1379. (format
  1380. (format org-export-xhtml-footnote-format
  1381. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1382. n n n)))
  1383. (defun org-xhtml-end-footnote-definition (n)
  1384. (org-lparse-end-paragraph))
  1385. (defun org-xhtml-format-spaces (n)
  1386. (let ((space (or (and org-lparse-encode-pending "\\nbsp") "&nbsp;")) out)
  1387. (while (> n 0)
  1388. (setq out (concat out space))
  1389. (setq n (1- n))) out))
  1390. (defun org-xhtml-format-tabs (&optional n)
  1391. (ignore))
  1392. (defun org-xhtml-format-line-break ()
  1393. (org-xhtml-format-tags "<br/>" ""))
  1394. (defun org-xhtml-format-horizontal-line ()
  1395. (concat "\n" "<hr/>" "\n"))
  1396. (defun org-xhtml-format-line (line)
  1397. (case org-lparse-dyn-current-environment
  1398. ((quote fixedwidth) (concat (org-xml-encode-plain-text line) "\n"))
  1399. (t (concat line "\n"))))
  1400. (defun org-xhtml-format-comment (fmt &rest args)
  1401. (let ((comment (apply 'format fmt args)))
  1402. (format "\n<!-- %s -->\n" comment)))
  1403. (defun org-xhtml-format-fontify (text style &optional id)
  1404. (let (class extra how)
  1405. (cond
  1406. ((eq style 'underline)
  1407. (setq extra " style=\"text-decoration:underline;\"" ))
  1408. ((setq how (cdr (assoc style
  1409. '((bold . ("<b>" . "</b>"))
  1410. (emphasis . ("<i>" . "</i>"))
  1411. (code . ("<code>" . "</code>"))
  1412. (verbatim . ("<code>" . "</code>"))
  1413. (strike . ("<del>" . "</del>"))
  1414. (subscript . ("<sub>" . "</sub>"))
  1415. (superscript . ("<sup>" . "</sup>")))))))
  1416. ((listp style)
  1417. (setq class (mapconcat 'identity style " ")))
  1418. ((stringp style)
  1419. (setq class style))
  1420. (t (error "Unknown style %S" style)))
  1421. (setq extra (concat (when class (format " class=\"%s\"" class))
  1422. (when id (format " id=\"%s\"" id))
  1423. extra))
  1424. (org-xhtml-format-tags
  1425. (or how '("<span%s>" . "</span>")) text extra)))
  1426. (defun org-xhtml-format-link (text href &optional extra)
  1427. (let ((extra (concat (format " href=\"%s\"" href)
  1428. (and extra (concat " " extra)))))
  1429. (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
  1430. (defun org-xhtml-format-heading (text level &optional id)
  1431. (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
  1432. (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
  1433. (defun org-xhtml-format-headline (title extra-targets tags
  1434. &optional snumber level)
  1435. (concat
  1436. (org-lparse-format 'EXTRA-TARGETS extra-targets)
  1437. (concat (org-lparse-format 'SECTION-NUMBER snumber level) " ")
  1438. title
  1439. (and tags (concat (org-lparse-format 'SPACES 3)
  1440. (org-lparse-format 'ORG-TAGS tags)))))
  1441. (defun org-xhtml-format-anchor (text name &optional class)
  1442. (let* ((id name)
  1443. (extra (concat
  1444. (when name (format " name=\"%s\"" name))
  1445. (when id (format " id=\"%s\"" id))
  1446. (when class (format " class=\"%s\"" class)))))
  1447. (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
  1448. (defun org-xhtml-format-footnote-reference (n def refcnt)
  1449. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  1450. (format org-export-xhtml-footnote-format
  1451. (format
  1452. "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
  1453. n extra n n))))
  1454. (defun org-xhtml-format-footnotes-section (section-name definitions)
  1455. (if (not definitions) ""
  1456. (format org-export-xhtml-footnotes-section section-name definitions)))
  1457. (defun org-xhtml-format-org-entity (wd)
  1458. (org-entity-get-representation wd 'html))
  1459. (defun org-xhtml-format-tags (tag text &rest args)
  1460. (let ((prefix (when org-lparse-encode-pending "@"))
  1461. (suffix (when org-lparse-encode-pending "@")))
  1462. (apply 'org-lparse-format-tags tag text prefix suffix args)))
  1463. (defun org-xhtml-get (what &optional opt-plist)
  1464. (case what
  1465. (BACKEND 'html)
  1466. (INIT-METHOD nil)
  1467. (SAVE-METHOD nil)
  1468. (CLEANUP-METHOD nil)
  1469. ;; (OTHER-BACKENDS
  1470. ;; ;; There is a provision to register a per-backend converter and
  1471. ;; ;; output formats. Refer `org-lparse-get-converter' and
  1472. ;; ;; `org-lparse-get-other-backends'.
  1473. ;; ;; The default behaviour is to use `org-lparse-convert-process'
  1474. ;; ;; and `org-lparse-convert-capabilities'.
  1475. ;; )
  1476. ;; (CONVERT-METHOD
  1477. ;; ;; See note above
  1478. ;; )
  1479. (EXPORT-DIR (org-export-directory :html opt-plist))
  1480. (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
  1481. (EXPORT-BUFFER-NAME "*Org HTML Export*")
  1482. (ENTITY-CONTROL org-xhtml-entity-control-callbacks-alist)
  1483. (ENTITY-FORMAT org-xhtml-entity-format-callbacks-alist)
  1484. (TOPLEVEL-HLEVEL org-export-xhtml-toplevel-hlevel)
  1485. (SPECIAL-STRING-REGEXPS org-export-xhtml-special-string-regexps)
  1486. (CODING-SYSTEM-FOR-WRITE org-export-xhtml-coding-system)
  1487. (CODING-SYSTEM-FOR-SAVE org-export-xhtml-coding-system)
  1488. (INLINE-IMAGES org-export-xhtml-inline-images)
  1489. (INLINE-IMAGE-EXTENSIONS org-export-xhtml-inline-image-extensions)
  1490. (PLAIN-TEXT-MAP org-export-xhtml-protect-char-alist)
  1491. (TABLE-FIRST-COLUMN-AS-LABELS
  1492. org-export-xhtml-table-use-header-tags-for-first-column)
  1493. (TODO-KWD-CLASS-PREFIX org-export-xhtml-todo-kwd-class-prefix)
  1494. (TAG-CLASS-PREFIX org-export-xhtml-tag-class-prefix)
  1495. (FOOTNOTE-SEPARATOR org-export-xhtml-footnote-separator)
  1496. (t (error "Unknown property: %s" what))))
  1497. (defun org-xhtml-get-coding-system-for-write ()
  1498. (or org-export-xhtml-coding-system
  1499. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1500. (defun org-xhtml-get-coding-system-for-save ()
  1501. (or org-export-xhtml-coding-system
  1502. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1503. (defun org-xhtml-insert-toc (toc)
  1504. ;; locate where toc needs to be inserted
  1505. (goto-char (point-min))
  1506. (cond
  1507. ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  1508. (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t))
  1509. (goto-char (match-beginning 0))
  1510. (replace-match "")
  1511. (insert toc))
  1512. (org-lparse-dyn-first-heading-pos
  1513. (goto-char org-lparse-dyn-first-heading-pos)
  1514. (when (looking-at "\\s-*</p>")
  1515. (goto-char (match-end 0))
  1516. (insert "\n"))
  1517. (insert toc))
  1518. (t (ignore))))
  1519. (defun org-xhtml-insert-preamble (opt-plist)
  1520. (when (plist-get opt-plist :html-preamble)
  1521. (let ((html-pre (plist-get opt-plist :html-preamble))
  1522. (title (plist-get opt-plist :title))
  1523. (date (plist-get opt-plist :effective-date))
  1524. (author (plist-get opt-plist :author))
  1525. (lang-words (plist-get opt-plist :lang-words))
  1526. (email (plist-get opt-plist :email)))
  1527. (cond ((stringp html-pre)
  1528. (insert
  1529. (format-spec html-pre `((?t . ,title) (?a . ,author)
  1530. (?d . ,date) (?e . ,email)))))
  1531. ((functionp html-pre)
  1532. (funcall html-pre opt-plist))
  1533. (t
  1534. (insert
  1535. (format-spec
  1536. (or (cadr (assoc (nth 0 lang-words)
  1537. org-export-xhtml-preamble-format))
  1538. (cadr (assoc "en" org-export-xhtml-preamble-format)))
  1539. `((?t . ,title) (?a . ,author)
  1540. (?d . ,date) (?e . ,email)))))))))
  1541. (defun org-xhtml-insert-postamble (opt-plist)
  1542. (when org-lparse-footnote-definitions
  1543. (insert
  1544. (org-lparse-format
  1545. 'FOOTNOTES-SECTION (nth 4 (plist-get opt-plist :lang-words))
  1546. (mapconcat (lambda (x) (cdr x))
  1547. (nreverse org-lparse-footnote-definitions) "\n"))))
  1548. (let ((bib (org-export-xhtml-get-bibliography)))
  1549. (when bib
  1550. (insert "\n" bib "\n")))
  1551. ;; export html postamble
  1552. (unless body-only
  1553. (let* ((html-post (plist-get opt-plist :html-postamble))
  1554. (date (plist-get opt-plist :effective-date))
  1555. (author (plist-get opt-plist :author))
  1556. (email (plist-get opt-plist :email))
  1557. (lang-words (plist-get opt-plist :lang-words))
  1558. (html-validation-link (or org-export-xhtml-validation-link ""))
  1559. (email
  1560. (mapconcat (lambda(e)
  1561. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1562. (split-string email ",+ *")
  1563. ", "))
  1564. (creator-info
  1565. (concat "Org version " org-version " with Emacs version "
  1566. (number-to-string emacs-major-version))))
  1567. (when (plist-get opt-plist :html-postamble)
  1568. (cond ((stringp html-post)
  1569. (insert "<div id=\"postamble\">\n")
  1570. (insert (format-spec html-post
  1571. `((?a . ,author) (?e . ,email)
  1572. (?d . ,date) (?c . ,creator-info)
  1573. (?v . ,html-validation-link))))
  1574. (insert "</div>"))
  1575. ((functionp html-post)
  1576. (funcall html-post opt-plist))
  1577. ((eq html-post 'auto)
  1578. ;; fall back on default postamble
  1579. (insert "<div id=\"postamble\">\n")
  1580. (when (plist-get opt-plist :time-stamp-file)
  1581. (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
  1582. (when (and (plist-get opt-plist :author-info) author)
  1583. (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
  1584. (when (and (plist-get opt-plist :email-info) email)
  1585. (insert "<p class=\"email\">" email "</p>\n"))
  1586. (when (plist-get opt-plist :creator-info)
  1587. (insert "<p class=\"creator\">"
  1588. (concat "Org version " org-version " with Emacs version "
  1589. (number-to-string emacs-major-version) "</p>\n")))
  1590. (insert html-validation-link "\n</div>"))
  1591. (t
  1592. (insert "<div id=\"postamble\">\n")
  1593. (insert (format-spec
  1594. (or (cadr (assoc (nth 0 lang-words)
  1595. org-export-xhtml-postamble-format))
  1596. (cadr (assoc "en" org-export-xhtml-postamble-format)))
  1597. `((?a . ,author) (?e . ,email)
  1598. (?d . ,date) (?c . ,creator-info)
  1599. (?v . ,html-validation-link))))
  1600. (insert "</div>"))))))
  1601. (if org-export-xhtml-with-timestamp
  1602. (insert org-export-xhtml-html-helper-timestamp)))
  1603. ;; There are references to org-html-expand, org-html-protect and
  1604. ;; org-html-do-expand outside of org-html.el. For now provide a
  1605. ;; migration path. Ultimately these functions have to be removed.
  1606. ;; (defun org-html-expand (string)
  1607. ;; "A simple wrapper around `org-xml-encode-org-text-skip-links'."
  1608. ;; (org-xml-encode-org-text-skip-links string))
  1609. ;; (defun org-html-protect (s)
  1610. ;; "A simple wrapper around `org-xml-encode-plain-text'."
  1611. ;; (org-xml-encode-plain-text s))
  1612. ;; (defun org-html-do-expand (s)
  1613. ;; "A simple wrapper around `org-xml-encode-org-text'."
  1614. ;; (org-xml-encode-org-text s))
  1615. ;; (defun org-export-xhtml-format-href (s)
  1616. ;; "A simple wrapper around `org-xml-format-href'."
  1617. ;; (org-xml-format-href s))
  1618. ;; (defun org-export-xhtml-format-desc (s)
  1619. ;; "A simple wrapper around `org-xml-format-desc'."
  1620. ;; (org-xml-format-desc s))
  1621. (provide 'org-xhtml)
  1622. ;;; org-xhtml.el ends here