org-html.el 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278
  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. (org-string-match-p "^//" 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. ;; Make an image out of the description if that is so wanted
  1069. (when (and descp (org-file-image-p
  1070. desc org-export-html-inline-image-extensions))
  1071. (save-match-data
  1072. (if (string-match "^file:" desc)
  1073. (setq desc (substring desc (match-end 0)))))
  1074. (setq desc (org-add-props
  1075. (concat "<img src=\"" desc "\"/>")
  1076. '(org-protected t))))
  1077. (cond
  1078. ((equal type "internal")
  1079. (let
  1080. ((frag-0
  1081. (if (= (string-to-char path) ?#)
  1082. (substring path 1)
  1083. path)))
  1084. (setq rpl
  1085. (org-html-make-link
  1086. opt-plist
  1087. ""
  1088. ""
  1089. (org-solidify-link-text
  1090. (save-match-data (org-link-unescape frag-0))
  1091. nil)
  1092. desc attr nil))))
  1093. ((and (equal type "id")
  1094. (setq id-file (org-id-find-id-file path)))
  1095. ;; This is an id: link to another file (if it was the same file,
  1096. ;; it would have become an internal link...)
  1097. (save-match-data
  1098. (setq id-file (file-relative-name
  1099. id-file
  1100. (file-name-directory org-current-export-file)))
  1101. (setq rpl
  1102. (org-html-make-link opt-plist
  1103. "file" id-file
  1104. (concat (if (org-uuidgen-p path) "ID-") path)
  1105. desc
  1106. attr
  1107. nil))))
  1108. ((member type '("http" "https"))
  1109. ;; standard URL, can inline as image
  1110. (setq rpl
  1111. (org-html-make-link opt-plist
  1112. type path nil
  1113. desc
  1114. attr
  1115. (org-html-should-inline-p path descp))))
  1116. ((member type '("ftp" "mailto" "news"))
  1117. ;; standard URL, can't inline as image
  1118. (setq rpl
  1119. (org-html-make-link opt-plist
  1120. type path nil
  1121. desc
  1122. attr
  1123. nil)))
  1124. ((string= type "coderef")
  1125. (let*
  1126. ((coderef-str (format "coderef-%s" path))
  1127. (attr-1
  1128. (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  1129. coderef-str coderef-str)))
  1130. (setq rpl
  1131. (org-html-make-link opt-plist
  1132. type "" coderef-str
  1133. (format
  1134. (org-export-get-coderef-format
  1135. path
  1136. (and descp desc))
  1137. (cdr (assoc path org-export-code-refs)))
  1138. attr-1
  1139. nil))))
  1140. ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
  1141. ;; The link protocol has a function for format the link
  1142. (setq rpl
  1143. (save-match-data
  1144. (funcall fnc (org-link-unescape path) desc1 'html))))
  1145. ((string= type "file")
  1146. ;; FILE link
  1147. (save-match-data
  1148. (let*
  1149. ((components
  1150. (if
  1151. (string-match "::\\(.*\\)" path)
  1152. (list
  1153. (replace-match "" t nil path)
  1154. (match-string 1 path))
  1155. (list path nil)))
  1156. ;;The proper path, without a fragment
  1157. (path-1
  1158. (first components))
  1159. ;;The raw fragment
  1160. (fragment-0
  1161. (second components))
  1162. ;;Check the fragment. If it can't be used as
  1163. ;;target fragment we'll pass nil instead.
  1164. (fragment-1
  1165. (if
  1166. (and fragment-0
  1167. (not (string-match "^[0-9]*$" fragment-0))
  1168. (not (string-match "^\\*" fragment-0))
  1169. (not (string-match "^/.*/$" fragment-0)))
  1170. (org-solidify-link-text
  1171. (org-link-unescape fragment-0))
  1172. nil))
  1173. (desc-2
  1174. ;;Description minus "file:" and ".org"
  1175. (if (string-match "^file:" desc)
  1176. (let
  1177. ((desc-1 (replace-match "" t t desc)))
  1178. (if (string-match "\\.org$" desc-1)
  1179. (replace-match "" t t desc-1)
  1180. desc-1))
  1181. desc)))
  1182. (setq rpl
  1183. (if
  1184. (and
  1185. (functionp link-validate)
  1186. (not (funcall link-validate path-1 current-dir)))
  1187. desc
  1188. (org-html-make-link opt-plist
  1189. "file" path-1 fragment-1 desc-2 attr
  1190. (org-html-should-inline-p path-1 descp)))))))
  1191. (t
  1192. ;; just publish the path, as default
  1193. (setq rpl (concat "<i>&lt;" type ":"
  1194. (save-match-data (org-link-unescape path))
  1195. "&gt;</i>"))))
  1196. (setq line (replace-match rpl t t line)
  1197. start (+ start (length rpl))))
  1198. ;; TODO items
  1199. (if (and (string-match org-todo-line-regexp line)
  1200. (match-beginning 2))
  1201. (setq line
  1202. (concat (substring line 0 (match-beginning 2))
  1203. "<span class=\""
  1204. (if (member (match-string 2 line)
  1205. org-done-keywords)
  1206. "done" "todo")
  1207. " " (match-string 2 line)
  1208. "\"> " (org-export-html-get-todo-kwd-class-name
  1209. (match-string 2 line))
  1210. "</span>" (substring line (match-end 2)))))
  1211. ;; Does this contain a reference to a footnote?
  1212. (when org-export-with-footnotes
  1213. (setq start 0)
  1214. (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
  1215. (if (get-text-property (match-beginning 2) 'org-protected line)
  1216. (setq start (match-end 2))
  1217. (let ((n (match-string 2 line)) extra a)
  1218. (if (setq a (assoc n footref-seen))
  1219. (progn
  1220. (setcdr a (1+ (cdr a)))
  1221. (setq extra (format ".%d" (cdr a))))
  1222. (setq extra "")
  1223. (push (cons n 1) footref-seen))
  1224. (setq line
  1225. (replace-match
  1226. (format
  1227. (concat "%s"
  1228. (format org-export-html-footnote-format
  1229. "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"))
  1230. (or (match-string 1 line) "") n extra n n)
  1231. t t line))))))
  1232. (cond
  1233. ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
  1234. ;; This is a headline
  1235. (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
  1236. level-offset))
  1237. txt (match-string 2 line))
  1238. (if (string-match quote-re0 txt)
  1239. (setq txt (replace-match "" t t txt)))
  1240. (if (<= level (max umax umax-toc))
  1241. (setq head-count (+ head-count 1)))
  1242. (when in-local-list
  1243. ;; Close any local lists before inserting a new header line
  1244. (while local-list-type
  1245. (org-close-li (car local-list-type))
  1246. (insert (format "</%sl>\n" (car local-list-type)))
  1247. (pop local-list-type))
  1248. (setq local-list-indent nil
  1249. in-local-list nil))
  1250. (setq first-heading-pos (or first-heading-pos (point)))
  1251. (org-html-level-start level txt umax
  1252. (and org-export-with-toc (<= level umax))
  1253. head-count)
  1254. ;; QUOTES
  1255. (when (string-match quote-re line)
  1256. (org-close-par-maybe)
  1257. (insert "<pre>")
  1258. (setq inquote t)))
  1259. ((string-match "^[ \t]*- __+[ \t]*$" line)
  1260. ;; Explicit list closure
  1261. (when local-list-type
  1262. (let ((ind (org-get-indentation line)))
  1263. (while (and local-list-indent
  1264. (<= ind (car local-list-indent)))
  1265. (org-close-li (car local-list-type))
  1266. (insert (format "</%sl>\n" (car local-list-type)))
  1267. (pop local-list-type)
  1268. (pop local-list-indent))
  1269. (or local-list-indent (setq in-local-list nil))))
  1270. (throw 'nextline nil))
  1271. ((and org-export-with-tables
  1272. (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
  1273. (when (not table-open)
  1274. ;; New table starts
  1275. (setq table-open t table-buffer nil table-orig-buffer nil))
  1276. ;; Accumulate lines
  1277. (setq table-buffer (cons line table-buffer)
  1278. table-orig-buffer (cons origline table-orig-buffer))
  1279. (when (or (not lines)
  1280. (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
  1281. (car lines))))
  1282. (setq table-open nil
  1283. table-buffer (nreverse table-buffer)
  1284. table-orig-buffer (nreverse table-orig-buffer))
  1285. (org-close-par-maybe)
  1286. (insert (org-format-table-html table-buffer table-orig-buffer))))
  1287. (t
  1288. ;; Normal lines
  1289. (when (string-match
  1290. (cond
  1291. ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  1292. ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  1293. ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
  1294. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
  1295. line)
  1296. (setq ind (or (get-text-property 0 'original-indentation line)
  1297. (org-get-string-indentation line))
  1298. item-type (if (match-beginning 4) "o" "u")
  1299. starter (if (match-beginning 2)
  1300. (substring (match-string 2 line) 0 -1))
  1301. line (substring line (match-beginning 5))
  1302. initial-number nil
  1303. item-tag nil)
  1304. (if (string-match "\\`\\[@start:\\([0-9]+\\)\\][ \t]?" line)
  1305. (setq initial-number (match-string 1 line)
  1306. line (replace-match "" t t line)))
  1307. (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
  1308. (setq item-type "d"
  1309. item-tag (match-string 1 line)
  1310. line (substring line (match-end 0))))
  1311. (when (and (not (equal item-type "d"))
  1312. (not (string-match "[^ \t]" line)))
  1313. ;; empty line. Pretend indentation is large.
  1314. (setq ind (if org-empty-line-terminates-plain-lists
  1315. 0
  1316. (1+ (or (car local-list-indent) 1)))))
  1317. (setq didclose nil)
  1318. (while (and in-local-list
  1319. (or (and (= ind (car local-list-indent))
  1320. (not starter))
  1321. (< ind (car local-list-indent))))
  1322. (setq didclose t)
  1323. (org-close-li (car local-list-type))
  1324. (insert (format "</%sl>\n" (car local-list-type)))
  1325. (pop local-list-type) (pop local-list-indent)
  1326. (setq in-local-list local-list-indent))
  1327. (cond
  1328. ((and starter
  1329. (or (not in-local-list)
  1330. (> ind (car local-list-indent))))
  1331. ;; check for a specified start number
  1332. ;; Start new (level of) list
  1333. (org-close-par-maybe)
  1334. (insert (cond
  1335. ((equal item-type "u") "<ul>\n<li>\n")
  1336. ((equal item-type "o")
  1337. (if initial-number
  1338. (format "<ol start=%s>\n<li>\n" initial-number)
  1339. "<ol>\n<li>\n"))
  1340. ((equal item-type "d")
  1341. (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
  1342. (push item-type local-list-type)
  1343. (push ind local-list-indent)
  1344. (setq in-local-list t))
  1345. (starter
  1346. ;; continue current list
  1347. (org-close-li (car local-list-type))
  1348. (insert (cond
  1349. ((equal (car local-list-type) "d")
  1350. (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
  1351. (t "<li>\n"))))
  1352. (didclose
  1353. ;; we did close a list, normal text follows: need <p>
  1354. (org-open-par)))
  1355. (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
  1356. (setq line
  1357. (replace-match
  1358. (if (equal (match-string 1 line) "X")
  1359. "<b>[X]</b>"
  1360. "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
  1361. t t line))))
  1362. ;; Horizontal line
  1363. (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
  1364. (if org-par-open
  1365. (insert "\n</p>\n<hr/>\n<p>\n")
  1366. (insert "\n<hr/>\n"))
  1367. (throw 'nextline nil))
  1368. ;; Empty lines start a new paragraph. If hand-formatted lists
  1369. ;; are not fully interpreted, lines starting with "-", "+", "*"
  1370. ;; also start a new paragraph.
  1371. (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
  1372. ;; Is this the start of a footnote?
  1373. (when org-export-with-footnotes
  1374. (when (and (boundp 'footnote-section-tag-regexp)
  1375. (string-match (concat "^" footnote-section-tag-regexp)
  1376. line))
  1377. ;; ignore this line
  1378. (throw 'nextline nil))
  1379. (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
  1380. (org-close-par-maybe)
  1381. (let ((n (match-string 1 line)))
  1382. (setq org-par-open t
  1383. line (replace-match
  1384. (format
  1385. (concat "<p class=\"footnote\">"
  1386. (format org-export-html-footnote-format
  1387. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
  1388. n n n) t t line)))))
  1389. ;; Check if the line break needs to be conserved
  1390. (cond
  1391. ((string-match "\\\\\\\\[ \t]*$" line)
  1392. (setq line (replace-match "<br/>" t t line)))
  1393. (org-export-preserve-breaks
  1394. (setq line (concat line "<br/>"))))
  1395. ;; Check if a paragraph should be started
  1396. (let ((start 0))
  1397. (while (and org-par-open
  1398. (string-match "\\\\par\\>" line start))
  1399. ;; Leave a space in the </p> so that the footnote matcher
  1400. ;; does not see this.
  1401. (if (not (get-text-property (match-beginning 0)
  1402. 'org-protected line))
  1403. (setq line (replace-match "</p ><p >" t t line)))
  1404. (setq start (match-end 0))))
  1405. (insert line "\n")))))
  1406. ;; Properly close all local lists and other lists
  1407. (when inquote
  1408. (insert "</pre>\n")
  1409. (org-open-par))
  1410. (when in-local-list
  1411. ;; Close any local lists before inserting a new header line
  1412. (while local-list-type
  1413. (org-close-li (car local-list-type))
  1414. (insert (format "</%sl>\n" (car local-list-type)))
  1415. (pop local-list-type))
  1416. (setq local-list-indent nil
  1417. in-local-list nil))
  1418. (org-html-level-start 1 nil umax
  1419. (and org-export-with-toc (<= level umax))
  1420. head-count)
  1421. ;; the </div> to close the last text-... div.
  1422. (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
  1423. (save-excursion
  1424. (goto-char (point-min))
  1425. (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
  1426. (push (match-string 0) footnotes)
  1427. (replace-match "" t t)))
  1428. (when footnotes
  1429. (insert (format org-export-html-footnotes-section
  1430. (nth 4 lang-words)
  1431. (mapconcat 'identity (nreverse footnotes) "\n"))
  1432. "\n"))
  1433. (let ((bib (org-export-html-get-bibliography)))
  1434. (when bib
  1435. (insert "\n" bib "\n")))
  1436. (unless body-only
  1437. (when (plist-get opt-plist :auto-postamble)
  1438. (insert "<div id=\"postamble\">\n")
  1439. (when (and org-export-author-info author)
  1440. (insert "<p class=\"author\"> "
  1441. (nth 1 lang-words) ": " author "\n")
  1442. (when (and org-export-email-info email (string-match "\\S-" email))
  1443. (if (listp (split-string email ",+ *"))
  1444. (mapc (lambda(e)
  1445. (insert "<a href=\"mailto:" e "\">&lt;"
  1446. e "&gt;</a>\n"))
  1447. (split-string email ",+ *"))
  1448. (insert "<a href=\"mailto:" email "\">&lt;"
  1449. email "&gt;</a>\n")))
  1450. (insert "</p>\n"))
  1451. (when (and date org-export-time-stamp-file)
  1452. (insert "<p class=\"date\"> "
  1453. (nth 2 lang-words) ": "
  1454. date "</p>\n"))
  1455. (when org-export-creator-info
  1456. (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
  1457. org-version emacs-major-version)))
  1458. (when org-export-html-validation-link
  1459. (insert org-export-html-validation-link "\n"))
  1460. (insert "</div>"))
  1461. (if org-export-html-with-timestamp
  1462. (insert org-export-html-html-helper-timestamp))
  1463. (org-export-html-insert-plist-item opt-plist :postamble opt-plist)
  1464. (insert "\n</div>\n</body>\n</html>\n"))
  1465. (unless (plist-get opt-plist :buffer-will-be-killed)
  1466. (normal-mode)
  1467. (if (eq major-mode (default-value 'major-mode))
  1468. (html-mode)))
  1469. ;; insert the table of contents
  1470. (goto-char (point-min))
  1471. (when thetoc
  1472. (if (or (re-search-forward
  1473. "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
  1474. (re-search-forward
  1475. "\\[TABLE-OF-CONTENTS\\]" nil t))
  1476. (progn
  1477. (goto-char (match-beginning 0))
  1478. (replace-match ""))
  1479. (goto-char first-heading-pos)
  1480. (when (looking-at "\\s-*</p>")
  1481. (goto-char (match-end 0))
  1482. (insert "\n")))
  1483. (insert "<div id=\"table-of-contents\">\n")
  1484. (mapc 'insert thetoc)
  1485. (insert "</div>\n"))
  1486. ;; remove empty paragraphs and lists
  1487. (goto-char (point-min))
  1488. (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
  1489. (replace-match ""))
  1490. (goto-char (point-min))
  1491. (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
  1492. (replace-match ""))
  1493. (goto-char (point-min))
  1494. (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
  1495. (replace-match ""))
  1496. ;; Convert whitespace place holders
  1497. (goto-char (point-min))
  1498. (let (beg end n)
  1499. (while (setq beg (next-single-property-change (point) 'org-whitespace))
  1500. (setq n (get-text-property beg 'org-whitespace)
  1501. end (next-single-property-change beg 'org-whitespace))
  1502. (goto-char beg)
  1503. (delete-region beg end)
  1504. (insert (format "<span style=\"visibility:hidden;\">%s</span>"
  1505. (make-string n ?x)))))
  1506. ;; Remove empty lines at the beginning of the file.
  1507. (goto-char (point-min))
  1508. (when (looking-at "\\s-+\n") (replace-match ""))
  1509. ;; Remove display properties
  1510. (remove-text-properties (point-min) (point-max) '(display t))
  1511. ;; Run the hook
  1512. (run-hooks 'org-export-html-final-hook)
  1513. (or to-buffer (save-buffer))
  1514. (goto-char (point-min))
  1515. (or (org-export-push-to-kill-ring "HTML")
  1516. (message "Exporting... done"))
  1517. (if (eq to-buffer 'string)
  1518. (prog1 (buffer-substring (point-min) (point-max))
  1519. (kill-buffer (current-buffer)))
  1520. (current-buffer)))))
  1521. (defun org-export-html-insert-plist-item (plist key &rest args)
  1522. (let ((item (plist-get plist key)))
  1523. (cond ((functionp item)
  1524. (apply item args))
  1525. (item
  1526. (insert item)))))
  1527. (defun org-export-html-format-href (s)
  1528. "Make sure the S is valid as a href reference in an XHTML document."
  1529. (save-match-data
  1530. (let ((start 0))
  1531. (while (string-match "&" s start)
  1532. (setq start (+ (match-beginning 0) 3)
  1533. s (replace-match "&amp;" t t s)))))
  1534. s)
  1535. (defun org-export-html-format-desc (s)
  1536. "Make sure the S is valid as a description in a link."
  1537. (if (and s (not (get-text-property 1 'org-protected s)))
  1538. (save-match-data
  1539. (org-html-do-expand s))
  1540. s))
  1541. (defun org-export-html-format-image (src par-open)
  1542. "Create image tag with source and attributes."
  1543. (save-match-data
  1544. (if (string-match "^ltxpng/" src)
  1545. (format "<img src=\"%s\" alt=\"%s\"/>"
  1546. src (org-find-text-property-in-string 'org-latex-src src))
  1547. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  1548. (attr (org-find-text-property-in-string 'org-attributes src))
  1549. (label (org-find-text-property-in-string 'org-label src)))
  1550. (setq caption (and caption (org-html-do-expand caption)))
  1551. (concat
  1552. (if caption
  1553. (format "%s<div %sclass=\"figure\">
  1554. <p>"
  1555. (if org-par-open "</p>\n" "")
  1556. (if label (format "id=\"%s\" " label) "")))
  1557. (format "<img src=\"%s\"%s />"
  1558. src
  1559. (if (string-match "\\<alt=" (or attr ""))
  1560. (concat " " attr )
  1561. (concat " " attr " alt=\"" src "\"")))
  1562. (if caption
  1563. (format "</p>%s
  1564. </div>%s"
  1565. (concat "\n<p>" caption "</p>")
  1566. (if org-par-open "\n<p>" ""))))))))
  1567. (defun org-export-html-get-bibliography ()
  1568. "Find bibliography, cut it out and return it."
  1569. (catch 'exit
  1570. (let (beg end (cnt 1) bib)
  1571. (save-excursion
  1572. (goto-char (point-min))
  1573. (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  1574. (setq beg (match-beginning 0))
  1575. (while (re-search-forward "</?div\\>" nil t)
  1576. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  1577. (when (= cnt 0)
  1578. (and (looking-at ">") (forward-char 1))
  1579. (setq bib (buffer-substring beg (point)))
  1580. (delete-region beg (point))
  1581. (throw 'exit bib))))
  1582. nil))))
  1583. (defvar org-table-number-regexp) ; defined in org-table.el
  1584. (defun org-format-table-html (lines olines)
  1585. "Find out which HTML converter to use and return the HTML code."
  1586. (if (stringp lines)
  1587. (setq lines (org-split-string lines "\n")))
  1588. (if (string-match "^[ \t]*|" (car lines))
  1589. ;; A normal org table
  1590. (org-format-org-table-html lines)
  1591. ;; Table made by table.el - test for spanning
  1592. (let* ((hlines (delq nil (mapcar
  1593. (lambda (x)
  1594. (if (string-match "^[ \t]*\\+-" x) x
  1595. nil))
  1596. lines)))
  1597. (first (car hlines))
  1598. (ll (and (string-match "\\S-+" first)
  1599. (match-string 0 first)))
  1600. (re (concat "^[ \t]*" (regexp-quote ll)))
  1601. (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
  1602. hlines))))
  1603. (if (and (not spanning)
  1604. (not org-export-prefer-native-exporter-for-tables))
  1605. ;; We can use my own converter with HTML conversions
  1606. (org-format-table-table-html lines)
  1607. ;; Need to use the code generator in table.el, with the original text.
  1608. (org-format-table-table-html-using-table-generate-source olines)))))
  1609. (defvar org-table-number-fraction) ; defined in org-table.el
  1610. (defun org-format-org-table-html (lines &optional splice)
  1611. "Format a table into HTML."
  1612. (require 'org-table)
  1613. ;; Get rid of hlines at beginning and end
  1614. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1615. (setq lines (nreverse lines))
  1616. (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
  1617. (setq lines (nreverse lines))
  1618. (when org-export-table-remove-special-lines
  1619. ;; Check if the table has a marking column. If yes remove the
  1620. ;; column and the special lines
  1621. (setq lines (org-table-clean-before-export lines)))
  1622. (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
  1623. (label (org-find-text-property-in-string 'org-label (car lines)))
  1624. (attributes (org-find-text-property-in-string 'org-attributes
  1625. (car lines)))
  1626. (html-table-tag (org-export-splice-attributes
  1627. html-table-tag attributes))
  1628. (head (and org-export-highlight-first-table-line
  1629. (delq nil (mapcar
  1630. (lambda (x) (string-match "^[ \t]*|-" x))
  1631. (cdr lines)))))
  1632. (nline 0) fnum nfields i
  1633. tbopen line fields html gr colgropen rowstart rowend)
  1634. (setq caption (and caption (org-html-do-expand caption)))
  1635. (if splice (setq head nil))
  1636. (unless splice (push (if head "<thead>" "<tbody>") html))
  1637. (setq tbopen t)
  1638. (while (setq line (pop lines))
  1639. (catch 'next-line
  1640. (if (string-match "^[ \t]*|-" line)
  1641. (progn
  1642. (unless splice
  1643. (push (if head "</thead>" "</tbody>") html)
  1644. (if lines (push "<tbody>" html) (setq tbopen nil)))
  1645. (setq head nil) ;; head ends here, first time around
  1646. ;; ignore this line
  1647. (throw 'next-line t)))
  1648. ;; Break the line into fields
  1649. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1650. (unless fnum (setq fnum (make-vector (length fields) 0)
  1651. nfields (length fnum)))
  1652. (setq nline (1+ nline) i -1
  1653. rowstart (eval (car org-export-table-row-tags))
  1654. rowend (eval (cdr org-export-table-row-tags)))
  1655. (push (concat rowstart
  1656. (mapconcat
  1657. (lambda (x)
  1658. (setq i (1+ i))
  1659. (if (and (< i nfields) ; make sure no rogue line causes an error here
  1660. (string-match org-table-number-regexp x))
  1661. (incf (aref fnum i)))
  1662. (cond
  1663. (head
  1664. (concat
  1665. (format (car org-export-table-header-tags) "col")
  1666. x
  1667. (cdr org-export-table-header-tags)))
  1668. ((and (= i 0) org-export-html-table-use-header-tags-for-first-column)
  1669. (concat
  1670. (format (car org-export-table-header-tags) "row")
  1671. x
  1672. (cdr org-export-table-header-tags)))
  1673. (t
  1674. (concat (car org-export-table-data-tags) x
  1675. (cdr org-export-table-data-tags)))))
  1676. fields "")
  1677. rowend)
  1678. html)))
  1679. (unless splice (if tbopen (push "</tbody>" html)))
  1680. (unless splice (push "</table>\n" html))
  1681. (setq html (nreverse html))
  1682. (unless splice
  1683. ;; Put in col tags with the alignment (unfortunately often ignored...)
  1684. (unless (car org-table-colgroup-info)
  1685. (setq org-table-colgroup-info
  1686. (cons :start (cdr org-table-colgroup-info))))
  1687. (push (mapconcat
  1688. (lambda (x)
  1689. (setq gr (pop org-table-colgroup-info))
  1690. (format "%s<col align=\"%s\" />%s"
  1691. (if (memq gr '(:start :startend))
  1692. (prog1
  1693. (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
  1694. (setq colgropen t))
  1695. "")
  1696. (if (> (/ (float x) nline) org-table-number-fraction)
  1697. "right" "left")
  1698. (if (memq gr '(:end :startend))
  1699. (progn (setq colgropen nil) "</colgroup>")
  1700. "")))
  1701. fnum "")
  1702. html)
  1703. (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
  1704. ;; Since the output of HTML table formatter can also be used in
  1705. ;; DocBook document, we want to always include the caption to make
  1706. ;; DocBook XML file valid.
  1707. (push (format "<caption>%s</caption>" (or caption "")) html)
  1708. (when label (push (format "<a name=\"%s\" id=\"%s\"></a>" label label)
  1709. html))
  1710. (push html-table-tag html))
  1711. (concat (mapconcat 'identity html "\n") "\n")))
  1712. (defun org-export-splice-attributes (tag attributes)
  1713. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  1714. (if (not attributes)
  1715. tag
  1716. (let (oldatt newatt)
  1717. (setq oldatt (org-extract-attributes-from-string tag)
  1718. tag (pop oldatt)
  1719. newatt (cdr (org-extract-attributes-from-string attributes)))
  1720. (while newatt
  1721. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  1722. (if (string-match ">" tag)
  1723. (setq tag
  1724. (replace-match (concat (org-attributes-to-string oldatt) ">")
  1725. t t tag)))
  1726. tag)))
  1727. (defun org-format-table-table-html (lines)
  1728. "Format a table generated by table.el into HTML.
  1729. This conversion does *not* use `table-generate-source' from table.el.
  1730. This has the advantage that Org-mode's HTML conversions can be used.
  1731. But it has the disadvantage, that no cell- or row-spanning is allowed."
  1732. (let (line field-buffer
  1733. (head org-export-highlight-first-table-line)
  1734. fields html empty i)
  1735. (setq html (concat html-table-tag "\n"))
  1736. (while (setq line (pop lines))
  1737. (setq empty "&nbsp;")
  1738. (catch 'next-line
  1739. (if (string-match "^[ \t]*\\+-" line)
  1740. (progn
  1741. (if field-buffer
  1742. (progn
  1743. (setq
  1744. html
  1745. (concat
  1746. html
  1747. "<tr>"
  1748. (mapconcat
  1749. (lambda (x)
  1750. (if (equal x "") (setq x empty))
  1751. (if head
  1752. (concat
  1753. (format (car org-export-table-header-tags) "col")
  1754. x
  1755. (cdr org-export-table-header-tags))
  1756. (concat (car org-export-table-data-tags) x
  1757. (cdr org-export-table-data-tags))))
  1758. field-buffer "\n")
  1759. "</tr>\n"))
  1760. (setq head nil)
  1761. (setq field-buffer nil)))
  1762. ;; Ignore this line
  1763. (throw 'next-line t)))
  1764. ;; Break the line into fields and store the fields
  1765. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1766. (if field-buffer
  1767. (setq field-buffer (mapcar
  1768. (lambda (x)
  1769. (concat x "<br/>" (pop fields)))
  1770. field-buffer))
  1771. (setq field-buffer fields))))
  1772. (setq html (concat html "</table>\n"))
  1773. html))
  1774. (defun org-format-table-table-html-using-table-generate-source (lines)
  1775. "Format a table into html, using `table-generate-source' from table.el.
  1776. This has the advantage that cell- or row-spanning is allowed.
  1777. But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
  1778. (require 'table)
  1779. (with-current-buffer (get-buffer-create " org-tmp1 ")
  1780. (erase-buffer)
  1781. (insert (mapconcat 'identity lines "\n"))
  1782. (goto-char (point-min))
  1783. (if (not (re-search-forward "|[^+]" nil t))
  1784. (error "Error processing table"))
  1785. (table-recognize-table)
  1786. (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
  1787. (table-generate-source 'html " org-tmp2 ")
  1788. (set-buffer " org-tmp2 ")
  1789. (buffer-substring (point-min) (point-max))))
  1790. (defun org-export-splice-style (style extra)
  1791. "Splice EXTRA into STYLE, just before \"</style>\"."
  1792. (if (and (stringp extra)
  1793. (string-match "\\S-" extra)
  1794. (string-match "</style>" style))
  1795. (concat (substring style 0 (match-beginning 0))
  1796. "\n" extra "\n"
  1797. (substring style (match-beginning 0)))
  1798. style))
  1799. (defun org-html-handle-time-stamps (s)
  1800. "Format time stamps in string S, or remove them."
  1801. (catch 'exit
  1802. (let (r b)
  1803. (while (string-match org-maybe-keyword-time-regexp s)
  1804. (or b (setq b (substring s 0 (match-beginning 0))))
  1805. (setq r (concat
  1806. r (substring s 0 (match-beginning 0))
  1807. " @<span class=\"timestamp-wrapper\">"
  1808. (if (match-end 1)
  1809. (format "@<span class=\"timestamp-kwd\">%s @</span>"
  1810. (match-string 1 s)))
  1811. (format " @<span class=\"timestamp\">%s@</span>"
  1812. (substring
  1813. (org-translate-time (match-string 3 s)) 1 -1))
  1814. "@</span>")
  1815. s (substring s (match-end 0))))
  1816. ;; Line break if line started and ended with time stamp stuff
  1817. (if (not r)
  1818. s
  1819. (setq r (concat r s))
  1820. (unless (string-match "\\S-" (concat b s))
  1821. (setq r (concat r "@<br/>")))
  1822. r))))
  1823. (defvar htmlize-buffer-places) ; from htmlize.el
  1824. (defun org-export-htmlize-region-for-paste (beg end)
  1825. "Convert the region to HTML, using htmlize.el.
  1826. This is much like `htmlize-region-for-paste', only that it uses
  1827. the settings define in the org-... variables."
  1828. (let* ((htmlize-output-type org-export-htmlize-output-type)
  1829. (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
  1830. (htmlbuf (htmlize-region beg end)))
  1831. (unwind-protect
  1832. (with-current-buffer htmlbuf
  1833. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  1834. (plist-get htmlize-buffer-places 'content-end)))
  1835. (kill-buffer htmlbuf))))
  1836. ;;;###autoload
  1837. (defun org-export-htmlize-generate-css ()
  1838. "Create the CSS for all font definitions in the current Emacs session.
  1839. Use this to create face definitions in your CSS style file that can then
  1840. be used by code snippets transformed by htmlize.
  1841. This command just produces a buffer that contains class definitions for all
  1842. faces used in the current Emacs session. You can copy and paste the ones you
  1843. need into your CSS file.
  1844. If you then set `org-export-htmlize-output-type' to `css', calls to
  1845. the function `org-export-htmlize-region-for-paste' will produce code
  1846. that uses these same face definitions."
  1847. (interactive)
  1848. (require 'htmlize)
  1849. (and (get-buffer "*html*") (kill-buffer "*html*"))
  1850. (with-temp-buffer
  1851. (let ((fl (face-list))
  1852. (htmlize-css-name-prefix "org-")
  1853. (htmlize-output-type 'css)
  1854. f i)
  1855. (while (setq f (pop fl)
  1856. i (and f (face-attribute f :inherit)))
  1857. (when (and (symbolp f) (or (not i) (not (listp i))))
  1858. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  1859. (htmlize-region (point-min) (point-max))))
  1860. (switch-to-buffer "*html*")
  1861. (goto-char (point-min))
  1862. (if (re-search-forward "<style" nil t)
  1863. (delete-region (point-min) (match-beginning 0)))
  1864. (if (re-search-forward "</style>" nil t)
  1865. (delete-region (1+ (match-end 0)) (point-max)))
  1866. (beginning-of-line 1)
  1867. (if (looking-at " +") (replace-match ""))
  1868. (goto-char (point-min)))
  1869. (defun org-html-protect (s)
  1870. ;; convert & to &amp;, < to &lt; and > to &gt;
  1871. (let ((start 0))
  1872. (while (string-match "&" s start)
  1873. (setq s (replace-match "&amp;" t t s)
  1874. start (1+ (match-beginning 0))))
  1875. (while (string-match "<" s)
  1876. (setq s (replace-match "&lt;" t t s)))
  1877. (while (string-match ">" s)
  1878. (setq s (replace-match "&gt;" t t s)))
  1879. ; (while (string-match "\"" s)
  1880. ; (setq s (replace-match "&quot;" t t s)))
  1881. )
  1882. s)
  1883. (defun org-html-expand (string)
  1884. "Prepare STRING for HTML export. Applies all active conversions.
  1885. If there are links in the string, don't modify these."
  1886. (let* ((re (concat org-bracket-link-regexp "\\|"
  1887. (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
  1888. m s l res)
  1889. (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string)
  1890. string
  1891. (while (setq m (string-match re string))
  1892. (setq s (substring string 0 m)
  1893. l (match-string 0 string)
  1894. string (substring string (match-end 0)))
  1895. (push (org-html-do-expand s) res)
  1896. (push l res))
  1897. (push (org-html-do-expand string) res)
  1898. (apply 'concat (nreverse res)))))
  1899. (defun org-html-do-expand (s)
  1900. "Apply all active conversions to translate special ASCII to HTML."
  1901. (setq s (org-html-protect s))
  1902. (if org-export-html-expand
  1903. (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
  1904. (setq s (replace-match "<\\1>" t nil s))))
  1905. (if org-export-with-emphasize
  1906. (setq s (org-export-html-convert-emphasize s)))
  1907. (if org-export-with-special-strings
  1908. (setq s (org-export-html-convert-special-strings s)))
  1909. (if org-export-with-sub-superscripts
  1910. (setq s (org-export-html-convert-sub-super s)))
  1911. (if org-export-with-TeX-macros
  1912. (let ((start 0) wd rep)
  1913. (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
  1914. s start))
  1915. (if (get-text-property (match-beginning 0) 'org-protected s)
  1916. (setq start (match-end 0))
  1917. (setq wd (match-string 1 s))
  1918. (if (setq rep (org-entity-get-representation wd 'html))
  1919. (setq s (replace-match rep t t s))
  1920. (setq start (+ start (length wd))))))))
  1921. s)
  1922. (defun org-export-html-convert-special-strings (string)
  1923. "Convert special characters in STRING to HTML."
  1924. (let ((all org-export-html-special-string-regexps)
  1925. e a re rpl start)
  1926. (while (setq a (pop all))
  1927. (setq re (car a) rpl (cdr a) start 0)
  1928. (while (string-match re string start)
  1929. (if (get-text-property (match-beginning 0) 'org-protected string)
  1930. (setq start (match-end 0))
  1931. (setq string (replace-match rpl t nil string)))))
  1932. string))
  1933. (defun org-export-html-convert-sub-super (string)
  1934. "Convert sub- and superscripts in STRING to HTML."
  1935. (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
  1936. (while (string-match org-match-substring-regexp string s)
  1937. (cond
  1938. ((and requireb (match-end 8)) (setq s (match-end 2)))
  1939. ((get-text-property (match-beginning 2) 'org-protected string)
  1940. (setq s (match-end 2)))
  1941. (t
  1942. (setq s (match-end 1)
  1943. key (if (string= (match-string 2 string) "_") "sub" "sup")
  1944. c (or (match-string 8 string)
  1945. (match-string 6 string)
  1946. (match-string 5 string))
  1947. string (replace-match
  1948. (concat (match-string 1 string)
  1949. "<" key ">" c "</" key ">")
  1950. t t string)))))
  1951. (while (string-match "\\\\\\([_^]\\)" string)
  1952. (setq string (replace-match (match-string 1 string) t t string)))
  1953. string))
  1954. (defun org-export-html-convert-emphasize (string)
  1955. "Apply emphasis."
  1956. (let ((s 0) rpl)
  1957. (while (string-match org-emph-re string s)
  1958. (if (not (equal
  1959. (substring string (match-beginning 3) (1+ (match-beginning 3)))
  1960. (substring string (match-beginning 4) (1+ (match-beginning 4)))))
  1961. (setq s (match-beginning 0)
  1962. rpl
  1963. (concat
  1964. (match-string 1 string)
  1965. (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
  1966. (match-string 4 string)
  1967. (nth 3 (assoc (match-string 3 string)
  1968. org-emphasis-alist))
  1969. (match-string 5 string))
  1970. string (replace-match rpl t t string)
  1971. s (+ s (- (length rpl) 2)))
  1972. (setq s (1+ s))))
  1973. string))
  1974. (defun org-open-par ()
  1975. "Insert <p>, but first close previous paragraph if any."
  1976. (org-close-par-maybe)
  1977. (insert "\n<p>")
  1978. (setq org-par-open t))
  1979. (defun org-close-par-maybe ()
  1980. "Close paragraph if there is one open."
  1981. (when org-par-open
  1982. (insert "</p>")
  1983. (setq org-par-open nil)))
  1984. (defun org-close-li (&optional type)
  1985. "Close <li> if necessary."
  1986. (org-close-par-maybe)
  1987. (insert (if (equal type "d") "</dd>\n" "</li>\n")))
  1988. (defvar in-local-list)
  1989. (defvar local-list-indent)
  1990. (defvar local-list-type)
  1991. (defun org-export-html-close-lists-maybe (line)
  1992. "Close local lists based on the original indentation of the line."
  1993. (let* ((rawhtml (and in-local-list
  1994. (get-text-property 0 'org-protected line)
  1995. (not (get-text-property 0 'org-example line))))
  1996. ;; rawhtml means: This was between #+begin_html..#+end_html
  1997. ;; originally, thus it excludes stuff that was a source code example
  1998. ;; Actually, this code seems wrong, I don't know why it works, but
  1999. ;; it seems to work.... So keep it like this for now.
  2000. (ind (if rawhtml
  2001. (org-get-indentation line)
  2002. (get-text-property 0 'original-indentation line)))
  2003. didclose)
  2004. (when ind
  2005. (while (and in-local-list
  2006. (<= ind (car local-list-indent)))
  2007. (setq didclose t)
  2008. (org-close-li (car local-list-type))
  2009. (insert (format "</%sl>\n" (car local-list-type)))
  2010. (pop local-list-type) (pop local-list-indent)
  2011. (setq in-local-list local-list-indent))
  2012. (and didclose (org-open-par)))))
  2013. (defvar body-only) ; dynamically scoped into this.
  2014. (defun org-html-level-start (level title umax with-toc head-count)
  2015. "Insert a new level in HTML export.
  2016. When TITLE is nil, just close all open levels."
  2017. (org-close-par-maybe)
  2018. (let* ((target (and title (org-get-text-property-any 0 'target title)))
  2019. (extra-targets (and target
  2020. (assoc target org-export-target-aliases)))
  2021. (extra-class (and title (org-get-text-property-any 0 'html-container-class title)))
  2022. (preferred (and target
  2023. (cdr (assoc target org-export-preferred-target-alist))))
  2024. (remove (or preferred target))
  2025. (l org-level-max)
  2026. snumber snu href suffix)
  2027. (setq extra-targets (remove remove extra-targets))
  2028. (setq extra-targets
  2029. (mapconcat (lambda (x)
  2030. (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
  2031. (format "<a name=\"%s\" id=\"%s\"></a>"
  2032. x x))
  2033. extra-targets
  2034. ""))
  2035. (while (>= l level)
  2036. (if (aref org-levels-open (1- l))
  2037. (progn
  2038. (org-html-level-close l umax)
  2039. (aset org-levels-open (1- l) nil)))
  2040. (setq l (1- l)))
  2041. (when title
  2042. ;; If title is nil, this means this function is called to close
  2043. ;; all levels, so the rest is done only if title is given
  2044. (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
  2045. (setq title (replace-match
  2046. (if org-export-with-tags
  2047. (save-match-data
  2048. (concat
  2049. "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
  2050. (mapconcat
  2051. (lambda (x)
  2052. (format "<span class=\"%s\">%s</span>"
  2053. (org-export-html-get-tag-class-name x)
  2054. x))
  2055. (org-split-string (match-string 1 title) ":")
  2056. "&nbsp;")
  2057. "</span>"))
  2058. "")
  2059. t t title)))
  2060. (if (> level umax)
  2061. (progn
  2062. (if (aref org-levels-open (1- level))
  2063. (progn
  2064. (org-close-li)
  2065. (if target
  2066. (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
  2067. (insert "<li>" title "<br/>\n")))
  2068. (aset org-levels-open (1- level) t)
  2069. (org-close-par-maybe)
  2070. (if target
  2071. (insert (format "<ul>\n<li id=\"%s\">" target)
  2072. extra-targets title "<br/>\n")
  2073. (insert "<ul>\n<li>" title "<br/>\n"))))
  2074. (aset org-levels-open (1- level) t)
  2075. (setq snumber (org-section-number level)
  2076. snu (replace-regexp-in-string "\\." "_" snumber))
  2077. (setq level (+ level org-export-html-toplevel-hlevel -1))
  2078. (if (and org-export-with-section-numbers (not body-only))
  2079. (setq title (concat
  2080. (format "<span class=\"section-number-%d\">%s</span>"
  2081. level snumber)
  2082. " " title)))
  2083. (unless (= head-count 1) (insert "\n</div>\n"))
  2084. (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
  2085. (setq suffix (or href snu))
  2086. (setq href (or href (concat "sec-" snu)))
  2087. (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"
  2088. suffix level (if extra-class (concat " " extra-class) "")
  2089. level href
  2090. extra-targets
  2091. title level level suffix))
  2092. (org-open-par)))))
  2093. (defun org-export-html-get-tag-class-name (tag)
  2094. "Turn tag into a valid class name.
  2095. Replaces invalid characters with \"_\" and then prepends a prefix."
  2096. (save-match-data
  2097. (while (string-match "[^a-zA-Z0-9_]" tag)
  2098. (setq tag (replace-match "_" t t tag))))
  2099. (concat org-export-html-tag-class-prefix tag))
  2100. (defun org-export-html-get-todo-kwd-class-name (kwd)
  2101. "Turn todo keyword into a valid class name.
  2102. Replaces invalid characters with \"_\" and then prepends a prefix."
  2103. (save-match-data
  2104. (while (string-match "[^a-zA-Z0-9_]" kwd)
  2105. (setq kwd (replace-match "_" t t kwd))))
  2106. (concat org-export-html-todo-kwd-class-prefix kwd))
  2107. (defun org-html-level-close (level max-outline-level)
  2108. "Terminate one level in HTML export."
  2109. (if (<= level max-outline-level)
  2110. (insert "</div>\n")
  2111. (org-close-li)
  2112. (insert "</ul>\n")))
  2113. (provide 'org-html)
  2114. ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
  2115. ;;; org-html.el ends here