org-html.el 80 KB

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