org-xhtml.el 68 KB

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