org-html.el 92 KB

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