org-html.el 95 KB

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