org-html.el 79 KB

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