org-xhtml.el 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  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. (when (string= type-1 "coderef")
  641. (setq attr
  642. (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  643. fragment fragment)))
  644. (save-match-data
  645. (let* ((may-inline-p
  646. (and (member type-1 '("http" "https" "file"))
  647. (org-lparse-should-inline-p path descp)
  648. (not fragment)))
  649. (type (if (equal type-1 "id") "file" type-1))
  650. (filename path)
  651. ;;First pass. Just sanity stuff.
  652. (components-1
  653. (cond
  654. ((string= type "file")
  655. (list
  656. type
  657. ;;Substitute just if original path was absolute.
  658. ;;(Otherwise path must remain relative)
  659. (if (file-name-absolute-p path)
  660. (concat "file://" (expand-file-name path))
  661. path)))
  662. ((string= type "")
  663. (list nil path))
  664. (t (list type path))))
  665. ;;Second pass. Components converted so they can refer
  666. ;;to a remote site.
  667. (components-2
  668. (or
  669. (and org-html-cvt-link-fn
  670. (apply org-html-cvt-link-fn
  671. opt-plist components-1))
  672. (apply #'org-html-cvt-org-as-html
  673. opt-plist components-1)
  674. components-1))
  675. (type (first components-2))
  676. (thefile (second components-2)))
  677. ;;Third pass. Build final link except for leading type
  678. ;;spec.
  679. (cond
  680. ((or
  681. (not type)
  682. (string= type "http")
  683. (string= type "https")
  684. (string= type "file")
  685. (string= type "coderef"))
  686. (if fragment
  687. (setq thefile (concat thefile "#" fragment))))
  688. (t))
  689. ;;Final URL-build, for all types.
  690. (setq thefile
  691. (let
  692. ((str (org-xml-format-href thefile)))
  693. (if (and type (not (or (string= "file" type)
  694. (string= "coderef" type))))
  695. (concat type ":" str)
  696. str)))
  697. (if may-inline-p
  698. (org-xhtml-format-image thefile)
  699. (org-lparse-format
  700. 'LINK (org-xml-format-desc desc) thefile attr)))))
  701. (defun org-xhtml-format-inline-image (desc)
  702. ;; FIXME: alt text missing here?
  703. (org-xhtml-format-tags "<img src=\"%s\" alt=\"\"/>" "" desc))
  704. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  705. (defvar org-lparse-link-description-is-image)
  706. (defun org-xhtml-format-image (src)
  707. "Create image tag with source and attributes."
  708. (save-match-data
  709. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  710. (attr (org-find-text-property-in-string 'org-attributes src))
  711. (label (org-find-text-property-in-string 'org-label src))
  712. (caption (and caption (org-xml-encode-org-text caption)))
  713. (img-extras (if (string-match "^ltxpng/" src)
  714. (format " alt=\"%s\""
  715. (org-find-text-property-in-string
  716. 'org-latex-src src))
  717. (if (string-match "\\<alt=" (or attr ""))
  718. (concat " " attr )
  719. (concat " " attr " alt=\"" src "\""))))
  720. (img (format "<img src=\"%s\"%s />" src img-extras))
  721. (extra (concat
  722. (and label
  723. (format "id=\"%s\" " (org-solidify-link-text label)))
  724. "class=\"figure\"")))
  725. (if caption
  726. (with-temp-buffer
  727. (with-org-lparse-preserve-paragraph-state
  728. (insert
  729. (org-lparse-format
  730. '("<div %s>" . "\n</div>")
  731. (concat
  732. (org-lparse-format '("\n<p>" . "</p>") img)
  733. (org-lparse-format '("\n<p>" . "</p>") caption))
  734. extra)))
  735. (buffer-string))
  736. img))))
  737. (defun org-export-xhtml-get-bibliography ()
  738. "Find bibliography, cut it out and return it."
  739. (catch 'exit
  740. (let (beg end (cnt 1) bib)
  741. (save-excursion
  742. (goto-char (point-min))
  743. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  744. (setq beg (match-beginning 0))
  745. (while (re-search-forward "</?div\\>" nil t)
  746. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  747. (when (= cnt 0)
  748. (and (looking-at ">") (forward-char 1))
  749. (setq bib (buffer-substring beg (point)))
  750. (delete-region beg (point))
  751. (throw 'exit bib))))
  752. nil))))
  753. (defun org-xhtml-format-table (lines olines)
  754. (let ((org-xhtml-format-table-no-css nil))
  755. (org-lparse-format-table lines olines)))
  756. ;; Following variable is defined for native tables i.e., when
  757. ;; `org-lparse-table-is-styled' evals to t.
  758. (defvar org-xhtml-format-table-no-css)
  759. (defvar org-table-number-regexp) ; defined in org-table.el
  760. ;; FIXME: This function is called from other modules. Use xhtml suffix
  761. ;; to avoid conflict
  762. (defun org-format-table-xhtml (lines olines &optional no-css)
  763. "Find out which HTML converter to use and return the HTML code.
  764. NO-CSS is passed to the exporter."
  765. (let* ((org-lparse-backend 'xhtml)
  766. (org-lparse-entity-control-callbacks-alist
  767. (org-lparse-get 'ENTITY-CONTROL))
  768. (org-lparse-entity-format-callbacks-alist
  769. (org-lparse-get 'ENTITY-FORMAT))
  770. (org-xhtml-format-table-no-css no-css))
  771. (org-lparse-format-table lines olines)))
  772. ;; FIXME: This function is called from other modules. Use xhtml suffix
  773. ;; to avoid conflict
  774. (defun org-format-org-table-xhtml (lines &optional splice no-css)
  775. ;; This routine might get called outside of org-export-as-html. For
  776. ;; example, this could happen as part of org-table-export or as part
  777. ;; of org-export-as-docbook. Explicitly bind the parser callback to
  778. ;; the html ones for the duration of the call.
  779. (let* ((org-lparse-backend 'xhtml)
  780. (org-lparse-entity-control-callbacks-alist
  781. (org-lparse-get 'ENTITY-CONTROL))
  782. (org-lparse-entity-format-callbacks-alist
  783. (org-lparse-get 'ENTITY-FORMAT))
  784. (org-xhtml-format-table-no-css no-css))
  785. (org-lparse-format-org-table lines splice)))
  786. ;; FIXME: it already exists in org-html.el
  787. (defun org-export-splice-attributes (tag attributes)
  788. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  789. (if (not attributes)
  790. tag
  791. (let (oldatt newatt)
  792. (setq oldatt (org-extract-attributes-from-string tag)
  793. tag (pop oldatt)
  794. newatt (cdr (org-extract-attributes-from-string attributes)))
  795. (while newatt
  796. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  797. (if (string-match ">" tag)
  798. (setq tag
  799. (replace-match (concat (org-attributes-to-string oldatt) ">")
  800. t t tag)))
  801. tag)))
  802. ;; FIXME: This function is called from other modules. Use xhtml suffix
  803. ;; to avoid conflict
  804. (defun org-format-table-table-xhtml (lines)
  805. (let* ((org-lparse-get 'html)
  806. (org-lparse-entity-control-callbacks-alist
  807. (org-lparse-get 'ENTITY-CONTROL))
  808. (org-lparse-entity-format-callbacks-alist
  809. (org-lparse-get 'ENTITY-FORMAT)))
  810. (org-lparse-format-table-table lines)))
  811. ;; FIXME: it already exists in org-html.el
  812. (defun org-export-splice-style (style extra)
  813. "Splice EXTRA into STYLE, just before \"</style>\"."
  814. (if (and (stringp extra)
  815. (string-match "\\S-" extra)
  816. (string-match "</style>" style))
  817. (concat (substring style 0 (match-beginning 0))
  818. "\n" extra "\n"
  819. (substring style (match-beginning 0)))
  820. style))
  821. (defvar htmlize-buffer-places) ; from htmlize.el
  822. (defun org-export-xhtmlize-region-for-paste (beg end)
  823. "Convert the region to HTML, using htmlize.el.
  824. This is much like `htmlize-region-for-paste', only that it uses
  825. the settings define in the org-... variables."
  826. (let* ((htmlize-output-type org-export-xhtmlize-output-type)
  827. (htmlize-css-name-prefix org-export-xhtmlize-css-font-prefix)
  828. (htmlbuf (htmlize-region beg end)))
  829. (unwind-protect
  830. (with-current-buffer htmlbuf
  831. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  832. (plist-get htmlize-buffer-places 'content-end)))
  833. (kill-buffer htmlbuf))))
  834. ;;;###autoload
  835. (defun org-export-xhtmlize-generate-css ()
  836. "Create the CSS for all font definitions in the current Emacs session.
  837. Use this to create face definitions in your CSS style file that can then
  838. be used by code snippets transformed by htmlize.
  839. This command just produces a buffer that contains class definitions for all
  840. faces used in the current Emacs session. You can copy and paste the ones you
  841. need into your CSS file.
  842. If you then set `org-export-xhtmlize-output-type' to `css', calls to
  843. the function `org-export-xhtmlize-region-for-paste' will produce code
  844. that uses these same face definitions."
  845. (interactive)
  846. (require 'htmlize)
  847. (and (get-buffer "*html*") (kill-buffer "*html*"))
  848. (with-temp-buffer
  849. (let ((fl (face-list))
  850. (htmlize-css-name-prefix "org-")
  851. (htmlize-output-type 'css)
  852. f i)
  853. (while (setq f (pop fl)
  854. i (and f (face-attribute f :inherit)))
  855. (when (and (symbolp f) (or (not i) (not (listp i))))
  856. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  857. (htmlize-region (point-min) (point-max))))
  858. (org-pop-to-buffer-same-window "*html*")
  859. (goto-char (point-min))
  860. (if (re-search-forward "<style" nil t)
  861. (delete-region (point-min) (match-beginning 0)))
  862. (if (re-search-forward "</style>" nil t)
  863. (delete-region (1+ (match-end 0)) (point-max)))
  864. (beginning-of-line 1)
  865. (if (looking-at " +") (replace-match ""))
  866. (goto-char (point-min)))
  867. (defvar body-only) ; dynamically scoped into this.
  868. ;; Following variable is let bound when `org-do-lparse' is in
  869. ;; progress. See org-lparse.el.
  870. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  871. (defvar org-lparse-toc)
  872. (defvar org-lparse-footnote-definitions)
  873. (defvar org-lparse-dyn-first-heading-pos)
  874. (defun org-xhtml-end-export ()
  875. ;; insert the table of contents
  876. (when (and org-export-with-toc (not body-only) org-lparse-toc)
  877. (org-xhtml-insert-toc org-lparse-toc))
  878. ;; remove empty paragraphs
  879. (goto-char (point-min))
  880. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  881. (replace-match ""))
  882. ;; Convert whitespace place holders
  883. (goto-char (point-min))
  884. (let (beg end n)
  885. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  886. (setq n (get-text-property beg 'org-whitespace)
  887. end (next-single-property-change beg 'org-whitespace))
  888. (goto-char beg)
  889. (delete-region beg end)
  890. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  891. (make-string n ?x)))))
  892. ;; Remove empty lines at the beginning of the file.
  893. (goto-char (point-min))
  894. (when (looking-at "\\s-+\n") (replace-match ""))
  895. ;; Remove display properties
  896. (remove-text-properties (point-min) (point-max) '(display t))
  897. ;; Run the hook
  898. (run-hooks 'org-export-xhtml-final-hook))
  899. (defun org-xhtml-format-toc-entry (snumber todo headline tags href)
  900. (setq headline (concat
  901. (and org-export-with-section-numbers
  902. (concat snumber " "))
  903. headline
  904. (and tags
  905. (concat
  906. (org-lparse-format 'SPACES 3)
  907. (org-lparse-format 'FONTIFY tags "tag")))))
  908. (when todo
  909. (setq headline (org-lparse-format 'FONTIFY headline "todo")))
  910. (org-lparse-format 'LINK headline (concat "#" href)))
  911. (defun org-xhtml-format-toc-item (toc-entry level org-last-level)
  912. (when (> level org-last-level)
  913. (let ((cnt (- level org-last-level)))
  914. (while (>= (setq cnt (1- cnt)) 0)
  915. (org-lparse-begin-list 'unordered)
  916. (org-lparse-begin-list-item 'unordered))))
  917. (when (< level org-last-level)
  918. (let ((cnt (- org-last-level level)))
  919. (while (>= (setq cnt (1- cnt)) 0)
  920. (org-lparse-end-list-item-1)
  921. (org-lparse-end-list 'unordered))))
  922. (org-lparse-end-list-item-1)
  923. (org-lparse-begin-list-item 'unordered)
  924. (insert toc-entry))
  925. (defun org-xhtml-begin-toc (lang-specific-heading)
  926. (org-lparse-insert-tag "<div id=\"table-of-contents\">")
  927. (insert
  928. (org-lparse-format 'HEADING lang-specific-heading
  929. (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1)))
  930. (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
  931. (org-lparse-begin-list 'unordered)
  932. (org-lparse-begin-list-item 'unordered))
  933. (defun org-xhtml-end-toc ()
  934. (while (> org-last-level (1- org-min-level))
  935. (setq org-last-level (1- org-last-level))
  936. (org-lparse-end-list-item-1)
  937. (org-lparse-end-list 'unordered))
  938. (org-lparse-insert-tag "</div>")
  939. (org-lparse-insert-tag "</div>")
  940. ;; cleanup empty list items in toc
  941. (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
  942. (replace-match "")))
  943. ;;;###autoload
  944. (defun org-export-as-xhtml-and-open (arg)
  945. "Export the outline as HTML and immediately open it with a browser.
  946. If there is an active region, export only the region.
  947. The prefix ARG specifies how many levels of the outline should become
  948. headlines. The default is 3. Lower levels will become bulleted lists."
  949. (interactive "P")
  950. (org-lparse-and-open "xhtml" "xhtml" arg))
  951. ;;;###autoload
  952. (defun org-export-as-xhtml-batch ()
  953. "Call the function `org-lparse-batch'.
  954. This function can be used in batch processing as:
  955. emacs --batch
  956. --load=$HOME/lib/emacs/org.el
  957. --eval \"(setq org-export-headline-levels 2)\"
  958. --visit=MyFile --funcall org-export-as-html-batch"
  959. (org-lparse-batch "xhtml"))
  960. ;;;###autoload
  961. (defun org-export-as-xhtml-to-buffer (arg)
  962. "Call `org-lparse-to-buffer` with output to a temporary buffer.
  963. No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
  964. (interactive "P")
  965. (org-lparse-to-buffer "xhtml" arg))
  966. ;;;###autoload
  967. (defun org-replace-region-by-xhtml (beg end)
  968. "Assume the current region has org-mode syntax, and convert it to HTML.
  969. This can be used in any buffer. For example, you could write an
  970. itemized list in org-mode syntax in an HTML buffer and then use this
  971. command to convert it."
  972. (interactive "r")
  973. (org-replace-region-by "xhtml" beg end))
  974. ;;;###autoload
  975. (defun org-export-region-as-xhtml (beg end &optional body-only buffer)
  976. "Convert region from BEG to END in `org-mode' buffer to HTML.
  977. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  978. contents, and only produce the region of converted text, useful for
  979. cut-and-paste operations.
  980. If BUFFER is a buffer or a string, use/create that buffer as a target
  981. of the converted HTML. If BUFFER is the symbol `string', return the
  982. produced HTML as a string and leave not buffer behind. For example,
  983. a Lisp program could call this function in the following way:
  984. (setq html (org-export-region-as-html beg end t 'string))
  985. When called interactively, the output buffer is selected, and shown
  986. in a window. A non-interactive call will only return the buffer."
  987. (interactive "r\nP")
  988. (org-lparse-region "xhtml" beg end body-only buffer))
  989. ;;; org-export-as-xhtml
  990. ;;;###autoload
  991. (defun org-export-as-xhtml (arg &optional hidden ext-plist
  992. to-buffer body-only pub-dir)
  993. "Export the outline as a pretty HTML file.
  994. Use `org-lparse' internally to perform the actual export. This
  995. routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
  996. of `org-lparse' to \"html\"."
  997. (interactive "P")
  998. (org-lparse "xhtml" "xhtml" arg hidden ext-plist to-buffer body-only pub-dir))
  999. (defvar org-xhtml-entity-control-callbacks-alist
  1000. `((EXPORT
  1001. . (org-xhtml-begin-export org-xhtml-end-export))
  1002. (DOCUMENT-CONTENT
  1003. . (org-xhtml-begin-document-content org-xhtml-end-document-content))
  1004. (DOCUMENT-BODY
  1005. . (org-xhtml-begin-document-body org-xhtml-end-document-body))
  1006. (TOC
  1007. . (org-xhtml-begin-toc org-xhtml-end-toc))
  1008. (ENVIRONMENT
  1009. . (org-xhtml-begin-environment org-xhtml-end-environment))
  1010. (FOOTNOTE-DEFINITION
  1011. . (org-xhtml-begin-footnote-definition org-xhtml-end-footnote-definition))
  1012. (TABLE
  1013. . (org-xhtml-begin-table org-xhtml-end-table))
  1014. (TABLE-ROWGROUP
  1015. . (org-xhtml-begin-table-rowgroup org-xhtml-end-table-rowgroup))
  1016. (LIST
  1017. . (org-xhtml-begin-list org-xhtml-end-list))
  1018. (LIST-ITEM
  1019. . (org-xhtml-begin-list-item org-xhtml-end-list-item))
  1020. (OUTLINE
  1021. . (org-xhtml-begin-outline org-xhtml-end-outline))
  1022. (OUTLINE-TEXT
  1023. . (org-xhtml-begin-outline-text org-xhtml-end-outline-text))
  1024. (PARAGRAPH
  1025. . (org-xhtml-begin-paragraph org-xhtml-end-paragraph)))
  1026. "Alist of control callbacks registered with the exporter.
  1027. Each element is of the form (ENTITY . (BEGIN-ENTITY-FUNCTION
  1028. END-ENTITY-FUNCTION)). ENTITY is one of PARAGRAPH, LIST etc as
  1029. seen above. BEGIN-ENTITY-FUNCTION and END-ENTITY-FUNCTION are
  1030. functions that get called when the exporter needs to begin or end
  1031. an entity in the currently exported file. The signatures of
  1032. these callbacks are specific to the ENTITY being emitted. These
  1033. callbacks always get called with exported file as the current
  1034. buffer and need to insert the appropriate tags into the current
  1035. buffer. For example, `org-xhtml-begin-paragraph' inserts <p> and
  1036. `org-xhtml-end-paragraph' inserts </p> in to the current buffer.
  1037. These callbacks are invoked via `org-lparse-begin' and
  1038. `org-lparse-end'.")
  1039. (defvar org-xhtml-entity-format-callbacks-alist
  1040. `((EXTRA-TARGETS . org-lparse-format-extra-targets)
  1041. (ORG-TAGS . org-lparse-format-org-tags)
  1042. (SECTION-NUMBER . org-lparse-format-section-number)
  1043. (HEADLINE . org-xhtml-format-headline)
  1044. (TOC-ENTRY . org-xhtml-format-toc-entry)
  1045. (TOC-ITEM . org-xhtml-format-toc-item)
  1046. (TAGS . org-xhtml-format-tags)
  1047. (SPACES . org-xhtml-format-spaces)
  1048. (TABS . org-xhtml-format-tabs)
  1049. (LINE-BREAK . org-xhtml-format-line-break)
  1050. (FONTIFY . org-xhtml-format-fontify)
  1051. (TODO . org-lparse-format-todo)
  1052. (ORG-LINK . org-xhtml-format-org-link)
  1053. (LINK . org-xhtml-format-link)
  1054. (INLINE-IMAGE . org-xhtml-format-inline-image)
  1055. (HEADING . org-xhtml-format-heading)
  1056. (ANCHOR . org-xhtml-format-anchor)
  1057. (TABLE . org-xhtml-format-table)
  1058. (TABLE-ROW . org-xhtml-format-table-row)
  1059. (TABLE-CELL . org-xhtml-format-table-cell)
  1060. (FOOTNOTES-SECTION . org-xhtml-format-footnotes-section)
  1061. (FOOTNOTE-REFERENCE . org-xhtml-format-footnote-reference)
  1062. (HORIZONTAL-LINE . org-xhtml-format-horizontal-line)
  1063. (LINE . org-xhtml-format-line)
  1064. (COMMENT . org-xhtml-format-comment)
  1065. (ORG-ENTITY . org-xhtml-format-org-entity))
  1066. "Alist of format callbacks registered with the exporter.
  1067. Each element is of the form (ENTITY . ENTITY-FORMAT-FUNCTION).
  1068. ENTITY is one of LINE, HEADING, COMMENT, LINK, TABLE-ROW etc as
  1069. seen above. ENTITY-FORMAT-FUNCTION is a functions that gets
  1070. called when the exporter needs to format a string in `org-mode'
  1071. buffer in a backend specific way. The signatures of the
  1072. formatting callback is specific to the ENTITY being passed in.
  1073. These callbacks always need to encode the incoming entity in
  1074. backend specific way and return the same. These callbacks do not
  1075. make any modifications to the exporter file. For example,
  1076. `org-xhtml-format-table-row' encloses incoming entity in <tr>
  1077. </tr> tags and returns it. See also `org-lparse-format'.")
  1078. ;; register the xhtml exporter with org-lparse library
  1079. (org-lparse-register-backend 'xhtml)
  1080. (defun org-xhtml-unload-function ()
  1081. (org-lparse-unregister-backend 'xhtml)
  1082. (remove-hook 'org-export-preprocess-after-blockquote-hook
  1083. 'org-export-xhtml-preprocess-latex-fragments)
  1084. nil)
  1085. (defun org-xhtml-begin-document-body (opt-plist)
  1086. (let ((link-up (and (plist-get opt-plist :link-up)
  1087. (string-match "\\S-" (plist-get opt-plist :link-up))
  1088. (plist-get opt-plist :link-up)))
  1089. (link-home (and (plist-get opt-plist :link-home)
  1090. (string-match "\\S-" (plist-get opt-plist :link-home))
  1091. (plist-get opt-plist :link-home))))
  1092. (insert "\n<body>")
  1093. (org-lparse-insert-tag "<div id=\"content\">")
  1094. (insert "\n"
  1095. (or (and (or link-up link-home)
  1096. (format org-export-xhtml-home/up-format
  1097. (or link-up link-home)
  1098. (or link-home link-up))) "")
  1099. "\n"))
  1100. (org-xhtml-insert-preamble opt-plist))
  1101. (defun org-xhtml-end-document-body (opt-plist)
  1102. (org-xhtml-insert-postamble opt-plist)
  1103. (unless body-only
  1104. (org-lparse-insert-tag "</div>")
  1105. (insert "\n</body>")))
  1106. (defun org-xhtml-begin-document-content (opt-plist)
  1107. (let* ((language (plist-get opt-plist :language))
  1108. (charset (or (and coding-system-for-write
  1109. (fboundp 'coding-system-get)
  1110. (coding-system-get coding-system-for-write
  1111. 'mime-charset))
  1112. "iso-8859-1"))
  1113. (style (concat (if (plist-get opt-plist :style-include-default)
  1114. org-export-xhtml-style-default)
  1115. (plist-get opt-plist :style)
  1116. (plist-get opt-plist :style-extra)
  1117. "\n"
  1118. (if (plist-get opt-plist :style-include-scripts)
  1119. org-export-xhtml-scripts)))
  1120. (mathjax
  1121. (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
  1122. (and org-export-have-math
  1123. (eq (plist-get opt-plist :LaTeX-fragments) t)))
  1124. (org-export-xhtml-mathjax-config
  1125. org-export-xhtml-mathjax-template
  1126. org-export-xhtml-mathjax-options
  1127. (or (plist-get opt-plist :mathjax) "")) "")))
  1128. (insert (format
  1129. "%s
  1130. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1131. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  1132. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  1133. lang=\"%s\" xml:lang=\"%s\">
  1134. <head>
  1135. <title>%s</title>
  1136. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  1137. <meta name=\"generator\" content=\"Org-mode\"/>
  1138. <meta name=\"generated\" content=\"%s\"/>
  1139. <meta name=\"author\" content=\"%s\"/>
  1140. <meta name=\"description\" content=\"%s\"/>
  1141. <meta name=\"keywords\" content=\"%s\"/>
  1142. %s
  1143. %s
  1144. </head>
  1145. "
  1146. (format
  1147. (or (and (stringp org-export-xhtml-xml-declaration)
  1148. org-export-xhtml-xml-declaration)
  1149. (cdr (assoc (plist-get opt-plist :html-extension)
  1150. org-export-xhtml-xml-declaration))
  1151. (cdr (assoc "html" org-export-xhtml-xml-declaration))
  1152. "")
  1153. charset)
  1154. language language
  1155. (plist-get opt-plist :title)
  1156. charset
  1157. (plist-get opt-plist :effective-date)
  1158. (plist-get opt-plist :author)
  1159. (plist-get opt-plist :description)
  1160. (plist-get opt-plist :keywords)
  1161. style
  1162. mathjax))))
  1163. (defun org-xhtml-end-document-content ()
  1164. (insert "\n</html>\n"))
  1165. (defun org-xhtml-begin-outline (level1 snumber title tags
  1166. target extra-targets extra-class)
  1167. (let* ((class (format "outline-%d" level1))
  1168. (class (if extra-class (concat class " " extra-class) class))
  1169. (id (format "outline-container-%s"
  1170. (org-lparse-suffix-from-snumber snumber)))
  1171. (extra (concat (when id (format " id=\"%s\"" id))
  1172. (when class (format " class=\"%s\"" class)))))
  1173. (org-lparse-insert-tag "<div%s>" extra)
  1174. (insert
  1175. (org-lparse-format 'HEADING
  1176. (org-lparse-format
  1177. 'HEADLINE title extra-targets tags snumber level1)
  1178. level1 target))))
  1179. (defun org-xhtml-end-outline ()
  1180. (org-lparse-insert-tag "</div>"))
  1181. (defun org-xhtml-begin-outline-text (level1 snumber extra-class)
  1182. (let* ((class (format "outline-text-%d" level1))
  1183. (class (if extra-class (concat class " " extra-class) class))
  1184. (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
  1185. (extra (concat (when id (format " id=\"%s\"" id))
  1186. (when class (format " class=\"%s\"" class)))))
  1187. (org-lparse-insert-tag "<div%s>" extra)))
  1188. (defun org-xhtml-end-outline-text ()
  1189. (org-lparse-insert-tag "</div>"))
  1190. (defun org-xhtml-begin-paragraph (&optional style)
  1191. (let* ((class (cdr (assoc style '((footnote . "footnote")
  1192. (verse . nil)))))
  1193. (extra (if class (format " class=\"%s\"" class) "")))
  1194. (org-lparse-insert-tag "<p%s>" extra)))
  1195. (defun org-xhtml-end-paragraph ()
  1196. (insert "</p>"))
  1197. (defun org-xhtml-format-environment (style beg-end)
  1198. (assert (memq style '(blockquote center verse fixedwidth quote native)) t)
  1199. (case style
  1200. (blockquote
  1201. (case beg-end
  1202. (BEGIN
  1203. (org-lparse-end-paragraph)
  1204. (insert "<blockquote>\n")
  1205. (org-lparse-begin-paragraph))
  1206. (END
  1207. (org-lparse-end-paragraph)
  1208. (insert "\n</blockquote>\n")
  1209. (org-lparse-begin-paragraph))))
  1210. (verse
  1211. (case beg-end
  1212. (BEGIN
  1213. (org-lparse-end-paragraph)
  1214. (insert "\n<p class=\"verse\">\n")
  1215. (setq org-lparse-par-open t))
  1216. (END
  1217. (insert "</p>\n")
  1218. (setq org-lparse-par-open nil)
  1219. (org-lparse-begin-paragraph))))
  1220. (center
  1221. (case beg-end
  1222. (BEGIN
  1223. (org-lparse-end-paragraph)
  1224. (insert "\n<div style=\"text-align: center\">")
  1225. (org-lparse-begin-paragraph))
  1226. (END
  1227. (org-lparse-end-paragraph)
  1228. (insert "\n</div>")
  1229. (org-lparse-begin-paragraph))))
  1230. (fixedwidth
  1231. (case beg-end
  1232. (BEGIN
  1233. (org-lparse-end-paragraph)
  1234. (insert "<pre class=\"example\">\n"))
  1235. (END
  1236. (insert "</pre>\n")
  1237. (org-lparse-begin-paragraph))))
  1238. (quote
  1239. (case beg-end
  1240. (BEGIN
  1241. (org-lparse-end-paragraph)
  1242. (insert "<pre>"))
  1243. (END
  1244. (insert "</pre>\n")
  1245. (org-lparse-begin-paragraph))))
  1246. (native
  1247. (case beg-end
  1248. (BEGIN (org-lparse-end-paragraph))
  1249. (END (org-lparse-begin-paragraph))))
  1250. (t (error "Unknown environment %s" style))))
  1251. (defun org-xhtml-begin-environment (style)
  1252. (org-xhtml-format-environment style 'BEGIN))
  1253. (defun org-xhtml-end-environment (style)
  1254. (org-xhtml-format-environment style 'END))
  1255. (defun org-xhtml-begin-list (ltype)
  1256. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1257. ltype))
  1258. (case ltype
  1259. (ordered (let* ((arg1 nil)
  1260. (extra (if arg1 (format " start=\"%d\"" arg1) "")))
  1261. (org-lparse-insert-tag "<ol%s>" extra)))
  1262. (unordered (org-lparse-insert-tag "<ul>"))
  1263. (description (org-lparse-insert-tag "<dl>"))
  1264. (t (error "Unknown list type: %s" ltype))))
  1265. (defun org-xhtml-end-list (ltype)
  1266. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1267. ltype))
  1268. (org-lparse-insert-tag
  1269. (case ltype
  1270. (ordered "</ol>")
  1271. (unordered "</ul>")
  1272. (description "</dl>")
  1273. (t (error "Unknown list type: %s" ltype)))))
  1274. (defun org-xhtml-begin-list-item (ltype &optional arg headline)
  1275. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1276. ltype))
  1277. (case ltype
  1278. (ordered
  1279. (assert (not headline) t)
  1280. (let* ((counter arg)
  1281. (extra (if counter (format " value=\"%s\"" counter) "")))
  1282. (org-lparse-insert-tag "<li%s>" extra)))
  1283. (unordered
  1284. (let* ((id arg)
  1285. (extra (if id (format " id=\"%s\"" id) "")))
  1286. (org-lparse-insert-tag "<li%s>" extra)
  1287. (when headline
  1288. (insert headline (org-lparse-format 'LINE-BREAK) "\n"))))
  1289. (description
  1290. (assert (not headline) t)
  1291. (let* ((desc-tag (or arg "(no term)")))
  1292. (insert
  1293. (org-xhtml-format-tags '("<dt>" . "</dt>") desc-tag))
  1294. (org-lparse-insert-tag "<dd>")))
  1295. (t (error "Unknown list type"))))
  1296. (defun org-xhtml-end-list-item (ltype)
  1297. (setq ltype (or (org-lparse-html-list-type-to-canonical-list-type ltype)
  1298. ltype))
  1299. (case ltype
  1300. (ordered (org-lparse-insert-tag "</li>"))
  1301. (unordered (org-lparse-insert-tag "</li>"))
  1302. (description (org-lparse-insert-tag "</dd>"))
  1303. (t (error "Unknown list type"))))
  1304. ;; Following variables are let bound when table emission is in
  1305. ;; progress. See org-lparse.el.
  1306. ;; FIXME: the org-lparse defvar belongs to org-lparse.el
  1307. (defvar org-lparse-table-begin-marker)
  1308. (defvar org-lparse-table-ncols)
  1309. (defvar org-lparse-table-rowgrp-open)
  1310. (defvar org-lparse-table-rownum)
  1311. (defvar org-lparse-table-cur-rowgrp-is-hdr)
  1312. (defvar org-lparse-table-is-styled)
  1313. (defvar org-lparse-table-rowgrp-info)
  1314. (defvar org-lparse-table-colalign-vector)
  1315. (defvar org-lparse-table-num-numeric-items-per-column)
  1316. (defun org-xhtml-begin-table-rowgroup (&optional is-header-row)
  1317. (when org-lparse-table-rowgrp-open
  1318. (org-lparse-end 'TABLE-ROWGROUP))
  1319. (org-lparse-insert-tag (if is-header-row "<thead>" "<tbody>"))
  1320. (setq org-lparse-table-rowgrp-open t)
  1321. (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row))
  1322. (defun org-xhtml-end-table-rowgroup ()
  1323. (when org-lparse-table-rowgrp-open
  1324. (setq org-lparse-table-rowgrp-open nil)
  1325. (org-lparse-insert-tag
  1326. (if org-lparse-table-cur-rowgrp-is-hdr "</thead>" "</tbody>"))))
  1327. (defun org-xhtml-begin-table (caption label attributes)
  1328. (let ((html-table-tag
  1329. (org-export-splice-attributes html-table-tag attributes)))
  1330. (when label
  1331. (setq html-table-tag
  1332. (org-export-splice-attributes
  1333. html-table-tag
  1334. (format "id=\"%s\"" (org-solidify-link-text label)))))
  1335. (org-lparse-insert-tag html-table-tag))
  1336. ;; Since the output of HTML table formatter can also be used in
  1337. ;; DocBook document, we want to always include the caption to make
  1338. ;; DocBook XML file valid.
  1339. (insert (format "<caption>%s</caption>" (or caption "")) "\n"))
  1340. (defun org-xhtml-end-table ()
  1341. (when org-lparse-table-is-styled
  1342. (goto-char org-lparse-table-begin-marker)
  1343. (setq org-lparse-table-begin-marker nil)
  1344. (let ((c -1) gr colgropen)
  1345. (insert
  1346. (mapconcat
  1347. (lambda (x)
  1348. (incf c)
  1349. (setq gr (pop org-table-colgroup-info))
  1350. (concat
  1351. (if (memq gr '(:start :startend))
  1352. (prog1
  1353. (if colgropen
  1354. "</colgroup>\n<colgroup>"
  1355. "<colgroup>")
  1356. (setq colgropen t))
  1357. "")
  1358. (let* ((align (aref org-lparse-table-colalign-vector c))
  1359. (alignspec (if (and (boundp 'org-xhtml-format-table-no-css)
  1360. org-xhtml-format-table-no-css)
  1361. " align=\"%s\"" " class=\"%s\""))
  1362. (extra (format alignspec align)))
  1363. (format "<col%s />" extra))
  1364. (if (memq gr '(:end :startend))
  1365. (progn (setq colgropen nil) "</colgroup>")
  1366. "")))
  1367. org-lparse-table-num-numeric-items-per-column ""))
  1368. (if colgropen (insert "</colgroup>")))
  1369. ;; fill style attributes for table cells
  1370. (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t)
  1371. (let ((c (string-to-number (match-string 1))))
  1372. (replace-match
  1373. (if org-export-xhtml-table-align-individual-fields
  1374. (format (if (and (boundp 'org-xhtml-format-table-no-css)
  1375. org-xhtml-format-table-no-css)
  1376. " align=\"%s\"" " class=\"%s\"")
  1377. (or (aref org-lparse-table-colalign-vector c) "left")) "")
  1378. t t)))
  1379. (goto-char (point-max)))
  1380. (org-lparse-insert-tag "</table>\n"))
  1381. (defun org-xhtml-format-table-row (row)
  1382. (org-xhtml-format-tags
  1383. (cons (eval (car org-export-table-row-tags))
  1384. (eval (cdr org-export-table-row-tags))) row))
  1385. (defun org-xhtml-format-table-cell (text r c)
  1386. (let ((cell-style-cookie (or (and org-lparse-table-is-styled
  1387. (format "@@class%03d@@" c)) "")))
  1388. (cond
  1389. (org-lparse-table-cur-rowgrp-is-hdr
  1390. (org-xhtml-format-tags
  1391. org-export-table-header-tags text "col" cell-style-cookie))
  1392. ((and (= c 0) org-export-xhtml-table-use-header-tags-for-first-column)
  1393. (org-xhtml-format-tags
  1394. org-export-table-header-tags text "row" cell-style-cookie))
  1395. (t
  1396. (org-xhtml-format-tags
  1397. org-export-table-data-tags text cell-style-cookie)))))
  1398. (defun org-xhtml-begin-footnote-definition (n)
  1399. (org-lparse-begin-paragraph 'footnote)
  1400. (insert
  1401. (format
  1402. (format org-export-xhtml-footnote-format
  1403. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1404. n n n)))
  1405. (defun org-xhtml-end-footnote-definition (n)
  1406. (org-lparse-end-paragraph))
  1407. (defun org-xhtml-format-spaces (n)
  1408. (let ((space (or (and org-lparse-encode-pending "\\nbsp") "&nbsp;")) out)
  1409. (while (> n 0)
  1410. (setq out (concat out space))
  1411. (setq n (1- n))) out))
  1412. (defun org-xhtml-format-tabs (&optional n)
  1413. (ignore))
  1414. (defun org-xhtml-format-line-break ()
  1415. (org-xhtml-format-tags "<br/>" ""))
  1416. (defun org-xhtml-format-horizontal-line ()
  1417. (concat "\n" "<hr/>" "\n"))
  1418. (defun org-xhtml-format-line (line)
  1419. (case org-lparse-dyn-current-environment
  1420. ((quote fixedwidth) (concat (org-xml-encode-plain-text line) "\n"))
  1421. (t (concat line "\n"))))
  1422. (defun org-xhtml-format-comment (fmt &rest args)
  1423. (let ((comment (apply 'format fmt args)))
  1424. (format "\n<!-- %s -->\n" comment)))
  1425. (defun org-xhtml-format-fontify (text style &optional id)
  1426. (let (class extra how)
  1427. (cond
  1428. ((eq style 'underline)
  1429. (setq extra " style=\"text-decoration:underline;\"" ))
  1430. ((setq how (cdr (assoc style
  1431. '((bold . ("<b>" . "</b>"))
  1432. (emphasis . ("<i>" . "</i>"))
  1433. (code . ("<code>" . "</code>"))
  1434. (verbatim . ("<code>" . "</code>"))
  1435. (strike . ("<del>" . "</del>"))
  1436. (subscript . ("<sub>" . "</sub>"))
  1437. (superscript . ("<sup>" . "</sup>")))))))
  1438. ((listp style)
  1439. (setq class (mapconcat 'identity style " ")))
  1440. ((stringp style)
  1441. (setq class style))
  1442. (t (error "Unknown style %S" style)))
  1443. (setq extra (concat (when class (format " class=\"%s\"" class))
  1444. (when id (format " id=\"%s\"" id))
  1445. extra))
  1446. (org-xhtml-format-tags
  1447. (or how '("<span%s>" . "</span>")) text extra)))
  1448. (defun org-xhtml-format-link (text href &optional extra)
  1449. (let ((extra (concat (format " href=\"%s\"" href)
  1450. (and extra (concat " " extra)))))
  1451. (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
  1452. (defun org-xhtml-format-heading (text level &optional id)
  1453. (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
  1454. (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
  1455. (defun org-xhtml-format-headline (title extra-targets tags
  1456. &optional snumber level)
  1457. (concat
  1458. (org-lparse-format 'EXTRA-TARGETS extra-targets)
  1459. (concat (org-lparse-format 'SECTION-NUMBER snumber level) " ")
  1460. title
  1461. (and tags (concat (org-lparse-format 'SPACES 3)
  1462. (org-lparse-format 'ORG-TAGS tags)))))
  1463. (defun org-xhtml-format-anchor (text name &optional class)
  1464. (let* ((id name)
  1465. (extra (concat
  1466. (when name (format " name=\"%s\"" name))
  1467. (when id (format " id=\"%s\"" id))
  1468. (when class (format " class=\"%s\"" class)))))
  1469. (org-xhtml-format-tags '("<a%s>" . "</a>") text extra)))
  1470. (defun org-xhtml-format-footnote-reference (n def refcnt)
  1471. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  1472. (format org-export-xhtml-footnote-format
  1473. (format
  1474. "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
  1475. n extra n n))))
  1476. (defun org-xhtml-format-footnotes-section (section-name definitions)
  1477. (if (not definitions) ""
  1478. (format org-export-xhtml-footnotes-section section-name definitions)))
  1479. (defun org-xhtml-format-org-entity (wd)
  1480. (org-entity-get-representation wd 'html))
  1481. (defun org-xhtml-format-tags (tag text &rest args)
  1482. (let ((prefix (when org-lparse-encode-pending "@"))
  1483. (suffix (when org-lparse-encode-pending "@")))
  1484. (apply 'org-lparse-format-tags tag text prefix suffix args)))
  1485. (defun org-xhtml-get (what &optional opt-plist)
  1486. (case what
  1487. (BACKEND 'html)
  1488. (INIT-METHOD nil)
  1489. (SAVE-METHOD nil)
  1490. (CLEANUP-METHOD nil)
  1491. ;; (OTHER-BACKENDS
  1492. ;; ;; There is a provision to register a per-backend converter and
  1493. ;; ;; output formats. Refer `org-lparse-get-converter' and
  1494. ;; ;; `org-lparse-get-other-backends'.
  1495. ;; ;; The default behaviour is to use `org-lparse-convert-process'
  1496. ;; ;; and `org-lparse-convert-capabilities'.
  1497. ;; )
  1498. ;; (CONVERT-METHOD
  1499. ;; ;; See note above
  1500. ;; )
  1501. (EXPORT-DIR (org-export-directory :html opt-plist))
  1502. (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
  1503. (EXPORT-BUFFER-NAME "*Org HTML Export*")
  1504. (ENTITY-CONTROL org-xhtml-entity-control-callbacks-alist)
  1505. (ENTITY-FORMAT org-xhtml-entity-format-callbacks-alist)
  1506. (TOPLEVEL-HLEVEL org-export-xhtml-toplevel-hlevel)
  1507. (SPECIAL-STRING-REGEXPS org-export-xhtml-special-string-regexps)
  1508. (CODING-SYSTEM-FOR-WRITE org-export-xhtml-coding-system)
  1509. (CODING-SYSTEM-FOR-SAVE org-export-xhtml-coding-system)
  1510. (INLINE-IMAGES org-export-xhtml-inline-images)
  1511. (INLINE-IMAGE-EXTENSIONS org-export-xhtml-inline-image-extensions)
  1512. (PLAIN-TEXT-MAP org-export-xhtml-protect-char-alist)
  1513. (TABLE-FIRST-COLUMN-AS-LABELS
  1514. org-export-xhtml-table-use-header-tags-for-first-column)
  1515. (TODO-KWD-CLASS-PREFIX org-export-xhtml-todo-kwd-class-prefix)
  1516. (TAG-CLASS-PREFIX org-export-xhtml-tag-class-prefix)
  1517. (FOOTNOTE-SEPARATOR org-export-xhtml-footnote-separator)
  1518. (t (error "Unknown property: %s" what))))
  1519. (defun org-xhtml-get-coding-system-for-write ()
  1520. (or org-export-xhtml-coding-system
  1521. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1522. (defun org-xhtml-get-coding-system-for-save ()
  1523. (or org-export-xhtml-coding-system
  1524. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1525. (defun org-xhtml-insert-toc (toc)
  1526. ;; locate where toc needs to be inserted
  1527. (goto-char (point-min))
  1528. (cond
  1529. ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  1530. (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t))
  1531. (goto-char (match-beginning 0))
  1532. (replace-match "")
  1533. (insert toc))
  1534. (org-lparse-dyn-first-heading-pos
  1535. (goto-char org-lparse-dyn-first-heading-pos)
  1536. (when (looking-at "\\s-*</p>")
  1537. (goto-char (match-end 0))
  1538. (insert "\n"))
  1539. (insert toc))
  1540. (t (ignore))))
  1541. (defun org-xhtml-insert-preamble (opt-plist)
  1542. (when (plist-get opt-plist :html-preamble)
  1543. (let ((html-pre (plist-get opt-plist :html-preamble))
  1544. (title (plist-get opt-plist :title))
  1545. (date (plist-get opt-plist :effective-date))
  1546. (author (plist-get opt-plist :author))
  1547. (lang-words (plist-get opt-plist :lang-words))
  1548. (email (plist-get opt-plist :email)))
  1549. (cond ((stringp html-pre)
  1550. (insert
  1551. (format-spec html-pre `((?t . ,title) (?a . ,author)
  1552. (?d . ,date) (?e . ,email)))))
  1553. ((functionp html-pre)
  1554. (funcall html-pre opt-plist))
  1555. (t
  1556. (insert
  1557. (format-spec
  1558. (or (cadr (assoc (nth 0 lang-words)
  1559. org-export-xhtml-preamble-format))
  1560. (cadr (assoc "en" org-export-xhtml-preamble-format)))
  1561. `((?t . ,title) (?a . ,author)
  1562. (?d . ,date) (?e . ,email)))))))))
  1563. (defun org-xhtml-insert-postamble (opt-plist)
  1564. (when org-lparse-footnote-definitions
  1565. (insert
  1566. (org-lparse-format
  1567. 'FOOTNOTES-SECTION (nth 4 (plist-get opt-plist :lang-words))
  1568. (mapconcat (lambda (x) (cdr x))
  1569. (nreverse org-lparse-footnote-definitions) "\n"))))
  1570. (let ((bib (org-export-xhtml-get-bibliography)))
  1571. (when bib
  1572. (insert "\n" bib "\n")))
  1573. ;; export html postamble
  1574. (unless body-only
  1575. (let* ((html-post (plist-get opt-plist :html-postamble))
  1576. (date (plist-get opt-plist :effective-date))
  1577. (author (plist-get opt-plist :author))
  1578. (email (plist-get opt-plist :email))
  1579. (lang-words (plist-get opt-plist :lang-words))
  1580. (html-validation-link (or org-export-xhtml-validation-link ""))
  1581. (email
  1582. (mapconcat (lambda(e)
  1583. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1584. (split-string email ",+ *")
  1585. ", "))
  1586. (creator-info
  1587. (concat "Org version " org-version " with Emacs version "
  1588. (number-to-string emacs-major-version))))
  1589. (when (plist-get opt-plist :html-postamble)
  1590. (cond ((stringp html-post)
  1591. (insert "<div id=\"postamble\">\n")
  1592. (insert (format-spec html-post
  1593. `((?a . ,author) (?e . ,email)
  1594. (?d . ,date) (?c . ,creator-info)
  1595. (?v . ,html-validation-link))))
  1596. (insert "</div>"))
  1597. ((functionp html-post)
  1598. (funcall html-post opt-plist))
  1599. ((eq html-post 'auto)
  1600. ;; fall back on default postamble
  1601. (insert "<div id=\"postamble\">\n")
  1602. (when (plist-get opt-plist :time-stamp-file)
  1603. (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
  1604. (when (and (plist-get opt-plist :author-info) author)
  1605. (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
  1606. (when (and (plist-get opt-plist :email-info) email)
  1607. (insert "<p class=\"email\">" email "</p>\n"))
  1608. (when (plist-get opt-plist :creator-info)
  1609. (insert "<p class=\"creator\">"
  1610. (concat "Org version " org-version " with Emacs version "
  1611. (number-to-string emacs-major-version) "</p>\n")))
  1612. (insert html-validation-link "\n</div>"))
  1613. (t
  1614. (insert "<div id=\"postamble\">\n")
  1615. (insert (format-spec
  1616. (or (cadr (assoc (nth 0 lang-words)
  1617. org-export-xhtml-postamble-format))
  1618. (cadr (assoc "en" org-export-xhtml-postamble-format)))
  1619. `((?a . ,author) (?e . ,email)
  1620. (?d . ,date) (?c . ,creator-info)
  1621. (?v . ,html-validation-link))))
  1622. (insert "</div>"))))))
  1623. (if org-export-xhtml-with-timestamp
  1624. (insert org-export-xhtml-html-helper-timestamp)))
  1625. ;; There are references to org-html-expand, org-html-protect and
  1626. ;; org-html-do-expand outside of org-html.el. For now provide a
  1627. ;; migration path. Ultimately these functions have to be removed.
  1628. ;; (defun org-html-expand (string)
  1629. ;; "A simple wrapper around `org-xml-encode-org-text-skip-links'."
  1630. ;; (org-xml-encode-org-text-skip-links string))
  1631. ;; (defun org-html-protect (s)
  1632. ;; "A simple wrapper around `org-xml-encode-plain-text'."
  1633. ;; (org-xml-encode-plain-text s))
  1634. ;; (defun org-html-do-expand (s)
  1635. ;; "A simple wrapper around `org-xml-encode-org-text'."
  1636. ;; (org-xml-encode-org-text s))
  1637. ;; (defun org-export-xhtml-format-href (s)
  1638. ;; "A simple wrapper around `org-xml-format-href'."
  1639. ;; (org-xml-format-href s))
  1640. ;; (defun org-export-xhtml-format-desc (s)
  1641. ;; "A simple wrapper around `org-xml-format-desc'."
  1642. ;; (org-xml-format-desc s))
  1643. (provide 'org-xhtml)
  1644. ;;; org-xhtml.el ends here