org-xhtml.el 65 KB

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