org-html.el 93 KB

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