org-html.el 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611
  1. ;;; org-html.el --- HTML export for Org-mode
  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: 7.7
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;;; Code:
  25. (require 'org-exp)
  26. (require 'format-spec)
  27. (eval-when-compile (require 'cl))
  28. (declare-function org-id-find-id-file "org-id" (id))
  29. (declare-function htmlize-region "ext:htmlize" (beg end))
  30. (declare-function org-pop-to-buffer-same-window
  31. "org-compat" (&optional buffer-or-name norecord label))
  32. (defgroup org-export-html nil
  33. "Options specific for HTML export of Org-mode files."
  34. :tag "Org Export HTML"
  35. :group 'org-export)
  36. (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
  37. <h2 class=\"footnotes\">%s: </h2>
  38. <div id=\"text-footnotes\">
  39. %s
  40. </div>
  41. </div>"
  42. "Format for the footnotes section.
  43. Should contain a two instances of %s. The first will be replaced with the
  44. language-specific word for \"Footnotes\", the second one will be replaced
  45. by the footnotes themselves."
  46. :group 'org-export-html
  47. :type 'string)
  48. (defcustom org-export-html-footnote-format "<sup>%s</sup>"
  49. "The format for the footnote reference.
  50. %s will be replaced by the footnote reference itself."
  51. :group 'org-export-html
  52. :type 'string)
  53. (defcustom org-export-html-footnote-separator "<sup>, </sup>"
  54. "Text used to separate footnotes."
  55. :group 'org-export-html
  56. :type 'string)
  57. (defcustom org-export-html-coding-system nil
  58. "Coding system for HTML export, defaults to `buffer-file-coding-system'."
  59. :group 'org-export-html
  60. :type 'coding-system)
  61. (defcustom org-export-html-extension "html"
  62. "The extension for exported HTML files."
  63. :group 'org-export-html
  64. :type 'string)
  65. (defcustom org-export-html-xml-declaration
  66. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  67. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  68. "The extension for exported HTML files.
  69. %s will be replaced with the charset of the exported file.
  70. This may be a string, or an alist with export extensions
  71. and corresponding declarations."
  72. :group 'org-export-html
  73. :type '(choice
  74. (string :tag "Single declaration")
  75. (repeat :tag "Dependent on extension"
  76. (cons (string :tag "Extension")
  77. (string :tag "Declaration")))))
  78. (defcustom org-export-html-style-include-scripts t
  79. "Non-nil means include the JavaScript snippets in exported HTML files.
  80. The actual script is defined in `org-export-html-scripts' and should
  81. not be modified."
  82. :group 'org-export-html
  83. :type 'boolean)
  84. (defconst org-export-html-scripts
  85. "<script type=\"text/javascript\">
  86. <!--/*--><![CDATA[/*><!--*/
  87. function CodeHighlightOn(elem, id)
  88. {
  89. var target = document.getElementById(id);
  90. if(null != target) {
  91. elem.cacheClassElem = elem.className;
  92. elem.cacheClassTarget = target.className;
  93. target.className = \"code-highlighted\";
  94. elem.className = \"code-highlighted\";
  95. }
  96. }
  97. function CodeHighlightOff(elem, id)
  98. {
  99. var target = document.getElementById(id);
  100. if(elem.cacheClassElem)
  101. elem.className = elem.cacheClassElem;
  102. if(elem.cacheClassTarget)
  103. target.className = elem.cacheClassTarget;
  104. }
  105. /*]]>*///-->
  106. </script>"
  107. "Basic JavaScript that is needed by HTML files produced by Org-mode.")
  108. (defconst org-export-html-style-default
  109. "<style type=\"text/css\">
  110. <!--/*--><![CDATA[/*><!--*/
  111. html { font-family: Times, serif; font-size: 12pt; }
  112. .title { text-align: center; }
  113. .todo { color: red; }
  114. .done { color: green; }
  115. .tag { background-color: #add8e6; font-weight:normal }
  116. .target { }
  117. .timestamp { color: #bebebe; }
  118. .timestamp-kwd { color: #5f9ea0; }
  119. .right {margin-left:auto; margin-right:0px; text-align:right;}
  120. .left {margin-left:0px; margin-right:auto; text-align:left;}
  121. .center {margin-left:auto; margin-right:auto; text-align:center;}
  122. p.verse { margin-left: 3% }
  123. pre {
  124. border: 1pt solid #AEBDCC;
  125. background-color: #F3F5F7;
  126. padding: 5pt;
  127. font-family: courier, monospace;
  128. font-size: 90%;
  129. overflow:auto;
  130. }
  131. table { border-collapse: collapse; }
  132. td, th { vertical-align: top; }
  133. th.right { text-align:center; }
  134. th.left { text-align:center; }
  135. th.center { text-align:center; }
  136. td.right { text-align:right; }
  137. td.left { text-align:left; }
  138. td.center { text-align:center; }
  139. dt { font-weight: bold; }
  140. div.figure { padding: 0.5em; }
  141. div.figure p { text-align: center; }
  142. textarea { overflow-x: auto; }
  143. .linenr { font-size:smaller }
  144. .code-highlighted {background-color:#ffff00;}
  145. .org-info-js_info-navigation { border-style:none; }
  146. #org-info-js_console-label { font-size:10px; font-weight:bold;
  147. white-space:nowrap; }
  148. .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
  149. font-weight:bold; }
  150. /*]]>*/-->
  151. </style>"
  152. "The default style specification for exported HTML files.
  153. Please use the variables `org-export-html-style' and
  154. `org-export-html-style-extra' to add to this style. If you wish to not
  155. have the default style included, customize the variable
  156. `org-export-html-style-include-default'.")
  157. (defcustom org-export-html-style-include-default t
  158. "Non-nil means include the default style in exported HTML files.
  159. The actual style is defined in `org-export-html-style-default' and should
  160. not be modified. Use the variables `org-export-html-style' to add
  161. your own style information."
  162. :group 'org-export-html
  163. :type 'boolean)
  164. ;;;###autoload
  165. (put 'org-export-html-style-include-default 'safe-local-variable 'booleanp)
  166. (defcustom org-export-html-style ""
  167. "Org-wide style definitions for exported HTML files.
  168. This variable needs to contain the full HTML structure to provide a style,
  169. including the surrounding HTML tags. If you set the value of this variable,
  170. you should consider to include definitions for the following classes:
  171. title, todo, done, timestamp, timestamp-kwd, tag, target.
  172. For example, a valid value would be:
  173. <style type=\"text/css\">
  174. <![CDATA[
  175. p { font-weight: normal; color: gray; }
  176. h1 { color: black; }
  177. .title { text-align: center; }
  178. .todo, .timestamp-kwd { color: red; }
  179. .done { color: green; }
  180. ]]>
  181. </style>
  182. If you'd like to refer to an external style file, use something like
  183. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  184. As the value of this option simply gets inserted into the HTML <head> header,
  185. you can \"misuse\" it to add arbitrary text to the header.
  186. See also the variable `org-export-html-style-extra'."
  187. :group 'org-export-html
  188. :type 'string)
  189. ;;;###autoload
  190. (put 'org-export-html-style 'safe-local-variable 'stringp)
  191. (defcustom org-export-html-style-extra ""
  192. "Additional style information for HTML export.
  193. The value of this variable is inserted into the HTML buffer right after
  194. the value of `org-export-html-style'. Use this variable for per-file
  195. settings of style information, and do not forget to surround the style
  196. settings with <style>...</style> tags."
  197. :group 'org-export-html
  198. :type 'string)
  199. ;;;###autoload
  200. (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
  201. (defcustom org-export-html-mathjax-options
  202. '((path "http://orgmode.org/mathjax/MathJax.js")
  203. (scale "100")
  204. (align "center")
  205. (indent "2em")
  206. (mathml nil))
  207. "Options for MathJax setup.
  208. path The path where to find MathJax
  209. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  210. align How to align display math: left, center, or right
  211. indent If align is not center, how far from the left/right side?
  212. mathml Should a MathML player be used if available?
  213. This is faster and reduces bandwidth use, but currently
  214. sometimes has lower spacing quality. Therefore, the default is
  215. nil. When browsers get better, this switch can be flipped.
  216. You can also customize this for each buffer, using something like
  217. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  218. :group 'org-export-html
  219. :type '(list :greedy t
  220. (list :tag "path (the path from where to load MathJax.js)"
  221. (const :format " " path) (string))
  222. (list :tag "scale (scaling for the displayed math)"
  223. (const :format " " scale) (string))
  224. (list :tag "align (alignment of displayed equations)"
  225. (const :format " " align) (string))
  226. (list :tag "indent (indentation with left or right alignment)"
  227. (const :format " " indent) (string))
  228. (list :tag "mathml (should MathML display be used is possible)"
  229. (const :format " " mathml) (boolean))))
  230. (defun org-export-html-mathjax-config (template options in-buffer)
  231. "Insert the user setup into the matchjax template."
  232. (let (name val (yes " ") (no "// ") x)
  233. (mapc
  234. (lambda (e)
  235. (setq name (car e) val (nth 1 e))
  236. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  237. (setq val (car (read-from-string
  238. (substring in-buffer (match-end 0))))))
  239. (if (not (stringp val)) (setq val (format "%s" val)))
  240. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  241. (setq template (replace-match val t t template))))
  242. options)
  243. (setq val (nth 1 (assq 'mathml options)))
  244. (if (string-match (concat "\\<mathml:") in-buffer)
  245. (setq val (car (read-from-string
  246. (substring in-buffer (match-end 0))))))
  247. ;; Exchange prefixes depending on mathml setting
  248. (if (not val) (setq x yes yes no no x))
  249. ;; Replace cookies to turn on or off the config/jax lines
  250. (if (string-match ":MMLYES:" template)
  251. (setq template (replace-match yes t t template)))
  252. (if (string-match ":MMLNO:" template)
  253. (setq template (replace-match no t t template)))
  254. ;; Return the modified template
  255. template))
  256. (defcustom org-export-html-mathjax-template
  257. "<script type=\"text/javascript\" src=\"%PATH\">
  258. <!--/*--><![CDATA[/*><!--*/
  259. MathJax.Hub.Config({
  260. // Only one of the two following lines, depending on user settings
  261. // First allows browser-native MathML display, second forces HTML/CSS
  262. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  263. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  264. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  265. \"TeX/noUndefined.js\"],
  266. tex2jax: {
  267. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  268. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  269. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  270. ignoreClass: \"tex2jax_ignore\",
  271. processEscapes: false,
  272. processEnvironments: true,
  273. preview: \"TeX\"
  274. },
  275. showProcessingMessages: true,
  276. displayAlign: \"%ALIGN\",
  277. displayIndent: \"%INDENT\",
  278. \"HTML-CSS\": {
  279. scale: %SCALE,
  280. availableFonts: [\"STIX\",\"TeX\"],
  281. preferredFont: \"TeX\",
  282. webFont: \"TeX\",
  283. imageFont: \"TeX\",
  284. showMathMenu: true,
  285. },
  286. MMLorHTML: {
  287. prefer: {
  288. MSIE: \"MML\",
  289. Firefox: \"MML\",
  290. Opera: \"HTML\",
  291. other: \"HTML\"
  292. }
  293. }
  294. });
  295. /*]]>*///-->
  296. </script>"
  297. "The MathJax setup for XHTML files."
  298. :group 'org-export-html
  299. :type 'string)
  300. (defcustom org-export-html-tag-class-prefix ""
  301. "Prefix to class names for TODO keywords.
  302. Each tag gets a class given by the tag itself, with this prefix.
  303. The default prefix is empty because it is nice to just use the keyword
  304. as a class name. But if you get into conflicts with other, existing
  305. CSS classes, then this prefix can be very useful."
  306. :group 'org-export-html
  307. :type 'string)
  308. (defcustom org-export-html-todo-kwd-class-prefix ""
  309. "Prefix to class names for TODO keywords.
  310. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  311. The default prefix is empty because it is nice to just use the keyword
  312. as a class name. But if you get into conflicts with other, existing
  313. CSS classes, then this prefix can be very useful."
  314. :group 'org-export-html
  315. :type 'string)
  316. (defcustom org-export-html-preamble t
  317. "Non-nil means insert a preamble in HTML export.
  318. When `t', insert a string as defined by one of the formatting
  319. strings in `org-export-html-preamble-format'. When set to a
  320. string, this string overrides `org-export-html-preamble-format'.
  321. When set to a function, apply this function and insert the
  322. returned string. The function takes the property list of export
  323. options as its only argument.
  324. Setting :html-preamble in publishing projects will take
  325. precedence over this variable."
  326. :group 'org-export-html
  327. :type '(choice (const :tag "No preamble" nil)
  328. (const :tag "Default preamble" t)
  329. (string :tag "Custom formatting string")
  330. (function :tag "Function (must return a string)")))
  331. (defcustom org-export-html-preamble-format '(("en" ""))
  332. "The format for the HTML preamble.
  333. %t stands for the title.
  334. %a stands for the author's name.
  335. %e stands for the author's email.
  336. %d stands for the date.
  337. If you need to use a \"%\" character, you need to escape it
  338. like that: \"%%\"."
  339. :group 'org-export-html
  340. :type 'string)
  341. (defcustom org-export-html-postamble 'auto
  342. "Non-nil means insert a postamble in HTML export.
  343. When `t', insert a string as defined by the formatting string in
  344. `org-export-html-postamble-format'. When set to a string, this
  345. string overrides `org-export-html-postamble-format'. When set to
  346. 'auto, discard `org-export-html-postamble-format' and honor
  347. `org-export-author/email/creator-info' variables. When set to a
  348. function, apply this function and insert the returned string.
  349. The function takes the property list of export options as its
  350. only argument.
  351. Setting :html-postamble in publishing projects will take
  352. precedence over this variable."
  353. :group 'org-export-html
  354. :type '(choice (const :tag "No postamble" nil)
  355. (const :tag "Auto preamble" 'auto)
  356. (const :tag "Default formatting string" t)
  357. (string :tag "Custom formatting string")
  358. (function :tag "Function (must return a string)")))
  359. (defcustom org-export-html-postamble-format
  360. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  361. <p class=\"date\">Date: %d</p>
  362. <p class=\"creator\">Generated by %c</p>
  363. <p class=\"xhtml-validation\">%v</p>
  364. "))
  365. "The format for the HTML postamble.
  366. %a stands for the author's name.
  367. %e stands for the author's email.
  368. %d stands for the date.
  369. %c will be replaced by information about Org/Emacs versions.
  370. %v will be replaced by `org-export-html-validation-link'.
  371. If you need to use a \"%\" character, you need to escape it
  372. like that: \"%%\"."
  373. :group 'org-export-html
  374. :type 'string)
  375. (defcustom org-export-html-home/up-format
  376. "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  377. <a accesskey=\"h\" href=\"%s\"> UP </a>
  378. |
  379. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  380. </div>"
  381. "Snippet used to insert the HOME and UP links.
  382. This is a format string, the first %s will receive the UP link,
  383. the second the HOME link. If both `org-export-html-link-up' and
  384. `org-export-html-link-home' are empty, the entire snippet will be
  385. ignored."
  386. :group 'org-export-html
  387. :type 'string)
  388. (defcustom org-export-html-toplevel-hlevel 2
  389. "The <H> level for level 1 headings in HTML export.
  390. This is also important for the classes that will be wrapped around headlines
  391. and outline structure. If this variable is 1, the top-level headlines will
  392. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  393. and outline-text-1. If this is 2, all of these will get a 2 instead.
  394. The default for this variable is 2, because we use <h1> for formatting the
  395. document title."
  396. :group 'org-export-html
  397. :type 'string)
  398. (defcustom org-export-html-link-org-files-as-html t
  399. "Non-nil means make file links to `file.org' point to `file.html'.
  400. When org-mode is exporting an org-mode file to HTML, links to
  401. non-html files are directly put into a href tag in HTML.
  402. However, links to other Org-mode files (recognized by the
  403. extension `.org.) should become links to the corresponding html
  404. file, assuming that the linked org-mode file will also be
  405. converted to HTML.
  406. When nil, the links still point to the plain `.org' file."
  407. :group 'org-export-html
  408. :type 'boolean)
  409. (defcustom org-export-html-inline-images 'maybe
  410. "Non-nil means inline images into exported HTML pages.
  411. This is done using an <img> tag. When nil, an anchor with href is used to
  412. link to the image. If this option is `maybe', then images in links with
  413. an empty description will be inlined, while images with a description will
  414. be linked only."
  415. :group 'org-export-html
  416. :type '(choice (const :tag "Never" nil)
  417. (const :tag "Always" t)
  418. (const :tag "When there is no description" maybe)))
  419. (defcustom org-export-html-inline-image-extensions
  420. '("png" "jpeg" "jpg" "gif" "svg")
  421. "Extensions of image files that can be inlined into HTML."
  422. :group 'org-export-html
  423. :type '(repeat (string :tag "Extension")))
  424. (defcustom org-export-html-table-tag
  425. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  426. "The HTML tag that is used to start a table.
  427. This must be a <table> tag, but you may change the options like
  428. borders and spacing."
  429. :group 'org-export-html
  430. :type 'string)
  431. (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  432. "The opening tag for table header fields.
  433. This is customizable so that alignment options can be specified.
  434. The first %s will be filled with the scope of the field, either row or col.
  435. The second %s will be replaced by a style entry to align the field.
  436. See also the variable `org-export-html-table-use-header-tags-for-first-column'.
  437. See also the variable `org-export-html-table-align-individual-fields'."
  438. :group 'org-export-tables
  439. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  440. (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
  441. "The opening tag for table data fields.
  442. This is customizable so that alignment options can be specified.
  443. The first %s will be filled with the scope of the field, either row or col.
  444. The second %s will be replaced by a style entry to align the field.
  445. See also the variable `org-export-html-table-align-individual-fields'."
  446. :group 'org-export-tables
  447. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  448. (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
  449. "The opening tag for table data fields.
  450. This is customizable so that alignment options can be specified.
  451. Instead of strings, these can be Lisp forms that will be evaluated
  452. for each row in order to construct the table row tags. During evaluation,
  453. the variable `head' will be true when this is a header line, nil when this
  454. is a body line. And the variable `nline' will contain the line number,
  455. starting from 1 in the first header line. For example
  456. (setq org-export-table-row-tags
  457. (cons '(if head
  458. \"<tr>\"
  459. (if (= (mod nline 2) 1)
  460. \"<tr class=\\\"tr-odd\\\">\"
  461. \"<tr class=\\\"tr-even\\\">\"))
  462. \"</tr>\"))
  463. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  464. :group 'org-export-tables
  465. :type '(cons
  466. (choice :tag "Opening tag"
  467. (string :tag "Specify")
  468. (sexp))
  469. (choice :tag "Closing tag"
  470. (string :tag "Specify")
  471. (sexp))))
  472. (defcustom org-export-html-table-align-individual-fields t
  473. "Non-nil means attach style attributes for alignment to each table field.
  474. When nil, alignment will only be specified in the column tags, but this
  475. is ignored by some browsers (like Firefox, Safari). Opera does it right
  476. though."
  477. :group 'org-export-tables
  478. :type 'boolean)
  479. (defcustom org-export-html-table-use-header-tags-for-first-column nil
  480. "Non-nil means format column one in tables with header tags.
  481. When nil, also column one will use data tags."
  482. :group 'org-export-tables
  483. :type 'boolean)
  484. (defcustom org-export-html-validation-link
  485. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  486. "Link to HTML validation service."
  487. :group 'org-export-html
  488. :type 'string)
  489. ;; FIXME Obsolete since Org 7.7
  490. ;; Use the :timestamp option or `org-export-time-stamp-file' instead
  491. (defvar org-export-html-with-timestamp nil
  492. "If non-nil, write container for HTML-helper-mode timestamp.")
  493. ;; FIXME Obsolete since Org 7.7
  494. (defvar org-export-html-html-helper-timestamp
  495. "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
  496. "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
  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. :group 'org-export-html
  503. :type '(repeat (cons (string :tag "Character")
  504. (string :tag "HTML equivalent"))))
  505. (defgroup org-export-htmlize nil
  506. "Options for processing examples with htmlize.el."
  507. :tag "Org Export Htmlize"
  508. :group 'org-export-html)
  509. (defcustom org-export-htmlize-output-type 'inline-css
  510. "Output type to be used by htmlize when formatting code snippets.
  511. Choices are `css', to export the CSS selectors only, or `inline-css', to
  512. export the CSS attribute values inline in the HTML. We use as default
  513. `inline-css', in order to make the resulting HTML self-containing.
  514. However, this will fail when using Emacs in batch mode for export, because
  515. then no rich font definitions are in place. It will also not be good if
  516. people with different Emacs setup contribute HTML files to a website,
  517. because the fonts will represent the individual setups. In these cases,
  518. it is much better to let Org/Htmlize assign classes only, and to use
  519. a style file to define the look of these classes.
  520. To get a start for your css file, start Emacs session and make sure that
  521. all the faces you are interested in are defined, for example by loading files
  522. in all modes you want. Then, use the command
  523. \\[org-export-htmlize-generate-css] to extract class definitions."
  524. :group 'org-export-htmlize
  525. :type '(choice (const css) (const inline-css)))
  526. (defcustom org-export-htmlize-css-font-prefix "org-"
  527. "The prefix for CSS class names for htmlize font specifications."
  528. :group 'org-export-htmlize
  529. :type 'string)
  530. (defcustom org-export-htmlized-org-css-url nil
  531. "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
  532. Normally when creating an htmlized version of an Org buffer, htmlize will
  533. create CSS to define the font colors. However, this does not work when
  534. converting in batch mode, and it also can look bad if different people
  535. with different fontification setup work on the same website.
  536. When this variable is non-nil, creating an htmlized version of an Org buffer
  537. using `org-export-as-org' will remove the internal CSS section and replace it
  538. with a link to this URL."
  539. :group 'org-export-htmlize
  540. :type '(choice
  541. (const :tag "Keep internal css" nil)
  542. (string :tag "URL or local href")))
  543. ;; FIXME: The following variable is obsolete since Org 7.7 but is
  544. ;; still declared and checked within code for compatibility reasons.
  545. ;; Use the custom variables `org-export-html-divs' instead.
  546. (defvar org-export-html-content-div "content"
  547. "The name of the container DIV that holds all the page contents.
  548. This variable is obsolete since Org version 7.7.
  549. Please set `org-export-html-divs' instead.")
  550. (defcustom org-export-html-divs '("preamble" "content" "postamble")
  551. "The name of the main divs for HTML export."
  552. :group 'org-export-html
  553. :type '(list
  554. (string :tag " Div for the preamble:")
  555. (string :tag " Div for the content:")
  556. (string :tag "Div for the postamble:")))
  557. ;;; Hooks
  558. (defvar org-export-html-after-blockquotes-hook nil
  559. "Hook run during HTML export, after blockquote, verse, center are done.")
  560. (defvar org-export-html-final-hook nil
  561. "Hook run at the end of HTML export, in the new buffer.")
  562. ;;; HTML export
  563. (defun org-export-html-preprocess (parameters)
  564. "Convert LaTeX fragments to images."
  565. (when (and org-current-export-file
  566. (plist-get parameters :LaTeX-fragments))
  567. (org-format-latex
  568. (concat "ltxpng/" (file-name-sans-extension
  569. (file-name-nondirectory
  570. org-current-export-file)))
  571. org-current-export-dir nil "Creating LaTeX image %s"
  572. nil nil
  573. (cond
  574. ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
  575. ((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
  576. ((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
  577. ((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
  578. (t nil))))
  579. (goto-char (point-min))
  580. (let (label l1)
  581. (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
  582. (org-if-unprotected-at (match-beginning 1)
  583. (setq label (match-string 1))
  584. (save-match-data
  585. (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  586. (setq l1 (substring label (match-beginning 1)))
  587. (setq l1 label)))
  588. (replace-match (format "[[#%s][%s]]" label l1) t t)))))
  589. ;;;###autoload
  590. (defun org-export-as-html-and-open (arg)
  591. "Export the outline as HTML and immediately open it with a browser.
  592. If there is an active region, export only the region.
  593. The prefix ARG specifies how many levels of the outline should become
  594. headlines. The default is 3. Lower levels will become bulleted lists."
  595. (interactive "P")
  596. (org-export-as-html arg 'hidden)
  597. (org-open-file buffer-file-name)
  598. (when org-export-kill-product-buffer-when-displayed
  599. (kill-buffer (current-buffer))))
  600. ;;;###autoload
  601. (defun org-export-as-html-batch ()
  602. "Call the function `org-export-as-html'.
  603. This function can be used in batch processing as:
  604. emacs --batch
  605. --load=$HOME/lib/emacs/org.el
  606. --eval \"(setq org-export-headline-levels 2)\"
  607. --visit=MyFile --funcall org-export-as-html-batch"
  608. (org-export-as-html org-export-headline-levels 'hidden))
  609. ;;;###autoload
  610. (defun org-export-as-html-to-buffer (arg)
  611. "Call `org-export-as-html` with output to a temporary buffer.
  612. No file is created. The prefix ARG is passed through to `org-export-as-html'."
  613. (interactive "P")
  614. (org-export-as-html arg nil nil "*Org HTML Export*")
  615. (when org-export-show-temporary-export-buffer
  616. (switch-to-buffer-other-window "*Org HTML Export*")))
  617. ;;;###autoload
  618. (defun org-replace-region-by-html (beg end)
  619. "Assume the current region has org-mode syntax, and convert it to HTML.
  620. This can be used in any buffer. For example, you could write an
  621. itemized list in org-mode syntax in an HTML buffer and then use this
  622. command to convert it."
  623. (interactive "r")
  624. (let (reg html buf pop-up-frames)
  625. (save-window-excursion
  626. (if (org-mode-p)
  627. (setq html (org-export-region-as-html
  628. beg end t 'string))
  629. (setq reg (buffer-substring beg end)
  630. buf (get-buffer-create "*Org tmp*"))
  631. (with-current-buffer buf
  632. (erase-buffer)
  633. (insert reg)
  634. (org-mode)
  635. (setq html (org-export-region-as-html
  636. (point-min) (point-max) t 'string)))
  637. (kill-buffer buf)))
  638. (delete-region beg end)
  639. (insert html)))
  640. ;;;###autoload
  641. (defun org-export-region-as-html (beg end &optional body-only buffer)
  642. "Convert region from BEG to END in org-mode buffer to HTML.
  643. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  644. contents, and only produce the region of converted text, useful for
  645. cut-and-paste operations.
  646. If BUFFER is a buffer or a string, use/create that buffer as a target
  647. of the converted HTML. If BUFFER is the symbol `string', return the
  648. produced HTML as a string and leave not buffer behind. For example,
  649. a Lisp program could call this function in the following way:
  650. (setq html (org-export-region-as-html beg end t 'string))
  651. When called interactively, the output buffer is selected, and shown
  652. in a window. A non-interactive call will only return the buffer."
  653. (interactive "r\nP")
  654. (when (org-called-interactively-p 'any)
  655. (setq buffer "*Org HTML Export*"))
  656. (let ((transient-mark-mode t) (zmacs-regions t)
  657. ext-plist rtn)
  658. (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
  659. (goto-char end)
  660. (set-mark (point)) ;; to activate the region
  661. (goto-char beg)
  662. (setq rtn (org-export-as-html
  663. nil nil ext-plist
  664. buffer body-only))
  665. (if (fboundp 'deactivate-mark) (deactivate-mark))
  666. (if (and (org-called-interactively-p 'any) (bufferp rtn))
  667. (switch-to-buffer-other-window rtn)
  668. rtn)))
  669. (defvar html-table-tag nil) ; dynamically scoped into this.
  670. (defvar org-par-open nil)
  671. ;;; org-html-cvt-link-fn
  672. (defconst org-html-cvt-link-fn
  673. nil
  674. "Function to convert link URLs to exportable URLs.
  675. Takes two arguments, TYPE and PATH.
  676. Returns exportable url as (TYPE PATH), or nil to signal that it
  677. didn't handle this case.
  678. Intended to be locally bound around a call to `org-export-as-html'." )
  679. (defun org-html-cvt-org-as-html (opt-plist type path)
  680. "Convert an org filename to an equivalent html filename.
  681. If TYPE is not file, just return `nil'.
  682. See variable `org-export-html-link-org-files-as-html'"
  683. (save-match-data
  684. (and
  685. org-export-html-link-org-files-as-html
  686. (string= type "file")
  687. (string-match "\\.org$" path)
  688. (progn
  689. (list
  690. "file"
  691. (concat
  692. (substring path 0 (match-beginning 0))
  693. "."
  694. (plist-get opt-plist :html-extension)))))))
  695. ;;; org-html-should-inline-p
  696. (defun org-html-should-inline-p (filename descp)
  697. "Return non-nil if link FILENAME should be inlined.
  698. The decision to inline the FILENAME link is based on the current
  699. settings. DESCP is the boolean of whether there was a link
  700. description. See variables `org-export-html-inline-images' and
  701. `org-export-html-inline-image-extensions'."
  702. (declare (special
  703. org-export-html-inline-images
  704. org-export-html-inline-image-extensions))
  705. (and (or (eq t org-export-html-inline-images)
  706. (and org-export-html-inline-images (not descp)))
  707. (org-file-image-p
  708. filename org-export-html-inline-image-extensions)))
  709. ;;; org-html-make-link
  710. (defun org-html-make-link (opt-plist type path fragment desc attr
  711. may-inline-p)
  712. "Make an HTML link.
  713. OPT-PLIST is an options list.
  714. TYPE is the device-type of the link (THIS://foo.html)
  715. PATH is the path of the link (http://THIS#locationx)
  716. FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
  717. DESC is the link description, if any.
  718. ATTR is a string of other attributes of the a element.
  719. MAY-INLINE-P allows inlining it as an image."
  720. (declare (special org-par-open))
  721. (save-match-data
  722. (let* ((filename path)
  723. ;;First pass. Just sanity stuff.
  724. (components-1
  725. (cond
  726. ((string= type "file")
  727. (list
  728. type
  729. ;;Substitute just if original path was absolute.
  730. ;;(Otherwise path must remain relative)
  731. (if (file-name-absolute-p path)
  732. (concat "file://" (expand-file-name path))
  733. path)))
  734. ((string= type "")
  735. (list nil path))
  736. (t (list type path))))
  737. ;;Second pass. Components converted so they can refer
  738. ;;to a remote site.
  739. (components-2
  740. (or
  741. (and org-html-cvt-link-fn
  742. (apply org-html-cvt-link-fn
  743. opt-plist components-1))
  744. (apply #'org-html-cvt-org-as-html
  745. opt-plist components-1)
  746. components-1))
  747. (type (first components-2))
  748. (thefile (second components-2)))
  749. ;;Third pass. Build final link except for leading type
  750. ;;spec.
  751. (cond
  752. ((or
  753. (not type)
  754. (string= type "http")
  755. (string= type "https")
  756. (string= type "file")
  757. (string= type "coderef"))
  758. (if fragment
  759. (setq thefile (concat thefile "#" fragment))))
  760. (t))
  761. ;;Final URL-build, for all types.
  762. (setq thefile
  763. (let
  764. ((str (org-export-html-format-href thefile)))
  765. (if (and type (not (or (string= "file" type)
  766. (string= "coderef" type))))
  767. (concat type ":" str)
  768. str)))
  769. (if (and
  770. may-inline-p
  771. ;;Can't inline a URL with a fragment.
  772. (not fragment))
  773. (progn
  774. (message "image %s %s" thefile org-par-open)
  775. (org-export-html-format-image thefile org-par-open))
  776. (concat
  777. "<a href=\"" thefile "\"" (if attr (concat " " attr)) ">"
  778. (org-export-html-format-desc desc)
  779. "</a>")))))
  780. (defun org-html-handle-links (line opt-plist)
  781. "Return LINE with markup of Org mode links.
  782. OPT-PLIST is the export options list."
  783. (let ((start 0)
  784. (current-dir (if buffer-file-name
  785. (file-name-directory buffer-file-name)
  786. default-directory))
  787. (link-validate (plist-get opt-plist :link-validation-function))
  788. type id-file fnc
  789. rpl path attr desc descp desc1 desc2 link)
  790. (while (string-match org-bracket-link-analytic-regexp++ line start)
  791. (setq start (match-beginning 0))
  792. (setq path (save-match-data (org-link-unescape
  793. (match-string 3 line))))
  794. (setq type (cond
  795. ((match-end 2) (match-string 2 line))
  796. ((save-match-data
  797. (or (file-name-absolute-p path)
  798. (string-match "^\\.\\.?/" path)))
  799. "file")
  800. (t "internal")))
  801. (setq path (org-extract-attributes (org-link-unescape path)))
  802. (setq attr (get-text-property 0 'org-attributes path))
  803. (setq desc1 (if (match-end 5) (match-string 5 line))
  804. desc2 (if (match-end 2) (concat type ":" path) path)
  805. descp (and desc1 (not (equal desc1 desc2)))
  806. desc (or desc1 desc2))
  807. ;; Make an image out of the description if that is so wanted
  808. (when (and descp (org-file-image-p
  809. desc org-export-html-inline-image-extensions))
  810. (save-match-data
  811. (if (string-match "^file:" desc)
  812. (setq desc (substring desc (match-end 0)))))
  813. (setq desc (org-add-props
  814. (concat "<img src=\"" desc "\" alt=\""
  815. (file-name-nondirectory desc) "\"/>")
  816. '(org-protected t))))
  817. (cond
  818. ((equal type "internal")
  819. (let
  820. ((frag-0
  821. (if (= (string-to-char path) ?#)
  822. (substring path 1)
  823. path)))
  824. (setq rpl
  825. (org-html-make-link
  826. opt-plist
  827. ""
  828. ""
  829. (org-solidify-link-text
  830. (save-match-data (org-link-unescape frag-0))
  831. nil)
  832. desc attr nil))))
  833. ((and (equal type "id")
  834. (setq id-file (org-id-find-id-file path)))
  835. ;; This is an id: link to another file (if it was the same file,
  836. ;; it would have become an internal link...)
  837. (save-match-data
  838. (setq id-file (file-relative-name
  839. id-file
  840. (file-name-directory org-current-export-file)))
  841. (setq rpl
  842. (org-html-make-link opt-plist
  843. "file" id-file
  844. (concat (if (org-uuidgen-p path) "ID-") path)
  845. desc
  846. attr
  847. nil))))
  848. ((member type '("http" "https"))
  849. ;; standard URL, can inline as image
  850. (setq rpl
  851. (org-html-make-link opt-plist
  852. type path nil
  853. desc
  854. attr
  855. (org-html-should-inline-p path descp))))
  856. ((member type '("ftp" "mailto" "news"))
  857. ;; standard URL, can't inline as image
  858. (setq rpl
  859. (org-html-make-link opt-plist
  860. type path nil
  861. desc
  862. attr
  863. nil)))
  864. ((string= type "coderef")
  865. (let*
  866. ((coderef-str (format "coderef-%s" path))
  867. (attr-1
  868. (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  869. coderef-str coderef-str)))
  870. (setq rpl
  871. (org-html-make-link opt-plist
  872. type "" coderef-str
  873. (format
  874. (org-export-get-coderef-format
  875. path
  876. (and descp desc))
  877. (cdr (assoc path org-export-code-refs)))
  878. attr-1
  879. nil))))
  880. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  881. ;; The link protocol has a function for format the link
  882. (setq rpl
  883. (save-match-data
  884. (funcall fnc (org-link-unescape path) desc1 'html))))
  885. ((string= type "file")
  886. ;; FILE link
  887. (save-match-data
  888. (let*
  889. ((components
  890. (if
  891. (string-match "::\\(.*\\)" path)
  892. (list
  893. (replace-match "" t nil path)
  894. (match-string 1 path))
  895. (list path nil)))
  896. ;;The proper path, without a fragment
  897. (path-1
  898. (first components))
  899. ;;The raw fragment
  900. (fragment-0
  901. (second components))
  902. ;;Check the fragment. If it can't be used as
  903. ;;target fragment we'll pass nil instead.
  904. (fragment-1
  905. (if
  906. (and fragment-0
  907. (not (string-match "^[0-9]*$" fragment-0))
  908. (not (string-match "^\\*" fragment-0))
  909. (not (string-match "^/.*/$" fragment-0)))
  910. (org-solidify-link-text
  911. (org-link-unescape fragment-0))
  912. nil))
  913. (desc-2
  914. ;;Description minus "file:" and ".org"
  915. (if (string-match "^file:" desc)
  916. (let
  917. ((desc-1 (replace-match "" t t desc)))
  918. (if (string-match "\\.org$" desc-1)
  919. (replace-match "" t t desc-1)
  920. desc-1))
  921. desc)))
  922. (setq rpl
  923. (if
  924. (and
  925. (functionp link-validate)
  926. (not (funcall link-validate path-1 current-dir)))
  927. desc
  928. (org-html-make-link opt-plist
  929. "file" path-1 fragment-1 desc-2 attr
  930. (org-html-should-inline-p path-1 descp)))))))
  931. (t
  932. ;; just publish the path, as default
  933. (setq rpl (concat "@<i>&lt;" type ":"
  934. (save-match-data (org-link-unescape path))
  935. "&gt;@</i>"))))
  936. (setq line (replace-match rpl t t line)
  937. start (+ start (length rpl))))
  938. line))
  939. ;;; org-export-as-html
  940. ;;;###autoload
  941. (defun org-export-as-html (arg &optional hidden ext-plist
  942. to-buffer body-only pub-dir)
  943. "Export the outline as a pretty HTML file.
  944. If there is an active region, export only the region. The prefix
  945. ARG specifies how many levels of the outline should become
  946. headlines. The default is 3. Lower levels will become bulleted
  947. lists. HIDDEN is obsolete and does nothing.
  948. EXT-PLIST is a property list with external parameters overriding
  949. org-mode's default settings, but still inferior to file-local
  950. settings. When TO-BUFFER is non-nil, create a buffer with that
  951. name and export to that buffer. If TO-BUFFER is the symbol
  952. `string', don't leave any buffer behind but just return the
  953. resulting HTML as a string. When BODY-ONLY is set, don't produce
  954. the file header and footer, simply return the content of
  955. <body>...</body>, without even the body tags themselves. When
  956. PUB-DIR is set, use this as the publishing directory."
  957. (interactive "P")
  958. (run-hooks 'org-export-first-hook)
  959. ;; Make sure we have a file name when we need it.
  960. (when (and (not (or to-buffer body-only))
  961. (not buffer-file-name))
  962. (if (buffer-base-buffer)
  963. (org-set-local 'buffer-file-name
  964. (with-current-buffer (buffer-base-buffer)
  965. buffer-file-name))
  966. (error "Need a file name to be able to export")))
  967. (message "Exporting...")
  968. (setq-default org-todo-line-regexp org-todo-line-regexp)
  969. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  970. (setq-default org-done-keywords org-done-keywords)
  971. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  972. (let* ((opt-plist
  973. (org-export-process-option-filters
  974. (org-combine-plists (org-default-export-plist)
  975. ext-plist
  976. (org-infile-export-plist))))
  977. (body-only (or body-only (plist-get opt-plist :body-only)))
  978. (style (concat (if (plist-get opt-plist :style-include-default)
  979. org-export-html-style-default)
  980. (plist-get opt-plist :style)
  981. (plist-get opt-plist :style-extra)
  982. "\n"
  983. (if (plist-get opt-plist :style-include-scripts)
  984. org-export-html-scripts)))
  985. (html-extension (plist-get opt-plist :html-extension))
  986. valid thetoc have-headings first-heading-pos
  987. (odd org-odd-levels-only)
  988. (region-p (org-region-active-p))
  989. (rbeg (and region-p (region-beginning)))
  990. (rend (and region-p (region-end)))
  991. (subtree-p
  992. (if (plist-get opt-plist :ignore-subtree-p)
  993. nil
  994. (when region-p
  995. (save-excursion
  996. (goto-char rbeg)
  997. (and (org-at-heading-p)
  998. (>= (org-end-of-subtree t t) rend))))))
  999. (level-offset (if subtree-p
  1000. (save-excursion
  1001. (goto-char rbeg)
  1002. (+ (funcall outline-level)
  1003. (if org-odd-levels-only 1 0)))
  1004. 0))
  1005. (opt-plist (setq org-export-opt-plist
  1006. (if subtree-p
  1007. (org-export-add-subtree-options opt-plist rbeg)
  1008. opt-plist)))
  1009. ;; The following two are dynamically scoped into other
  1010. ;; routines below.
  1011. (org-current-export-dir
  1012. (or pub-dir (org-export-directory :html opt-plist)))
  1013. (org-current-export-file buffer-file-name)
  1014. (level 0) (line "") (origline "") txt todo
  1015. (umax nil)
  1016. (umax-toc nil)
  1017. (filename (if to-buffer nil
  1018. (expand-file-name
  1019. (concat
  1020. (file-name-sans-extension
  1021. (or (and subtree-p
  1022. (org-entry-get (region-beginning)
  1023. "EXPORT_FILE_NAME" t))
  1024. (file-name-nondirectory buffer-file-name)))
  1025. "." html-extension)
  1026. (file-name-as-directory
  1027. (or pub-dir (org-export-directory :html opt-plist))))))
  1028. (current-dir (if buffer-file-name
  1029. (file-name-directory buffer-file-name)
  1030. default-directory))
  1031. (buffer (if to-buffer
  1032. (cond
  1033. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  1034. (t (get-buffer-create to-buffer)))
  1035. (find-file-noselect filename)))
  1036. (org-levels-open (make-vector org-level-max nil))
  1037. (date (plist-get opt-plist :date))
  1038. (author (plist-get opt-plist :author))
  1039. (html-validation-link (or org-export-html-validation-link ""))
  1040. (title (org-html-expand
  1041. (or (and subtree-p (org-export-get-title-from-subtree))
  1042. (plist-get opt-plist :title)
  1043. (and (not body-only)
  1044. (not
  1045. (plist-get opt-plist :skip-before-1st-heading))
  1046. (org-export-grab-title-from-buffer))
  1047. (and buffer-file-name
  1048. (file-name-sans-extension
  1049. (file-name-nondirectory buffer-file-name)))
  1050. "UNTITLED")))
  1051. (link-up (and (plist-get opt-plist :link-up)
  1052. (string-match "\\S-" (plist-get opt-plist :link-up))
  1053. (plist-get opt-plist :link-up)))
  1054. (link-home (and (plist-get opt-plist :link-home)
  1055. (string-match "\\S-" (plist-get opt-plist :link-home))
  1056. (plist-get opt-plist :link-home)))
  1057. (dummy (setq opt-plist (plist-put opt-plist :title title)))
  1058. (html-table-tag (plist-get opt-plist :html-table-tag))
  1059. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  1060. (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
  1061. (inquote nil)
  1062. (infixed nil)
  1063. (inverse nil)
  1064. (email (plist-get opt-plist :email))
  1065. (language (plist-get opt-plist :language))
  1066. (keywords (plist-get opt-plist :keywords))
  1067. (description (plist-get opt-plist :description))
  1068. (num (plist-get opt-plist :section-numbers))
  1069. (lang-words nil)
  1070. (head-count 0) cnt
  1071. (start 0)
  1072. (coding-system (and (boundp 'buffer-file-coding-system)
  1073. buffer-file-coding-system))
  1074. (coding-system-for-write (or org-export-html-coding-system
  1075. coding-system))
  1076. (save-buffer-coding-system (or org-export-html-coding-system
  1077. coding-system))
  1078. (charset (and coding-system-for-write
  1079. (fboundp 'coding-system-get)
  1080. (coding-system-get coding-system-for-write
  1081. 'mime-charset)))
  1082. (region
  1083. (buffer-substring
  1084. (if region-p (region-beginning) (point-min))
  1085. (if region-p (region-end) (point-max))))
  1086. (org-export-have-math nil)
  1087. (org-export-footnotes-seen nil)
  1088. (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
  1089. (lines
  1090. (org-split-string
  1091. (org-export-preprocess-string
  1092. region
  1093. :emph-multiline t
  1094. :for-backend 'html
  1095. :skip-before-1st-heading
  1096. (plist-get opt-plist :skip-before-1st-heading)
  1097. :drawers (plist-get opt-plist :drawers)
  1098. :todo-keywords (plist-get opt-plist :todo-keywords)
  1099. :tasks (plist-get opt-plist :tasks)
  1100. :tags (plist-get opt-plist :tags)
  1101. :priority (plist-get opt-plist :priority)
  1102. :footnotes (plist-get opt-plist :footnotes)
  1103. :timestamps (plist-get opt-plist :timestamps)
  1104. :archived-trees
  1105. (plist-get opt-plist :archived-trees)
  1106. :select-tags (plist-get opt-plist :select-tags)
  1107. :exclude-tags (plist-get opt-plist :exclude-tags)
  1108. :add-text
  1109. (plist-get opt-plist :text)
  1110. :LaTeX-fragments
  1111. (plist-get opt-plist :LaTeX-fragments))
  1112. "[\r\n]"))
  1113. (mathjax
  1114. (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
  1115. (and org-export-have-math
  1116. (eq (plist-get opt-plist :LaTeX-fragments) t)))
  1117. (org-export-html-mathjax-config
  1118. org-export-html-mathjax-template
  1119. org-export-html-mathjax-options
  1120. (or (plist-get opt-plist :mathjax) ""))
  1121. ""))
  1122. table-open
  1123. table-buffer table-orig-buffer
  1124. ind
  1125. rpl path attr desc descp desc1 desc2 link
  1126. snumber fnc
  1127. footnotes footref-seen
  1128. href
  1129. )
  1130. (let ((inhibit-read-only t))
  1131. (org-unmodified
  1132. (remove-text-properties (point-min) (point-max)
  1133. '(:org-license-to-kill t))))
  1134. (message "Exporting...")
  1135. (setq org-min-level (org-get-min-level lines level-offset))
  1136. (setq org-last-level org-min-level)
  1137. (org-init-section-numbers)
  1138. (cond
  1139. ((and date (string-match "%" date))
  1140. (setq date (format-time-string date)))
  1141. (date)
  1142. (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
  1143. ;; Get the language-dependent settings
  1144. (setq lang-words (or (assoc language org-export-language-setup)
  1145. (assoc "en" org-export-language-setup)))
  1146. ;; Switch to the output buffer
  1147. (set-buffer buffer)
  1148. (let ((inhibit-read-only t)) (erase-buffer))
  1149. (fundamental-mode)
  1150. (org-install-letbind)
  1151. (and (fboundp 'set-buffer-file-coding-system)
  1152. (set-buffer-file-coding-system coding-system-for-write))
  1153. (let ((case-fold-search nil)
  1154. (org-odd-levels-only odd))
  1155. ;; create local variables for all options, to make sure all called
  1156. ;; functions get the correct information
  1157. (mapc (lambda (x)
  1158. (set (make-local-variable (nth 2 x))
  1159. (plist-get opt-plist (car x))))
  1160. org-export-plist-vars)
  1161. (setq umax (if arg (prefix-numeric-value arg)
  1162. org-export-headline-levels))
  1163. (setq umax-toc (if (integerp org-export-with-toc)
  1164. (min org-export-with-toc umax)
  1165. umax))
  1166. (unless body-only
  1167. ;; File header
  1168. (insert (format
  1169. "%s
  1170. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1171. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  1172. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  1173. lang=\"%s\" xml:lang=\"%s\">
  1174. <head>
  1175. <title>%s</title>
  1176. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  1177. <meta name=\"generator\" content=\"Org-mode\"/>
  1178. <meta name=\"generated\" content=\"%s\"/>
  1179. <meta name=\"author\" content=\"%s\"/>
  1180. <meta name=\"description\" content=\"%s\"/>
  1181. <meta name=\"keywords\" content=\"%s\"/>
  1182. %s
  1183. %s
  1184. </head>
  1185. <body>
  1186. %s
  1187. "
  1188. (format
  1189. (or (and (stringp org-export-html-xml-declaration)
  1190. org-export-html-xml-declaration)
  1191. (cdr (assoc html-extension org-export-html-xml-declaration))
  1192. (cdr (assoc "html" org-export-html-xml-declaration))
  1193. "")
  1194. (or charset "iso-8859-1"))
  1195. language language
  1196. title
  1197. (or charset "iso-8859-1")
  1198. date author description keywords
  1199. style
  1200. mathjax
  1201. (if (or link-up link-home)
  1202. (concat
  1203. (format org-export-html-home/up-format
  1204. (or link-up link-home)
  1205. (or link-home link-up))
  1206. "\n")
  1207. "")))
  1208. ;; insert html preamble
  1209. (when (plist-get opt-plist :html-preamble)
  1210. (let ((html-pre (plist-get opt-plist :html-preamble)))
  1211. (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
  1212. (cond ((stringp html-pre)
  1213. (insert
  1214. (format-spec html-pre `((?t . ,title) (?a . ,author)
  1215. (?d . ,date) (?e . ,email)))))
  1216. ((functionp html-pre)
  1217. (funcall html-pre))
  1218. (t
  1219. (insert
  1220. (format-spec
  1221. (or (cadr (assoc (nth 0 lang-words)
  1222. org-export-html-preamble-format))
  1223. (cadr (assoc "en" org-export-html-preamble-format)))
  1224. `((?t . ,title) (?a . ,author)
  1225. (?d . ,date) (?e . ,email))))))
  1226. (insert "\n</div>\n")))
  1227. ;; begin wrap around body
  1228. (insert (format "\n<div id=\"%s\">"
  1229. ;; FIXME org-export-html-content-div is obsolete since 7.7
  1230. (or org-export-html-content-div
  1231. (nth 1 org-export-html-divs)))
  1232. ;; FIXME this should go in the preamble but is here so
  1233. ;; that org-infojs can still find it
  1234. "\n<h1 class=\"title\">" title "</h1>\n"))
  1235. ;; insert body
  1236. (if (and org-export-with-toc (not body-only))
  1237. (progn
  1238. (push (format "<h%d>%s</h%d>\n"
  1239. org-export-html-toplevel-hlevel
  1240. (nth 3 lang-words)
  1241. org-export-html-toplevel-hlevel)
  1242. thetoc)
  1243. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  1244. (push "<ul>\n<li>" thetoc)
  1245. (setq lines
  1246. (mapcar
  1247. #'(lambda (line)
  1248. (if (and (string-match org-todo-line-regexp line)
  1249. (not (get-text-property 0 'org-protected line)))
  1250. ;; This is a headline
  1251. (progn
  1252. (setq have-headings t)
  1253. (setq level (- (match-end 1) (match-beginning 1)
  1254. level-offset)
  1255. level (org-tr-level level)
  1256. txt (save-match-data
  1257. (org-html-expand
  1258. (org-export-cleanup-toc-line
  1259. (match-string 3 line))))
  1260. todo
  1261. (or (and org-export-mark-todo-in-toc
  1262. (match-beginning 2)
  1263. (not (member (match-string 2 line)
  1264. org-done-keywords)))
  1265. ; TODO, not DONE
  1266. (and org-export-mark-todo-in-toc
  1267. (= level umax-toc)
  1268. (org-search-todo-below
  1269. line lines level))))
  1270. (if (string-match
  1271. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  1272. (setq txt (replace-match
  1273. "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
  1274. (if (string-match quote-re0 txt)
  1275. (setq txt (replace-match "" t t txt)))
  1276. (setq snumber (org-section-number level))
  1277. (if (and num (if (integerp num)
  1278. (>= num level)
  1279. num))
  1280. (setq txt (concat snumber " " txt)))
  1281. (if (<= level (max umax umax-toc))
  1282. (setq head-count (+ head-count 1)))
  1283. (if (<= level umax-toc)
  1284. (progn
  1285. (if (> level org-last-level)
  1286. (progn
  1287. (setq cnt (- level org-last-level))
  1288. (while (>= (setq cnt (1- cnt)) 0)
  1289. (push "\n<ul>\n<li>" thetoc))
  1290. (push "\n" thetoc)))
  1291. (if (< level org-last-level)
  1292. (progn
  1293. (setq cnt (- org-last-level level))
  1294. (while (>= (setq cnt (1- cnt)) 0)
  1295. (push "</li>\n</ul>" thetoc))
  1296. (push "\n" thetoc)))
  1297. ;; Check for targets
  1298. (while (string-match org-any-target-regexp line)
  1299. (setq line (replace-match
  1300. (concat "@<span class=\"target\">"
  1301. (match-string 1 line) "@</span> ")
  1302. t t line)))
  1303. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  1304. (setq txt (replace-match "" t t txt)))
  1305. (setq href
  1306. (replace-regexp-in-string
  1307. "\\." "-" (format "sec-%s" snumber)))
  1308. (setq href (org-solidify-link-text
  1309. (or (cdr (assoc href
  1310. org-export-preferred-target-alist)) href)))
  1311. (push
  1312. (format
  1313. (if todo
  1314. "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
  1315. "</li>\n<li><a href=\"#%s\">%s</a>")
  1316. href txt) thetoc)
  1317. (setq org-last-level level)))))
  1318. line)
  1319. lines))
  1320. (while (> org-last-level (1- org-min-level))
  1321. (setq org-last-level (1- org-last-level))
  1322. (push "</li>\n</ul>\n" thetoc))
  1323. (push "</div>\n" thetoc)
  1324. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  1325. (setq head-count 0)
  1326. (org-init-section-numbers)
  1327. (org-open-par)
  1328. (while (setq line (pop lines) origline line)
  1329. (catch 'nextline
  1330. ;; end of quote section?
  1331. (when (and inquote (string-match org-outline-regexp-bol line))
  1332. (insert "</pre>\n")
  1333. (org-open-par)
  1334. (setq inquote nil))
  1335. ;; inside a quote section?
  1336. (when inquote
  1337. (insert (org-html-protect line) "\n")
  1338. (throw 'nextline nil))
  1339. ;; Fixed-width, verbatim lines (examples)
  1340. (when (and org-export-with-fixed-width
  1341. (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
  1342. (when (not infixed)
  1343. (setq infixed t)
  1344. (org-close-par-maybe)
  1345. (insert "<pre class=\"example\">\n"))
  1346. (insert (org-html-protect (match-string 3 line)) "\n")
  1347. (when (or (not lines)
  1348. (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
  1349. (car lines))))
  1350. (setq infixed nil)
  1351. (insert "</pre>\n")
  1352. (org-open-par))
  1353. (throw 'nextline nil))
  1354. ;; Protected HTML
  1355. (when (and (get-text-property 0 'org-protected line)
  1356. ;; Make sure it is the entire line that is protected
  1357. (not (< (or (next-single-property-change
  1358. 0 'org-protected line) 10000)
  1359. (length line))))
  1360. (let (par (ind (get-text-property 0 'original-indentation line)))
  1361. (when (re-search-backward
  1362. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  1363. (setq par (match-string 1))
  1364. (replace-match "\\2\n"))
  1365. (insert line "\n")
  1366. (while (and lines
  1367. (or (= (length (car lines)) 0)
  1368. (not ind)
  1369. (equal ind (get-text-property 0 'original-indentation (car lines))))
  1370. (or (= (length (car lines)) 0)
  1371. (get-text-property 0 'org-protected (car lines))))
  1372. (insert (pop lines) "\n"))
  1373. (and par (insert "<p>\n")))
  1374. (throw 'nextline nil))
  1375. ;; Blockquotes, verse, and center
  1376. (when (equal "ORG-BLOCKQUOTE-START" line)
  1377. (org-close-par-maybe)
  1378. (insert "<blockquote>\n")
  1379. (org-open-par)
  1380. (throw 'nextline nil))
  1381. (when (equal "ORG-BLOCKQUOTE-END" line)
  1382. (org-close-par-maybe)
  1383. (insert "\n</blockquote>\n")
  1384. (org-open-par)
  1385. (throw 'nextline nil))
  1386. (when (equal "ORG-VERSE-START" line)
  1387. (org-close-par-maybe)
  1388. (insert "\n<p class=\"verse\">\n")
  1389. (setq org-par-open t)
  1390. (setq inverse t)
  1391. (throw 'nextline nil))
  1392. (when (equal "ORG-VERSE-END" line)
  1393. (insert "</p>\n")
  1394. (setq org-par-open nil)
  1395. (org-open-par)
  1396. (setq inverse nil)
  1397. (throw 'nextline nil))
  1398. (when (equal "ORG-CENTER-START" line)
  1399. (org-close-par-maybe)
  1400. (insert "\n<div style=\"text-align: center\">")
  1401. (org-open-par)
  1402. (throw 'nextline nil))
  1403. (when (equal "ORG-CENTER-END" line)
  1404. (org-close-par-maybe)
  1405. (insert "\n</div>")
  1406. (org-open-par)
  1407. (throw 'nextline nil))
  1408. (run-hooks 'org-export-html-after-blockquotes-hook)
  1409. (when inverse
  1410. (let ((i (org-get-string-indentation line)))
  1411. (if (> i 0)
  1412. (setq line (concat (mapconcat 'identity
  1413. (make-list (* 2 i) "\\nbsp") "")
  1414. " " (org-trim line))))
  1415. (unless (string-match "\\\\\\\\[ \t]*$" line)
  1416. (setq line (concat line "\\\\")))))
  1417. ;; make targets to anchors
  1418. (setq start 0)
  1419. (while (string-match
  1420. "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
  1421. (cond
  1422. ((get-text-property (match-beginning 1) 'org-protected line)
  1423. (setq start (match-end 1)))
  1424. ((match-end 2)
  1425. (setq line (replace-match
  1426. (format
  1427. "@<a name=\"%s\" id=\"%s\">@</a>"
  1428. (org-solidify-link-text (match-string 1 line))
  1429. (org-solidify-link-text (match-string 1 line)))
  1430. t t line)))
  1431. ((and org-export-with-toc (equal (string-to-char line) ?*))
  1432. ;; FIXME: NOT DEPENDENT on TOC?????????????????????
  1433. (setq line (replace-match
  1434. (concat "@<span class=\"target\">"
  1435. (match-string 1 line) "@</span> ")
  1436. ;; (concat "@<i>" (match-string 1 line) "@</i> ")
  1437. t t line)))
  1438. (t
  1439. (setq line (replace-match
  1440. (concat "@<a name=\""
  1441. (org-solidify-link-text (match-string 1 line))
  1442. "\" class=\"target\">" (match-string 1 line)
  1443. "@</a> ")
  1444. t t line)))))
  1445. (setq line (org-html-handle-time-stamps line))
  1446. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  1447. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  1448. ;; Also handle sub_superscripts and checkboxes
  1449. (or (string-match org-table-hline-regexp line)
  1450. (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" line)
  1451. (setq line (org-html-expand line)))
  1452. ;; Format the links
  1453. (setq line (org-html-handle-links line opt-plist))
  1454. ;; TODO items
  1455. (if (and (string-match org-todo-line-regexp line)
  1456. (match-beginning 2))
  1457. (setq line
  1458. (concat (substring line 0 (match-beginning 2))
  1459. "<span class=\""
  1460. (if (member (match-string 2 line)
  1461. org-done-keywords)
  1462. "done" "todo")
  1463. " " (match-string 2 line)
  1464. "\"> " (org-export-html-get-todo-kwd-class-name
  1465. (match-string 2 line))
  1466. "</span>" (substring line (match-end 2)))))
  1467. ;; Does this contain a reference to a footnote?
  1468. (when org-export-with-footnotes
  1469. (setq start 0)
  1470. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
  1471. ;; Discard protected matches not clearly identified as
  1472. ;; footnote markers.
  1473. (if (or (get-text-property (match-beginning 2) 'org-protected line)
  1474. (not (get-text-property (match-beginning 2) 'org-footnote line)))
  1475. (setq start (match-end 2))
  1476. (let ((n (match-string 2 line)) extra a)
  1477. (if (setq a (assoc n footref-seen))
  1478. (progn
  1479. (setcdr a (1+ (cdr a)))
  1480. (setq extra (format ".%d" (cdr a))))
  1481. (setq extra "")
  1482. (push (cons n 1) footref-seen))
  1483. (setq line
  1484. (replace-match
  1485. (concat
  1486. (format
  1487. (concat "%s"
  1488. (format org-export-html-footnote-format
  1489. (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
  1490. (or (match-string 1 line) "") n extra n n)
  1491. ;; If another footnote is following the
  1492. ;; current one, add a separator.
  1493. (if (save-match-data
  1494. (string-match "\\`\\[[0-9]+\\]"
  1495. (substring line (match-end 0))))
  1496. org-export-html-footnote-separator
  1497. ""))
  1498. t t line))))))
  1499. (cond
  1500. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  1501. ;; This is a headline
  1502. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
  1503. level-offset))
  1504. txt (match-string 2 line))
  1505. (if (string-match quote-re0 txt)
  1506. (setq txt (replace-match "" t t txt)))
  1507. (if (<= level (max umax umax-toc))
  1508. (setq head-count (+ head-count 1)))
  1509. (setq first-heading-pos (or first-heading-pos (point)))
  1510. (org-html-level-start level txt umax
  1511. (and org-export-with-toc (<= level umax))
  1512. head-count opt-plist)
  1513. ;; QUOTES
  1514. (when (string-match quote-re line)
  1515. (org-close-par-maybe)
  1516. (insert "<pre>")
  1517. (setq inquote t)))
  1518. ((and org-export-with-tables
  1519. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  1520. (when (not table-open)
  1521. ;; New table starts
  1522. (setq table-open t table-buffer nil table-orig-buffer nil))
  1523. ;; Accumulate lines
  1524. (setq table-buffer (cons line table-buffer)
  1525. table-orig-buffer (cons origline table-orig-buffer))
  1526. (when (or (not lines)
  1527. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  1528. (car lines))))
  1529. (setq table-open nil
  1530. table-buffer (nreverse table-buffer)
  1531. table-orig-buffer (nreverse table-orig-buffer))
  1532. (org-close-par-maybe)
  1533. (insert (org-format-table-html table-buffer table-orig-buffer))))
  1534. ;; Normal lines
  1535. (t
  1536. ;; This line either is list item or end a list.
  1537. (when (get-text-property 0 'list-item line)
  1538. (setq line (org-html-export-list-line
  1539. line
  1540. (get-text-property 0 'list-item line)
  1541. (get-text-property 0 'list-struct line)
  1542. (get-text-property 0 'list-prevs line))))
  1543. ;; Horizontal line
  1544. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
  1545. (if org-par-open
  1546. (insert "\n</p>\n<hr/>\n<p>\n")
  1547. (insert "\n<hr/>\n"))
  1548. (throw 'nextline nil))
  1549. ;; Empty lines start a new paragraph. If hand-formatted lists
  1550. ;; are not fully interpreted, lines starting with "-", "+", "*"
  1551. ;; also start a new paragraph.
  1552. (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
  1553. ;; Is this the start of a footnote?
  1554. (when org-export-with-footnotes
  1555. (when (and (boundp 'footnote-section-tag-regexp)
  1556. (string-match (concat "^" footnote-section-tag-regexp)
  1557. line))
  1558. ;; ignore this line
  1559. (throw 'nextline nil))
  1560. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
  1561. (org-close-par-maybe)
  1562. (let ((n (match-string 1 line)))
  1563. (setq org-par-open t
  1564. line (replace-match
  1565. (format
  1566. (concat "<p class=\"footnote\">"
  1567. (format org-export-html-footnote-format
  1568. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
  1569. n n n) t t line)))))
  1570. ;; Check if the line break needs to be conserved
  1571. (cond
  1572. ((string-match "\\\\\\\\[ \t]*$" line)
  1573. (setq line (replace-match "<br/>" t t line)))
  1574. (org-export-preserve-breaks
  1575. (setq line (concat line "<br/>"))))
  1576. ;; Check if a paragraph should be started
  1577. (let ((start 0))
  1578. (while (and org-par-open
  1579. (string-match "\\\\par\\>" line start))
  1580. ;; Leave a space in the </p> so that the footnote matcher
  1581. ;; does not see this.
  1582. (if (not (get-text-property (match-beginning 0)
  1583. 'org-protected line))
  1584. (setq line (replace-match "</p ><p >" t t line)))
  1585. (setq start (match-end 0))))
  1586. (insert line "\n")))))
  1587. ;; Properly close all local lists and other lists
  1588. (when inquote
  1589. (insert "</pre>\n")
  1590. (org-open-par))
  1591. (org-html-level-start 1 nil umax
  1592. (and org-export-with-toc (<= level umax))
  1593. head-count opt-plist)
  1594. ;; the </div> to close the last text-... div.
  1595. (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
  1596. (save-excursion
  1597. (goto-char (point-min))
  1598. (while (re-search-forward
  1599. "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
  1600. nil t)
  1601. (push (match-string 1) footnotes)
  1602. (replace-match "\\4" t nil)
  1603. (goto-char (match-beginning 0))))
  1604. (when footnotes
  1605. (insert (format org-export-html-footnotes-section
  1606. (nth 4 lang-words)
  1607. (mapconcat 'identity (nreverse footnotes) "\n"))
  1608. "\n"))
  1609. (let ((bib (org-export-html-get-bibliography)))
  1610. (when bib
  1611. (insert "\n" bib "\n")))
  1612. (unless body-only
  1613. ;; end wrap around body
  1614. (insert "</div>\n")
  1615. ;; export html postamble
  1616. (let ((html-post (plist-get opt-plist :html-postamble))
  1617. (email
  1618. (mapconcat (lambda(e)
  1619. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1620. (split-string email ",+ *")
  1621. ", "))
  1622. (creator-info
  1623. (concat "Org version " org-version " with Emacs version "
  1624. (number-to-string emacs-major-version))))
  1625. (when (plist-get opt-plist :html-postamble)
  1626. (insert "\n<div id=\"" (nth 2 org-export-html-divs) "\">\n")
  1627. (cond ((stringp html-post)
  1628. (insert (format-spec html-post
  1629. `((?a . ,author) (?e . ,email)
  1630. (?d . ,date) (?c . ,creator-info)
  1631. (?v . ,html-validation-link)))))
  1632. ((functionp html-post)
  1633. (funcall html-post))
  1634. ((eq html-post 'auto)
  1635. ;; fall back on default postamble
  1636. (when (plist-get opt-plist :time-stamp-file)
  1637. (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
  1638. (when (and (plist-get opt-plist :author-info) author)
  1639. (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
  1640. (when (and (plist-get opt-plist :email-info) email)
  1641. (insert "<p class=\"email\">" email "</p>\n"))
  1642. (when (plist-get opt-plist :creator-info)
  1643. (insert "<p class=\"creator\">"
  1644. (concat "Org version " org-version " with Emacs version "
  1645. (number-to-string emacs-major-version) "</p>\n")))
  1646. (insert html-validation-link "\n"))
  1647. (t
  1648. (insert (format-spec
  1649. (or (cadr (assoc (nth 0 lang-words)
  1650. org-export-html-postamble-format))
  1651. (cadr (assoc "en" org-export-html-postamble-format)))
  1652. `((?a . ,author) (?e . ,email)
  1653. (?d . ,date) (?c . ,creator-info)
  1654. (?v . ,html-validation-link))))))
  1655. (insert "\n</div>"))))
  1656. ;; FIXME `org-export-html-with-timestamp' has been declared
  1657. ;; obsolete since Org 7.7 -- don't forget to remove this.
  1658. (if org-export-html-with-timestamp
  1659. (insert org-export-html-html-helper-timestamp))
  1660. (unless body-only (insert "\n</body>\n</html>\n"))
  1661. (unless (plist-get opt-plist :buffer-will-be-killed)
  1662. (normal-mode)
  1663. (if (eq major-mode (default-value 'major-mode))
  1664. (html-mode)))
  1665. ;; insert the table of contents
  1666. (goto-char (point-min))
  1667. (when thetoc
  1668. (if (or (re-search-forward
  1669. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  1670. (re-search-forward
  1671. "\\[TABLE-OF-CONTENTS\\]" nil t))
  1672. (progn
  1673. (goto-char (match-beginning 0))
  1674. (replace-match ""))
  1675. (goto-char first-heading-pos)
  1676. (when (looking-at "\\s-*</p>")
  1677. (goto-char (match-end 0))
  1678. (insert "\n")))
  1679. (insert "<div id=\"table-of-contents\">\n")
  1680. (let ((beg (point)))
  1681. (mapc 'insert thetoc)
  1682. (insert "</div>\n")
  1683. (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t)
  1684. (replace-match ""))))
  1685. ;; remove empty paragraphs
  1686. (goto-char (point-min))
  1687. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  1688. (replace-match ""))
  1689. (goto-char (point-min))
  1690. ;; Convert whitespace place holders
  1691. (goto-char (point-min))
  1692. (let (beg end n)
  1693. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  1694. (setq n (get-text-property beg 'org-whitespace)
  1695. end (next-single-property-change beg 'org-whitespace))
  1696. (goto-char beg)
  1697. (delete-region beg end)
  1698. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  1699. (make-string n ?x)))))
  1700. ;; Remove empty lines at the beginning of the file.
  1701. (goto-char (point-min))
  1702. (when (looking-at "\\s-+\n") (replace-match ""))
  1703. ;; Remove display properties
  1704. (remove-text-properties (point-min) (point-max) '(display t))
  1705. ;; Run the hook
  1706. (run-hooks 'org-export-html-final-hook)
  1707. (or to-buffer (save-buffer))
  1708. (goto-char (point-min))
  1709. (or (org-export-push-to-kill-ring "HTML")
  1710. (message "Exporting... done"))
  1711. (if (eq to-buffer 'string)
  1712. (prog1 (buffer-substring (point-min) (point-max))
  1713. (kill-buffer (current-buffer)))
  1714. (current-buffer)))))
  1715. (defun org-export-html-format-href (s)
  1716. "Make sure the S is valid as a href reference in an XHTML document."
  1717. (save-match-data
  1718. (let ((start 0))
  1719. (while (string-match "&" s start)
  1720. (setq start (+ (match-beginning 0) 3)
  1721. s (replace-match "&amp;" t t s)))))
  1722. s)
  1723. (defun org-export-html-format-desc (s)
  1724. "Make sure the S is valid as a description in a link."
  1725. (if (and s (not (get-text-property 1 'org-protected s)))
  1726. (save-match-data
  1727. (org-html-do-expand s))
  1728. s))
  1729. (defun org-export-html-format-image (src par-open)
  1730. "Create image tag with source and attributes."
  1731. (save-match-data
  1732. (if (string-match "^ltxpng/" src)
  1733. (format "<img src=\"%s\" alt=\"%s\"/>"
  1734. src (org-find-text-property-in-string 'org-latex-src src))
  1735. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  1736. (attr (org-find-text-property-in-string 'org-attributes src))
  1737. (label (org-find-text-property-in-string 'org-label src)))
  1738. (setq caption (and caption (org-html-do-expand caption)))
  1739. (concat
  1740. (if caption
  1741. (format "%s<div %sclass=\"figure\">
  1742. <p>"
  1743. (if org-par-open "</p>\n" "")
  1744. (if label (format "id=\"%s\" " (org-solidify-link-text label)) "")))
  1745. (format "<img src=\"%s\"%s />"
  1746. src
  1747. (if (string-match "\\<alt=" (or attr ""))
  1748. (concat " " attr )
  1749. (concat " " attr " alt=\"" src "\"")))
  1750. (if caption
  1751. (format "</p>%s
  1752. </div>%s"
  1753. (concat "\n<p>" caption "</p>")
  1754. (if org-par-open "\n<p>" ""))))))))
  1755. (defun org-export-html-get-bibliography ()
  1756. "Find bibliography, cut it out and return it."
  1757. (catch 'exit
  1758. (let (beg end (cnt 1) bib)
  1759. (save-excursion
  1760. (goto-char (point-min))
  1761. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  1762. (setq beg (match-beginning 0))
  1763. (while (re-search-forward "</?div\\>" nil t)
  1764. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  1765. (when (= cnt 0)
  1766. (and (looking-at ">") (forward-char 1))
  1767. (setq bib (buffer-substring beg (point)))
  1768. (delete-region beg (point))
  1769. (throw 'exit bib))))
  1770. nil))))
  1771. (defvar org-table-number-regexp) ; defined in org-table.el
  1772. (defun org-format-table-html (lines olines &optional no-css)
  1773. "Find out which HTML converter to use and return the HTML code.
  1774. NO-CSS is passed to the exporter."
  1775. (if (stringp lines)
  1776. (setq lines (org-split-string lines "\n")))
  1777. (if (string-match "^[ \t]*|" (car lines))
  1778. ;; A normal org table
  1779. (org-format-org-table-html lines nil no-css)
  1780. ;; Table made by table.el
  1781. (or (org-format-table-table-html-using-table-generate-source
  1782. olines (not org-export-prefer-native-exporter-for-tables))
  1783. ;; We are here only when table.el table has NO col or row
  1784. ;; spanning and the user prefers using org's own converter for
  1785. ;; exporting of such simple table.el tables.
  1786. (org-format-table-table-html lines))))
  1787. (defvar org-table-number-fraction) ; defined in org-table.el
  1788. (defun org-format-org-table-html (lines &optional splice no-css)
  1789. "Format a table into HTML.
  1790. LINES is a list of lines. Optional argument SPLICE means, do not
  1791. insert header and surrounding <table> tags, just format the lines.
  1792. Optional argument NO-CSS means use XHTML attributes instead of CSS
  1793. for formatting. This is required for the DocBook exporter."
  1794. (require 'org-table)
  1795. ;; Get rid of hlines at beginning and end
  1796. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1797. (setq lines (nreverse lines))
  1798. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1799. (setq lines (nreverse lines))
  1800. (when org-export-table-remove-special-lines
  1801. ;; Check if the table has a marking column. If yes remove the
  1802. ;; column and the special lines
  1803. (setq lines (org-table-clean-before-export lines)))
  1804. (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
  1805. (label (org-find-text-property-in-string 'org-label (car lines)))
  1806. (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
  1807. (car lines)))
  1808. (attributes (org-find-text-property-in-string 'org-attributes
  1809. (car lines)))
  1810. (html-table-tag (org-export-splice-attributes
  1811. html-table-tag attributes))
  1812. (head (and org-export-highlight-first-table-line
  1813. (delq nil (mapcar
  1814. (lambda (x) (string-match "^[ \t]*|-" x))
  1815. (cdr lines)))))
  1816. (nline 0) fnum nfields i (cnt 0)
  1817. tbopen line fields html gr colgropen rowstart rowend
  1818. ali align aligns n)
  1819. (setq caption (and caption (org-html-do-expand caption)))
  1820. (when (and forced-aligns org-table-clean-did-remove-column)
  1821. (setq forced-aligns
  1822. (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
  1823. (if splice (setq head nil))
  1824. (unless splice (push (if head "<thead>" "<tbody>") html))
  1825. (setq tbopen t)
  1826. (while (setq line (pop lines))
  1827. (catch 'next-line
  1828. (if (string-match "^[ \t]*|-" line)
  1829. (progn
  1830. (unless splice
  1831. (push (if head "</thead>" "</tbody>") html)
  1832. (if lines (push "<tbody>" html) (setq tbopen nil)))
  1833. (setq head nil) ;; head ends here, first time around
  1834. ;; ignore this line
  1835. (throw 'next-line t)))
  1836. ;; Break the line into fields
  1837. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1838. (unless fnum (setq fnum (make-vector (length fields) 0)
  1839. nfields (length fnum)))
  1840. (setq nline (1+ nline) i -1
  1841. rowstart (eval (car org-export-table-row-tags))
  1842. rowend (eval (cdr org-export-table-row-tags)))
  1843. (push (concat rowstart
  1844. (mapconcat
  1845. (lambda (x)
  1846. (setq i (1+ i) ali (format "@@class%03d@@" i))
  1847. (if (and (< i nfields) ; make sure no rogue line causes an error here
  1848. (string-match org-table-number-regexp x))
  1849. (incf (aref fnum i)))
  1850. (cond
  1851. (head
  1852. (concat
  1853. (format (car org-export-table-header-tags)
  1854. "col" ali)
  1855. x
  1856. (cdr org-export-table-header-tags)))
  1857. ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
  1858. (concat
  1859. (format (car org-export-table-header-tags)
  1860. "row" ali)
  1861. x
  1862. (cdr org-export-table-header-tags)))
  1863. (t
  1864. (concat (format (car org-export-table-data-tags) ali)
  1865. x
  1866. (cdr org-export-table-data-tags)))))
  1867. fields "")
  1868. rowend)
  1869. html)))
  1870. (unless splice (if tbopen (push "</tbody>" html)))
  1871. (unless splice (push "</table>\n" html))
  1872. (setq html (nreverse html))
  1873. (unless splice
  1874. ;; Put in col tags with the alignment (unfortunately often ignored...)
  1875. (unless (car org-table-colgroup-info)
  1876. (setq org-table-colgroup-info
  1877. (cons :start (cdr org-table-colgroup-info))))
  1878. (setq i 0)
  1879. (push (mapconcat
  1880. (lambda (x)
  1881. (setq gr (pop org-table-colgroup-info)
  1882. i (1+ i)
  1883. align (if (assoc i forced-aligns)
  1884. (cdr (assoc (cdr (assoc i forced-aligns))
  1885. '(("l" . "left") ("r" . "right")
  1886. ("c" . "center"))))
  1887. (if (> (/ (float x) nline)
  1888. org-table-number-fraction)
  1889. "right" "left")))
  1890. (push align aligns)
  1891. (format (if no-css
  1892. "%s<col align=\"%s\" />%s"
  1893. "%s<col class=\"%s\" />%s")
  1894. (if (memq gr '(:start :startend))
  1895. (prog1
  1896. (if colgropen
  1897. "</colgroup>\n<colgroup>"
  1898. "<colgroup>")
  1899. (setq colgropen t))
  1900. "")
  1901. align
  1902. (if (memq gr '(:end :startend))
  1903. (progn (setq colgropen nil) "</colgroup>")
  1904. "")))
  1905. fnum "")
  1906. html)
  1907. (setq aligns (nreverse aligns))
  1908. (if colgropen (setq html (cons (car html)
  1909. (cons "</colgroup>" (cdr html)))))
  1910. ;; Since the output of HTML table formatter can also be used in
  1911. ;; DocBook document, we want to always include the caption to make
  1912. ;; DocBook XML file valid.
  1913. (push (format "<caption>%s</caption>" (or caption "")) html)
  1914. (when label
  1915. (setq html-table-tag (org-export-splice-attributes html-table-tag (format "id=\"%s\"" (org-solidify-link-text label)))))
  1916. (push html-table-tag html))
  1917. (setq html (mapcar
  1918. (lambda (x)
  1919. (replace-regexp-in-string
  1920. "@@class\\([0-9]+\\)@@"
  1921. (lambda (txt)
  1922. (if (not org-export-html-table-align-individual-fields)
  1923. ""
  1924. (setq n (string-to-number (match-string 1 txt)))
  1925. (format (if no-css " align=\"%s\"" " class=\"%s\"")
  1926. (or (nth n aligns) "left"))))
  1927. x))
  1928. html))
  1929. (concat (mapconcat 'identity html "\n") "\n")))
  1930. (defun org-export-splice-attributes (tag attributes)
  1931. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  1932. (if (not attributes)
  1933. tag
  1934. (let (oldatt newatt)
  1935. (setq oldatt (org-extract-attributes-from-string tag)
  1936. tag (pop oldatt)
  1937. newatt (cdr (org-extract-attributes-from-string attributes)))
  1938. (while newatt
  1939. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  1940. (if (string-match ">" tag)
  1941. (setq tag
  1942. (replace-match (concat (org-attributes-to-string oldatt) ">")
  1943. t t tag)))
  1944. tag)))
  1945. (defun org-format-table-table-html (lines)
  1946. "Format a table generated by table.el into HTML.
  1947. This conversion does *not* use `table-generate-source' from table.el.
  1948. This has the advantage that Org-mode's HTML conversions can be used.
  1949. But it has the disadvantage, that no cell- or row-spanning is allowed."
  1950. (let (line field-buffer
  1951. (head org-export-highlight-first-table-line)
  1952. fields html empty i)
  1953. (setq html (concat html-table-tag "\n"))
  1954. (while (setq line (pop lines))
  1955. (setq empty "&nbsp;")
  1956. (catch 'next-line
  1957. (if (string-match "^[ \t]*\\+-" line)
  1958. (progn
  1959. (if field-buffer
  1960. (progn
  1961. (setq
  1962. html
  1963. (concat
  1964. html
  1965. "<tr>"
  1966. (mapconcat
  1967. (lambda (x)
  1968. (if (equal x "") (setq x empty))
  1969. (if head
  1970. (concat
  1971. (format (car org-export-table-header-tags) "col" "")
  1972. x
  1973. (cdr org-export-table-header-tags))
  1974. (concat (format (car org-export-table-data-tags) "") x
  1975. (cdr org-export-table-data-tags))))
  1976. field-buffer "\n")
  1977. "</tr>\n"))
  1978. (setq head nil)
  1979. (setq field-buffer nil)))
  1980. ;; Ignore this line
  1981. (throw 'next-line t)))
  1982. ;; Break the line into fields and store the fields
  1983. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1984. (if field-buffer
  1985. (setq field-buffer (mapcar
  1986. (lambda (x)
  1987. (concat x "<br/>" (pop fields)))
  1988. field-buffer))
  1989. (setq field-buffer fields))))
  1990. (setq html (concat html "</table>\n"))
  1991. html))
  1992. (defun org-format-table-table-html-using-table-generate-source (lines
  1993. &optional
  1994. spanned-only)
  1995. "Format a table into html, using `table-generate-source' from table.el.
  1996. Use SPANNED-ONLY to suppress exporting of simple table.el tables.
  1997. When SPANNED-ONLY is nil, all table.el tables are exported. When
  1998. SPANNED-ONLY is non-nil, only tables with either row or column
  1999. spans are exported.
  2000. This routine returns the generated source or nil as appropriate.
  2001. Refer docstring of `org-export-prefer-native-exporter-for-tables'
  2002. for further information."
  2003. (require 'table)
  2004. (with-current-buffer (get-buffer-create " org-tmp1 ")
  2005. (erase-buffer)
  2006. (insert (mapconcat 'identity lines "\n"))
  2007. (goto-char (point-min))
  2008. (if (not (re-search-forward "|[^+]" nil t))
  2009. (error "Error processing table"))
  2010. (table-recognize-table)
  2011. (when (or (not spanned-only)
  2012. (let* ((dim (table-query-dimension))
  2013. (c (nth 4 dim)) (r (nth 5 dim)) (cells (nth 6 dim)))
  2014. (not (= (* c r) cells))))
  2015. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  2016. (table-generate-source 'html " org-tmp2 ")
  2017. (set-buffer " org-tmp2 ")
  2018. (buffer-substring (point-min) (point-max)))))
  2019. (defun org-export-splice-style (style extra)
  2020. "Splice EXTRA into STYLE, just before \"</style>\"."
  2021. (if (and (stringp extra)
  2022. (string-match "\\S-" extra)
  2023. (string-match "</style>" style))
  2024. (concat (substring style 0 (match-beginning 0))
  2025. "\n" extra "\n"
  2026. (substring style (match-beginning 0)))
  2027. style))
  2028. (defun org-html-handle-time-stamps (s)
  2029. "Format time stamps in string S, or remove them."
  2030. (catch 'exit
  2031. (let (r b)
  2032. (while (string-match org-maybe-keyword-time-regexp s)
  2033. (or b (setq b (substring s 0 (match-beginning 0))))
  2034. (setq r (concat
  2035. r (substring s 0 (match-beginning 0))
  2036. " @<span class=\"timestamp-wrapper\">"
  2037. (if (match-end 1)
  2038. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  2039. (match-string 1 s)))
  2040. (format " @<span class=\"timestamp\">%s@</span>"
  2041. (substring
  2042. (org-translate-time (match-string 3 s)) 1 -1))
  2043. "@</span>")
  2044. s (substring s (match-end 0))))
  2045. ;; Line break if line started and ended with time stamp stuff
  2046. (if (not r)
  2047. s
  2048. (setq r (concat r s))
  2049. (unless (string-match "\\S-" (concat b s))
  2050. (setq r (concat r "@<br/>")))
  2051. r))))
  2052. (defvar htmlize-buffer-places) ; from htmlize.el
  2053. (defun org-export-htmlize-region-for-paste (beg end)
  2054. "Convert the region to HTML, using htmlize.el.
  2055. This is much like `htmlize-region-for-paste', only that it uses
  2056. the settings define in the org-... variables."
  2057. (let* ((htmlize-output-type org-export-htmlize-output-type)
  2058. (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
  2059. (htmlbuf (htmlize-region beg end)))
  2060. (unwind-protect
  2061. (with-current-buffer htmlbuf
  2062. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  2063. (plist-get htmlize-buffer-places 'content-end)))
  2064. (kill-buffer htmlbuf))))
  2065. ;;;###autoload
  2066. (defun org-export-htmlize-generate-css ()
  2067. "Create the CSS for all font definitions in the current Emacs session.
  2068. Use this to create face definitions in your CSS style file that can then
  2069. be used by code snippets transformed by htmlize.
  2070. This command just produces a buffer that contains class definitions for all
  2071. faces used in the current Emacs session. You can copy and paste the ones you
  2072. need into your CSS file.
  2073. If you then set `org-export-htmlize-output-type' to `css', calls to
  2074. the function `org-export-htmlize-region-for-paste' will produce code
  2075. that uses these same face definitions."
  2076. (interactive)
  2077. (require 'htmlize)
  2078. (and (get-buffer "*html*") (kill-buffer "*html*"))
  2079. (with-temp-buffer
  2080. (let ((fl (face-list))
  2081. (htmlize-css-name-prefix "org-")
  2082. (htmlize-output-type 'css)
  2083. f i)
  2084. (while (setq f (pop fl)
  2085. i (and f (face-attribute f :inherit)))
  2086. (when (and (symbolp f) (or (not i) (not (listp i))))
  2087. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  2088. (htmlize-region (point-min) (point-max))))
  2089. (org-pop-to-buffer-same-window "*html*")
  2090. (goto-char (point-min))
  2091. (if (re-search-forward "<style" nil t)
  2092. (delete-region (point-min) (match-beginning 0)))
  2093. (if (re-search-forward "</style>" nil t)
  2094. (delete-region (1+ (match-end 0)) (point-max)))
  2095. (beginning-of-line 1)
  2096. (if (looking-at " +") (replace-match ""))
  2097. (goto-char (point-min)))
  2098. (defun org-html-protect (s)
  2099. "Convert characters to HTML equivalent.
  2100. Possible conversions are set in `org-export-html-protect-char-alist'."
  2101. (let ((cl org-export-html-protect-char-alist) c)
  2102. (while (setq c (pop cl))
  2103. (let ((start 0))
  2104. (while (string-match (car c) s start)
  2105. (setq s (replace-match (cdr c) t t s)
  2106. start (1+ (match-beginning 0))))))
  2107. s))
  2108. (defun org-html-expand (string)
  2109. "Prepare STRING for HTML export. Apply all active conversions.
  2110. If there are links in the string, don't modify these."
  2111. (let* ((re (concat org-bracket-link-regexp "\\|"
  2112. (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
  2113. m s l res)
  2114. (while (setq m (string-match re string))
  2115. (setq s (substring string 0 m)
  2116. l (match-string 0 string)
  2117. string (substring string (match-end 0)))
  2118. (push (org-html-do-expand s) res)
  2119. (push l res))
  2120. (push (org-html-do-expand string) res)
  2121. (apply 'concat (nreverse res))))
  2122. (defun org-html-do-expand (s)
  2123. "Apply all active conversions to translate special ASCII to HTML."
  2124. (setq s (org-html-protect s))
  2125. (if org-export-html-expand
  2126. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  2127. (setq s (replace-match "<\\1>" t nil s))))
  2128. (if org-export-with-emphasize
  2129. (setq s (org-export-html-convert-emphasize s)))
  2130. (if org-export-with-special-strings
  2131. (setq s (org-export-html-convert-special-strings s)))
  2132. (if org-export-with-sub-superscripts
  2133. (setq s (org-export-html-convert-sub-super s)))
  2134. (if org-export-with-TeX-macros
  2135. (let ((start 0) wd rep)
  2136. (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
  2137. s start))
  2138. (if (get-text-property (match-beginning 0) 'org-protected s)
  2139. (setq start (match-end 0))
  2140. (setq wd (match-string 1 s))
  2141. (if (setq rep (org-entity-get-representation wd 'html))
  2142. (setq s (replace-match rep t t s))
  2143. (setq start (+ start (length wd))))))))
  2144. s)
  2145. (defun org-export-html-convert-special-strings (string)
  2146. "Convert special characters in STRING to HTML."
  2147. (let ((all org-export-html-special-string-regexps)
  2148. e a re rpl start)
  2149. (while (setq a (pop all))
  2150. (setq re (car a) rpl (cdr a) start 0)
  2151. (while (string-match re string start)
  2152. (if (get-text-property (match-beginning 0) 'org-protected string)
  2153. (setq start (match-end 0))
  2154. (setq string (replace-match rpl t nil string)))))
  2155. string))
  2156. (defun org-export-html-convert-sub-super (string)
  2157. "Convert sub- and superscripts in STRING to HTML."
  2158. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  2159. (while (string-match org-match-substring-regexp string s)
  2160. (cond
  2161. ((and requireb (match-end 8)) (setq s (match-end 2)))
  2162. ((get-text-property (match-beginning 2) 'org-protected string)
  2163. (setq s (match-end 2)))
  2164. (t
  2165. (setq s (match-end 1)
  2166. key (if (string= (match-string 2 string) "_") "sub" "sup")
  2167. c (or (match-string 8 string)
  2168. (match-string 6 string)
  2169. (match-string 5 string))
  2170. string (replace-match
  2171. (concat (match-string 1 string)
  2172. "<" key ">" c "</" key ">")
  2173. t t string)))))
  2174. (while (string-match "\\\\\\([_^]\\)" string)
  2175. (setq string (replace-match (match-string 1 string) t t string)))
  2176. string))
  2177. (defun org-export-html-convert-emphasize (string)
  2178. "Apply emphasis."
  2179. (let ((s 0) rpl)
  2180. (while (string-match org-emph-re string s)
  2181. (if (not (equal
  2182. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  2183. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  2184. (setq s (match-beginning 0)
  2185. rpl
  2186. (concat
  2187. (match-string 1 string)
  2188. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  2189. (match-string 4 string)
  2190. (nth 3 (assoc (match-string 3 string)
  2191. org-emphasis-alist))
  2192. (match-string 5 string))
  2193. string (replace-match rpl t t string)
  2194. s (+ s (- (length rpl) 2)))
  2195. (setq s (1+ s))))
  2196. string))
  2197. (defun org-open-par ()
  2198. "Insert <p>, but first close previous paragraph if any."
  2199. (org-close-par-maybe)
  2200. (insert "\n<p>")
  2201. (setq org-par-open t))
  2202. (defun org-close-par-maybe ()
  2203. "Close paragraph if there is one open."
  2204. (when org-par-open
  2205. (insert "</p>")
  2206. (setq org-par-open nil)))
  2207. (defun org-close-li (&optional type)
  2208. "Close <li> if necessary."
  2209. (org-close-par-maybe)
  2210. (insert (if (equal type "d") "</dd>\n" "</li>\n")))
  2211. (defvar body-only) ; dynamically scoped into this.
  2212. (defun org-html-level-start (level title umax with-toc head-count &optional opt-plist)
  2213. "Insert a new level in HTML export.
  2214. When TITLE is nil, just close all open levels."
  2215. (org-close-par-maybe)
  2216. (let* ((target (and title (org-get-text-property-any 0 'target title)))
  2217. (extra-targets (and target
  2218. (assoc target org-export-target-aliases)))
  2219. (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
  2220. (preferred (and target
  2221. (cdr (assoc target org-export-preferred-target-alist))))
  2222. (l org-level-max)
  2223. (num (plist-get opt-plist :section-numbers))
  2224. snumber snu href suffix)
  2225. (setq extra-targets (remove (or preferred target) extra-targets))
  2226. (setq extra-targets
  2227. (mapconcat (lambda (x)
  2228. (setq x (org-solidify-link-text
  2229. (if (org-uuidgen-p x) (concat "ID-" x) x)))
  2230. (format "<a name=\"%s\" id=\"%s\"></a>"
  2231. x x))
  2232. extra-targets
  2233. ""))
  2234. (while (>= l level)
  2235. (if (aref org-levels-open (1- l))
  2236. (progn
  2237. (org-html-level-close l umax)
  2238. (aset org-levels-open (1- l) nil)))
  2239. (setq l (1- l)))
  2240. (when title
  2241. ;; If title is nil, this means this function is called to close
  2242. ;; all levels, so the rest is done only if title is given
  2243. (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
  2244. (setq title (replace-match
  2245. (if org-export-with-tags
  2246. (save-match-data
  2247. (concat
  2248. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  2249. (mapconcat
  2250. (lambda (x)
  2251. (format "<span class=\"%s\">%s</span>"
  2252. (org-export-html-get-tag-class-name x)
  2253. x))
  2254. (org-split-string (match-string 1 title) ":")
  2255. "&nbsp;")
  2256. "</span>"))
  2257. "")
  2258. t t title)))
  2259. (if (> level umax)
  2260. (progn
  2261. (if (aref org-levels-open (1- level))
  2262. (progn
  2263. (org-close-li)
  2264. (if target
  2265. (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
  2266. extra-targets title "<br/>\n")
  2267. (insert "<li>" title "<br/>\n")))
  2268. (aset org-levels-open (1- level) t)
  2269. (org-close-par-maybe)
  2270. (if target
  2271. (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target)))
  2272. extra-targets title "<br/>\n")
  2273. (insert "<ul>\n<li>" title "<br/>\n"))))
  2274. (aset org-levels-open (1- level) t)
  2275. (setq snumber (org-section-number level)
  2276. snu (replace-regexp-in-string "\\." "-" snumber))
  2277. (setq level (+ level org-export-html-toplevel-hlevel -1))
  2278. (if (and num (not body-only))
  2279. (setq title (concat
  2280. (format "<span class=\"section-number-%d\">%s</span>"
  2281. level
  2282. (if (and num
  2283. (if (integerp num)
  2284. ;; fix up num to take into
  2285. ;; account the top-level
  2286. ;; heading value
  2287. (>= (+ num org-export-html-toplevel-hlevel -1)
  2288. level)
  2289. num))
  2290. snumber
  2291. ""))
  2292. " " title)))
  2293. (unless (= head-count 1) (insert "\n</div>\n"))
  2294. (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
  2295. (setq suffix (org-solidify-link-text (or href snu)))
  2296. (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
  2297. (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d%s\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
  2298. suffix level (if extra-class (concat " " extra-class) "")
  2299. level href
  2300. extra-targets
  2301. title level level suffix))
  2302. (org-open-par)))))
  2303. (defun org-export-html-get-tag-class-name (tag)
  2304. "Turn tag into a valid class name.
  2305. Replaces invalid characters with \"_\" and then prepends a prefix."
  2306. (save-match-data
  2307. (while (string-match "[^a-zA-Z0-9_]" tag)
  2308. (setq tag (replace-match "_" t t tag))))
  2309. (concat org-export-html-tag-class-prefix tag))
  2310. (defun org-export-html-get-todo-kwd-class-name (kwd)
  2311. "Turn todo keyword into a valid class name.
  2312. Replaces invalid characters with \"_\" and then prepends a prefix."
  2313. (save-match-data
  2314. (while (string-match "[^a-zA-Z0-9_]" kwd)
  2315. (setq kwd (replace-match "_" t t kwd))))
  2316. (concat org-export-html-todo-kwd-class-prefix kwd))
  2317. (defun org-html-level-close (level max-outline-level)
  2318. "Terminate one level in HTML export."
  2319. (if (<= level max-outline-level)
  2320. (insert "</div>\n")
  2321. (org-close-li)
  2322. (insert "</ul>\n")))
  2323. (defun org-html-export-list-line (line pos struct prevs)
  2324. "Insert list syntax in export buffer. Return LINE, maybe modified.
  2325. POS is the item position or line position the line had before
  2326. modifications to buffer. STRUCT is the list structure. PREVS is
  2327. the alist of previous items."
  2328. (let* ((get-type
  2329. (function
  2330. ;; Translate type of list containing POS to "d", "o" or
  2331. ;; "u".
  2332. (lambda (pos struct prevs)
  2333. (let ((type (org-list-get-list-type pos struct prevs)))
  2334. (cond
  2335. ((eq 'ordered type) "o")
  2336. ((eq 'descriptive type) "d")
  2337. (t "u"))))))
  2338. (get-closings
  2339. (function
  2340. ;; Return list of all items and sublists ending at POS, in
  2341. ;; reverse order.
  2342. (lambda (pos)
  2343. (let (out)
  2344. (catch 'exit
  2345. (mapc (lambda (e)
  2346. (let ((end (nth 6 e))
  2347. (item (car e)))
  2348. (cond
  2349. ((= end pos) (push item out))
  2350. ((>= item pos) (throw 'exit nil)))))
  2351. struct))
  2352. out)))))
  2353. ;; First close any previous item, or list, ending at POS.
  2354. (mapc (lambda (e)
  2355. (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
  2356. (first-item (org-list-get-list-begin e struct prevs))
  2357. (type (funcall get-type first-item struct prevs)))
  2358. (org-close-par-maybe)
  2359. ;; Ending for every item
  2360. (org-close-li type)
  2361. ;; We're ending last item of the list: end list.
  2362. (when lastp
  2363. (insert (format "</%sl>\n" type))
  2364. (org-open-par))))
  2365. (funcall get-closings pos))
  2366. (cond
  2367. ;; At an item: insert appropriate tags in export buffer.
  2368. ((assq pos struct)
  2369. (string-match
  2370. (concat "[ \t]*\\(\\S-+[ \t]*\\)"
  2371. "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
  2372. "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
  2373. "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
  2374. "\\(.*\\)") line)
  2375. (let* ((checkbox (match-string 3 line))
  2376. (desc-tag (or (match-string 4 line) "???"))
  2377. (body (or (match-string 5 line) ""))
  2378. (list-beg (org-list-get-list-begin pos struct prevs))
  2379. (firstp (= list-beg pos))
  2380. ;; Always refer to first item to determine list type, in
  2381. ;; case list is ill-formed.
  2382. (type (funcall get-type list-beg struct prevs))
  2383. (counter (let ((count-tmp (org-list-get-counter pos struct)))
  2384. (cond
  2385. ((not count-tmp) nil)
  2386. ((string-match "[A-Za-z]" count-tmp)
  2387. (- (string-to-char (upcase count-tmp)) 64))
  2388. ((string-match "[0-9]+" count-tmp)
  2389. count-tmp)))))
  2390. (when firstp
  2391. (org-close-par-maybe)
  2392. (insert (format "<%sl>\n" type)))
  2393. (insert (cond
  2394. ((equal type "d")
  2395. (format "<dt>%s</dt><dd>" desc-tag))
  2396. ((and (equal type "o") counter)
  2397. (format "<li value=\"%s\">" counter))
  2398. (t "<li>")))
  2399. ;; If line had a checkbox, some additional modification is required.
  2400. (when checkbox
  2401. (setq body
  2402. (concat
  2403. (cond
  2404. ((string-match "X" checkbox) "<code>[X]</code> ")
  2405. ((string-match " " checkbox) "<code>[&nbsp;]</code> ")
  2406. (t "<code>[-]</code> "))
  2407. body)))
  2408. ;; Return modified line
  2409. body))
  2410. ;; At a list ender: go to next line (side-effects only).
  2411. ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
  2412. ;; Not at an item: return line unchanged (side-effects only).
  2413. (t line))))
  2414. (provide 'org-html)
  2415. ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
  2416. ;;; org-html.el ends here