org-html.el 98 KB

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