org-html.el 79 KB

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