org-html.el 84 KB

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