org-html.el 93 KB

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