org-html.el 92 KB

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