org-html.el 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285
  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.01
  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. (or
  512. (eq t org-export-html-inline-images)
  513. (and
  514. org-export-html-inline-images
  515. (not descp)))
  516. (org-file-image-p
  517. filename org-export-html-inline-image-extensions))
  518. ;;; org-html-make-link
  519. (defun org-html-make-link (opt-plist type path fragment desc attr
  520. may-inline-p)
  521. "Make an HTML link.
  522. OPT-PLIST is an options list.
  523. TYPE is the device-type of the link (THIS://foo.html)
  524. PATH is the path of the link (http://THIS#locationx)
  525. FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
  526. DESC is the link description, if any.
  527. ATTR is a string of other attributes of the a element.
  528. MAY-INLINE-P allows inlining it as an image."
  529. (declare (special org-par-open))
  530. (save-match-data
  531. (let* ((filename path)
  532. ;;First pass. Just sanity stuff.
  533. (components-1
  534. (cond
  535. ((string= type "file")
  536. (list
  537. type
  538. ;;Substitute just if original path was absolute.
  539. ;;(Otherwise path must remain relative)
  540. (if (file-name-absolute-p path)
  541. (expand-file-name path)
  542. path)))
  543. ((string= type "")
  544. (list nil path))
  545. (t (list type path))))
  546. ;;Second pass. Components converted so they can refer
  547. ;;to a remote site.
  548. (components-2
  549. (or
  550. (and org-html-cvt-link-fn
  551. (apply org-html-cvt-link-fn
  552. opt-plist components-1))
  553. (apply #'org-html-cvt-org-as-html
  554. opt-plist components-1)
  555. components-1))
  556. (type (first components-2))
  557. (thefile (second components-2)))
  558. ;;Third pass. Build final link except for leading type
  559. ;;spec.
  560. (cond
  561. ((or
  562. (not type)
  563. (string= type "http")
  564. (string= type "https"))
  565. (if fragment
  566. (setq thefile (concat thefile "#" fragment))))
  567. (t))
  568. ;;Final URL-build, for all types.
  569. (setq thefile
  570. (let
  571. ((str (org-export-html-format-href thefile)))
  572. (if (and type (not (string= "file" type))
  573. (org-string-match-p "^//" str))
  574. (concat type ":" str)
  575. str)))
  576. (if (and
  577. may-inline-p
  578. ;;Can't inline a URL with a fragment.
  579. (not fragment))
  580. (progn
  581. (message "image %s %s" thefile org-par-open)
  582. (org-export-html-format-image thefile org-par-open))
  583. (concat
  584. "<a href=\"" thefile "\"" attr ">"
  585. (org-export-html-format-desc desc)
  586. "</a>")))))
  587. ;;; org-export-as-html
  588. ;;;###autoload
  589. (defun org-export-as-html (arg &optional hidden ext-plist
  590. to-buffer body-only pub-dir)
  591. "Export the outline as a pretty HTML file.
  592. If there is an active region, export only the region. The prefix
  593. ARG specifies how many levels of the outline should become
  594. headlines. The default is 3. Lower levels will become bulleted
  595. lists. HIDDEN is obsolete and does nothing.
  596. EXT-PLIST is a property list with external parameters overriding
  597. org-mode's default settings, but still inferior to file-local
  598. settings. When TO-BUFFER is non-nil, create a buffer with that
  599. name and export to that buffer. If TO-BUFFER is the symbol
  600. `string', don't leave any buffer behind but just return the
  601. resulting HTML as a string. When BODY-ONLY is set, don't produce
  602. the file header and footer, simply return the content of
  603. <body>...</body>, without even the body tags themselves. When
  604. PUB-DIR is set, use this as the publishing directory."
  605. (interactive "P")
  606. (run-hooks 'org-export-first-hook)
  607. ;; Make sure we have a file name when we need it.
  608. (when (and (not (or to-buffer body-only))
  609. (not buffer-file-name))
  610. (if (buffer-base-buffer)
  611. (org-set-local 'buffer-file-name
  612. (with-current-buffer (buffer-base-buffer)
  613. buffer-file-name))
  614. (error "Need a file name to be able to export")))
  615. (message "Exporting...")
  616. (setq-default org-todo-line-regexp org-todo-line-regexp)
  617. (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  618. (setq-default org-done-keywords org-done-keywords)
  619. (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  620. (let* ((opt-plist
  621. (org-export-process-option-filters
  622. (org-combine-plists (org-default-export-plist)
  623. ext-plist
  624. (org-infile-export-plist))))
  625. (body-only (or body-only (plist-get opt-plist :body-only)))
  626. (style (concat (if (plist-get opt-plist :style-include-default)
  627. org-export-html-style-default)
  628. (plist-get opt-plist :style)
  629. (plist-get opt-plist :style-extra)
  630. "\n"
  631. (if (plist-get opt-plist :style-include-scripts)
  632. org-export-html-scripts)))
  633. (html-extension (plist-get opt-plist :html-extension))
  634. (link-validate (plist-get opt-plist :link-validation-function))
  635. valid thetoc have-headings first-heading-pos
  636. (odd org-odd-levels-only)
  637. (region-p (org-region-active-p))
  638. (rbeg (and region-p (region-beginning)))
  639. (rend (and region-p (region-end)))
  640. (subtree-p
  641. (if (plist-get opt-plist :ignore-subtree-p)
  642. nil
  643. (when region-p
  644. (save-excursion
  645. (goto-char rbeg)
  646. (and (org-at-heading-p)
  647. (>= (org-end-of-subtree t t) rend))))))
  648. (level-offset (if subtree-p
  649. (save-excursion
  650. (goto-char rbeg)
  651. (+ (funcall outline-level)
  652. (if org-odd-levels-only 1 0)))
  653. 0))
  654. (opt-plist (setq org-export-opt-plist
  655. (if subtree-p
  656. (org-export-add-subtree-options opt-plist rbeg)
  657. opt-plist)))
  658. ;; The following two are dynamically scoped into other
  659. ;; routines below.
  660. (org-current-export-dir
  661. (or pub-dir (org-export-directory :html opt-plist)))
  662. (org-current-export-file buffer-file-name)
  663. (level 0) (line "") (origline "") txt todo
  664. (umax nil)
  665. (umax-toc nil)
  666. (filename (if to-buffer nil
  667. (expand-file-name
  668. (concat
  669. (file-name-sans-extension
  670. (or (and subtree-p
  671. (org-entry-get (region-beginning)
  672. "EXPORT_FILE_NAME" t))
  673. (file-name-nondirectory buffer-file-name)))
  674. "." html-extension)
  675. (file-name-as-directory
  676. (or pub-dir (org-export-directory :html opt-plist))))))
  677. (current-dir (if buffer-file-name
  678. (file-name-directory buffer-file-name)
  679. default-directory))
  680. (buffer (if to-buffer
  681. (cond
  682. ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
  683. (t (get-buffer-create to-buffer)))
  684. (find-file-noselect filename)))
  685. (org-levels-open (make-vector org-level-max nil))
  686. (date (plist-get opt-plist :date))
  687. (author (plist-get opt-plist :author))
  688. (title (or (and subtree-p (org-export-get-title-from-subtree))
  689. (plist-get opt-plist :title)
  690. (and (not body-only)
  691. (not
  692. (plist-get opt-plist :skip-before-1st-heading))
  693. (org-export-grab-title-from-buffer))
  694. (and buffer-file-name
  695. (file-name-sans-extension
  696. (file-name-nondirectory buffer-file-name)))
  697. "UNTITLED"))
  698. (link-up (and (plist-get opt-plist :link-up)
  699. (string-match "\\S-" (plist-get opt-plist :link-up))
  700. (plist-get opt-plist :link-up)))
  701. (link-home (and (plist-get opt-plist :link-home)
  702. (string-match "\\S-" (plist-get opt-plist :link-home))
  703. (plist-get opt-plist :link-home)))
  704. (dummy (setq opt-plist (plist-put opt-plist :title title)))
  705. (html-table-tag (plist-get opt-plist :html-table-tag))
  706. (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
  707. (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
  708. (inquote nil)
  709. (infixed nil)
  710. (inverse nil)
  711. (in-local-list nil)
  712. (local-list-type nil)
  713. (local-list-indent nil)
  714. (llt org-plain-list-ordered-item-terminator)
  715. (email (plist-get opt-plist :email))
  716. (language (plist-get opt-plist :language))
  717. (keywords (plist-get opt-plist :keywords))
  718. (description (plist-get opt-plist :description))
  719. (lang-words nil)
  720. (head-count 0) cnt
  721. (start 0)
  722. (coding-system (and (boundp 'buffer-file-coding-system)
  723. buffer-file-coding-system))
  724. (coding-system-for-write (or org-export-html-coding-system
  725. coding-system))
  726. (save-buffer-coding-system (or org-export-html-coding-system
  727. coding-system))
  728. (charset (and coding-system-for-write
  729. (fboundp 'coding-system-get)
  730. (coding-system-get coding-system-for-write
  731. 'mime-charset)))
  732. (region
  733. (buffer-substring
  734. (if region-p (region-beginning) (point-min))
  735. (if region-p (region-end) (point-max))))
  736. (lines
  737. (org-split-string
  738. (org-export-preprocess-string
  739. region
  740. :emph-multiline t
  741. :for-html t
  742. :skip-before-1st-heading
  743. (plist-get opt-plist :skip-before-1st-heading)
  744. :drawers (plist-get opt-plist :drawers)
  745. :todo-keywords (plist-get opt-plist :todo-keywords)
  746. :tags (plist-get opt-plist :tags)
  747. :priority (plist-get opt-plist :priority)
  748. :footnotes (plist-get opt-plist :footnotes)
  749. :timestamps (plist-get opt-plist :timestamps)
  750. :archived-trees
  751. (plist-get opt-plist :archived-trees)
  752. :select-tags (plist-get opt-plist :select-tags)
  753. :exclude-tags (plist-get opt-plist :exclude-tags)
  754. :add-text
  755. (plist-get opt-plist :text)
  756. :LaTeX-fragments
  757. (plist-get opt-plist :LaTeX-fragments))
  758. "[\r\n]"))
  759. table-open type
  760. table-buffer table-orig-buffer
  761. ind item-type starter didclose
  762. rpl path attr desc descp desc1 desc2 link
  763. snumber fnc item-tag initial-number
  764. footnotes footref-seen
  765. id-file href
  766. )
  767. (let ((inhibit-read-only t))
  768. (org-unmodified
  769. (remove-text-properties (point-min) (point-max)
  770. '(:org-license-to-kill t))))
  771. (message "Exporting...")
  772. (setq org-min-level (org-get-min-level lines level-offset))
  773. (setq org-last-level org-min-level)
  774. (org-init-section-numbers)
  775. (cond
  776. ((and date (string-match "%" date))
  777. (setq date (format-time-string date)))
  778. (date)
  779. (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
  780. ;; Get the language-dependent settings
  781. (setq lang-words (or (assoc language org-export-language-setup)
  782. (assoc "en" org-export-language-setup)))
  783. ;; Switch to the output buffer
  784. (set-buffer buffer)
  785. (let ((inhibit-read-only t)) (erase-buffer))
  786. (fundamental-mode)
  787. (org-install-letbind)
  788. (and (fboundp 'set-buffer-file-coding-system)
  789. (set-buffer-file-coding-system coding-system-for-write))
  790. (let ((case-fold-search nil)
  791. (org-odd-levels-only odd))
  792. ;; create local variables for all options, to make sure all called
  793. ;; functions get the correct information
  794. (mapc (lambda (x)
  795. (set (make-local-variable (nth 2 x))
  796. (plist-get opt-plist (car x))))
  797. org-export-plist-vars)
  798. (setq umax (if arg (prefix-numeric-value arg)
  799. org-export-headline-levels))
  800. (setq umax-toc (if (integerp org-export-with-toc)
  801. (min org-export-with-toc umax)
  802. umax))
  803. (unless body-only
  804. ;; File header
  805. (insert (format
  806. "%s
  807. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  808. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  809. <html xmlns=\"http://www.w3.org/1999/xhtml\"
  810. lang=\"%s\" xml:lang=\"%s\">
  811. <head>
  812. <title>%s</title>
  813. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
  814. <meta name=\"generator\" content=\"Org-mode\"/>
  815. <meta name=\"generated\" content=\"%s\"/>
  816. <meta name=\"author\" content=\"%s\"/>
  817. <meta name=\"description\" content=\"%s\"/>
  818. <meta name=\"keywords\" content=\"%s\"/>
  819. %s
  820. </head>
  821. <body>
  822. <div id=\"content\">
  823. %s
  824. "
  825. (format
  826. (or (and (stringp org-export-html-xml-declaration)
  827. org-export-html-xml-declaration)
  828. (cdr (assoc html-extension org-export-html-xml-declaration))
  829. (cdr (assoc "html" org-export-html-xml-declaration))
  830. "")
  831. (or charset "iso-8859-1"))
  832. language language
  833. title
  834. (or charset "iso-8859-1")
  835. date author description keywords
  836. style
  837. (if (or link-up link-home)
  838. (concat
  839. (format org-export-html-home/up-format
  840. (or link-up link-home)
  841. (or link-home link-up))
  842. "\n")
  843. "")))
  844. (org-export-html-insert-plist-item opt-plist :preamble opt-plist)
  845. (when (plist-get opt-plist :auto-preamble)
  846. (if title (insert (format org-export-html-title-format
  847. (org-html-expand title))))))
  848. (if (and org-export-with-toc (not body-only))
  849. (progn
  850. (push (format "<h%d>%s</h%d>\n"
  851. org-export-html-toplevel-hlevel
  852. (nth 3 lang-words)
  853. org-export-html-toplevel-hlevel)
  854. thetoc)
  855. (push "<div id=\"text-table-of-contents\">\n" thetoc)
  856. (push "<ul>\n<li>" thetoc)
  857. (setq lines
  858. (mapcar '(lambda (line)
  859. (if (and (string-match org-todo-line-regexp line)
  860. (not (get-text-property 0 'org-protected line)))
  861. ;; This is a headline
  862. (progn
  863. (setq have-headings t)
  864. (setq level (- (match-end 1) (match-beginning 1)
  865. level-offset)
  866. level (org-tr-level level)
  867. txt (save-match-data
  868. (org-html-expand
  869. (org-export-cleanup-toc-line
  870. (match-string 3 line))))
  871. todo
  872. (or (and org-export-mark-todo-in-toc
  873. (match-beginning 2)
  874. (not (member (match-string 2 line)
  875. org-done-keywords)))
  876. ; TODO, not DONE
  877. (and org-export-mark-todo-in-toc
  878. (= level umax-toc)
  879. (org-search-todo-below
  880. line lines level))))
  881. (if (string-match
  882. (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
  883. (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
  884. (if (string-match quote-re0 txt)
  885. (setq txt (replace-match "" t t txt)))
  886. (setq snumber (org-section-number level))
  887. (if org-export-with-section-numbers
  888. (setq txt (concat snumber " " txt)))
  889. (if (<= level (max umax umax-toc))
  890. (setq head-count (+ head-count 1)))
  891. (if (<= level umax-toc)
  892. (progn
  893. (if (> level org-last-level)
  894. (progn
  895. (setq cnt (- level org-last-level))
  896. (while (>= (setq cnt (1- cnt)) 0)
  897. (push "\n<ul>\n<li>" thetoc))
  898. (push "\n" thetoc)))
  899. (if (< level org-last-level)
  900. (progn
  901. (setq cnt (- org-last-level level))
  902. (while (>= (setq cnt (1- cnt)) 0)
  903. (push "</li>\n</ul>" thetoc))
  904. (push "\n" thetoc)))
  905. ;; Check for targets
  906. (while (string-match org-any-target-regexp line)
  907. (setq line (replace-match
  908. (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
  909. t t line)))
  910. (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
  911. (setq txt (replace-match "" t t txt)))
  912. (setq href
  913. (replace-regexp-in-string
  914. "\\." "_" (format "sec-%s" snumber)))
  915. (setq href (or (cdr (assoc href org-export-preferred-target-alist)) href))
  916. (push
  917. (format
  918. (if todo
  919. "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
  920. "</li>\n<li><a href=\"#%s\">%s</a>")
  921. href txt) thetoc)
  922. (setq org-last-level level))
  923. )))
  924. line)
  925. lines))
  926. (while (> org-last-level (1- org-min-level))
  927. (setq org-last-level (1- org-last-level))
  928. (push "</li>\n</ul>\n" thetoc))
  929. (push "</div>\n" thetoc)
  930. (setq thetoc (if have-headings (nreverse thetoc) nil))))
  931. (setq head-count 0)
  932. (org-init-section-numbers)
  933. (org-open-par)
  934. (while (setq line (pop lines) origline line)
  935. (catch 'nextline
  936. ;; end of quote section?
  937. (when (and inquote (string-match "^\\*+ " line))
  938. (insert "</pre>\n")
  939. (org-open-par)
  940. (setq inquote nil))
  941. ;; inside a quote section?
  942. (when inquote
  943. (insert (org-html-protect line) "\n")
  944. (throw 'nextline nil))
  945. ;; Fixed-width, verbatim lines (examples)
  946. (when (and org-export-with-fixed-width
  947. (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
  948. (when (not infixed)
  949. (setq infixed t)
  950. (org-close-par-maybe)
  951. (insert "<pre class=\"example\">\n"))
  952. (insert (org-html-protect (match-string 3 line)) "\n")
  953. (when (or (not lines)
  954. (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
  955. (car lines))))
  956. (setq infixed nil)
  957. (insert "</pre>\n")
  958. (org-open-par))
  959. (throw 'nextline nil))
  960. (org-export-html-close-lists-maybe line)
  961. ;; Protected HTML
  962. (when (get-text-property 0 'org-protected line)
  963. (let (par (ind (get-text-property 0 'original-indentation line)))
  964. (when (re-search-backward
  965. "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
  966. (setq par (match-string 1))
  967. (replace-match "\\2\n"))
  968. (insert line "\n")
  969. (while (and lines
  970. (or (= (length (car lines)) 0)
  971. (not ind)
  972. (equal ind (get-text-property 0 'original-indentation (car lines))))
  973. (or (= (length (car lines)) 0)
  974. (get-text-property 0 'org-protected (car lines))))
  975. (insert (pop lines) "\n"))
  976. (and par (insert "<p>\n")))
  977. (throw 'nextline nil))
  978. ;; Blockquotes, verse, and center
  979. (when (equal "ORG-BLOCKQUOTE-START" line)
  980. (org-close-par-maybe)
  981. (insert "<blockquote>\n")
  982. (org-open-par)
  983. (throw 'nextline nil))
  984. (when (equal "ORG-BLOCKQUOTE-END" line)
  985. (org-close-par-maybe)
  986. (insert "\n</blockquote>\n")
  987. (org-open-par)
  988. (throw 'nextline nil))
  989. (when (equal "ORG-VERSE-START" line)
  990. (org-close-par-maybe)
  991. (insert "\n<p class=\"verse\">\n")
  992. (setq org-par-open t)
  993. (setq inverse t)
  994. (throw 'nextline nil))
  995. (when (equal "ORG-VERSE-END" line)
  996. (insert "</p>\n")
  997. (setq org-par-open nil)
  998. (org-open-par)
  999. (setq inverse nil)
  1000. (throw 'nextline nil))
  1001. (when (equal "ORG-CENTER-START" line)
  1002. (org-close-par-maybe)
  1003. (insert "\n<div style=\"text-align: center\">")
  1004. (org-open-par)
  1005. (throw 'nextline nil))
  1006. (when (equal "ORG-CENTER-END" line)
  1007. (org-close-par-maybe)
  1008. (insert "\n</div>")
  1009. (org-open-par)
  1010. (throw 'nextline nil))
  1011. (run-hooks 'org-export-html-after-blockquotes-hook)
  1012. (when inverse
  1013. (let ((i (org-get-string-indentation line)))
  1014. (if (> i 0)
  1015. (setq line (concat (mapconcat 'identity
  1016. (make-list (* 2 i) "\\nbsp") "")
  1017. " " (org-trim line))))
  1018. (unless (string-match "\\\\\\\\[ \t]*$" line)
  1019. (setq line (concat line "\\\\")))))
  1020. ;; make targets to anchors
  1021. (setq start 0)
  1022. (while (string-match
  1023. "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
  1024. (cond
  1025. ((get-text-property (match-beginning 1) 'org-protected line)
  1026. (setq start (match-end 1)))
  1027. ((match-end 2)
  1028. (setq line (replace-match
  1029. (format
  1030. "@<a name=\"%s\" id=\"%s\">@</a>"
  1031. (org-solidify-link-text (match-string 1 line))
  1032. (org-solidify-link-text (match-string 1 line)))
  1033. t t line)))
  1034. ((and org-export-with-toc (equal (string-to-char line) ?*))
  1035. ;; FIXME: NOT DEPENDENT on TOC?????????????????????
  1036. (setq line (replace-match
  1037. (concat "@<span class=\"target\">"
  1038. (match-string 1 line) "@</span> ")
  1039. ;; (concat "@<i>" (match-string 1 line) "@</i> ")
  1040. t t line)))
  1041. (t
  1042. (setq line (replace-match
  1043. (concat "@<a name=\""
  1044. (org-solidify-link-text (match-string 1 line))
  1045. "\" class=\"target\">" (match-string 1 line)
  1046. "@</a> ")
  1047. t t line)))))
  1048. (setq line (org-html-handle-time-stamps line))
  1049. ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
  1050. ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
  1051. ;; Also handle sub_superscripts and checkboxes
  1052. (or (string-match org-table-hline-regexp line)
  1053. (setq line (org-html-expand line)))
  1054. ;; Format the links
  1055. (setq start 0)
  1056. (while (string-match org-bracket-link-analytic-regexp++ line start)
  1057. (setq start (match-beginning 0))
  1058. (setq path (save-match-data (org-link-unescape
  1059. (match-string 3 line))))
  1060. (setq type (cond
  1061. ((match-end 2) (match-string 2 line))
  1062. ((save-match-data
  1063. (or (file-name-absolute-p path)
  1064. (string-match "^\\.\\.?/" path)))
  1065. "file")
  1066. (t "internal")))
  1067. (setq path (org-extract-attributes (org-link-unescape path)))
  1068. (setq attr (get-text-property 0 'org-attributes path))
  1069. (setq desc1 (if (match-end 5) (match-string 5 line))
  1070. desc2 (if (match-end 2) (concat type ":" path) path)
  1071. descp (and desc1 (not (equal desc1 desc2)))
  1072. desc (or desc1 desc2))
  1073. ;; Make an image out of the description if that is so wanted
  1074. (when (and descp (org-file-image-p
  1075. desc org-export-html-inline-image-extensions))
  1076. (save-match-data
  1077. (if (string-match "^file:" desc)
  1078. (setq desc (substring desc (match-end 0)))))
  1079. (setq desc (org-add-props
  1080. (concat "<img src=\"" desc "\"/>")
  1081. '(org-protected t))))
  1082. (cond
  1083. ((equal type "internal")
  1084. (let
  1085. ((frag-0
  1086. (if (= (string-to-char path) ?#)
  1087. (substring path 1)
  1088. path)))
  1089. (setq rpl
  1090. (org-html-make-link
  1091. opt-plist
  1092. ""
  1093. ""
  1094. (org-solidify-link-text
  1095. (save-match-data (org-link-unescape frag-0))
  1096. nil)
  1097. desc attr nil))))
  1098. ((and (equal type "id")
  1099. (setq id-file (org-id-find-id-file path)))
  1100. ;; This is an id: link to another file (if it was the same file,
  1101. ;; it would have become an internal link...)
  1102. (save-match-data
  1103. (setq id-file (file-relative-name
  1104. id-file
  1105. (file-name-directory org-current-export-file)))
  1106. (setq rpl
  1107. (org-html-make-link opt-plist
  1108. "file" id-file
  1109. (concat (if (org-uuidgen-p path) "ID-") path)
  1110. desc
  1111. attr
  1112. nil))))
  1113. ((member type '("http" "https"))
  1114. ;; standard URL, can inline as image
  1115. (setq rpl
  1116. (org-html-make-link opt-plist
  1117. type path nil
  1118. desc
  1119. attr
  1120. (org-html-should-inline-p path descp))))
  1121. ((member type '("ftp" "mailto" "news"))
  1122. ;; standard URL, can't inline as image
  1123. (setq rpl
  1124. (org-html-make-link opt-plist
  1125. type path nil
  1126. desc
  1127. attr
  1128. nil)))
  1129. ((string= type "coderef")
  1130. (let*
  1131. ((coderef-str (format "coderef-%s" path))
  1132. (attr-1
  1133. (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  1134. coderef-str coderef-str)))
  1135. (setq rpl
  1136. (org-html-make-link opt-plist
  1137. type "" coderef-str
  1138. (format
  1139. (org-export-get-coderef-format
  1140. path
  1141. (and descp desc))
  1142. (cdr (assoc path org-export-code-refs)))
  1143. attr-1
  1144. nil))))
  1145. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  1146. ;; The link protocol has a function for format the link
  1147. (setq rpl
  1148. (save-match-data
  1149. (funcall fnc (org-link-unescape path) desc1 'html))))
  1150. ((string= type "file")
  1151. ;; FILE link
  1152. (save-match-data
  1153. (let*
  1154. ((components
  1155. (if
  1156. (string-match "::\\(.*\\)" path)
  1157. (list
  1158. (replace-match "" t nil path)
  1159. (match-string 1 path))
  1160. (list path nil)))
  1161. ;;The proper path, without a fragment
  1162. (path-1
  1163. (first components))
  1164. ;;The raw fragment
  1165. (fragment-0
  1166. (second components))
  1167. ;;Check the fragment. If it can't be used as
  1168. ;;target fragment we'll pass nil instead.
  1169. (fragment-1
  1170. (if
  1171. (and fragment-0
  1172. (not (string-match "^[0-9]*$" fragment-0))
  1173. (not (string-match "^\\*" fragment-0))
  1174. (not (string-match "^/.*/$" fragment-0)))
  1175. (org-solidify-link-text
  1176. (org-link-unescape fragment-0))
  1177. nil))
  1178. (desc-2
  1179. ;;Description minus "file:" and ".org"
  1180. (if (string-match "^file:" desc)
  1181. (let
  1182. ((desc-1 (replace-match "" t t desc)))
  1183. (if (string-match "\\.org$" desc-1)
  1184. (replace-match "" t t desc-1)
  1185. desc-1))
  1186. desc)))
  1187. (setq rpl
  1188. (if
  1189. (and
  1190. (functionp link-validate)
  1191. (not (funcall link-validate path-1 current-dir)))
  1192. desc
  1193. (org-html-make-link opt-plist
  1194. "file" path-1 fragment-1 desc-2 attr
  1195. (org-html-should-inline-p path-1 descp)))))))
  1196. (t
  1197. ;; just publish the path, as default
  1198. (setq rpl (concat "<i>&lt;" type ":"
  1199. (save-match-data (org-link-unescape path))
  1200. "&gt;</i>"))))
  1201. (setq line (replace-match rpl t t line)
  1202. start (+ start (length rpl))))
  1203. ;; TODO items
  1204. (if (and (string-match org-todo-line-regexp line)
  1205. (match-beginning 2))
  1206. (setq line
  1207. (concat (substring line 0 (match-beginning 2))
  1208. "<span class=\""
  1209. (if (member (match-string 2 line)
  1210. org-done-keywords)
  1211. "done" "todo")
  1212. " " (match-string 2 line)
  1213. "\"> " (org-export-html-get-todo-kwd-class-name
  1214. (match-string 2 line))
  1215. "</span>" (substring line (match-end 2)))))
  1216. ;; Does this contain a reference to a footnote?
  1217. (when org-export-with-footnotes
  1218. (setq start 0)
  1219. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
  1220. (if (get-text-property (match-beginning 2) 'org-protected line)
  1221. (setq start (match-end 2))
  1222. (let ((n (match-string 2 line)) extra a)
  1223. (if (setq a (assoc n footref-seen))
  1224. (progn
  1225. (setcdr a (1+ (cdr a)))
  1226. (setq extra (format ".%d" (cdr a))))
  1227. (setq extra "")
  1228. (push (cons n 1) footref-seen))
  1229. (setq line
  1230. (replace-match
  1231. (format
  1232. (concat "%s"
  1233. (format org-export-html-footnote-format
  1234. "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"))
  1235. (or (match-string 1 line) "") n extra n n)
  1236. t t line))))))
  1237. (cond
  1238. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  1239. ;; This is a headline
  1240. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
  1241. level-offset))
  1242. txt (match-string 2 line))
  1243. (if (string-match quote-re0 txt)
  1244. (setq txt (replace-match "" t t txt)))
  1245. (if (<= level (max umax umax-toc))
  1246. (setq head-count (+ head-count 1)))
  1247. (when in-local-list
  1248. ;; Close any local lists before inserting a new header line
  1249. (while local-list-type
  1250. (org-close-li (car local-list-type))
  1251. (insert (format "</%sl>\n" (car local-list-type)))
  1252. (pop local-list-type))
  1253. (setq local-list-indent nil
  1254. in-local-list nil))
  1255. (setq first-heading-pos (or first-heading-pos (point)))
  1256. (org-html-level-start level txt umax
  1257. (and org-export-with-toc (<= level umax))
  1258. head-count)
  1259. ;; QUOTES
  1260. (when (string-match quote-re line)
  1261. (org-close-par-maybe)
  1262. (insert "<pre>")
  1263. (setq inquote t)))
  1264. ((string-match "^[ \t]*- __+[ \t]*$" line)
  1265. ;; Explicit list closure
  1266. (when local-list-type
  1267. (let ((ind (org-get-indentation line)))
  1268. (while (and local-list-indent
  1269. (<= ind (car local-list-indent)))
  1270. (org-close-li (car local-list-type))
  1271. (insert (format "</%sl>\n" (car local-list-type)))
  1272. (pop local-list-type)
  1273. (pop local-list-indent))
  1274. (or local-list-indent (setq in-local-list nil))))
  1275. (throw 'nextline nil))
  1276. ((and org-export-with-tables
  1277. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  1278. (when (not table-open)
  1279. ;; New table starts
  1280. (setq table-open t table-buffer nil table-orig-buffer nil))
  1281. ;; Accumulate lines
  1282. (setq table-buffer (cons line table-buffer)
  1283. table-orig-buffer (cons origline table-orig-buffer))
  1284. (when (or (not lines)
  1285. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  1286. (car lines))))
  1287. (setq table-open nil
  1288. table-buffer (nreverse table-buffer)
  1289. table-orig-buffer (nreverse table-orig-buffer))
  1290. (org-close-par-maybe)
  1291. (insert (org-format-table-html table-buffer table-orig-buffer))))
  1292. (t
  1293. ;; Normal lines
  1294. (when (string-match
  1295. (cond
  1296. ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  1297. ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  1298. ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  1299. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
  1300. line)
  1301. (setq ind (or (get-text-property 0 'original-indentation line)
  1302. (org-get-string-indentation line))
  1303. item-type (if (match-beginning 4) "o" "u")
  1304. starter (if (match-beginning 2)
  1305. (substring (match-string 2 line) 0 -1))
  1306. line (substring line (match-beginning 5))
  1307. initial-number nil
  1308. item-tag nil)
  1309. (if (string-match "\\`\\[@start:\\([0-9]+\\)\\][ \t]?" line)
  1310. (setq initial-number (match-string 1 line)
  1311. line (replace-match "" t t line)))
  1312. (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
  1313. (setq item-type "d"
  1314. item-tag (match-string 1 line)
  1315. line (substring line (match-end 0))))
  1316. (when (and (not (equal item-type "d"))
  1317. (not (string-match "[^ \t]" line)))
  1318. ;; empty line. Pretend indentation is large.
  1319. (setq ind (if org-empty-line-terminates-plain-lists
  1320. 0
  1321. (1+ (or (car local-list-indent) 1)))))
  1322. (setq didclose nil)
  1323. (while (and in-local-list
  1324. (or (and (= ind (car local-list-indent))
  1325. (not starter))
  1326. (< ind (car local-list-indent))))
  1327. (setq didclose t)
  1328. (org-close-li (car local-list-type))
  1329. (insert (format "</%sl>\n" (car local-list-type)))
  1330. (pop local-list-type) (pop local-list-indent)
  1331. (setq in-local-list local-list-indent))
  1332. (cond
  1333. ((and starter
  1334. (or (not in-local-list)
  1335. (> ind (car local-list-indent))))
  1336. ;; check for a specified start number
  1337. ;; Start new (level of) list
  1338. (org-close-par-maybe)
  1339. (insert (cond
  1340. ((equal item-type "u") "<ul>\n<li>\n")
  1341. ((equal item-type "o")
  1342. (if initial-number
  1343. (format "<ol start=%s>\n<li>\n" initial-number)
  1344. "<ol>\n<li>\n"))
  1345. ((equal item-type "d")
  1346. (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
  1347. (push item-type local-list-type)
  1348. (push ind local-list-indent)
  1349. (setq in-local-list t))
  1350. (starter
  1351. ;; continue current list
  1352. (org-close-li (car local-list-type))
  1353. (insert (cond
  1354. ((equal (car local-list-type) "d")
  1355. (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
  1356. (t "<li>\n"))))
  1357. (didclose
  1358. ;; we did close a list, normal text follows: need <p>
  1359. (org-open-par)))
  1360. (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
  1361. (setq line
  1362. (replace-match
  1363. (if (equal (match-string 1 line) "X")
  1364. "<b>[X]</b>"
  1365. "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
  1366. t t line))))
  1367. ;; Horizontal line
  1368. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
  1369. (if org-par-open
  1370. (insert "\n</p>\n<hr/>\n<p>\n")
  1371. (insert "\n<hr/>\n"))
  1372. (throw 'nextline nil))
  1373. ;; Empty lines start a new paragraph. If hand-formatted lists
  1374. ;; are not fully interpreted, lines starting with "-", "+", "*"
  1375. ;; also start a new paragraph.
  1376. (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
  1377. ;; Is this the start of a footnote?
  1378. (when org-export-with-footnotes
  1379. (when (and (boundp 'footnote-section-tag-regexp)
  1380. (string-match (concat "^" footnote-section-tag-regexp)
  1381. line))
  1382. ;; ignore this line
  1383. (throw 'nextline nil))
  1384. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
  1385. (org-close-par-maybe)
  1386. (let ((n (match-string 1 line)))
  1387. (setq org-par-open t
  1388. line (replace-match
  1389. (format
  1390. (concat "<p class=\"footnote\">"
  1391. (format org-export-html-footnote-format
  1392. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
  1393. n n n) t t line)))))
  1394. ;; Check if the line break needs to be conserved
  1395. (cond
  1396. ((string-match "\\\\\\\\[ \t]*$" line)
  1397. (setq line (replace-match "<br/>" t t line)))
  1398. (org-export-preserve-breaks
  1399. (setq line (concat line "<br/>"))))
  1400. ;; Check if a paragraph should be started
  1401. (let ((start 0))
  1402. (while (and org-par-open
  1403. (string-match "\\\\par\\>" line start))
  1404. ;; Leave a space in the </p> so that the footnote matcher
  1405. ;; does not see this.
  1406. (if (not (get-text-property (match-beginning 0)
  1407. 'org-protected line))
  1408. (setq line (replace-match "</p ><p >" t t line)))
  1409. (setq start (match-end 0))))
  1410. (insert line "\n")))))
  1411. ;; Properly close all local lists and other lists
  1412. (when inquote
  1413. (insert "</pre>\n")
  1414. (org-open-par))
  1415. (when in-local-list
  1416. ;; Close any local lists before inserting a new header line
  1417. (while local-list-type
  1418. (org-close-li (car local-list-type))
  1419. (insert (format "</%sl>\n" (car local-list-type)))
  1420. (pop local-list-type))
  1421. (setq local-list-indent nil
  1422. in-local-list nil))
  1423. (org-html-level-start 1 nil umax
  1424. (and org-export-with-toc (<= level umax))
  1425. head-count)
  1426. ;; the </div> to close the last text-... div.
  1427. (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
  1428. (save-excursion
  1429. (goto-char (point-min))
  1430. (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
  1431. (push (match-string 0) footnotes)
  1432. (replace-match "" t t)))
  1433. (when footnotes
  1434. (insert (format org-export-html-footnotes-section
  1435. (nth 4 lang-words)
  1436. (mapconcat 'identity (nreverse footnotes) "\n"))
  1437. "\n"))
  1438. (let ((bib (org-export-html-get-bibliography)))
  1439. (when bib
  1440. (insert "\n" bib "\n")))
  1441. (unless body-only
  1442. (when (plist-get opt-plist :auto-postamble)
  1443. (insert "<div id=\"postamble\">\n")
  1444. (when (and org-export-author-info author)
  1445. (insert "<p class=\"author\"> "
  1446. (nth 1 lang-words) ": " author "\n")
  1447. (when (and org-export-email-info email (string-match "\\S-" email))
  1448. (if (listp (split-string email ",+ *"))
  1449. (mapc (lambda(e)
  1450. (insert "<a href=\"mailto:" e "\">&lt;"
  1451. e "&gt;</a>\n"))
  1452. (split-string email ",+ *"))
  1453. (insert "<a href=\"mailto:" email "\">&lt;"
  1454. email "&gt;</a>\n")))
  1455. (insert "</p>\n"))
  1456. (when (and date org-export-time-stamp-file)
  1457. (insert "<p class=\"date\"> "
  1458. (nth 2 lang-words) ": "
  1459. date "</p>\n"))
  1460. (when org-export-creator-info
  1461. (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
  1462. org-version emacs-major-version)))
  1463. (when org-export-html-validation-link
  1464. (insert org-export-html-validation-link "\n"))
  1465. (insert "</div>"))
  1466. (if org-export-html-with-timestamp
  1467. (insert org-export-html-html-helper-timestamp))
  1468. (org-export-html-insert-plist-item opt-plist :postamble opt-plist)
  1469. (insert "\n</div>\n</body>\n</html>\n"))
  1470. (unless (plist-get opt-plist :buffer-will-be-killed)
  1471. (normal-mode)
  1472. (if (eq major-mode (default-value 'major-mode))
  1473. (html-mode)))
  1474. ;; insert the table of contents
  1475. (goto-char (point-min))
  1476. (when thetoc
  1477. (if (or (re-search-forward
  1478. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  1479. (re-search-forward
  1480. "\\[TABLE-OF-CONTENTS\\]" nil t))
  1481. (progn
  1482. (goto-char (match-beginning 0))
  1483. (replace-match ""))
  1484. (goto-char first-heading-pos)
  1485. (when (looking-at "\\s-*</p>")
  1486. (goto-char (match-end 0))
  1487. (insert "\n")))
  1488. (insert "<div id=\"table-of-contents\">\n")
  1489. (mapc 'insert thetoc)
  1490. (insert "</div>\n"))
  1491. ;; remove empty paragraphs and lists
  1492. (goto-char (point-min))
  1493. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  1494. (replace-match ""))
  1495. (goto-char (point-min))
  1496. (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
  1497. (replace-match ""))
  1498. (goto-char (point-min))
  1499. (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
  1500. (replace-match ""))
  1501. ;; Convert whitespace place holders
  1502. (goto-char (point-min))
  1503. (let (beg end n)
  1504. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  1505. (setq n (get-text-property beg 'org-whitespace)
  1506. end (next-single-property-change beg 'org-whitespace))
  1507. (goto-char beg)
  1508. (delete-region beg end)
  1509. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  1510. (make-string n ?x)))))
  1511. ;; Remove empty lines at the beginning of the file.
  1512. (goto-char (point-min))
  1513. (when (looking-at "\\s-+\n") (replace-match ""))
  1514. ;; Remove display properties
  1515. (remove-text-properties (point-min) (point-max) '(display t))
  1516. ;; Run the hook
  1517. (run-hooks 'org-export-html-final-hook)
  1518. (or to-buffer (save-buffer))
  1519. (goto-char (point-min))
  1520. (or (org-export-push-to-kill-ring "HTML")
  1521. (message "Exporting... done"))
  1522. (if (eq to-buffer 'string)
  1523. (prog1 (buffer-substring (point-min) (point-max))
  1524. (kill-buffer (current-buffer)))
  1525. (current-buffer)))))
  1526. (defun org-export-html-insert-plist-item (plist key &rest args)
  1527. (let ((item (plist-get plist key)))
  1528. (cond ((functionp item)
  1529. (apply item args))
  1530. (item
  1531. (insert item)))))
  1532. (defun org-export-html-format-href (s)
  1533. "Make sure the S is valid as a href reference in an XHTML document."
  1534. (save-match-data
  1535. (let ((start 0))
  1536. (while (string-match "&" s start)
  1537. (setq start (+ (match-beginning 0) 3)
  1538. s (replace-match "&amp;" t t s)))))
  1539. s)
  1540. (defun org-export-html-format-desc (s)
  1541. "Make sure the S is valid as a description in a link."
  1542. (if (and s (not (get-text-property 1 'org-protected s)))
  1543. (save-match-data
  1544. (org-html-do-expand s))
  1545. s))
  1546. (defun org-export-html-format-image (src par-open)
  1547. "Create image tag with source and attributes."
  1548. (save-match-data
  1549. (if (string-match "^ltxpng/" src)
  1550. (format "<img src=\"%s\" alt=\"%s\"/>"
  1551. src (org-find-text-property-in-string 'org-latex-src src))
  1552. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  1553. (attr (org-find-text-property-in-string 'org-attributes src))
  1554. (label (org-find-text-property-in-string 'org-label src)))
  1555. (setq caption (and caption (org-html-do-expand caption)))
  1556. (concat
  1557. (if caption
  1558. (format "%s<div %sclass=\"figure\">
  1559. <p>"
  1560. (if org-par-open "</p>\n" "")
  1561. (if label (format "id=\"%s\" " label) "")))
  1562. (format "<img src=\"%s\"%s />"
  1563. src
  1564. (if (string-match "\\<alt=" (or attr ""))
  1565. (concat " " attr )
  1566. (concat " " attr " alt=\"" src "\"")))
  1567. (if caption
  1568. (format "</p>%s
  1569. </div>%s"
  1570. (concat "\n<p>" caption "</p>")
  1571. (if org-par-open "\n<p>" ""))))))))
  1572. (defun org-export-html-get-bibliography ()
  1573. "Find bibliography, cut it out and return it."
  1574. (catch 'exit
  1575. (let (beg end (cnt 1) bib)
  1576. (save-excursion
  1577. (goto-char (point-min))
  1578. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  1579. (setq beg (match-beginning 0))
  1580. (while (re-search-forward "</?div\\>" nil t)
  1581. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  1582. (when (= cnt 0)
  1583. (and (looking-at ">") (forward-char 1))
  1584. (setq bib (buffer-substring beg (point)))
  1585. (delete-region beg (point))
  1586. (throw 'exit bib))))
  1587. nil))))
  1588. (defvar org-table-number-regexp) ; defined in org-table.el
  1589. (defun org-format-table-html (lines olines)
  1590. "Find out which HTML converter to use and return the HTML code."
  1591. (if (stringp lines)
  1592. (setq lines (org-split-string lines "\n")))
  1593. (if (string-match "^[ \t]*|" (car lines))
  1594. ;; A normal org table
  1595. (org-format-org-table-html lines)
  1596. ;; Table made by table.el - test for spanning
  1597. (let* ((hlines (delq nil (mapcar
  1598. (lambda (x)
  1599. (if (string-match "^[ \t]*\\+-" x) x
  1600. nil))
  1601. lines)))
  1602. (first (car hlines))
  1603. (ll (and (string-match "\\S-+" first)
  1604. (match-string 0 first)))
  1605. (re (concat "^[ \t]*" (regexp-quote ll)))
  1606. (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
  1607. hlines))))
  1608. (if (and (not spanning)
  1609. (not org-export-prefer-native-exporter-for-tables))
  1610. ;; We can use my own converter with HTML conversions
  1611. (org-format-table-table-html lines)
  1612. ;; Need to use the code generator in table.el, with the original text.
  1613. (org-format-table-table-html-using-table-generate-source olines)))))
  1614. (defvar org-table-number-fraction) ; defined in org-table.el
  1615. (defun org-format-org-table-html (lines &optional splice)
  1616. "Format a table into HTML."
  1617. (require 'org-table)
  1618. ;; Get rid of hlines at beginning and end
  1619. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1620. (setq lines (nreverse lines))
  1621. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1622. (setq lines (nreverse lines))
  1623. (when org-export-table-remove-special-lines
  1624. ;; Check if the table has a marking column. If yes remove the
  1625. ;; column and the special lines
  1626. (setq lines (org-table-clean-before-export lines)))
  1627. (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
  1628. (label (org-find-text-property-in-string 'org-label (car lines)))
  1629. (attributes (org-find-text-property-in-string 'org-attributes
  1630. (car lines)))
  1631. (html-table-tag (org-export-splice-attributes
  1632. html-table-tag attributes))
  1633. (head (and org-export-highlight-first-table-line
  1634. (delq nil (mapcar
  1635. (lambda (x) (string-match "^[ \t]*|-" x))
  1636. (cdr lines)))))
  1637. (nline 0) fnum nfields i
  1638. tbopen line fields html gr colgropen rowstart rowend)
  1639. (setq caption (and caption (org-html-do-expand caption)))
  1640. (if splice (setq head nil))
  1641. (unless splice (push (if head "<thead>" "<tbody>") html))
  1642. (setq tbopen t)
  1643. (while (setq line (pop lines))
  1644. (catch 'next-line
  1645. (if (string-match "^[ \t]*|-" line)
  1646. (progn
  1647. (unless splice
  1648. (push (if head "</thead>" "</tbody>") html)
  1649. (if lines (push "<tbody>" html) (setq tbopen nil)))
  1650. (setq head nil) ;; head ends here, first time around
  1651. ;; ignore this line
  1652. (throw 'next-line t)))
  1653. ;; Break the line into fields
  1654. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1655. (unless fnum (setq fnum (make-vector (length fields) 0)
  1656. nfields (length fnum)))
  1657. (setq nline (1+ nline) i -1
  1658. rowstart (eval (car org-export-table-row-tags))
  1659. rowend (eval (cdr org-export-table-row-tags)))
  1660. (push (concat rowstart
  1661. (mapconcat
  1662. (lambda (x)
  1663. (setq i (1+ i))
  1664. (if (and (< i nfields) ; make sure no rogue line causes an error here
  1665. (string-match org-table-number-regexp x))
  1666. (incf (aref fnum i)))
  1667. (cond
  1668. (head
  1669. (concat
  1670. (format (car org-export-table-header-tags) "col")
  1671. x
  1672. (cdr org-export-table-header-tags)))
  1673. ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
  1674. (concat
  1675. (format (car org-export-table-header-tags) "row")
  1676. x
  1677. (cdr org-export-table-header-tags)))
  1678. (t
  1679. (concat (car org-export-table-data-tags) x
  1680. (cdr org-export-table-data-tags)))))
  1681. fields "")
  1682. rowend)
  1683. html)))
  1684. (unless splice (if tbopen (push "</tbody>" html)))
  1685. (unless splice (push "</table>\n" html))
  1686. (setq html (nreverse html))
  1687. (unless splice
  1688. ;; Put in col tags with the alignment (unfortunately often ignored...)
  1689. (unless (car org-table-colgroup-info)
  1690. (setq org-table-colgroup-info
  1691. (cons :start (cdr org-table-colgroup-info))))
  1692. (push (mapconcat
  1693. (lambda (x)
  1694. (setq gr (pop org-table-colgroup-info))
  1695. (format "%s<col align=\"%s\" />%s"
  1696. (if (memq gr '(:start :startend))
  1697. (prog1
  1698. (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
  1699. (setq colgropen t))
  1700. "")
  1701. (if (> (/ (float x) nline) org-table-number-fraction)
  1702. "right" "left")
  1703. (if (memq gr '(:end :startend))
  1704. (progn (setq colgropen nil) "</colgroup>")
  1705. "")))
  1706. fnum "")
  1707. html)
  1708. (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
  1709. ;; Since the output of HTML table formatter can also be used in
  1710. ;; DocBook document, we want to always include the caption to make
  1711. ;; DocBook XML file valid.
  1712. (push (format "<caption>%s</caption>" (or caption "")) html)
  1713. (when label (push (format "<a name=\"%s\" id=\"%s\"></a>" label label)
  1714. html))
  1715. (push html-table-tag html))
  1716. (concat (mapconcat 'identity html "\n") "\n")))
  1717. (defun org-export-splice-attributes (tag attributes)
  1718. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  1719. (if (not attributes)
  1720. tag
  1721. (let (oldatt newatt)
  1722. (setq oldatt (org-extract-attributes-from-string tag)
  1723. tag (pop oldatt)
  1724. newatt (cdr (org-extract-attributes-from-string attributes)))
  1725. (while newatt
  1726. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  1727. (if (string-match ">" tag)
  1728. (setq tag
  1729. (replace-match (concat (org-attributes-to-string oldatt) ">")
  1730. t t tag)))
  1731. tag)))
  1732. (defun org-format-table-table-html (lines)
  1733. "Format a table generated by table.el into HTML.
  1734. This conversion does *not* use `table-generate-source' from table.el.
  1735. This has the advantage that Org-mode's HTML conversions can be used.
  1736. But it has the disadvantage, that no cell- or row-spanning is allowed."
  1737. (let (line field-buffer
  1738. (head org-export-highlight-first-table-line)
  1739. fields html empty i)
  1740. (setq html (concat html-table-tag "\n"))
  1741. (while (setq line (pop lines))
  1742. (setq empty "&nbsp;")
  1743. (catch 'next-line
  1744. (if (string-match "^[ \t]*\\+-" line)
  1745. (progn
  1746. (if field-buffer
  1747. (progn
  1748. (setq
  1749. html
  1750. (concat
  1751. html
  1752. "<tr>"
  1753. (mapconcat
  1754. (lambda (x)
  1755. (if (equal x "") (setq x empty))
  1756. (if head
  1757. (concat
  1758. (format (car org-export-table-header-tags) "col")
  1759. x
  1760. (cdr org-export-table-header-tags))
  1761. (concat (car org-export-table-data-tags) x
  1762. (cdr org-export-table-data-tags))))
  1763. field-buffer "\n")
  1764. "</tr>\n"))
  1765. (setq head nil)
  1766. (setq field-buffer nil)))
  1767. ;; Ignore this line
  1768. (throw 'next-line t)))
  1769. ;; Break the line into fields and store the fields
  1770. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1771. (if field-buffer
  1772. (setq field-buffer (mapcar
  1773. (lambda (x)
  1774. (concat x "<br/>" (pop fields)))
  1775. field-buffer))
  1776. (setq field-buffer fields))))
  1777. (setq html (concat html "</table>\n"))
  1778. html))
  1779. (defun org-format-table-table-html-using-table-generate-source (lines)
  1780. "Format a table into html, using `table-generate-source' from table.el.
  1781. This has the advantage that cell- or row-spanning is allowed.
  1782. But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
  1783. (require 'table)
  1784. (with-current-buffer (get-buffer-create " org-tmp1 ")
  1785. (erase-buffer)
  1786. (insert (mapconcat 'identity lines "\n"))
  1787. (goto-char (point-min))
  1788. (if (not (re-search-forward "|[^+]" nil t))
  1789. (error "Error processing table"))
  1790. (table-recognize-table)
  1791. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  1792. (table-generate-source 'html " org-tmp2 ")
  1793. (set-buffer " org-tmp2 ")
  1794. (buffer-substring (point-min) (point-max))))
  1795. (defun org-export-splice-style (style extra)
  1796. "Splice EXTRA into STYLE, just before \"</style>\"."
  1797. (if (and (stringp extra)
  1798. (string-match "\\S-" extra)
  1799. (string-match "</style>" style))
  1800. (concat (substring style 0 (match-beginning 0))
  1801. "\n" extra "\n"
  1802. (substring style (match-beginning 0)))
  1803. style))
  1804. (defun org-html-handle-time-stamps (s)
  1805. "Format time stamps in string S, or remove them."
  1806. (catch 'exit
  1807. (let (r b)
  1808. (while (string-match org-maybe-keyword-time-regexp s)
  1809. (or b (setq b (substring s 0 (match-beginning 0))))
  1810. (setq r (concat
  1811. r (substring s 0 (match-beginning 0))
  1812. " @<span class=\"timestamp-wrapper\">"
  1813. (if (match-end 1)
  1814. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  1815. (match-string 1 s)))
  1816. (format " @<span class=\"timestamp\">%s@</span>"
  1817. (substring
  1818. (org-translate-time (match-string 3 s)) 1 -1))
  1819. "@</span>")
  1820. s (substring s (match-end 0))))
  1821. ;; Line break if line started and ended with time stamp stuff
  1822. (if (not r)
  1823. s
  1824. (setq r (concat r s))
  1825. (unless (string-match "\\S-" (concat b s))
  1826. (setq r (concat r "@<br/>")))
  1827. r))))
  1828. (defvar htmlize-buffer-places) ; from htmlize.el
  1829. (defun org-export-htmlize-region-for-paste (beg end)
  1830. "Convert the region to HTML, using htmlize.el.
  1831. This is much like `htmlize-region-for-paste', only that it uses
  1832. the settings define in the org-... variables."
  1833. (let* ((htmlize-output-type org-export-htmlize-output-type)
  1834. (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
  1835. (htmlbuf (htmlize-region beg end)))
  1836. (unwind-protect
  1837. (with-current-buffer htmlbuf
  1838. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  1839. (plist-get htmlize-buffer-places 'content-end)))
  1840. (kill-buffer htmlbuf))))
  1841. ;;;###autoload
  1842. (defun org-export-htmlize-generate-css ()
  1843. "Create the CSS for all font definitions in the current Emacs session.
  1844. Use this to create face definitions in your CSS style file that can then
  1845. be used by code snippets transformed by htmlize.
  1846. This command just produces a buffer that contains class definitions for all
  1847. faces used in the current Emacs session. You can copy and paste the ones you
  1848. need into your CSS file.
  1849. If you then set `org-export-htmlize-output-type' to `css', calls to
  1850. the function `org-export-htmlize-region-for-paste' will produce code
  1851. that uses these same face definitions."
  1852. (interactive)
  1853. (require 'htmlize)
  1854. (and (get-buffer "*html*") (kill-buffer "*html*"))
  1855. (with-temp-buffer
  1856. (let ((fl (face-list))
  1857. (htmlize-css-name-prefix "org-")
  1858. (htmlize-output-type 'css)
  1859. f i)
  1860. (while (setq f (pop fl)
  1861. i (and f (face-attribute f :inherit)))
  1862. (when (and (symbolp f) (or (not i) (not (listp i))))
  1863. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  1864. (htmlize-region (point-min) (point-max))))
  1865. (switch-to-buffer "*html*")
  1866. (goto-char (point-min))
  1867. (if (re-search-forward "<style" nil t)
  1868. (delete-region (point-min) (match-beginning 0)))
  1869. (if (re-search-forward "</style>" nil t)
  1870. (delete-region (1+ (match-end 0)) (point-max)))
  1871. (beginning-of-line 1)
  1872. (if (looking-at " +") (replace-match ""))
  1873. (goto-char (point-min)))
  1874. (defun org-html-protect (s)
  1875. "convert & to &amp;, < to &lt; and > to &gt;"
  1876. (let ((start 0))
  1877. (while (string-match "&" s start)
  1878. (setq s (replace-match "&amp;" t t s)
  1879. start (1+ (match-beginning 0))))
  1880. (while (string-match "<" s)
  1881. (setq s (replace-match "&lt;" t t s)))
  1882. (while (string-match ">" s)
  1883. (setq s (replace-match "&gt;" t t s)))
  1884. ; (while (string-match "\"" s)
  1885. ; (setq s (replace-match "&quot;" t t s)))
  1886. )
  1887. s)
  1888. (defun org-html-expand (string)
  1889. "Prepare STRING for HTML export. Apply all active conversions.
  1890. If there are links in the string, don't modify these."
  1891. (let* ((re (concat org-bracket-link-regexp "\\|"
  1892. (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
  1893. m s l res)
  1894. (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string)
  1895. string
  1896. (while (setq m (string-match re string))
  1897. (setq s (substring string 0 m)
  1898. l (match-string 0 string)
  1899. string (substring string (match-end 0)))
  1900. (push (org-html-do-expand s) res)
  1901. (push l res))
  1902. (push (org-html-do-expand string) res)
  1903. (apply 'concat (nreverse res)))))
  1904. (defun org-html-do-expand (s)
  1905. "Apply all active conversions to translate special ASCII to HTML."
  1906. (setq s (org-html-protect s))
  1907. (if org-export-html-expand
  1908. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  1909. (setq s (replace-match "<\\1>" t nil s))))
  1910. (if org-export-with-emphasize
  1911. (setq s (org-export-html-convert-emphasize s)))
  1912. (if org-export-with-special-strings
  1913. (setq s (org-export-html-convert-special-strings s)))
  1914. (if org-export-with-sub-superscripts
  1915. (setq s (org-export-html-convert-sub-super s)))
  1916. (if org-export-with-TeX-macros
  1917. (let ((start 0) wd rep)
  1918. (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
  1919. s start))
  1920. (if (get-text-property (match-beginning 0) 'org-protected s)
  1921. (setq start (match-end 0))
  1922. (setq wd (match-string 1 s))
  1923. (if (setq rep (org-entity-get-representation wd 'html))
  1924. (setq s (replace-match rep t t s))
  1925. (setq start (+ start (length wd))))))))
  1926. s)
  1927. (defun org-export-html-convert-special-strings (string)
  1928. "Convert special characters in STRING to HTML."
  1929. (let ((all org-export-html-special-string-regexps)
  1930. e a re rpl start)
  1931. (while (setq a (pop all))
  1932. (setq re (car a) rpl (cdr a) start 0)
  1933. (while (string-match re string start)
  1934. (if (get-text-property (match-beginning 0) 'org-protected string)
  1935. (setq start (match-end 0))
  1936. (setq string (replace-match rpl t nil string)))))
  1937. string))
  1938. (defun org-export-html-convert-sub-super (string)
  1939. "Convert sub- and superscripts in STRING to HTML."
  1940. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  1941. (while (string-match org-match-substring-regexp string s)
  1942. (cond
  1943. ((and requireb (match-end 8)) (setq s (match-end 2)))
  1944. ((get-text-property (match-beginning 2) 'org-protected string)
  1945. (setq s (match-end 2)))
  1946. (t
  1947. (setq s (match-end 1)
  1948. key (if (string= (match-string 2 string) "_") "sub" "sup")
  1949. c (or (match-string 8 string)
  1950. (match-string 6 string)
  1951. (match-string 5 string))
  1952. string (replace-match
  1953. (concat (match-string 1 string)
  1954. "<" key ">" c "</" key ">")
  1955. t t string)))))
  1956. (while (string-match "\\\\\\([_^]\\)" string)
  1957. (setq string (replace-match (match-string 1 string) t t string)))
  1958. string))
  1959. (defun org-export-html-convert-emphasize (string)
  1960. "Apply emphasis."
  1961. (let ((s 0) rpl)
  1962. (while (string-match org-emph-re string s)
  1963. (if (not (equal
  1964. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  1965. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  1966. (setq s (match-beginning 0)
  1967. rpl
  1968. (concat
  1969. (match-string 1 string)
  1970. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  1971. (match-string 4 string)
  1972. (nth 3 (assoc (match-string 3 string)
  1973. org-emphasis-alist))
  1974. (match-string 5 string))
  1975. string (replace-match rpl t t string)
  1976. s (+ s (- (length rpl) 2)))
  1977. (setq s (1+ s))))
  1978. string))
  1979. (defun org-open-par ()
  1980. "Insert <p>, but first close previous paragraph if any."
  1981. (org-close-par-maybe)
  1982. (insert "\n<p>")
  1983. (setq org-par-open t))
  1984. (defun org-close-par-maybe ()
  1985. "Close paragraph if there is one open."
  1986. (when org-par-open
  1987. (insert "</p>")
  1988. (setq org-par-open nil)))
  1989. (defun org-close-li (&optional type)
  1990. "Close <li> if necessary."
  1991. (org-close-par-maybe)
  1992. (insert (if (equal type "d") "</dd>\n" "</li>\n")))
  1993. (defvar in-local-list)
  1994. (defvar local-list-indent)
  1995. (defvar local-list-type)
  1996. (defun org-export-html-close-lists-maybe (line)
  1997. "Close local lists based on the original indentation of the line."
  1998. (let* ((rawhtml (and in-local-list
  1999. (get-text-property 0 'org-protected line)
  2000. (not (get-text-property 0 'org-example line))))
  2001. ;; rawhtml means: This was between #+begin_html..#+end_html
  2002. ;; originally, thus it excludes stuff that was a source code example
  2003. ;; Actually, this code seems wrong, I don't know why it works, but
  2004. ;; it seems to work.... So keep it like this for now.
  2005. (ind (if rawhtml
  2006. (org-get-indentation line)
  2007. (get-text-property 0 'original-indentation line)))
  2008. didclose)
  2009. (when ind
  2010. (while (and in-local-list
  2011. (<= ind (car local-list-indent)))
  2012. (setq didclose t)
  2013. (org-close-li (car local-list-type))
  2014. (insert (format "</%sl>\n" (car local-list-type)))
  2015. (pop local-list-type) (pop local-list-indent)
  2016. (setq in-local-list local-list-indent))
  2017. (and didclose (org-open-par)))))
  2018. (defvar body-only) ; dynamically scoped into this.
  2019. (defun org-html-level-start (level title umax with-toc head-count)
  2020. "Insert a new level in HTML export.
  2021. When TITLE is nil, just close all open levels."
  2022. (org-close-par-maybe)
  2023. (let* ((target (and title (org-get-text-property-any 0 'target title)))
  2024. (extra-targets (and target
  2025. (assoc target org-export-target-aliases)))
  2026. (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
  2027. (preferred (and target
  2028. (cdr (assoc target org-export-preferred-target-alist))))
  2029. (remove (or preferred target))
  2030. (l org-level-max)
  2031. snumber snu href suffix)
  2032. (setq extra-targets (remove remove extra-targets))
  2033. (setq extra-targets
  2034. (mapconcat (lambda (x)
  2035. (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
  2036. (format "<a name=\"%s\" id=\"%s\"></a>"
  2037. x x))
  2038. extra-targets
  2039. ""))
  2040. (while (>= l level)
  2041. (if (aref org-levels-open (1- l))
  2042. (progn
  2043. (org-html-level-close l umax)
  2044. (aset org-levels-open (1- l) nil)))
  2045. (setq l (1- l)))
  2046. (when title
  2047. ;; If title is nil, this means this function is called to close
  2048. ;; all levels, so the rest is done only if title is given
  2049. (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  2050. (setq title (replace-match
  2051. (if org-export-with-tags
  2052. (save-match-data
  2053. (concat
  2054. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  2055. (mapconcat
  2056. (lambda (x)
  2057. (format "<span class=\"%s\">%s</span>"
  2058. (org-export-html-get-tag-class-name x)
  2059. x))
  2060. (org-split-string (match-string 1 title) ":")
  2061. "&nbsp;")
  2062. "</span>"))
  2063. "")
  2064. t t title)))
  2065. (if (> level umax)
  2066. (progn
  2067. (if (aref org-levels-open (1- level))
  2068. (progn
  2069. (org-close-li)
  2070. (if target
  2071. (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
  2072. (insert "<li>" title "<br/>\n")))
  2073. (aset org-levels-open (1- level) t)
  2074. (org-close-par-maybe)
  2075. (if target
  2076. (insert (format "<ul>\n<li id=\"%s\">" target)
  2077. extra-targets title "<br/>\n")
  2078. (insert "<ul>\n<li>" title "<br/>\n"))))
  2079. (aset org-levels-open (1- level) t)
  2080. (setq snumber (org-section-number level)
  2081. snu (replace-regexp-in-string "\\." "_" snumber))
  2082. (setq level (+ level org-export-html-toplevel-hlevel -1))
  2083. (if (and org-export-with-section-numbers (not body-only))
  2084. (setq title (concat
  2085. (format "<span class=\"section-number-%d\">%s</span>"
  2086. level snumber)
  2087. " " title)))
  2088. (unless (= head-count 1) (insert "\n</div>\n"))
  2089. (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
  2090. (setq suffix (or href snu))
  2091. (setq href (or href (concat "sec-" snu)))
  2092. (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"
  2093. suffix level (if extra-class (concat " " extra-class) "")
  2094. level href
  2095. extra-targets
  2096. title level level suffix))
  2097. (org-open-par)))))
  2098. (defun org-export-html-get-tag-class-name (tag)
  2099. "Turn tag into a valid class name.
  2100. Replaces invalid characters with \"_\" and then prepends a prefix."
  2101. (save-match-data
  2102. (while (string-match "[^a-zA-Z0-9_]" tag)
  2103. (setq tag (replace-match "_" t t tag))))
  2104. (concat org-export-html-tag-class-prefix tag))
  2105. (defun org-export-html-get-todo-kwd-class-name (kwd)
  2106. "Turn todo keyword into a valid class name.
  2107. Replaces invalid characters with \"_\" and then prepends a prefix."
  2108. (save-match-data
  2109. (while (string-match "[^a-zA-Z0-9_]" kwd)
  2110. (setq kwd (replace-match "_" t t kwd))))
  2111. (concat org-export-html-todo-kwd-class-prefix kwd))
  2112. (defun org-html-level-close (level max-outline-level)
  2113. "Terminate one level in HTML export."
  2114. (if (<= level max-outline-level)
  2115. (insert "</div>\n")
  2116. (org-close-li)
  2117. (insert "</ul>\n")))
  2118. (provide 'org-html)
  2119. ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
  2120. ;;; org-html.el ends here