org-html.el 84 KB

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