org-html.el 91 KB

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