org-html.el 85 KB

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