org-xhtml.el 67 KB

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