org-html.el 91 KB

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