org-html.el 90 KB

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