org-html.el 84 KB

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