org-html.el 90 KB

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