org-html.el 98 KB

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