org-xhtml.el 69 KB

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