org-html.el 83 KB

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