org-html.el 79 KB

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