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. (t nil))))
  617. (goto-char (point-min))
  618. (let (label l1)
  619. (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
  620. (org-if-unprotected-at (match-beginning 1)
  621. (setq label (match-string 1))
  622. (save-match-data
  623. (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
  624. (setq l1 (substring label (match-beginning 1)))
  625. (setq l1 label)))
  626. (replace-match (format "[[#%s][%s]]" label l1) t t)))))
  627. ;;;###autoload
  628. (defun org-export-as-html-and-open (arg)
  629. "Export the outline as HTML and immediately open it with a browser.
  630. If there is an active region, export only the region.
  631. The prefix ARG specifies how many levels of the outline should become
  632. headlines. The default is 3. Lower levels will become bulleted lists."
  633. (interactive "P")
  634. (org-export-as-html arg 'hidden)
  635. (org-open-file buffer-file-name)
  636. (when org-export-kill-product-buffer-when-displayed
  637. (kill-buffer (current-buffer))))
  638. ;;;###autoload
  639. (defun org-export-as-html-batch ()
  640. "Call the function `org-export-as-html'.
  641. This function can be used in batch processing as:
  642. emacs --batch
  643. --load=$HOME/lib/emacs/org.el
  644. --eval \"(setq org-export-headline-levels 2)\"
  645. --visit=MyFile --funcall org-export-as-html-batch"
  646. (org-export-as-html org-export-headline-levels 'hidden))
  647. ;;;###autoload
  648. (defun org-export-as-html-to-buffer (arg)
  649. "Call `org-export-as-html` with output to a temporary buffer.
  650. No file is created. The prefix ARG is passed through to `org-export-as-html'."
  651. (interactive "P")
  652. (org-export-as-html arg nil nil "*Org HTML Export*")
  653. (when org-export-show-temporary-export-buffer
  654. (switch-to-buffer-other-window "*Org HTML Export*")))
  655. ;;;###autoload
  656. (defun org-replace-region-by-html (beg end)
  657. "Assume the current region has org-mode syntax, and convert it to HTML.
  658. This can be used in any buffer. For example, you could write an
  659. itemized list in org-mode syntax in an HTML buffer and then use this
  660. command to convert it."
  661. (interactive "r")
  662. (let (reg html buf pop-up-frames)
  663. (save-window-excursion
  664. (if (derived-mode-p 'org-mode)
  665. (setq html (org-export-region-as-html
  666. beg end t 'string))
  667. (setq reg (buffer-substring beg end)
  668. buf (get-buffer-create "*Org tmp*"))
  669. (with-current-buffer buf
  670. (erase-buffer)
  671. (insert reg)
  672. (org-mode)
  673. (setq html (org-export-region-as-html
  674. (point-min) (point-max) t 'string)))
  675. (kill-buffer buf)))
  676. (delete-region beg end)
  677. (insert html)))
  678. ;;;###autoload
  679. (defun org-export-region-as-html (beg end &optional body-only buffer)
  680. "Convert region from BEG to END in org-mode buffer to HTML.
  681. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  682. contents, and only produce the region of converted text, useful for
  683. cut-and-paste operations.
  684. If BUFFER is a buffer or a string, use/create that buffer as a target
  685. of the converted HTML. If BUFFER is the symbol `string', return the
  686. produced HTML as a string and leave not buffer behind. For example,
  687. a Lisp program could call this function in the following way:
  688. (setq html (org-export-region-as-html beg end t 'string))
  689. When called interactively, the output buffer is selected, and shown
  690. in a window. A non-interactive call will only return the buffer."
  691. (interactive "r\nP")
  692. (when (org-called-interactively-p 'any)
  693. (setq buffer "*Org HTML Export*"))
  694. (let ((transient-mark-mode t) (zmacs-regions t)
  695. ext-plist rtn)
  696. (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
  697. (goto-char end)
  698. (set-mark (point)) ;; to activate the region
  699. (goto-char beg)
  700. (setq rtn (org-export-as-html
  701. nil nil ext-plist
  702. buffer body-only))
  703. (if (fboundp 'deactivate-mark) (deactivate-mark))
  704. (if (and (org-called-interactively-p 'any) (bufferp rtn))
  705. (switch-to-buffer-other-window rtn)
  706. rtn)))
  707. (defvar html-table-tag nil) ; dynamically scoped into this.
  708. (defvar org-par-open nil)
  709. ;;; org-html-cvt-link-fn
  710. (defconst org-html-cvt-link-fn
  711. nil
  712. "Function to convert link URLs to exportable URLs.
  713. Takes two arguments, TYPE and PATH.
  714. Returns exportable url as (TYPE PATH), or nil to signal that it
  715. didn't handle this case.
  716. Intended to be locally bound around a call to `org-export-as-html'." )
  717. (defun org-html-cvt-org-as-html (opt-plist type path)
  718. "Convert an org filename to an equivalent html filename.
  719. If TYPE is not file, just return `nil'.
  720. See variable `org-export-html-link-org-files-as-html'"
  721. (save-match-data
  722. (and
  723. org-export-html-link-org-files-as-html
  724. (string= type "file")
  725. (string-match "\\.org$" path)
  726. (progn
  727. (list
  728. "file"
  729. (concat
  730. (substring path 0 (match-beginning 0))
  731. "."
  732. (plist-get opt-plist :html-extension)))))))
  733. ;;; org-html-should-inline-p
  734. (defun org-html-should-inline-p (filename descp)
  735. "Return non-nil if link FILENAME should be inlined.
  736. The decision to inline the FILENAME link is based on the current
  737. settings. DESCP is the boolean of whether there was a link
  738. description. See variables `org-export-html-inline-images' and
  739. `org-export-html-inline-image-extensions'."
  740. (declare (special
  741. org-export-html-inline-images
  742. org-export-html-inline-image-extensions))
  743. (and (or (eq t org-export-html-inline-images)
  744. (and org-export-html-inline-images (not descp)))
  745. (org-file-image-p
  746. filename org-export-html-inline-image-extensions)))
  747. ;;; org-html-make-link
  748. (defun org-html-make-link (opt-plist type path fragment desc attr
  749. may-inline-p)
  750. "Make an HTML link.
  751. OPT-PLIST is an options list.
  752. TYPE is the device-type of the link (THIS://foo.html).
  753. PATH is the path of the link (http://THIS#location).
  754. FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
  755. DESC is the link description, if any.
  756. ATTR is a string of other attributes of the \"a\" element.
  757. MAY-INLINE-P allows inlining it as an image."
  758. (declare (special org-par-open))
  759. (save-match-data
  760. (let* ((filename path)
  761. ;;First pass. Just sanity stuff.
  762. (components-1
  763. (cond
  764. ((string= type "file")
  765. (list
  766. type
  767. ;;Substitute just if original path was absolute.
  768. ;;(Otherwise path must remain relative)
  769. (if (file-name-absolute-p path)
  770. (concat "file://" (expand-file-name path))
  771. path)))
  772. ((string= type "")
  773. (list nil path))
  774. (t (list type path))))
  775. ;;Second pass. Components converted so they can refer
  776. ;;to a remote site.
  777. (components-2
  778. (or
  779. (and org-html-cvt-link-fn
  780. (apply org-html-cvt-link-fn
  781. opt-plist components-1))
  782. (apply #'org-html-cvt-org-as-html
  783. opt-plist components-1)
  784. components-1))
  785. (type (first components-2))
  786. (thefile (second components-2)))
  787. ;;Third pass. Build final link except for leading type
  788. ;;spec.
  789. (cond
  790. ((or
  791. (not type)
  792. (string= type "http")
  793. (string= type "https")
  794. (string= type "file")
  795. (string= type "coderef"))
  796. (if fragment
  797. (setq thefile (concat thefile "#" fragment))))
  798. (t))
  799. ;;Final URL-build, for all types.
  800. (setq thefile
  801. (let
  802. ((str (org-export-html-format-href thefile)))
  803. (if (and type (not (or (string= "file" type)
  804. (string= "coderef" type))))
  805. (concat type ":" str)
  806. str)))
  807. (if (and
  808. may-inline-p
  809. ;;Can't inline a URL with a fragment.
  810. (not fragment))
  811. (progn
  812. (message "image %s %s" thefile org-par-open)
  813. (org-export-html-format-image thefile org-par-open))
  814. (concat
  815. "<a href=\"" thefile "\"" (if attr (concat " " attr)) ">"
  816. (org-export-html-format-desc desc)
  817. "</a>")))))
  818. (defun org-html-handle-links (org-line opt-plist)
  819. "Return ORG-LINE with markup of Org mode links.
  820. OPT-PLIST is the export options list."
  821. (let ((start 0)
  822. (current-dir (if buffer-file-name
  823. (file-name-directory buffer-file-name)
  824. default-directory))
  825. (link-validate (plist-get opt-plist :link-validation-function))
  826. type id-file fnc
  827. rpl path attr desc descp desc1 desc2 link)
  828. (while (string-match org-bracket-link-analytic-regexp++ org-line start)
  829. (setq start (match-beginning 0))
  830. (setq path (save-match-data (org-link-unescape
  831. (match-string 3 org-line))))
  832. (setq type (cond
  833. ((match-end 2) (match-string 2 org-line))
  834. ((save-match-data
  835. (or (file-name-absolute-p path)
  836. (string-match "^\\.\\.?/" path)))
  837. "file")
  838. (t "internal")))
  839. (setq path (org-extract-attributes path))
  840. (setq attr (get-text-property 0 'org-attributes path))
  841. (setq desc1 (if (match-end 5) (match-string 5 org-line))
  842. desc2 (if (match-end 2) (concat type ":" path) path)
  843. descp (and desc1 (not (equal desc1 desc2)))
  844. desc (or desc1 desc2))
  845. ;; Make an image out of the description if that is so wanted
  846. (when (and descp (org-file-image-p
  847. desc org-export-html-inline-image-extensions))
  848. (save-match-data
  849. (if (string-match "^file:" desc)
  850. (setq desc (substring desc (match-end 0)))))
  851. (setq desc (org-add-props
  852. (concat "<img src=\"" desc "\" alt=\""
  853. (file-name-nondirectory desc) "\"/>")
  854. '(org-protected t))))
  855. (cond
  856. ((equal type "internal")
  857. (let
  858. ((frag-0
  859. (if (= (string-to-char path) ?#)
  860. (substring path 1)
  861. path)))
  862. (setq rpl
  863. (org-html-make-link
  864. opt-plist
  865. ""
  866. ""
  867. (org-solidify-link-text
  868. (save-match-data (org-link-unescape frag-0))
  869. nil)
  870. desc attr nil))))
  871. ((and (equal type "id")
  872. (setq id-file (org-id-find-id-file path)))
  873. ;; This is an id: link to another file (if it was the same file,
  874. ;; it would have become an internal link...)
  875. (save-match-data
  876. (setq id-file (file-relative-name
  877. id-file
  878. (file-name-directory org-current-export-file)))
  879. (setq rpl
  880. (org-html-make-link opt-plist
  881. "file" id-file
  882. (concat (if (org-uuidgen-p path) "ID-") path)
  883. desc
  884. attr
  885. nil))))
  886. ((member type '("http" "https"))
  887. ;; standard URL, can inline as image
  888. (setq rpl
  889. (org-html-make-link opt-plist
  890. type path nil
  891. desc
  892. attr
  893. (org-html-should-inline-p path descp))))
  894. ((member type '("ftp" "mailto" "news"))
  895. ;; standard URL, can't inline as image
  896. (setq rpl
  897. (org-html-make-link opt-plist
  898. type path nil
  899. desc
  900. attr
  901. nil)))
  902. ((string= type "coderef")
  903. (let*
  904. ((coderef-str (format "coderef-%s" path))
  905. (attr-1
  906. (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  907. coderef-str coderef-str)))
  908. (setq rpl
  909. (org-html-make-link opt-plist
  910. type "" coderef-str
  911. (format
  912. (org-export-get-coderef-format
  913. path
  914. (and descp desc))
  915. (cdr (assoc path org-export-code-refs)))
  916. attr-1
  917. nil))))
  918. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  919. ;; The link protocol has a function for format the link
  920. (setq rpl
  921. (save-match-data
  922. (funcall fnc (org-link-unescape path) desc1 'html))))
  923. ((string= type "file")
  924. ;; FILE link
  925. (save-match-data
  926. (let*
  927. ((components
  928. (if
  929. (string-match "::\\(.*\\)" path)
  930. (list
  931. (replace-match "" t nil path)
  932. (match-string 1 path))
  933. (list path nil)))
  934. ;;The proper path, without a fragment
  935. (path-1
  936. (first components))
  937. ;;The raw fragment
  938. (fragment-0
  939. (second components))
  940. ;;Check the fragment. If it can't be used as
  941. ;;target fragment we'll pass nil instead.
  942. (fragment-1
  943. (if
  944. (and fragment-0
  945. (not (string-match "^[0-9]*$" fragment-0))
  946. (not (string-match "^\\*" fragment-0))
  947. (not (string-match "^/.*/$" fragment-0)))
  948. (org-solidify-link-text
  949. (org-link-unescape fragment-0))
  950. nil))
  951. (desc-2
  952. ;;Description minus "file:" and ".org"
  953. (if (string-match "^file:" desc)
  954. (let
  955. ((desc-1 (replace-match "" t t desc)))
  956. (if (string-match "\\.org$" desc-1)
  957. (replace-match "" t t desc-1)
  958. desc-1))
  959. desc)))
  960. (setq rpl
  961. (if
  962. (and
  963. (functionp link-validate)
  964. (not (funcall link-validate path-1 current-dir)))
  965. desc
  966. (org-html-make-link opt-plist
  967. "file" path-1 fragment-1 desc-2 attr
  968. (org-html-should-inline-p path-1 descp)))))))
  969. (t
  970. ;; just publish the path, as default
  971. (setq rpl (concat "<i>&lt;" type ":"
  972. (save-match-data (org-link-unescape path))
  973. "&gt;</i>"))))
  974. (setq org-line (replace-match rpl t t org-line)
  975. start (+ start (length rpl))))
  976. org-line))
  977. ;;; org-export-as-html
  978. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  979. ;;;###autoload
  980. (defun org-export-as-html (arg &optional hidden ext-plist
  981. to-buffer body-only pub-dir)
  982. "Export the outline as a pretty HTML file.
  983. If there is an active region, export only the region. The prefix
  984. ARG specifies how many levels of the outline should become
  985. headlines. The default is 3. Lower levels will become bulleted
  986. lists. HIDDEN is obsolete and does nothing.
  987. EXT-PLIST is a property list with external parameters overriding
  988. org-mode's default settings, but still inferior to file-local
  989. settings. When TO-BUFFER is non-nil, create a buffer with that
  990. name and export to that buffer. If TO-BUFFER is the symbol
  991. `string', don't leave any buffer behind but just return the
  992. resulting HTML as a string. When BODY-ONLY is set, don't produce
  993. the file header and footer, simply return the content of
  994. <body>...</body>, without even the body tags themselves. When
  995. PUB-DIR is set, use this as the publishing directory."
  996. (interactive "P")
  997. (run-hooks 'org-export-first-hook)
  998. ;; Make sure we have a file name when we need it.
  999. (when (and (not (or to-buffer body-only))
  1000. (not buffer-file-name))
  1001. (if (buffer-base-buffer)
  1002. (org-set-local 'buffer-file-name
  1003. (with-current-buffer (buffer-base-buffer)
  1004. buffer-file-name))
  1005. (error "Need a file name to be able to export")))
  1006. (message "Exporting...")
  1007. (setq-default org-todo-line-regexp org-todo-line-regexp)
  1008. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  1009. (setq-default org-done-keywords org-done-keywords)
  1010. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  1011. (let* ((opt-plist
  1012. (org-export-process-option-filters
  1013. (org-combine-plists (org-default-export-plist)
  1014. ext-plist
  1015. (org-infile-export-plist))))
  1016. (body-only (or body-only (plist-get opt-plist :body-only)))
  1017. (style (concat (if (plist-get opt-plist :style-include-default)
  1018. org-export-html-style-default)
  1019. (plist-get opt-plist :style)
  1020. (plist-get opt-plist :style-extra)
  1021. "\n"
  1022. (if (plist-get opt-plist :style-include-scripts)
  1023. org-export-html-scripts)))
  1024. (html-extension (plist-get opt-plist :html-extension))
  1025. valid thetoc have-headings first-heading-pos
  1026. (odd org-odd-levels-only)
  1027. (region-p (org-region-active-p))
  1028. (rbeg (and region-p (region-beginning)))
  1029. (rend (and region-p (region-end)))
  1030. (subtree-p
  1031. (if (plist-get opt-plist :ignore-subtree-p)
  1032. nil
  1033. (when region-p
  1034. (save-excursion
  1035. (goto-char rbeg)
  1036. (and (org-at-heading-p)
  1037. (>= (org-end-of-subtree t t) rend))))))
  1038. (level-offset (if subtree-p
  1039. (save-excursion
  1040. (goto-char rbeg)
  1041. (+ (funcall outline-level)
  1042. (if org-odd-levels-only 1 0)))
  1043. 0))
  1044. (opt-plist (setq org-export-opt-plist
  1045. (if subtree-p
  1046. (org-export-add-subtree-options opt-plist rbeg)
  1047. opt-plist)))
  1048. ;; The following two are dynamically scoped into other
  1049. ;; routines below.
  1050. (org-current-export-dir
  1051. (or pub-dir (org-export-directory :html opt-plist)))
  1052. (org-current-export-file buffer-file-name)
  1053. (level 0) (org-line "") (origline "") txt todo
  1054. (umax nil)
  1055. (umax-toc nil)
  1056. (filename (if to-buffer nil
  1057. (expand-file-name
  1058. (concat
  1059. (file-name-sans-extension
  1060. (or (and subtree-p
  1061. (org-entry-get (region-beginning)
  1062. "EXPORT_FILE_NAME" t))
  1063. (file-name-nondirectory buffer-file-name)))
  1064. "." html-extension)
  1065. (file-name-as-directory
  1066. (or pub-dir (org-export-directory :html opt-plist))))))
  1067. (current-dir (if buffer-file-name
  1068. (file-name-directory buffer-file-name)
  1069. default-directory))
  1070. (auto-insert nil); Avoid any auto-insert stuff for the new file
  1071. (buffer (if to-buffer
  1072. (cond
  1073. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  1074. (t (get-buffer-create to-buffer)))
  1075. (find-file-noselect filename)))
  1076. (org-levels-open (make-vector org-level-max nil))
  1077. (date (org-html-expand (plist-get opt-plist :date)))
  1078. (author (org-html-expand (plist-get opt-plist :author)))
  1079. (html-validation-link (or org-export-html-validation-link ""))
  1080. (title (org-html-expand
  1081. (or (and subtree-p (org-export-get-title-from-subtree))
  1082. (plist-get opt-plist :title)
  1083. (and (not body-only)
  1084. (not
  1085. (plist-get opt-plist :skip-before-1st-heading))
  1086. (org-export-grab-title-from-buffer))
  1087. (and buffer-file-name
  1088. (file-name-sans-extension
  1089. (file-name-nondirectory buffer-file-name)))
  1090. "UNTITLED")))
  1091. (link-up (and (plist-get opt-plist :link-up)
  1092. (string-match "\\S-" (plist-get opt-plist :link-up))
  1093. (plist-get opt-plist :link-up)))
  1094. (link-home (and (plist-get opt-plist :link-home)
  1095. (string-match "\\S-" (plist-get opt-plist :link-home))
  1096. (plist-get opt-plist :link-home)))
  1097. (dummy (setq opt-plist (plist-put opt-plist :title title)))
  1098. (html-table-tag (plist-get opt-plist :html-table-tag))
  1099. (quote-re0 (concat "^ *" org-quote-string "\\( +\\|[ \t]*$\\)"))
  1100. (quote-re (format org-heading-keyword-regexp-format
  1101. org-quote-string))
  1102. (inquote nil)
  1103. (infixed nil)
  1104. (inverse nil)
  1105. (email (plist-get opt-plist :email))
  1106. (language (plist-get opt-plist :language))
  1107. (keywords (org-html-expand (plist-get opt-plist :keywords)))
  1108. (description (org-html-expand (plist-get opt-plist :description)))
  1109. (num (plist-get opt-plist :section-numbers))
  1110. (lang-words nil)
  1111. (head-count 0) cnt
  1112. (start 0)
  1113. (coding-system (and (boundp 'buffer-file-coding-system)
  1114. buffer-file-coding-system))
  1115. (coding-system-for-write (or org-export-html-coding-system
  1116. coding-system))
  1117. (save-buffer-coding-system (or org-export-html-coding-system
  1118. coding-system))
  1119. (charset (and coding-system-for-write
  1120. (fboundp 'coding-system-get)
  1121. (coding-system-get coding-system-for-write
  1122. 'mime-charset)))
  1123. (region
  1124. (buffer-substring
  1125. (if region-p (region-beginning) (point-min))
  1126. (if region-p (region-end) (point-max))))
  1127. (org-export-have-math nil)
  1128. (org-export-footnotes-seen nil)
  1129. (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
  1130. (custom-id (or (org-entry-get nil "CUSTOM_ID" t) ""))
  1131. (footnote-def-prefix (format "fn-%s" custom-id))
  1132. (footnote-ref-prefix (format "fnr-%s" custom-id))
  1133. (lines
  1134. (org-split-string
  1135. (org-export-preprocess-string
  1136. region
  1137. :emph-multiline t
  1138. :for-backend 'html
  1139. :skip-before-1st-heading
  1140. (plist-get opt-plist :skip-before-1st-heading)
  1141. :drawers (plist-get opt-plist :drawers)
  1142. :todo-keywords (plist-get opt-plist :todo-keywords)
  1143. :tasks (plist-get opt-plist :tasks)
  1144. :tags (plist-get opt-plist :tags)
  1145. :priority (plist-get opt-plist :priority)
  1146. :footnotes (plist-get opt-plist :footnotes)
  1147. :timestamps (plist-get opt-plist :timestamps)
  1148. :archived-trees
  1149. (plist-get opt-plist :archived-trees)
  1150. :select-tags (plist-get opt-plist :select-tags)
  1151. :exclude-tags (plist-get opt-plist :exclude-tags)
  1152. :add-text
  1153. (plist-get opt-plist :text)
  1154. :LaTeX-fragments
  1155. (plist-get opt-plist :LaTeX-fragments))
  1156. "[\r\n]"))
  1157. (mathjax
  1158. (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
  1159. (and org-export-have-math
  1160. (eq (plist-get opt-plist :LaTeX-fragments) t)))
  1161. (org-export-html-mathjax-config
  1162. org-export-html-mathjax-template
  1163. org-export-html-mathjax-options
  1164. (or (plist-get opt-plist :mathjax) ""))
  1165. ""))
  1166. table-open
  1167. table-buffer table-orig-buffer
  1168. ind
  1169. rpl path attr desc descp desc1 desc2 link
  1170. snumber fnc
  1171. footnotes footref-seen
  1172. href
  1173. )
  1174. (let ((inhibit-read-only t))
  1175. (org-unmodified
  1176. (remove-text-properties (point-min) (point-max)
  1177. '(:org-license-to-kill t))))
  1178. (message "Exporting...")
  1179. (setq org-min-level (org-get-min-level lines level-offset))
  1180. (setq org-last-level org-min-level)
  1181. (org-init-section-numbers)
  1182. (cond
  1183. ((and date (string-match "%" date))
  1184. (setq date (format-time-string date)))
  1185. (date)
  1186. (t (setq date (format-time-string org-export-html-date-format-string))))
  1187. ;; Get the language-dependent settings
  1188. (setq lang-words (or (assoc language org-export-language-setup)
  1189. (assoc "en" org-export-language-setup)))
  1190. ;; Switch to the output buffer
  1191. (set-buffer buffer)
  1192. (let ((inhibit-read-only t)) (erase-buffer))
  1193. (fundamental-mode)
  1194. (org-install-letbind)
  1195. (and (fboundp 'set-buffer-file-coding-system)
  1196. (set-buffer-file-coding-system coding-system-for-write))
  1197. (let ((case-fold-search nil)
  1198. (org-odd-levels-only odd))
  1199. ;; create local variables for all options, to make sure all called
  1200. ;; functions get the correct information
  1201. (mapc (lambda (x)
  1202. (set (make-local-variable (nth 2 x))
  1203. (plist-get opt-plist (car x))))
  1204. org-export-plist-vars)
  1205. (setq umax (if arg (prefix-numeric-value arg)
  1206. org-export-headline-levels))
  1207. (setq umax-toc (if (integerp org-export-with-toc)
  1208. (min org-export-with-toc umax)
  1209. umax))
  1210. (unless body-only
  1211. ;; File header
  1212. (insert (format
  1213. "%s
  1214. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1215. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  1216. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">
  1217. <head>
  1218. <title>%s</title>
  1219. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  1220. <meta name=\"title\" content=\"%s\"/>
  1221. <meta name=\"generator\" content=\"Org-mode\"/>
  1222. <meta name=\"generated\" content=\"%s\"/>
  1223. <meta name=\"author\" content=\"%s\"/>
  1224. <meta name=\"description\" content=\"%s\"/>
  1225. <meta name=\"keywords\" content=\"%s\"/>
  1226. %s
  1227. %s
  1228. </head>
  1229. <body>
  1230. %s
  1231. "
  1232. (format
  1233. (or (and (stringp org-export-html-xml-declaration)
  1234. org-export-html-xml-declaration)
  1235. (cdr (assoc html-extension org-export-html-xml-declaration))
  1236. (cdr (assoc "html" org-export-html-xml-declaration))
  1237. "")
  1238. (or charset "iso-8859-1"))
  1239. language language
  1240. title
  1241. (or charset "iso-8859-1")
  1242. title date author description keywords
  1243. style
  1244. mathjax
  1245. (if (or link-up link-home)
  1246. (concat
  1247. (format org-export-html-home/up-format
  1248. (or link-up link-home)
  1249. (or link-home link-up))
  1250. "\n")
  1251. "")))
  1252. ;; insert html preamble
  1253. (when (plist-get opt-plist :html-preamble)
  1254. (let ((html-pre (plist-get opt-plist :html-preamble))
  1255. (html-pre-real-contents ""))
  1256. (cond ((stringp html-pre)
  1257. (setq html-pre-real-contents
  1258. (format-spec html-pre `((?t . ,title) (?a . ,author)
  1259. (?d . ,date) (?e . ,email)))))
  1260. ((functionp html-pre)
  1261. (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
  1262. (if (stringp (funcall html-pre)) (insert (funcall html-pre)))
  1263. (insert "\n</div>\n"))
  1264. (t
  1265. (setq html-pre-real-contents
  1266. (format-spec
  1267. (or (cadr (assoc (nth 0 lang-words)
  1268. org-export-html-preamble-format))
  1269. (cadr (assoc "en" org-export-html-preamble-format)))
  1270. `((?t . ,title) (?a . ,author)
  1271. (?d . ,date) (?e . ,email))))))
  1272. ;; don't output an empty preamble DIV
  1273. (unless (and (functionp html-pre)
  1274. (equal html-pre-real-contents ""))
  1275. (insert "<div id=\"" (nth 0 org-export-html-divs) "\">\n")
  1276. (insert html-pre-real-contents)
  1277. (insert "\n</div>\n"))))
  1278. ;; begin wrap around body
  1279. (insert (format "\n<div id=\"%s\">"
  1280. ;; FIXME org-export-html-content-div is obsolete since 7.7
  1281. (or org-export-html-content-div
  1282. (nth 1 org-export-html-divs)))
  1283. ;; FIXME this should go in the preamble but is here so
  1284. ;; that org-infojs can still find it
  1285. "\n<h1 class=\"title\">" title "</h1>\n"))
  1286. ;; insert body
  1287. (if org-export-with-toc
  1288. (progn
  1289. (push (format "<h%d>%s</h%d>\n"
  1290. org-export-html-toplevel-hlevel
  1291. (nth 3 lang-words)
  1292. org-export-html-toplevel-hlevel)
  1293. thetoc)
  1294. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  1295. (push "<ul>\n<li>" thetoc)
  1296. (setq lines
  1297. (mapcar
  1298. #'(lambda (org-line)
  1299. (if (and (string-match org-todo-line-regexp org-line)
  1300. (not (get-text-property 0 'org-protected org-line)))
  1301. ;; This is a headline
  1302. (progn
  1303. (setq have-headings t)
  1304. (setq level (- (match-end 1) (match-beginning 1)
  1305. level-offset)
  1306. level (org-tr-level level)
  1307. txt (save-match-data
  1308. (org-html-expand
  1309. (org-export-cleanup-toc-line
  1310. (match-string 3 org-line))))
  1311. todo
  1312. (or (and org-export-mark-todo-in-toc
  1313. (match-beginning 2)
  1314. (not (member (match-string 2 org-line)
  1315. org-done-keywords)))
  1316. ; TODO, not DONE
  1317. (and org-export-mark-todo-in-toc
  1318. (= level umax-toc)
  1319. (org-search-todo-below
  1320. org-line lines level))))
  1321. (if (string-match
  1322. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  1323. (setq txt (replace-match
  1324. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">\\1</span>" t nil txt)))
  1325. (if (string-match quote-re0 txt)
  1326. (setq txt (replace-match "" t t txt)))
  1327. (setq snumber (org-section-number level))
  1328. (if (and num (if (integerp num)
  1329. (>= num level)
  1330. num))
  1331. (setq txt (concat snumber " " txt)))
  1332. (if (<= level (max umax umax-toc))
  1333. (setq head-count (+ head-count 1)))
  1334. (if (<= level umax-toc)
  1335. (progn
  1336. (if (> level org-last-level)
  1337. (progn
  1338. (setq cnt (- level org-last-level))
  1339. (while (>= (setq cnt (1- cnt)) 0)
  1340. (push "\n<ul>\n<li>" thetoc))
  1341. (push "\n" thetoc)))
  1342. (if (< level org-last-level)
  1343. (progn
  1344. (setq cnt (- org-last-level level))
  1345. (while (>= (setq cnt (1- cnt)) 0)
  1346. (push "</li>\n</ul>" thetoc))
  1347. (push "\n" thetoc)))
  1348. ;; Check for targets
  1349. (while (string-match org-any-target-regexp org-line)
  1350. (setq org-line (replace-match
  1351. (concat "@<span class=\"target\">"
  1352. (match-string 1 org-line) "@</span> ")
  1353. t t org-line)))
  1354. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  1355. (setq txt (replace-match "" t t txt)))
  1356. (setq href
  1357. (replace-regexp-in-string
  1358. "\\." "-" (format "sec-%s" snumber)))
  1359. (setq href (org-solidify-link-text
  1360. (or (cdr (assoc href
  1361. org-export-preferred-target-alist)) href)))
  1362. (push
  1363. (format
  1364. (if todo
  1365. "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
  1366. "</li>\n<li><a href=\"#%s\">%s</a>")
  1367. href txt) thetoc)
  1368. (setq org-last-level level)))))
  1369. org-line)
  1370. lines))
  1371. (while (> org-last-level (1- org-min-level))
  1372. (setq org-last-level (1- org-last-level))
  1373. (push "</li>\n</ul>\n" thetoc))
  1374. (push "</div>\n" thetoc)
  1375. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  1376. (setq head-count 0)
  1377. (org-init-section-numbers)
  1378. (org-open-par)
  1379. (while (setq org-line (pop lines) origline org-line)
  1380. (catch 'nextline
  1381. ;; end of quote section?
  1382. (when (and inquote (string-match org-outline-regexp-bol org-line))
  1383. (insert "</pre>\n")
  1384. (org-open-par)
  1385. (setq inquote nil))
  1386. ;; inside a quote section?
  1387. (when inquote
  1388. (insert (org-html-protect org-line) "\n")
  1389. (throw 'nextline nil))
  1390. ;; Fixed-width, verbatim lines (examples)
  1391. (when (and org-export-with-fixed-width
  1392. (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" org-line))
  1393. (when (not infixed)
  1394. (setq infixed t)
  1395. (org-close-par-maybe)
  1396. (insert "<pre class=\"example\">\n"))
  1397. (insert (org-html-protect (match-string 3 org-line)) "\n")
  1398. (when (or (not lines)
  1399. (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
  1400. (car lines))))
  1401. (setq infixed nil)
  1402. (insert "</pre>\n")
  1403. (org-open-par))
  1404. (throw 'nextline nil))
  1405. ;; Protected HTML
  1406. (when (and (get-text-property 0 'org-protected org-line)
  1407. ;; Make sure it is the entire line that is protected
  1408. (not (< (or (next-single-property-change
  1409. 0 'org-protected org-line) 10000)
  1410. (length org-line))))
  1411. (let (par (ind (get-text-property 0 'original-indentation org-line)))
  1412. (when (re-search-backward
  1413. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  1414. (setq par (match-string 1))
  1415. (replace-match "\\2\n"))
  1416. (insert org-line "\n")
  1417. (while (and lines
  1418. (or (= (length (car lines)) 0)
  1419. (not ind)
  1420. (equal ind (get-text-property 0 'original-indentation (car lines))))
  1421. (or (= (length (car lines)) 0)
  1422. (get-text-property 0 'org-protected (car lines))))
  1423. (insert (pop lines) "\n"))
  1424. (and par (insert "<p>\n")))
  1425. (throw 'nextline nil))
  1426. ;; Blockquotes, verse, and center
  1427. (when (equal "ORG-BLOCKQUOTE-START" org-line)
  1428. (org-close-par-maybe)
  1429. (insert "<blockquote>\n")
  1430. (org-open-par)
  1431. (throw 'nextline nil))
  1432. (when (equal "ORG-BLOCKQUOTE-END" org-line)
  1433. (org-close-par-maybe)
  1434. (insert "\n</blockquote>\n")
  1435. (org-open-par)
  1436. (throw 'nextline nil))
  1437. (when (equal "ORG-VERSE-START" org-line)
  1438. (org-close-par-maybe)
  1439. (insert "\n<p class=\"verse\">\n")
  1440. (setq org-par-open t)
  1441. (setq inverse t)
  1442. (throw 'nextline nil))
  1443. (when (equal "ORG-VERSE-END" org-line)
  1444. (insert "</p>\n")
  1445. (setq org-par-open nil)
  1446. (org-open-par)
  1447. (setq inverse nil)
  1448. (throw 'nextline nil))
  1449. (when (equal "ORG-CENTER-START" org-line)
  1450. (org-close-par-maybe)
  1451. (insert "\n<div style=\"text-align: center\">")
  1452. (org-open-par)
  1453. (throw 'nextline nil))
  1454. (when (equal "ORG-CENTER-END" org-line)
  1455. (org-close-par-maybe)
  1456. (insert "\n</div>")
  1457. (org-open-par)
  1458. (throw 'nextline nil))
  1459. (run-hooks 'org-export-html-after-blockquotes-hook)
  1460. (when inverse
  1461. (let ((i (org-get-string-indentation org-line)))
  1462. (if (> i 0)
  1463. (setq org-line (concat (mapconcat 'identity
  1464. (make-list (* 2 i) "\\nbsp") "")
  1465. " " (org-trim org-line))))
  1466. (unless (string-match "\\\\\\\\[ \t]*$" org-line)
  1467. (setq org-line (concat org-line "\\\\")))))
  1468. ;; make targets to anchors
  1469. (setq start 0)
  1470. (while (string-match
  1471. "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" org-line start)
  1472. (cond
  1473. ((get-text-property (match-beginning 1) 'org-protected org-line)
  1474. (setq start (match-end 1)))
  1475. ((match-end 2)
  1476. (setq org-line (replace-match
  1477. (format
  1478. "@<a name=\"%s\" id=\"%s\">@</a>"
  1479. (org-solidify-link-text (match-string 1 org-line))
  1480. (org-solidify-link-text (match-string 1 org-line)))
  1481. t t org-line)))
  1482. ((and org-export-with-toc (equal (string-to-char org-line) ?*))
  1483. ;; FIXME: NOT DEPENDENT on TOC?????????????????????
  1484. (setq org-line (replace-match
  1485. (concat "@<span class=\"target\">"
  1486. (match-string 1 org-line) "@</span> ")
  1487. ;; (concat "@<i>" (match-string 1 org-line) "@</i> ")
  1488. t t org-line)))
  1489. (t
  1490. (setq org-line (replace-match
  1491. (concat "@<a name=\""
  1492. (org-solidify-link-text (match-string 1 org-line))
  1493. "\" class=\"target\">" (match-string 1 org-line)
  1494. "@</a> ")
  1495. t t org-line)))))
  1496. (setq org-line (org-html-handle-time-stamps org-line))
  1497. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  1498. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  1499. ;; Also handle sub_superscripts and checkboxes
  1500. (or (string-match org-table-hline-regexp org-line)
  1501. (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" org-line)
  1502. (setq org-line (org-html-expand org-line)))
  1503. ;; Format the links
  1504. (setq org-line (org-html-handle-links org-line opt-plist))
  1505. ;; TODO items
  1506. (if (and org-todo-line-regexp
  1507. (string-match org-todo-line-regexp org-line)
  1508. (match-beginning 2))
  1509. (setq org-line
  1510. (concat (substring org-line 0 (match-beginning 2))
  1511. "<span class=\""
  1512. (if (member (match-string 2 org-line)
  1513. org-done-keywords)
  1514. "done" "todo")
  1515. " " (org-export-html-get-todo-kwd-class-name
  1516. (match-string 2 org-line))
  1517. "\">" (match-string 2 org-line)
  1518. "</span>" (substring org-line (match-end 2)))))
  1519. ;; Does this contain a reference to a footnote?
  1520. (when org-export-with-footnotes
  1521. (setq start 0)
  1522. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" org-line start)
  1523. ;; Discard protected matches not clearly identified as
  1524. ;; footnote markers.
  1525. (if (or (get-text-property (match-beginning 2) 'org-protected org-line)
  1526. (not (get-text-property (match-beginning 2) 'org-footnote org-line)))
  1527. (setq start (match-end 2))
  1528. (let ((n (match-string 2 org-line)) extra a)
  1529. (if (setq a (assoc n footref-seen))
  1530. (progn
  1531. (setcdr a (1+ (cdr a)))
  1532. (setq extra (format ".%d" (cdr a))))
  1533. (setq extra "")
  1534. (push (cons n 1) footref-seen))
  1535. (setq org-line
  1536. (replace-match
  1537. (concat
  1538. (format
  1539. (concat "%s"
  1540. (format org-export-html-footnote-format
  1541. (concat "<a class=\"footref\" name=\"" footnote-ref-prefix ".%s%s\" href=\"#" footnote-def-prefix ".%s\">%s</a>")))
  1542. (or (match-string 1 org-line) "") n extra n n)
  1543. ;; If another footnote is following the
  1544. ;; current one, add a separator.
  1545. (if (save-match-data
  1546. (string-match "\\`\\[[0-9]+\\]"
  1547. (substring org-line (match-end 0))))
  1548. org-export-html-footnote-separator
  1549. ""))
  1550. t t org-line))))))
  1551. (cond
  1552. ((string-match "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$" org-line)
  1553. ;; This is a headline
  1554. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
  1555. level-offset))
  1556. txt (match-string 2 org-line))
  1557. (if (string-match quote-re0 txt)
  1558. (setq txt (replace-match "" t t txt)))
  1559. (if (<= level (max umax umax-toc))
  1560. (setq head-count (+ head-count 1)))
  1561. (setq first-heading-pos (or first-heading-pos (point)))
  1562. (org-html-level-start level txt umax
  1563. (and org-export-with-toc (<= level umax))
  1564. head-count opt-plist)
  1565. ;; QUOTES
  1566. (when (string-match quote-re org-line)
  1567. (org-close-par-maybe)
  1568. (insert "<pre>")
  1569. (setq inquote t)))
  1570. ((and org-export-with-tables
  1571. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" org-line))
  1572. (when (not table-open)
  1573. ;; New table starts
  1574. (setq table-open t table-buffer nil table-orig-buffer nil))
  1575. ;; Accumulate lines
  1576. (setq table-buffer (cons org-line table-buffer)
  1577. table-orig-buffer (cons origline table-orig-buffer))
  1578. (when (or (not lines)
  1579. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  1580. (car lines))))
  1581. (setq table-open nil
  1582. table-buffer (nreverse table-buffer)
  1583. table-orig-buffer (nreverse table-orig-buffer))
  1584. (org-close-par-maybe)
  1585. (insert (org-format-table-html table-buffer table-orig-buffer))))
  1586. ;; Normal lines
  1587. (t
  1588. ;; This line either is list item or end a list.
  1589. (when (get-text-property 0 'list-item org-line)
  1590. (setq org-line (org-html-export-list-line
  1591. org-line
  1592. (get-text-property 0 'list-item org-line)
  1593. (get-text-property 0 'list-struct org-line)
  1594. (get-text-property 0 'list-prevs org-line))))
  1595. ;; Horizontal line
  1596. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" org-line)
  1597. (if org-par-open
  1598. (insert "\n</p>\n<hr/>\n<p>\n")
  1599. (insert "\n<hr/>\n"))
  1600. (throw 'nextline nil))
  1601. ;; Empty lines start a new paragraph. If hand-formatted lists
  1602. ;; are not fully interpreted, lines starting with "-", "+", "*"
  1603. ;; also start a new paragraph.
  1604. (if (string-match "^ [-+*]-\\|^[ \t]*$" org-line) (org-open-par))
  1605. ;; Is this the start of a footnote?
  1606. (when org-export-with-footnotes
  1607. (when (and (boundp 'footnote-section-tag-regexp)
  1608. (string-match (concat "^" footnote-section-tag-regexp)
  1609. org-line))
  1610. ;; ignore this line
  1611. (throw 'nextline nil))
  1612. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" org-line)
  1613. (org-close-par-maybe)
  1614. (let ((n (match-string 1 org-line)))
  1615. (setq org-par-open t
  1616. org-line (replace-match
  1617. (format
  1618. (concat "<p class=\"footnote\">"
  1619. (format org-export-html-footnote-format
  1620. (concat
  1621. "<a class=\"footnum\" name=\"" footnote-def-prefix ".%s\" href=\"#" footnote-ref-prefix ".%s\">%s</a>")))
  1622. n n n) t t org-line)))))
  1623. ;; Check if the line break needs to be conserved
  1624. (cond
  1625. ((string-match "\\\\\\\\[ \t]*$" org-line)
  1626. (setq org-line (replace-match "<br/>" t t org-line)))
  1627. (org-export-preserve-breaks
  1628. (setq org-line (concat org-line "<br/>"))))
  1629. ;; Check if a paragraph should be started
  1630. (let ((start 0))
  1631. (while (and org-par-open
  1632. (string-match "\\\\par\\>" org-line start))
  1633. ;; Leave a space in the </p> so that the footnote matcher
  1634. ;; does not see this.
  1635. (if (not (get-text-property (match-beginning 0)
  1636. 'org-protected org-line))
  1637. (setq org-line (replace-match "</p ><p >" t t org-line)))
  1638. (setq start (match-end 0))))
  1639. (insert org-line "\n")))))
  1640. ;; Properly close all local lists and other lists
  1641. (when inquote
  1642. (insert "</pre>\n")
  1643. (org-open-par))
  1644. (org-html-level-start 1 nil umax
  1645. (and org-export-with-toc (<= level umax))
  1646. head-count opt-plist)
  1647. ;; the </div> to close the last text-... div.
  1648. (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
  1649. (save-excursion
  1650. (goto-char (point-min))
  1651. (while (re-search-forward
  1652. "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
  1653. nil t)
  1654. (push (match-string 1) footnotes)
  1655. (replace-match "\\4" t nil)
  1656. (goto-char (match-beginning 0))))
  1657. (when footnotes
  1658. (insert (format org-export-html-footnotes-section
  1659. (nth 4 lang-words)
  1660. (mapconcat 'identity (nreverse footnotes) "\n"))
  1661. "\n"))
  1662. (let ((bib (org-export-html-get-bibliography)))
  1663. (when bib
  1664. (insert "\n" bib "\n")))
  1665. (unless body-only
  1666. ;; end wrap around body
  1667. (insert "</div>\n")
  1668. ;; export html postamble
  1669. (let ((html-post (plist-get opt-plist :html-postamble))
  1670. (email
  1671. (mapconcat (lambda(e)
  1672. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1673. (split-string email ",+ *")
  1674. ", "))
  1675. (creator-info
  1676. (concat "<a href=\"http://orgmode.org\">Org</a> version "
  1677. (org-version) " with <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> version "
  1678. (number-to-string emacs-major-version))))
  1679. (when (plist-get opt-plist :html-postamble)
  1680. (insert "\n<div id=\"" (nth 2 org-export-html-divs) "\">\n")
  1681. (cond ((stringp html-post)
  1682. (insert (format-spec html-post
  1683. `((?a . ,author) (?e . ,email)
  1684. (?d . ,date) (?c . ,creator-info)
  1685. (?v . ,html-validation-link)))))
  1686. ((functionp html-post)
  1687. (if (stringp (funcall html-post)) (insert (funcall html-post))))
  1688. ((eq html-post 'auto)
  1689. ;; fall back on default postamble
  1690. (when (plist-get opt-plist :time-stamp-file)
  1691. (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
  1692. (when (and (plist-get opt-plist :author-info) author)
  1693. (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
  1694. (when (and (plist-get opt-plist :email-info) email)
  1695. (insert "<p class=\"email\">" email "</p>\n"))
  1696. (when (plist-get opt-plist :creator-info)
  1697. (insert "<p class=\"creator\">"
  1698. (concat "<a href=\"http://orgmode.org\">Org</a> version "
  1699. (org-version) " with <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> version "
  1700. (number-to-string emacs-major-version) "</p>\n")))
  1701. (insert html-validation-link "\n"))
  1702. (t
  1703. (insert (format-spec
  1704. (or (cadr (assoc (nth 0 lang-words)
  1705. org-export-html-postamble-format))
  1706. (cadr (assoc "en" org-export-html-postamble-format)))
  1707. `((?a . ,author) (?e . ,email)
  1708. (?d . ,date) (?c . ,creator-info)
  1709. (?v . ,html-validation-link))))))
  1710. (insert "\n</div>"))))
  1711. ;; FIXME `org-export-html-with-timestamp' has been declared
  1712. ;; obsolete since Org 7.7 -- don't forget to remove this.
  1713. (if org-export-html-with-timestamp
  1714. (insert org-export-html-html-helper-timestamp))
  1715. (unless body-only (insert "\n</body>\n</html>\n"))
  1716. (unless (plist-get opt-plist :buffer-will-be-killed)
  1717. (normal-mode)
  1718. (if (eq major-mode (default-value 'major-mode))
  1719. (html-mode)))
  1720. ;; insert the table of contents
  1721. (goto-char (point-min))
  1722. (when thetoc
  1723. (if (or (re-search-forward
  1724. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  1725. (re-search-forward
  1726. "\\[TABLE-OF-CONTENTS\\]" nil t))
  1727. (progn
  1728. (goto-char (match-beginning 0))
  1729. (replace-match ""))
  1730. (goto-char first-heading-pos)
  1731. (when (looking-at "\\s-*</p>")
  1732. (goto-char (match-end 0))
  1733. (insert "\n")))
  1734. (insert "<div id=\"table-of-contents\">\n")
  1735. (let ((beg (point)))
  1736. (mapc 'insert thetoc)
  1737. (insert "</div>\n")
  1738. (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t)
  1739. (replace-match ""))))
  1740. ;; remove empty paragraphs
  1741. (goto-char (point-min))
  1742. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  1743. (replace-match ""))
  1744. (goto-char (point-min))
  1745. ;; Convert whitespace place holders
  1746. (goto-char (point-min))
  1747. (let (beg end n)
  1748. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  1749. (setq n (get-text-property beg 'org-whitespace)
  1750. end (next-single-property-change beg 'org-whitespace))
  1751. (goto-char beg)
  1752. (delete-region beg end)
  1753. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  1754. (make-string n ?x)))))
  1755. ;; Remove empty lines at the beginning of the file.
  1756. (goto-char (point-min))
  1757. (when (looking-at "\\s-+\n") (replace-match ""))
  1758. ;; Remove display properties
  1759. (remove-text-properties (point-min) (point-max) '(display t))
  1760. ;; Run the hook
  1761. (run-hooks 'org-export-html-final-hook)
  1762. (or to-buffer (save-buffer))
  1763. (goto-char (point-min))
  1764. (or (org-export-push-to-kill-ring "HTML")
  1765. (message "Exporting... done"))
  1766. (if (eq to-buffer 'string)
  1767. (prog1 (buffer-substring (point-min) (point-max))
  1768. (kill-buffer (current-buffer)))
  1769. (current-buffer)))))
  1770. (defun org-export-html-format-href (s)
  1771. "Make sure the S is valid as a href reference in an XHTML document."
  1772. (save-match-data
  1773. (let ((start 0))
  1774. (while (string-match "&" s start)
  1775. (setq start (+ (match-beginning 0) 3)
  1776. s (replace-match "&amp;" t t s)))))
  1777. s)
  1778. (defun org-export-html-format-desc (s)
  1779. "Make sure the S is valid as a description in a link."
  1780. (if (and s (not (get-text-property 1 'org-protected s)))
  1781. (save-match-data
  1782. (org-html-do-expand s))
  1783. s))
  1784. (defun org-export-html-format-image (src par-open)
  1785. "Create image tag with source and attributes."
  1786. (save-match-data
  1787. (if (string-match "^ltxpng/" src)
  1788. (format "<img src=\"%s\" alt=\"%s\"/>"
  1789. src (org-find-text-property-in-string 'org-latex-src src))
  1790. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  1791. (attr (org-find-text-property-in-string 'org-attributes src))
  1792. (label (org-find-text-property-in-string 'org-label src)))
  1793. (setq caption (and caption (org-html-do-expand caption)))
  1794. (concat
  1795. (if caption
  1796. (format "%s<div %sclass=\"figure\">
  1797. <p>"
  1798. (if org-par-open "</p>\n" "")
  1799. (if label (format "id=\"%s\" " (org-solidify-link-text label)) "")))
  1800. (format "<img src=\"%s\"%s />"
  1801. src
  1802. (if (string-match "\\<alt=" (or attr ""))
  1803. (concat " " attr )
  1804. (concat " " attr " alt=\"" src "\"")))
  1805. (if caption
  1806. (format "</p>%s
  1807. </div>%s"
  1808. (concat "\n<p>" caption "</p>")
  1809. (if org-par-open "\n<p>" ""))))))))
  1810. (defun org-export-html-get-bibliography ()
  1811. "Find bibliography, cut it out and return it."
  1812. (catch 'exit
  1813. (let (beg end (cnt 1) bib)
  1814. (save-excursion
  1815. (goto-char (point-min))
  1816. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  1817. (setq beg (match-beginning 0))
  1818. (while (re-search-forward "</?div\\>" nil t)
  1819. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  1820. (when (= cnt 0)
  1821. (and (looking-at ">") (forward-char 1))
  1822. (setq bib (buffer-substring beg (point)))
  1823. (delete-region beg (point))
  1824. (throw 'exit bib))))
  1825. nil))))
  1826. (defvar org-table-number-regexp) ; defined in org-table.el
  1827. (defun org-format-table-html (lines olines &optional no-css)
  1828. "Find out which HTML converter to use and return the HTML code.
  1829. NO-CSS is passed to the exporter."
  1830. (if (stringp lines)
  1831. (setq lines (org-split-string lines "\n")))
  1832. (if (string-match "^[ \t]*|" (car lines))
  1833. ;; A normal org table
  1834. (org-format-org-table-html lines nil no-css)
  1835. ;; Table made by table.el
  1836. (or (org-format-table-table-html-using-table-generate-source
  1837. olines (not org-export-prefer-native-exporter-for-tables))
  1838. ;; We are here only when table.el table has NO col or row
  1839. ;; spanning and the user prefers using org's own converter for
  1840. ;; exporting of such simple table.el tables.
  1841. (org-format-table-table-html lines))))
  1842. (defvar org-table-number-fraction) ; defined in org-table.el
  1843. (defun org-format-org-table-html (lines &optional splice no-css)
  1844. "Format a table into HTML.
  1845. LINES is a list of lines. Optional argument SPLICE means, do not
  1846. insert header and surrounding <table> tags, just format the lines.
  1847. Optional argument NO-CSS means use XHTML attributes instead of CSS
  1848. for formatting. This is required for the DocBook exporter."
  1849. (require 'org-table)
  1850. ;; Get rid of hlines at beginning and end
  1851. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1852. (setq lines (nreverse lines))
  1853. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1854. (setq lines (nreverse lines))
  1855. (when org-export-table-remove-special-lines
  1856. ;; Check if the table has a marking column. If yes remove the
  1857. ;; column and the special lines
  1858. (setq lines (org-table-clean-before-export lines)))
  1859. (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
  1860. (label (org-find-text-property-in-string 'org-label (car lines)))
  1861. (col-cookies (org-find-text-property-in-string 'org-col-cookies
  1862. (car lines)))
  1863. (attributes (org-find-text-property-in-string 'org-attributes
  1864. (car lines)))
  1865. (html-table-tag (org-export-splice-attributes
  1866. html-table-tag attributes))
  1867. (head (and org-export-highlight-first-table-line
  1868. (delq nil (mapcar
  1869. (lambda (x) (string-match "^[ \t]*|-" x))
  1870. (cdr lines)))))
  1871. (nline 0) fnum nfields i (cnt 0)
  1872. tbopen org-line fields html gr colgropen rowstart rowend
  1873. ali align aligns n)
  1874. (setq caption (and caption (org-html-do-expand caption)))
  1875. (when (and col-cookies org-table-clean-did-remove-column)
  1876. (setq col-cookies
  1877. (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies)))
  1878. (if splice (setq head nil))
  1879. (unless splice (push (if head "<thead>" "<tbody>") html))
  1880. (setq tbopen t)
  1881. (while (setq org-line (pop lines))
  1882. (catch 'next-line
  1883. (if (string-match "^[ \t]*|-" org-line)
  1884. (progn
  1885. (unless splice
  1886. (push (if head "</thead>" "</tbody>") html)
  1887. (if lines (push "<tbody>" html) (setq tbopen nil)))
  1888. (setq head nil) ;; head ends here, first time around
  1889. ;; ignore this line
  1890. (throw 'next-line t)))
  1891. ;; Break the line into fields
  1892. (setq fields (org-split-string org-line "[ \t]*|[ \t]*"))
  1893. (unless fnum (setq fnum (make-vector (length fields) 0)
  1894. nfields (length fnum)))
  1895. (setq nline (1+ nline) i -1
  1896. rowstart (eval (car org-export-table-row-tags))
  1897. rowend (eval (cdr org-export-table-row-tags)))
  1898. (push (concat rowstart
  1899. (mapconcat
  1900. (lambda (x)
  1901. (setq i (1+ i) ali (format "@@class%03d@@" i))
  1902. (if (and (< i nfields) ; make sure no rogue line causes an error here
  1903. (string-match org-table-number-regexp x))
  1904. (incf (aref fnum i)))
  1905. (cond
  1906. (head
  1907. (concat
  1908. (format (car org-export-table-header-tags)
  1909. "col" ali)
  1910. x
  1911. (cdr org-export-table-header-tags)))
  1912. ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
  1913. (concat
  1914. (format (car org-export-table-header-tags)
  1915. "row" ali)
  1916. x
  1917. (cdr org-export-table-header-tags)))
  1918. (t
  1919. (concat (format (car org-export-table-data-tags) ali)
  1920. x
  1921. (cdr org-export-table-data-tags)))))
  1922. fields "")
  1923. rowend)
  1924. html)))
  1925. (unless splice (if tbopen (push "</tbody>" html)))
  1926. (unless splice (push "</table>\n" html))
  1927. (setq html (nreverse html))
  1928. (unless splice
  1929. ;; Put in col tags with the alignment (unfortunately often ignored...)
  1930. (unless (car org-table-colgroup-info)
  1931. (setq org-table-colgroup-info
  1932. (cons :start (cdr org-table-colgroup-info))))
  1933. (setq i 0)
  1934. (push (mapconcat
  1935. (lambda (x)
  1936. (setq gr (pop org-table-colgroup-info)
  1937. i (1+ i)
  1938. align (if (nth 1 (assoc i col-cookies))
  1939. (cdr (assoc (nth 1 (assoc i col-cookies))
  1940. '(("l" . "left") ("r" . "right")
  1941. ("c" . "center"))))
  1942. (if (> (/ (float x) nline)
  1943. org-table-number-fraction)
  1944. "right" "left")))
  1945. (push align aligns)
  1946. (format (if no-css
  1947. "%s<col align=\"%s\" />%s"
  1948. "%s<col class=\"%s\" />%s")
  1949. (if (memq gr '(:start :startend))
  1950. (prog1
  1951. (if colgropen
  1952. "</colgroup>\n<colgroup>"
  1953. "<colgroup>")
  1954. (setq colgropen t))
  1955. "")
  1956. align
  1957. (if (memq gr '(:end :startend))
  1958. (progn (setq colgropen nil) "</colgroup>")
  1959. "")))
  1960. fnum "")
  1961. html)
  1962. (setq aligns (nreverse aligns))
  1963. (if colgropen (setq html (cons (car html)
  1964. (cons "</colgroup>" (cdr html)))))
  1965. ;; Since the output of HTML table formatter can also be used in
  1966. ;; DocBook document, we want to always include the caption to make
  1967. ;; DocBook XML file valid.
  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