org-html.el 93 KB

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