org-html.el 86 KB

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