org-html.el 85 KB

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