org-xhtml.el 66 KB

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