ox-html.el 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944
  1. ;;; ox-html.el --- HTML Back-End for Org Export Engine
  2. ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
  3. ;; Author: Jambunathan K <kjambunathan at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This library implements a HTML back-end for Org generic exporter.
  17. ;; To test it, run:
  18. ;;
  19. ;; M-x org-export-as-html
  20. ;;
  21. ;; in an Org mode buffer. See ox.el for more details on how this
  22. ;; exporter works.
  23. ;;; Code:
  24. ;;; Dependencies
  25. (require 'ox)
  26. (require 'ox-publish)
  27. (require 'format-spec)
  28. (eval-when-compile (require 'cl) (require 'table))
  29. ;;; Function Declarations
  30. (declare-function org-id-find-id-file "org-id" (id))
  31. (declare-function htmlize-region "ext:htmlize" (beg end))
  32. (declare-function org-pop-to-buffer-same-window
  33. "org-compat" (&optional buffer-or-name norecord label))
  34. ;;; Define Back-End
  35. (org-export-define-backend html
  36. ((bold . org-html-bold)
  37. (center-block . org-html-center-block)
  38. (clock . org-html-clock)
  39. (code . org-html-code)
  40. (drawer . org-html-drawer)
  41. (dynamic-block . org-html-dynamic-block)
  42. (entity . org-html-entity)
  43. (example-block . org-html-example-block)
  44. (export-block . org-html-export-block)
  45. (export-snippet . org-html-export-snippet)
  46. (fixed-width . org-html-fixed-width)
  47. (footnote-definition . org-html-footnote-definition)
  48. (footnote-reference . org-html-footnote-reference)
  49. (headline . org-html-headline)
  50. (horizontal-rule . org-html-horizontal-rule)
  51. (inline-src-block . org-html-inline-src-block)
  52. (inlinetask . org-html-inlinetask)
  53. (inner-template . org-html-inner-template)
  54. (italic . org-html-italic)
  55. (item . org-html-item)
  56. (keyword . org-html-keyword)
  57. (latex-environment . org-html-latex-environment)
  58. (latex-fragment . org-html-latex-fragment)
  59. (line-break . org-html-line-break)
  60. (link . org-html-link)
  61. (paragraph . org-html-paragraph)
  62. (plain-list . org-html-plain-list)
  63. (plain-text . org-html-plain-text)
  64. (planning . org-html-planning)
  65. (property-drawer . org-html-property-drawer)
  66. (quote-block . org-html-quote-block)
  67. (quote-section . org-html-quote-section)
  68. (radio-target . org-html-radio-target)
  69. (section . org-html-section)
  70. (special-block . org-html-special-block)
  71. (src-block . org-html-src-block)
  72. (statistics-cookie . org-html-statistics-cookie)
  73. (strike-through . org-html-strike-through)
  74. (subscript . org-html-subscript)
  75. (superscript . org-html-superscript)
  76. (table . org-html-table)
  77. (table-cell . org-html-table-cell)
  78. (table-row . org-html-table-row)
  79. (target . org-html-target)
  80. (template . org-html-template)
  81. (timestamp . org-html-timestamp)
  82. (underline . org-html-underline)
  83. (verbatim . org-html-verbatim)
  84. (verse-block . org-html-verse-block))
  85. :export-block "HTML"
  86. :filters-alist ((:filter-final-output . org-html-final-function))
  87. :menu-entry
  88. (?h "Export to HTML"
  89. ((?H "As HTML buffer" org-html-export-as-html)
  90. (?h "As HTML file" org-html-export-to-html)
  91. (?o "As HTML file and open"
  92. (lambda (a s v b)
  93. (if a (org-html-export-to-html t s v b)
  94. (org-open-file (org-html-export-to-html nil s v b)))))))
  95. :options-alist
  96. ((:html-extension nil nil org-html-extension)
  97. (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
  98. (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
  99. (:html-mathjax "HTML_MATHJAX" nil "" space)
  100. (:html-postamble nil "html-postamble" org-html-postamble)
  101. (:html-preamble nil "html-preamble" org-html-preamble)
  102. (:html-style nil nil org-html-style)
  103. (:html-style-extra "HTML_STYLE" nil org-html-style-extra newline)
  104. (:html-style-include-default nil nil org-html-style-include-default)
  105. (:html-style-include-scripts nil nil org-html-style-include-scripts)
  106. (:html-table-tag nil nil org-html-table-tag)
  107. ;; Redefine regular options.
  108. (:creator "CREATOR" nil org-html-creator-string)
  109. (:with-latex nil "tex" org-html-with-latex)
  110. ;; Leave room for "ox-infojs.el" extension.
  111. (:infojs-opt "INFOJS_OPT" nil nil)))
  112. ;;; Internal Variables
  113. (defvar org-html-format-table-no-css)
  114. (defvar htmlize-buffer-places) ; from htmlize.el
  115. (defconst org-html-special-string-regexps
  116. '(("\\\\-" . "&shy;")
  117. ("---\\([^-]\\)" . "&mdash;\\1")
  118. ("--\\([^-]\\)" . "&ndash;\\1")
  119. ("\\.\\.\\." . "&hellip;"))
  120. "Regular expressions for special string conversion.")
  121. (defconst org-html-scripts
  122. "<script type=\"text/javascript\">
  123. /*
  124. @licstart The following is the entire license notice for the
  125. JavaScript code in this tag.
  126. Copyright (C) 2012 Free Software Foundation, Inc.
  127. The JavaScript code in this tag is free software: you can
  128. redistribute it and/or modify it under the terms of the GNU
  129. General Public License (GNU GPL) as published by the Free Software
  130. Foundation, either version 3 of the License, or (at your option)
  131. any later version. The code is distributed WITHOUT ANY WARRANTY;
  132. without even the implied warranty of MERCHANTABILITY or FITNESS
  133. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  134. As additional permission under GNU GPL version 3 section 7, you
  135. may distribute non-source (e.g., minimized or compacted) forms of
  136. that code without the copy of the GNU GPL normally required by
  137. section 4, provided you include this license notice and a URL
  138. through which recipients can access the Corresponding Source.
  139. @licend The above is the entire license notice
  140. for the JavaScript code in this tag.
  141. */
  142. <!--/*--><![CDATA[/*><!--*/
  143. function CodeHighlightOn(elem, id)
  144. {
  145. var target = document.getElementById(id);
  146. if(null != target) {
  147. elem.cacheClassElem = elem.className;
  148. elem.cacheClassTarget = target.className;
  149. target.className = \"code-highlighted\";
  150. elem.className = \"code-highlighted\";
  151. }
  152. }
  153. function CodeHighlightOff(elem, id)
  154. {
  155. var target = document.getElementById(id);
  156. if(elem.cacheClassElem)
  157. elem.className = elem.cacheClassElem;
  158. if(elem.cacheClassTarget)
  159. target.className = elem.cacheClassTarget;
  160. }
  161. /*]]>*///-->
  162. </script>"
  163. "Basic JavaScript that is needed by HTML files produced by Org mode.")
  164. (defconst org-html-style-default
  165. "<style type=\"text/css\">
  166. <!--/*--><![CDATA[/*><!--*/
  167. html { font-family: Times, serif; font-size: 12pt; }
  168. .title { text-align: center; }
  169. .todo { color: red; }
  170. .done { color: green; }
  171. .tag { background-color: #add8e6; font-weight:normal }
  172. .target { }
  173. .timestamp { color: #bebebe; }
  174. .timestamp-kwd { color: #5f9ea0; }
  175. .right {margin-left:auto; margin-right:0px; text-align:right;}
  176. .left {margin-left:0px; margin-right:auto; text-align:left;}
  177. .center {margin-left:auto; margin-right:auto; text-align:center;}
  178. p.verse { margin-left: 3% }
  179. pre {
  180. border: 1pt solid #AEBDCC;
  181. background-color: #F3F5F7;
  182. padding: 5pt;
  183. font-family: courier, monospace;
  184. font-size: 90%;
  185. overflow:auto;
  186. }
  187. table { border-collapse: collapse; }
  188. td, th { vertical-align: top; }
  189. th.right { text-align:center; }
  190. th.left { text-align:center; }
  191. th.center { text-align:center; }
  192. td.right { text-align:right; }
  193. td.left { text-align:left; }
  194. td.center { text-align:center; }
  195. dt { font-weight: bold; }
  196. div.figure { padding: 0.5em; }
  197. div.figure p { text-align: center; }
  198. div.inlinetask {
  199. padding:10px;
  200. border:2px solid gray;
  201. margin:10px;
  202. background: #ffffcc;
  203. }
  204. textarea { overflow-x: auto; }
  205. .linenr { font-size:smaller }
  206. .code-highlighted {background-color:#ffff00;}
  207. .org-info-js_info-navigation { border-style:none; }
  208. #org-info-js_console-label { font-size:10px; font-weight:bold;
  209. white-space:nowrap; }
  210. .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
  211. font-weight:bold; }
  212. /*]]>*/-->
  213. </style>"
  214. "The default style specification for exported HTML files.
  215. Please use the variables `org-html-style' and
  216. `org-html-style-extra' to add to this style. If you wish to not
  217. have the default style included, customize the variable
  218. `org-html-style-include-default'.")
  219. ;;; User Configuration Variables
  220. (defgroup org-export-html nil
  221. "Options for exporting Org mode files to HTML."
  222. :tag "Org Export HTML"
  223. :group 'org-export)
  224. (defgroup org-export-htmlize nil
  225. "Options for processing examples with htmlize.el."
  226. :tag "Org Export Htmlize"
  227. :group 'org-export-html)
  228. ;;;; Bold etc
  229. (defcustom org-html-text-markup-alist
  230. '((bold . "<b>%s</b>")
  231. (code . "<code>%s</code>")
  232. (italic . "<i>%s</i>")
  233. (strike-through . "<del>%s</del>")
  234. (underline . "<span style=\"text-decoration:underline;\">%s</span>")
  235. (verbatim . "<code>%s</code>"))
  236. "Alist of HTML expressions to convert text markup
  237. The key must be a symbol among `bold', `code', `italic',
  238. `strike-through', `underline' and `verbatim'. The value is
  239. a formatting string to wrap fontified text with.
  240. If no association can be found for a given markup, text will be
  241. returned as-is."
  242. :group 'org-export-html
  243. :type '(alist :key-type (symbol :tag "Markup type")
  244. :value-type (string :tag "Format string"))
  245. :options '(bold code italic strike-through underline verbatim))
  246. ;;;; Debugging
  247. (defcustom org-html-pretty-output nil
  248. "Enable this to generate pretty HTML."
  249. :group 'org-export-html
  250. :type 'boolean)
  251. ;;;; Drawers
  252. (defcustom org-html-format-drawer-function nil
  253. "Function called to format a drawer in HTML code.
  254. The function must accept two parameters:
  255. NAME the drawer name, like \"LOGBOOK\"
  256. CONTENTS the contents of the drawer.
  257. The function should return the string to be exported.
  258. For example, the variable could be set to the following function
  259. in order to mimic default behaviour:
  260. \(defun org-html-format-drawer-default \(name contents\)
  261. \"Format a drawer element for HTML export.\"
  262. contents\)"
  263. :group 'org-export-html
  264. :type 'function)
  265. ;;;; Footnotes
  266. (defcustom org-html-footnotes-section "<div id=\"footnotes\">
  267. <h2 class=\"footnotes\">%s: </h2>
  268. <div id=\"text-footnotes\">
  269. %s
  270. </div>
  271. </div>"
  272. "Format for the footnotes section.
  273. Should contain a two instances of %s. The first will be replaced with the
  274. language-specific word for \"Footnotes\", the second one will be replaced
  275. by the footnotes themselves."
  276. :group 'org-export-html
  277. :type 'string)
  278. (defcustom org-html-footnote-format "<sup>%s</sup>"
  279. "The format for the footnote reference.
  280. %s will be replaced by the footnote reference itself."
  281. :group 'org-export-html
  282. :type 'string)
  283. (defcustom org-html-footnote-separator "<sup>, </sup>"
  284. "Text used to separate footnotes."
  285. :group 'org-export-html
  286. :type 'string)
  287. ;;;; Headline
  288. (defcustom org-html-toplevel-hlevel 2
  289. "The <H> level for level 1 headings in HTML export.
  290. This is also important for the classes that will be wrapped around headlines
  291. and outline structure. If this variable is 1, the top-level headlines will
  292. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  293. and outline-text-1. If this is 2, all of these will get a 2 instead.
  294. The default for this variable is 2, because we use <h1> for formatting the
  295. document title."
  296. :group 'org-export-html
  297. :type 'integer)
  298. (defcustom org-html-format-headline-function nil
  299. "Function to format headline text.
  300. This function will be called with 5 arguments:
  301. TODO the todo keyword (string or nil).
  302. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  303. PRIORITY the priority of the headline (integer or nil)
  304. TEXT the main headline text (string).
  305. TAGS the tags (string or nil).
  306. The function result will be used in the section format string.
  307. As an example, one could set the variable to the following, in
  308. order to reproduce the default set-up:
  309. \(defun org-html-format-headline \(todo todo-type priority text tags)
  310. \"Default format function for an headline.\"
  311. \(concat \(when todo
  312. \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
  313. \(when priority
  314. \(format \"\\\\framebox{\\\\#%c} \" priority))
  315. text
  316. \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags))))"
  317. :group 'org-export-html
  318. :type 'function)
  319. ;;;; HTML-specific
  320. (defcustom org-html-allow-name-attribute-in-anchors t
  321. "When nil, do not set \"name\" attribute in anchors.
  322. By default, anchors are formatted with both \"id\" and \"name\"
  323. attributes, when appropriate."
  324. :group 'org-export-html
  325. :type 'boolean)
  326. ;;;; Inlinetasks
  327. (defcustom org-html-format-inlinetask-function nil
  328. "Function called to format an inlinetask in HTML code.
  329. The function must accept six parameters:
  330. TODO the todo keyword, as a string
  331. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  332. PRIORITY the inlinetask priority, as a string
  333. NAME the inlinetask name, as a string.
  334. TAGS the inlinetask tags, as a list of strings.
  335. CONTENTS the contents of the inlinetask, as a string.
  336. The function should return the string to be exported.
  337. For example, the variable could be set to the following function
  338. in order to mimic default behaviour:
  339. \(defun org-html-format-inlinetask \(todo type priority name tags contents\)
  340. \"Format an inline task element for HTML export.\"
  341. \(let \(\(full-title
  342. \(concat
  343. \(when todo
  344. \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
  345. \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
  346. title
  347. \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags)))))
  348. \(format (concat \"\\\\begin{center}\\n\"
  349. \"\\\\fbox{\\n\"
  350. \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
  351. \"%s\\n\\n\"
  352. \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
  353. \"%s\"
  354. \"\\\\end{minipage}}\"
  355. \"\\\\end{center}\")
  356. full-title contents))"
  357. :group 'org-export-html
  358. :type 'function)
  359. ;;;; LaTeX
  360. (defcustom org-html-with-latex org-export-with-latex
  361. "Non-nil means process LaTeX math snippets.
  362. When set, the exporter will process LaTeX environments and
  363. fragments.
  364. This option can also be set with the +OPTIONS line,
  365. e.g. \"tex:mathjax\". Allowed values are:
  366. nil Ignore math snippets.
  367. `verbatim' Keep everything in verbatim
  368. `dvipng' Process the LaTeX fragments to images. This will also
  369. include processing of non-math environments.
  370. `imagemagick' Convert the LaTeX fragments to pdf files and use
  371. imagemagick to convert pdf files to png files.
  372. `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
  373. be loaded.
  374. t Synonym for `mathjax'."
  375. :group 'org-export-html
  376. :type '(choice
  377. (const :tag "Do not process math in any way" nil)
  378. (const :tag "Use dvipng to make images" dvipng)
  379. (const :tag "Use imagemagick to make images" imagemagick)
  380. (const :tag "Use MathJax to display math" mathjax)
  381. (const :tag "Leave math verbatim" verbatim)))
  382. ;;;; Links :: Generic
  383. (defcustom org-html-link-org-files-as-html t
  384. "Non-nil means make file links to `file.org' point to `file.html'.
  385. When org-mode is exporting an org-mode file to HTML, links to
  386. non-html files are directly put into a href tag in HTML.
  387. However, links to other Org-mode files (recognized by the
  388. extension `.org.) should become links to the corresponding html
  389. file, assuming that the linked org-mode file will also be
  390. converted to HTML.
  391. When nil, the links still point to the plain `.org' file."
  392. :group 'org-export-html
  393. :type 'boolean)
  394. ;;;; Links :: Inline images
  395. (defcustom org-html-inline-images 'maybe
  396. "Non-nil means inline images into exported HTML pages.
  397. This is done using an <img> tag. When nil, an anchor with href is used to
  398. link to the image. If this option is `maybe', then images in links with
  399. an empty description will be inlined, while images with a description will
  400. be linked only."
  401. :group 'org-export-html
  402. :type '(choice (const :tag "Never" nil)
  403. (const :tag "Always" t)
  404. (const :tag "When there is no description" maybe)))
  405. (defcustom org-html-inline-image-rules
  406. '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
  407. ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
  408. ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
  409. "Rules characterizing image files that can be inlined into HTML.
  410. A rule consists in an association whose key is the type of link
  411. to consider, and value is a regexp that will be matched against
  412. link's path.
  413. Note that, by default, the image extension *actually* allowed
  414. depend on the way the HTML file is processed. When used with
  415. pdflatex, pdf, jpg and png images are OK. When processing
  416. through dvi to Postscript, only ps and eps are allowed. The
  417. default we use here encompasses both."
  418. :group 'org-export-html
  419. :type '(alist :key-type (string :tag "Type")
  420. :value-type (regexp :tag "Path")))
  421. ;;;; Plain Text
  422. (defcustom org-html-protect-char-alist
  423. '(("&" . "&amp;")
  424. ("<" . "&lt;")
  425. (">" . "&gt;"))
  426. "Alist of characters to be converted by `org-html-protect'."
  427. :group 'org-export-html
  428. :type '(repeat (cons (string :tag "Character")
  429. (string :tag "HTML equivalent"))))
  430. ;;;; Src Block
  431. (defcustom org-export-htmlize-output-type 'inline-css
  432. "Output type to be used by htmlize when formatting code snippets.
  433. Choices are `css', to export the CSS selectors only, or `inline-css', to
  434. export the CSS attribute values inline in the HTML. We use as default
  435. `inline-css', in order to make the resulting HTML self-containing.
  436. However, this will fail when using Emacs in batch mode for export, because
  437. then no rich font definitions are in place. It will also not be good if
  438. people with different Emacs setup contribute HTML files to a website,
  439. because the fonts will represent the individual setups. In these cases,
  440. it is much better to let Org/Htmlize assign classes only, and to use
  441. a style file to define the look of these classes.
  442. To get a start for your css file, start Emacs session and make sure that
  443. all the faces you are interested in are defined, for example by loading files
  444. in all modes you want. Then, use the command
  445. \\[org-export-htmlize-generate-css] to extract class definitions."
  446. :group 'org-export-htmlize
  447. :type '(choice (const css) (const inline-css)))
  448. (defcustom org-export-htmlize-font-prefix "org-"
  449. "The prefix for CSS class names for htmlize font specifications."
  450. :group 'org-export-htmlize
  451. :type 'string)
  452. (defcustom org-export-htmlized-org-css-url nil
  453. "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
  454. Normally when creating an htmlized version of an Org buffer, htmlize will
  455. create CSS to define the font colors. However, this does not work when
  456. converting in batch mode, and it also can look bad if different people
  457. with different fontification setup work on the same website.
  458. When this variable is non-nil, creating an htmlized version of an Org buffer
  459. using `org-export-as-org' will remove the internal CSS section and replace it
  460. with a link to this URL."
  461. :group 'org-export-htmlize
  462. :type '(choice
  463. (const :tag "Keep internal css" nil)
  464. (string :tag "URL or local href")))
  465. ;;;; Table
  466. (defcustom org-html-table-tag
  467. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  468. "The HTML tag that is used to start a table.
  469. This must be a <table> tag, but you may change the options like
  470. borders and spacing."
  471. :group 'org-export-html
  472. :type 'string)
  473. (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  474. "The opening tag for table header fields.
  475. This is customizable so that alignment options can be specified.
  476. The first %s will be filled with the scope of the field, either row or col.
  477. The second %s will be replaced by a style entry to align the field.
  478. See also the variable `org-html-table-use-header-tags-for-first-column'.
  479. See also the variable `org-html-table-align-individual-fields'."
  480. :group 'org-export-tables ; FIXME: change group?
  481. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  482. (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
  483. "The opening tag for table data fields.
  484. This is customizable so that alignment options can be specified.
  485. The first %s will be filled with the scope of the field, either row or col.
  486. The second %s will be replaced by a style entry to align the field.
  487. See also the variable `org-html-table-align-individual-fields'."
  488. :group 'org-export-tables
  489. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  490. (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
  491. "The opening tag for table data fields.
  492. This is customizable so that alignment options can be specified.
  493. Instead of strings, these can be Lisp forms that will be evaluated
  494. for each row in order to construct the table row tags. During evaluation,
  495. the variable `head' will be true when this is a header line, nil when this
  496. is a body line. And the variable `nline' will contain the line number,
  497. starting from 1 in the first header line. For example
  498. (setq org-html-table-row-tags
  499. (cons '(if head
  500. \"<tr>\"
  501. (if (= (mod nline 2) 1)
  502. \"<tr class=\\\"tr-odd\\\">\"
  503. \"<tr class=\\\"tr-even\\\">\"))
  504. \"</tr>\"))
  505. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  506. :group 'org-export-tables
  507. :type '(cons
  508. (choice :tag "Opening tag"
  509. (string :tag "Specify")
  510. (sexp))
  511. (choice :tag "Closing tag"
  512. (string :tag "Specify")
  513. (sexp))))
  514. (defcustom org-html-table-align-individual-fields t
  515. "Non-nil means attach style attributes for alignment to each table field.
  516. When nil, alignment will only be specified in the column tags, but this
  517. is ignored by some browsers (like Firefox, Safari). Opera does it right
  518. though."
  519. :group 'org-export-tables
  520. :type 'boolean)
  521. (defcustom org-html-table-use-header-tags-for-first-column nil
  522. "Non-nil means format column one in tables with header tags.
  523. When nil, also column one will use data tags."
  524. :group 'org-export-tables
  525. :type 'boolean)
  526. (defcustom org-html-table-caption-above t
  527. "When non-nil, place caption string at the beginning of the table.
  528. Otherwise, place it near the end."
  529. :group 'org-export-html
  530. :type 'boolean)
  531. ;;;; Tags
  532. (defcustom org-html-tag-class-prefix ""
  533. "Prefix to class names for TODO keywords.
  534. Each tag gets a class given by the tag itself, with this prefix.
  535. The default prefix is empty because it is nice to just use the keyword
  536. as a class name. But if you get into conflicts with other, existing
  537. CSS classes, then this prefix can be very useful."
  538. :group 'org-export-html
  539. :type 'string)
  540. ;;;; Template :: Generic
  541. (defcustom org-html-extension "html"
  542. "The extension for exported HTML files."
  543. :group 'org-export-html
  544. :type 'string)
  545. (defcustom org-html-xml-declaration
  546. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  547. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  548. "The extension for exported HTML files.
  549. %s will be replaced with the charset of the exported file.
  550. This may be a string, or an alist with export extensions
  551. and corresponding declarations."
  552. :group 'org-export-html
  553. :type '(choice
  554. (string :tag "Single declaration")
  555. (repeat :tag "Dependent on extension"
  556. (cons (string :tag "Extension")
  557. (string :tag "Declaration")))))
  558. (defcustom org-html-coding-system 'utf-8
  559. "Coding system for HTML export.
  560. Use utf-8 as the default value."
  561. :group 'org-export-html
  562. :type 'coding-system)
  563. (defcustom org-html-divs '("preamble" "content" "postamble")
  564. "The name of the main divs for HTML export.
  565. This is a list of three strings, the first one for the preamble
  566. DIV, the second one for the content DIV and the third one for the
  567. postamble DIV."
  568. :group 'org-export-html
  569. :type '(list
  570. (string :tag " Div for the preamble:")
  571. (string :tag " Div for the content:")
  572. (string :tag "Div for the postamble:")))
  573. ;;;; Template :: Mathjax
  574. (defcustom org-html-mathjax-options
  575. '((path "http://orgmode.org/mathjax/MathJax.js")
  576. (scale "100")
  577. (align "center")
  578. (indent "2em")
  579. (mathml nil))
  580. "Options for MathJax setup.
  581. path The path where to find MathJax
  582. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  583. align How to align display math: left, center, or right
  584. indent If align is not center, how far from the left/right side?
  585. mathml Should a MathML player be used if available?
  586. This is faster and reduces bandwidth use, but currently
  587. sometimes has lower spacing quality. Therefore, the default is
  588. nil. When browsers get better, this switch can be flipped.
  589. You can also customize this for each buffer, using something like
  590. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  591. :group 'org-export-html
  592. :type '(list :greedy t
  593. (list :tag "path (the path from where to load MathJax.js)"
  594. (const :format " " path) (string))
  595. (list :tag "scale (scaling for the displayed math)"
  596. (const :format " " scale) (string))
  597. (list :tag "align (alignment of displayed equations)"
  598. (const :format " " align) (string))
  599. (list :tag "indent (indentation with left or right alignment)"
  600. (const :format " " indent) (string))
  601. (list :tag "mathml (should MathML display be used is possible)"
  602. (const :format " " mathml) (boolean))))
  603. (defcustom org-html-mathjax-template
  604. "<script type=\"text/javascript\" src=\"%PATH\">
  605. <!--/*--><![CDATA[/*><!--*/
  606. MathJax.Hub.Config({
  607. // Only one of the two following lines, depending on user settings
  608. // First allows browser-native MathML display, second forces HTML/CSS
  609. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  610. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  611. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  612. \"TeX/noUndefined.js\"],
  613. tex2jax: {
  614. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  615. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  616. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  617. ignoreClass: \"tex2jax_ignore\",
  618. processEscapes: false,
  619. processEnvironments: true,
  620. preview: \"TeX\"
  621. },
  622. showProcessingMessages: true,
  623. displayAlign: \"%ALIGN\",
  624. displayIndent: \"%INDENT\",
  625. \"HTML-CSS\": {
  626. scale: %SCALE,
  627. availableFonts: [\"STIX\",\"TeX\"],
  628. preferredFont: \"TeX\",
  629. webFont: \"TeX\",
  630. imageFont: \"TeX\",
  631. showMathMenu: true,
  632. },
  633. MMLorHTML: {
  634. prefer: {
  635. MSIE: \"MML\",
  636. Firefox: \"MML\",
  637. Opera: \"HTML\",
  638. other: \"HTML\"
  639. }
  640. }
  641. });
  642. /*]]>*///-->
  643. </script>"
  644. "The MathJax setup for XHTML files."
  645. :group 'org-export-html
  646. :type 'string)
  647. ;;;; Template :: Postamble
  648. (defcustom org-html-postamble 'auto
  649. "Non-nil means insert a postamble in HTML export.
  650. When `t', insert a string as defined by the formatting string in
  651. `org-html-postamble-format'. When set to a string, this
  652. string overrides `org-html-postamble-format'. When set to
  653. 'auto, discard `org-html-postamble-format' and honor
  654. `org-export-author/email/creator-info' variables. When set to a
  655. function, apply this function and insert the returned string.
  656. The function takes the property list of export options as its
  657. only argument.
  658. Setting :html-postamble in publishing projects will take
  659. precedence over this variable."
  660. :group 'org-export-html
  661. :type '(choice (const :tag "No postamble" nil)
  662. (const :tag "Auto preamble" 'auto)
  663. (const :tag "Default formatting string" t)
  664. (string :tag "Custom formatting string")
  665. (function :tag "Function (must return a string)")))
  666. (defcustom org-html-postamble-format
  667. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  668. <p class=\"date\">Date: %d</p>
  669. <p class=\"creator\">Generated by %c</p>
  670. <p class=\"xhtml-validation\">%v</p>"))
  671. "Alist of languages and format strings for the HTML postamble.
  672. The first element of each list is the language code, as used for
  673. the #+LANGUAGE keyword.
  674. The second element of each list is a format string to format the
  675. postamble itself. This format string can contain these elements:
  676. %a stands for the author's name.
  677. %e stands for the author's email.
  678. %d stands for the date.
  679. %c will be replaced by information about Org/Emacs versions.
  680. %v will be replaced by `org-html-validation-link'.
  681. If you need to use a \"%\" character, you need to escape it
  682. like that: \"%%\"."
  683. :group 'org-export-html
  684. :type '(alist :key-type (string :tag "Language")
  685. :value-type (string :tag "Format string")))
  686. (defcustom org-html-validation-link
  687. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  688. "Link to HTML validation service."
  689. :group 'org-export-html
  690. :type 'string)
  691. (defcustom org-html-creator-string
  692. (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
  693. (if (fboundp 'org-version) (org-version) "(Unknown)")
  694. emacs-version)
  695. "String to insert at the end of the HTML document."
  696. :group 'org-export-html
  697. :type '(string :tag "Creator string"))
  698. ;;;; Template :: Preamble
  699. (defcustom org-html-preamble t
  700. "Non-nil means insert a preamble in HTML export.
  701. When `t', insert a string as defined by one of the formatting
  702. strings in `org-html-preamble-format'. When set to a
  703. string, this string overrides `org-html-preamble-format'.
  704. When set to a function, apply this function and insert the
  705. returned string. The function takes the property list of export
  706. options as its only argument.
  707. Setting :html-preamble in publishing projects will take
  708. precedence over this variable."
  709. :group 'org-export-html
  710. :type '(choice (const :tag "No preamble" nil)
  711. (const :tag "Default preamble" t)
  712. (string :tag "Custom formatting string")
  713. (function :tag "Function (must return a string)")))
  714. (defcustom org-html-preamble-format '(("en" ""))
  715. "Alist of languages and format strings for the HTML preamble.
  716. The first element of each list is the language code, as used for
  717. the #+LANGUAGE keyword.
  718. The second element of each list is a format string to format the
  719. preamble itself. This format string can contain these elements:
  720. %t stands for the title.
  721. %a stands for the author's name.
  722. %e stands for the author's email.
  723. %d stands for the date.
  724. If you need to use a \"%\" character, you need to escape it
  725. like that: \"%%\"."
  726. :group 'org-export-html
  727. :type '(alist :key-type (string :tag "Language")
  728. :value-type (string :tag "Format string")))
  729. (defcustom org-html-link-up ""
  730. "Where should the \"UP\" link of exported HTML pages lead?"
  731. :group 'org-export-html
  732. :type '(string :tag "File or URL"))
  733. (defcustom org-html-link-home ""
  734. "Where should the \"HOME\" link of exported HTML pages lead?"
  735. :group 'org-export-html
  736. :type '(string :tag "File or URL"))
  737. (defcustom org-html-home/up-format
  738. "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  739. <a accesskey=\"h\" href=\"%s\"> UP </a>
  740. |
  741. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  742. </div>"
  743. "Snippet used to insert the HOME and UP links.
  744. This is a format string, the first %s will receive the UP link,
  745. the second the HOME link. If both `org-html-link-up' and
  746. `org-html-link-home' are empty, the entire snippet will be
  747. ignored."
  748. :group 'org-export-html
  749. :type 'string)
  750. ;;;; Template :: Scripts
  751. (defcustom org-html-style-include-scripts t
  752. "Non-nil means include the JavaScript snippets in exported HTML files.
  753. The actual script is defined in `org-html-scripts' and should
  754. not be modified."
  755. :group 'org-export-html
  756. :type 'boolean)
  757. ;;;; Template :: Styles
  758. (defcustom org-html-style-include-default t
  759. "Non-nil means include the default style in exported HTML files.
  760. The actual style is defined in `org-html-style-default' and should
  761. not be modified. Use the variables `org-html-style' to add
  762. your own style information."
  763. :group 'org-export-html
  764. :type 'boolean)
  765. ;;;###autoload
  766. (put 'org-html-style-include-default 'safe-local-variable 'booleanp)
  767. (defcustom org-html-style ""
  768. "Org-wide style definitions for exported HTML files.
  769. This variable needs to contain the full HTML structure to provide a style,
  770. including the surrounding HTML tags. If you set the value of this variable,
  771. you should consider to include definitions for the following classes:
  772. title, todo, done, timestamp, timestamp-kwd, tag, target.
  773. For example, a valid value would be:
  774. <style type=\"text/css\">
  775. <![CDATA[
  776. p { font-weight: normal; color: gray; }
  777. h1 { color: black; }
  778. .title { text-align: center; }
  779. .todo, .timestamp-kwd { color: red; }
  780. .done { color: green; }
  781. ]]>
  782. </style>
  783. If you'd like to refer to an external style file, use something like
  784. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  785. As the value of this option simply gets inserted into the HTML <head> header,
  786. you can \"misuse\" it to add arbitrary text to the header.
  787. See also the variable `org-html-style-extra'."
  788. :group 'org-export-html
  789. :type 'string)
  790. ;;;###autoload
  791. (put 'org-html-style 'safe-local-variable 'stringp)
  792. (defcustom org-html-style-extra ""
  793. "Additional style information for HTML export.
  794. The value of this variable is inserted into the HTML buffer right after
  795. the value of `org-html-style'. Use this variable for per-file
  796. settings of style information, and do not forget to surround the style
  797. settings with <style>...</style> tags."
  798. :group 'org-export-html
  799. :type 'string)
  800. ;;;###autoload
  801. (put 'org-html-style-extra 'safe-local-variable 'stringp)
  802. ;;;; Todos
  803. (defcustom org-html-todo-kwd-class-prefix ""
  804. "Prefix to class names for TODO keywords.
  805. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  806. The default prefix is empty because it is nice to just use the keyword
  807. as a class name. But if you get into conflicts with other, existing
  808. CSS classes, then this prefix can be very useful."
  809. :group 'org-export-html
  810. :type 'string)
  811. (defcustom org-html-display-buffer-mode 'html-mode
  812. "Default mode when visiting the HTML output."
  813. :group 'org-export-html
  814. :version "24.3"
  815. :type '(choice (function 'html-mode)
  816. (function 'nxml-mode)
  817. (function :tag "Other mode")))
  818. ;;; Internal Functions
  819. (defun org-html-format-inline-image (src &optional
  820. caption label attr standalone-p)
  821. (let* ((id (if (not label) ""
  822. (format " id=\"%s\"" (org-export-solidify-link-text label))))
  823. (attr (concat attr
  824. (cond
  825. ((string-match "\\<alt=" (or attr "")) "")
  826. ((string-match "^ltxpng/" src)
  827. (format " alt=\"%s\""
  828. (org-html-encode-plain-text
  829. (org-find-text-property-in-string
  830. 'org-latex-src src))))
  831. (t (format " alt=\"%s\""
  832. (file-name-nondirectory src)))))))
  833. (cond
  834. (standalone-p
  835. (let ((img (format "<img src=\"%s\" %s/>" src attr)))
  836. (format "\n<div%s class=\"figure\">%s%s\n</div>"
  837. id (format "\n<p>%s</p>" img)
  838. (when caption (format "\n<p>%s</p>" caption)))))
  839. (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
  840. (defun org-html--textarea-block (element)
  841. "Transcode ELEMENT into a textarea block.
  842. ELEMENT is either a src block or an example block."
  843. (let ((code (car (org-export-unravel-code element)))
  844. (attr (org-export-read-attribute :attr_html element)))
  845. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
  846. (or (plist-get attr :width) 80)
  847. (or (plist-get attr :height) (org-count-lines code))
  848. code)))
  849. ;;;; Bibliography
  850. (defun org-html-bibliography ()
  851. "Find bibliography, cut it out and return it."
  852. (catch 'exit
  853. (let (beg end (cnt 1) bib)
  854. (save-excursion
  855. (goto-char (point-min))
  856. (when (re-search-forward
  857. "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  858. (setq beg (match-beginning 0))
  859. (while (re-search-forward "</?div\\>" nil t)
  860. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  861. (when (= cnt 0)
  862. (and (looking-at ">") (forward-char 1))
  863. (setq bib (buffer-substring beg (point)))
  864. (delete-region beg (point))
  865. (throw 'exit bib))))
  866. nil))))
  867. ;;;; Table
  868. (defun org-html-splice-attributes (tag attributes)
  869. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  870. (if (not attributes)
  871. tag
  872. (let (oldatt newatt)
  873. (setq oldatt (org-extract-attributes-from-string tag)
  874. tag (pop oldatt)
  875. newatt (cdr (org-extract-attributes-from-string attributes)))
  876. (while newatt
  877. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  878. (if (string-match ">" tag)
  879. (setq tag
  880. (replace-match (concat (org-attributes-to-string oldatt) ">")
  881. t t tag)))
  882. tag)))
  883. (defun org-export-splice-style (style extra)
  884. "Splice EXTRA into STYLE, just before \"</style>\"."
  885. (if (and (stringp extra)
  886. (string-match "\\S-" extra)
  887. (string-match "</style>" style))
  888. (concat (substring style 0 (match-beginning 0))
  889. "\n" extra "\n"
  890. (substring style (match-beginning 0)))
  891. style))
  892. (defun org-export-htmlize-region-for-paste (beg end)
  893. "Convert the region to HTML, using htmlize.el.
  894. This is much like `htmlize-region-for-paste', only that it uses
  895. the settings define in the org-... variables."
  896. (let* ((htmlize-output-type org-export-htmlize-output-type)
  897. (htmlize-css-name-prefix org-export-htmlize-font-prefix)
  898. (htmlbuf (htmlize-region beg end)))
  899. (unwind-protect
  900. (with-current-buffer htmlbuf
  901. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  902. (plist-get htmlize-buffer-places 'content-end)))
  903. (kill-buffer htmlbuf))))
  904. ;;;###autoload
  905. (defun org-export-htmlize-generate-css ()
  906. "Create the CSS for all font definitions in the current Emacs session.
  907. Use this to create face definitions in your CSS style file that can then
  908. be used by code snippets transformed by htmlize.
  909. This command just produces a buffer that contains class definitions for all
  910. faces used in the current Emacs session. You can copy and paste the ones you
  911. need into your CSS file.
  912. If you then set `org-export-htmlize-output-type' to `css', calls
  913. to the function `org-export-htmlize-region-for-paste' will
  914. produce code that uses these same face definitions."
  915. (interactive)
  916. (require 'htmlize)
  917. (and (get-buffer "*html*") (kill-buffer "*html*"))
  918. (with-temp-buffer
  919. (let ((fl (face-list))
  920. (htmlize-css-name-prefix "org-")
  921. (htmlize-output-type 'css)
  922. f i)
  923. (while (setq f (pop fl)
  924. i (and f (face-attribute f :inherit)))
  925. (when (and (symbolp f) (or (not i) (not (listp i))))
  926. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  927. (htmlize-region (point-min) (point-max))))
  928. (org-pop-to-buffer-same-window "*html*")
  929. (goto-char (point-min))
  930. (if (re-search-forward "<style" nil t)
  931. (delete-region (point-min) (match-beginning 0)))
  932. (if (re-search-forward "</style>" nil t)
  933. (delete-region (1+ (match-end 0)) (point-max)))
  934. (beginning-of-line 1)
  935. (if (looking-at " +") (replace-match ""))
  936. (goto-char (point-min)))
  937. (defun org-html--make-string (n string)
  938. "Build a string by concatenating N times STRING."
  939. (let (out) (dotimes (i n out) (setq out (concat string out)))))
  940. (defun org-html-toc-text (toc-entries)
  941. (let* ((prev-level (1- (nth 1 (car toc-entries))))
  942. (start-level prev-level))
  943. (concat
  944. (mapconcat
  945. (lambda (entry)
  946. (let ((headline (nth 0 entry))
  947. (level (nth 1 entry)))
  948. (concat
  949. (let* ((cnt (- level prev-level))
  950. (times (if (> cnt 0) (1- cnt) (- cnt)))
  951. rtn)
  952. (setq prev-level level)
  953. (concat
  954. (org-html--make-string
  955. times (cond ((> cnt 0) "\n<ul>\n<li>")
  956. ((< cnt 0) "</li>\n</ul>\n")))
  957. (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
  958. headline)))
  959. toc-entries "")
  960. (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
  961. (defun* org-html-format-toc-headline
  962. (todo todo-type priority text tags
  963. &key level section-number headline-label &allow-other-keys)
  964. (let ((headline (concat
  965. section-number (and section-number ". ")
  966. text
  967. (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags))))
  968. (format "<a href=\"#%s\">%s</a>"
  969. (org-export-solidify-link-text headline-label)
  970. (if (not nil) headline
  971. (format "<span class=\"%s\">%s</span>" todo-type headline)))))
  972. (defun org-html-toc (depth info)
  973. (let* ((headlines (org-export-collect-headlines info depth))
  974. (toc-entries
  975. (loop for headline in headlines collect
  976. (list (org-html-format-headline--wrap
  977. headline info 'org-html-format-toc-headline)
  978. (org-export-get-relative-level headline info)))))
  979. (when toc-entries
  980. (concat
  981. "<div id=\"table-of-contents\">\n"
  982. (format "<h%d>%s</h%d>\n"
  983. org-html-toplevel-hlevel
  984. (org-html--translate "Table of Contents" info)
  985. org-html-toplevel-hlevel)
  986. "<div id=\"text-table-of-contents\">"
  987. (org-html-toc-text toc-entries)
  988. "</div>\n"
  989. "</div>\n"))))
  990. (defun org-html-fix-class-name (kwd) ; audit callers of this function
  991. "Turn todo keyword into a valid class name.
  992. Replaces invalid characters with \"_\"."
  993. (save-match-data
  994. (while (string-match "[^a-zA-Z0-9_]" kwd)
  995. (setq kwd (replace-match "_" t t kwd))))
  996. kwd)
  997. (defun org-html-format-footnote-reference (n def refcnt)
  998. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  999. (format org-html-footnote-format
  1000. (let* ((id (format "fnr.%s%s" n extra))
  1001. (href (format " href=\"#fn.%s\"" n))
  1002. (attributes (concat " class=\"footref\"" href)))
  1003. (org-html--anchor id n attributes)))))
  1004. (defun org-html-format-footnotes-section (section-name definitions)
  1005. (if (not definitions) ""
  1006. (format org-html-footnotes-section section-name definitions)))
  1007. (defun org-html-format-footnote-definition (fn)
  1008. (let ((n (car fn)) (def (cdr fn)))
  1009. (format
  1010. "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
  1011. (format org-html-footnote-format
  1012. (let* ((id (format "fn.%s" n))
  1013. (href (format " href=\"#fnr.%s\"" n))
  1014. (attributes (concat " class=\"footnum\"" href)))
  1015. (org-html--anchor id n attributes)))
  1016. def)))
  1017. (defun org-html-footnote-section (info)
  1018. (let* ((fn-alist (org-export-collect-footnote-definitions
  1019. (plist-get info :parse-tree) info))
  1020. (fn-alist
  1021. (loop for (n type raw) in fn-alist collect
  1022. (cons n (if (eq (org-element-type raw) 'org-data)
  1023. (org-trim (org-export-data raw info))
  1024. (format "<p>%s</p>"
  1025. (org-trim (org-export-data raw info))))))))
  1026. (when fn-alist
  1027. (org-html-format-footnotes-section
  1028. (org-html--translate "Footnotes" info)
  1029. (format
  1030. "<table>\n%s\n</table>\n"
  1031. (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
  1032. ;;; Template
  1033. (defun org-html--build-meta-info (info)
  1034. "Return meta tags for exported document.
  1035. INFO is a plist used as a communication channel."
  1036. (let* ((title (org-export-data (plist-get info :title) info))
  1037. (author (and (plist-get info :with-author)
  1038. (let ((auth (plist-get info :author)))
  1039. (and auth (org-export-data auth info)))))
  1040. (date (and (plist-get info :with-date)
  1041. (let ((date (plist-get info :date)))
  1042. (and date (org-export-data date info)))))
  1043. (description (plist-get info :description))
  1044. (keywords (plist-get info :keywords)))
  1045. (concat
  1046. (format "<title>%s</title>\n" title)
  1047. (format
  1048. "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
  1049. (or (and org-html-coding-system
  1050. (fboundp 'coding-system-get)
  1051. (coding-system-get org-html-coding-system 'mime-charset))
  1052. "iso-8859-1"))
  1053. (format "<meta name=\"title\" content=\"%s\"/>\n" title)
  1054. (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
  1055. (and date (format "<meta name=\"generated\" content=\"%s\"/>\n" date))
  1056. (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
  1057. (and description
  1058. (format "<meta name=\"description\" content=\"%s\"/>\n" description))
  1059. (and keywords
  1060. (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
  1061. (defun org-html--build-style (info)
  1062. "Return style information for exported document.
  1063. INFO is a plist used as a communication channel."
  1064. (org-element-normalize-string
  1065. (concat
  1066. (when (plist-get info :html-style-include-default) org-html-style-default)
  1067. (org-element-normalize-string (plist-get info :html-style))
  1068. (org-element-normalize-string (plist-get info :html-style-extra))
  1069. (when (plist-get info :html-style-include-scripts) org-html-scripts))))
  1070. (defun org-html--build-mathjax-config (info)
  1071. "Insert the user setup into the mathjax template.
  1072. INFO is a plist used as a communication channel."
  1073. (when (memq (plist-get info :with-latex) '(mathjax t))
  1074. (let ((template org-html-mathjax-template)
  1075. (options org-html-mathjax-options)
  1076. (in-buffer (or (plist-get info :html-mathjax) ""))
  1077. name val (yes " ") (no "// ") x)
  1078. (mapc
  1079. (lambda (e)
  1080. (setq name (car e) val (nth 1 e))
  1081. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  1082. (setq val (car (read-from-string
  1083. (substring in-buffer (match-end 0))))))
  1084. (if (not (stringp val)) (setq val (format "%s" val)))
  1085. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  1086. (setq template (replace-match val t t template))))
  1087. options)
  1088. (setq val (nth 1 (assq 'mathml options)))
  1089. (if (string-match (concat "\\<mathml:") in-buffer)
  1090. (setq val (car (read-from-string
  1091. (substring in-buffer (match-end 0))))))
  1092. ;; Exchange prefixes depending on mathml setting.
  1093. (if (not val) (setq x yes yes no no x))
  1094. ;; Replace cookies to turn on or off the config/jax lines.
  1095. (if (string-match ":MMLYES:" template)
  1096. (setq template (replace-match yes t t template)))
  1097. (if (string-match ":MMLNO:" template)
  1098. (setq template (replace-match no t t template)))
  1099. ;; Return the modified template.
  1100. (org-element-normalize-string template))))
  1101. (defun org-html--build-preamble (info)
  1102. "Return document preamble as a string, or nil.
  1103. INFO is a plist used as a communication channel."
  1104. (let ((preamble (plist-get info :html-preamble)))
  1105. (when preamble
  1106. (let ((preamble-contents
  1107. (if (functionp preamble) (funcall preamble info)
  1108. (let ((title (org-export-data (plist-get info :title) info))
  1109. (date (if (not (plist-get info :with-date)) ""
  1110. (org-export-data (plist-get info :date) info)))
  1111. (author (if (not (plist-get info :with-author)) ""
  1112. (org-export-data (plist-get info :author) info)))
  1113. (email (if (not (plist-get info :with-email)) ""
  1114. (plist-get info :email))))
  1115. (if (stringp preamble)
  1116. (format-spec preamble
  1117. `((?t . ,title) (?a . ,author)
  1118. (?d . ,date) (?e . ,email)))
  1119. (format-spec
  1120. (or (cadr (assoc (plist-get info :language)
  1121. org-html-preamble-format))
  1122. (cadr (assoc "en" org-html-preamble-format)))
  1123. `((?t . ,title) (?a . ,author)
  1124. (?d . ,date) (?e . ,email))))))))
  1125. (when (org-string-nw-p preamble-contents)
  1126. (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs))
  1127. (org-element-normalize-string preamble-contents)
  1128. "</div>\n"))))))
  1129. (defun org-html--build-postamble (info)
  1130. "Return document postamble as a string, or nil.
  1131. INFO is a plist used as a communication channel."
  1132. (let ((postamble (plist-get info :html-postamble)))
  1133. (when postamble
  1134. (let ((postamble-contents
  1135. (if (functionp postamble) (funcall postamble info)
  1136. (let ((date (if (not (plist-get info :with-date)) ""
  1137. (org-export-data (plist-get info :date) info)))
  1138. (author (let ((author (plist-get info :author)))
  1139. (and author (org-export-data author info))))
  1140. (email (mapconcat
  1141. (lambda (e)
  1142. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1143. (split-string (plist-get info :email) ",+ *")
  1144. ", "))
  1145. (html-validation-link (or org-html-validation-link ""))
  1146. (creator-info (plist-get info :creator)))
  1147. (cond ((stringp postamble)
  1148. (format-spec postamble
  1149. `((?a . ,author) (?e . ,email)
  1150. (?d . ,date) (?c . ,creator-info)
  1151. (?v . ,html-validation-link))))
  1152. ((eq postamble 'auto)
  1153. (concat
  1154. (when (plist-get info :time-stamp-file)
  1155. (format "<p class=\"date\">%s: %s</p>\n"
  1156. (org-html--translate "Date" info)
  1157. date))
  1158. (when (and (plist-get info :with-author) author)
  1159. (format "<p class=\"author\">%s : %s</p>\n"
  1160. (org-html--translate "Author" info)
  1161. author))
  1162. (when (and (plist-get info :with-email) email)
  1163. (format "<p class=\"email\">%s </p>\n" email))
  1164. (when (plist-get info :with-creator)
  1165. (format "<p class=\"creator\">%s</p>\n"
  1166. creator-info))
  1167. html-validation-link "\n"))
  1168. (t (format-spec
  1169. (or (cadr (assoc (plist-get info :language)
  1170. org-html-postamble-format))
  1171. (cadr (assoc "en" org-html-postamble-format)))
  1172. `((?a . ,author) (?e . ,email)
  1173. (?d . ,date) (?c . ,creator-info)
  1174. (?v . ,html-validation-link)))))))))
  1175. (when (org-string-nw-p postamble-contents)
  1176. (concat
  1177. (format "<div id=\"%s\">\n" (nth 2 org-html-divs))
  1178. (org-element-normalize-string postamble-contents)
  1179. "</div>\n"))))))
  1180. (defun org-html-inner-template (contents info)
  1181. "Return body of document string after HTML conversion.
  1182. CONTENTS is the transcoded contents string. INFO is a plist
  1183. holding export options."
  1184. (concat
  1185. (format "<div id=\"%s\">\n" (nth 1 org-html-divs))
  1186. ;; Document title.
  1187. (format "<h1 class=\"title\">%s</h1>\n"
  1188. (org-export-data (plist-get info :title) info))
  1189. ;; Table of contents.
  1190. (let ((depth (plist-get info :with-toc)))
  1191. (when depth (org-html-toc depth info)))
  1192. ;; Document contents.
  1193. contents
  1194. ;; Footnotes section.
  1195. (org-html-footnote-section info)
  1196. ;; Bibliography.
  1197. (org-html-bibliography)
  1198. "\n</div>"))
  1199. (defun org-html-template (contents info)
  1200. "Return complete document string after HTML conversion.
  1201. CONTENTS is the transcoded contents string. INFO is a plist
  1202. holding export options."
  1203. (concat
  1204. (format
  1205. (or (and (stringp org-html-xml-declaration)
  1206. org-html-xml-declaration)
  1207. (cdr (assoc (plist-get info :html-extension)
  1208. org-html-xml-declaration))
  1209. (cdr (assoc "html" org-html-xml-declaration))
  1210. "")
  1211. (or (and org-html-coding-system
  1212. (fboundp 'coding-system-get)
  1213. (coding-system-get org-html-coding-system 'mime-charset))
  1214. "iso-8859-1"))
  1215. "\n"
  1216. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1217. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
  1218. (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
  1219. (plist-get info :language) (plist-get info :language))
  1220. "<head>\n"
  1221. (org-html--build-meta-info info)
  1222. (org-html--build-style info)
  1223. (org-html--build-mathjax-config info)
  1224. "</head>\n"
  1225. "<body>\n"
  1226. (let ((link-up (org-trim (plist-get info :html-link-up)))
  1227. (link-home (org-trim (plist-get info :html-link-home))))
  1228. (unless (and (string= link-up "") (string= link-up ""))
  1229. (format org-html-home/up-format
  1230. (or link-up link-home)
  1231. (or link-home link-up))))
  1232. ;; Preamble.
  1233. (org-html--build-preamble info)
  1234. ;; Document contents.
  1235. contents
  1236. ;; Postamble.
  1237. (org-html--build-postamble info)
  1238. ;; Closing document.
  1239. "</body>\n</html>"))
  1240. (defun org-html--translate (s info)
  1241. "Translate string S according to specified language.
  1242. INFO is a plist used as a communication channel."
  1243. (org-export-translate s :html info))
  1244. ;;;; Anchor
  1245. (defun org-html--anchor (&optional id desc attributes)
  1246. (let* ((name (and org-html-allow-name-attribute-in-anchors id))
  1247. (attributes (concat (and id (format " id=\"%s\"" id))
  1248. (and name (format " name=\"%s\"" name))
  1249. attributes)))
  1250. (format "<a%s>%s</a>" attributes (or desc ""))))
  1251. ;;;; Todo
  1252. (defun org-html--todo (todo)
  1253. (when todo
  1254. (format "<span class=\"%s %s%s\">%s</span>"
  1255. (if (member todo org-done-keywords) "done" "todo")
  1256. org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
  1257. todo)))
  1258. ;;;; Tags
  1259. (defun org-html--tags (tags)
  1260. (when tags
  1261. (format "<span class=\"tag\">%s</span>"
  1262. (mapconcat
  1263. (lambda (tag)
  1264. (format "<span class=\"%s\">%s</span>"
  1265. (concat org-html-tag-class-prefix
  1266. (org-html-fix-class-name tag))
  1267. tag))
  1268. tags "&nbsp;"))))
  1269. ;;;; Headline
  1270. (defun* org-html-format-headline
  1271. (todo todo-type priority text tags
  1272. &key level section-number headline-label &allow-other-keys)
  1273. (let ((section-number
  1274. (when section-number
  1275. (format "<span class=\"section-number-%d\">%s</span> "
  1276. level section-number)))
  1277. (todo (org-html--todo todo))
  1278. (tags (org-html--tags tags)))
  1279. (concat section-number todo (and todo " ") text
  1280. (and tags "&nbsp;&nbsp;&nbsp;") tags)))
  1281. ;;;; Src Code
  1282. (defun org-html-fontify-code (code lang)
  1283. "Color CODE with htmlize library.
  1284. CODE is a string representing the source code to colorize. LANG
  1285. is the language used for CODE, as a string, or nil."
  1286. (when code
  1287. (cond
  1288. ;; Case 1: No lang. Possibly an example block.
  1289. ((not lang)
  1290. ;; Simple transcoding.
  1291. (org-html-encode-plain-text code))
  1292. ;; Case 2: No htmlize or an inferior version of htmlize
  1293. ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
  1294. ;; Emit a warning.
  1295. (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
  1296. ;; Simple transcoding.
  1297. (org-html-encode-plain-text code))
  1298. (t
  1299. ;; Map language
  1300. (setq lang (or (assoc-default lang org-src-lang-modes) lang))
  1301. (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
  1302. (cond
  1303. ;; Case 1: Language is not associated with any Emacs mode
  1304. ((not (functionp lang-mode))
  1305. ;; Simple transcoding.
  1306. (org-html-encode-plain-text code))
  1307. ;; Case 2: Default. Fontify code.
  1308. (t
  1309. ;; htmlize
  1310. (setq code (with-temp-buffer
  1311. ;; Switch to language-specific mode.
  1312. (funcall lang-mode)
  1313. (insert code)
  1314. ;; Fontify buffer.
  1315. (font-lock-fontify-buffer)
  1316. ;; Remove formatting on newline characters.
  1317. (save-excursion
  1318. (let ((beg (point-min))
  1319. (end (point-max)))
  1320. (goto-char beg)
  1321. (while (progn (end-of-line) (< (point) end))
  1322. (put-text-property (point) (1+ (point)) 'face nil)
  1323. (forward-char 1))))
  1324. (org-src-mode)
  1325. (set-buffer-modified-p nil)
  1326. ;; Htmlize region.
  1327. (org-export-htmlize-region-for-paste
  1328. (point-min) (point-max))))
  1329. ;; Strip any encolosing <pre></pre> tags.
  1330. (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
  1331. (match-string 1 code)
  1332. code))))))))
  1333. (defun org-html-do-format-code
  1334. (code &optional lang refs retain-labels num-start)
  1335. "Format CODE string as source code.
  1336. Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
  1337. respectively, the language of the source code, as a string, an
  1338. alist between line numbers and references (as returned by
  1339. `org-export-unravel-code'), a boolean specifying if labels should
  1340. appear in the source code, and the number associated to the first
  1341. line of code."
  1342. (let* ((code-lines (org-split-string code "\n"))
  1343. (code-length (length code-lines))
  1344. (num-fmt
  1345. (and num-start
  1346. (format "%%%ds: "
  1347. (length (number-to-string (+ code-length num-start))))))
  1348. (code (org-html-fontify-code code lang)))
  1349. (org-export-format-code
  1350. code
  1351. (lambda (loc line-num ref)
  1352. (setq loc
  1353. (concat
  1354. ;; Add line number, if needed.
  1355. (when num-start
  1356. (format "<span class=\"linenr\">%s</span>"
  1357. (format num-fmt line-num)))
  1358. ;; Transcoded src line.
  1359. loc
  1360. ;; Add label, if needed.
  1361. (when (and ref retain-labels) (format " (%s)" ref))))
  1362. ;; Mark transcoded line as an anchor, if needed.
  1363. (if (not ref) loc
  1364. (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
  1365. ref loc)))
  1366. num-start refs)))
  1367. (defun org-html-format-code (element info)
  1368. "Format contents of ELEMENT as source code.
  1369. ELEMENT is either an example block or a src block. INFO is
  1370. a plist used as a communication channel."
  1371. (let* ((lang (org-element-property :language element))
  1372. ;; Extract code and references.
  1373. (code-info (org-export-unravel-code element))
  1374. (code (car code-info))
  1375. (refs (cdr code-info))
  1376. ;; Does the src block contain labels?
  1377. (retain-labels (org-element-property :retain-labels element))
  1378. ;; Does it have line numbers?
  1379. (num-start (case (org-element-property :number-lines element)
  1380. (continued (org-export-get-loc element info))
  1381. (new 0))))
  1382. (org-html-do-format-code code lang refs retain-labels num-start)))
  1383. ;;; Transcode Functions
  1384. ;;;; Bold
  1385. (defun org-html-bold (bold contents info)
  1386. "Transcode BOLD from Org to HTML.
  1387. CONTENTS is the text with bold markup. INFO is a plist holding
  1388. contextual information."
  1389. (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
  1390. contents))
  1391. ;;;; Center Block
  1392. (defun org-html-center-block (center-block contents info)
  1393. "Transcode a CENTER-BLOCK element from Org to HTML.
  1394. CONTENTS holds the contents of the block. INFO is a plist
  1395. holding contextual information."
  1396. (format "<div style=\"text-align: center\">\n%s</div>" contents))
  1397. ;;;; Clock
  1398. (defun org-html-clock (clock contents info)
  1399. "Transcode a CLOCK element from Org to HTML.
  1400. CONTENTS is nil. INFO is a plist used as a communication
  1401. channel."
  1402. (format "<p>
  1403. <span class=\"timestamp-wrapper\">
  1404. <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
  1405. </span>
  1406. </p>"
  1407. org-clock-string
  1408. (org-translate-time
  1409. (org-element-property :raw-value
  1410. (org-element-property :value clock)))
  1411. (let ((time (org-element-property :duration clock)))
  1412. (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
  1413. ;;;; Code
  1414. (defun org-html-code (code contents info)
  1415. "Transcode CODE from Org to HTML.
  1416. CONTENTS is nil. INFO is a plist holding contextual
  1417. information."
  1418. (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
  1419. (org-element-property :value code)))
  1420. ;;;; Drawer
  1421. (defun org-html-drawer (drawer contents info)
  1422. "Transcode a DRAWER element from Org to HTML.
  1423. CONTENTS holds the contents of the block. INFO is a plist
  1424. holding contextual information."
  1425. (if (functionp org-html-format-drawer-function)
  1426. (funcall org-html-format-drawer-function
  1427. (org-element-property :drawer-name drawer)
  1428. contents)
  1429. ;; If there's no user defined function: simply
  1430. ;; display contents of the drawer.
  1431. contents))
  1432. ;;;; Dynamic Block
  1433. (defun org-html-dynamic-block (dynamic-block contents info)
  1434. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1435. CONTENTS holds the contents of the block. INFO is a plist
  1436. holding contextual information. See `org-export-data'."
  1437. contents)
  1438. ;;;; Entity
  1439. (defun org-html-entity (entity contents info)
  1440. "Transcode an ENTITY object from Org to HTML.
  1441. CONTENTS are the definition itself. INFO is a plist holding
  1442. contextual information."
  1443. (org-element-property :html entity))
  1444. ;;;; Example Block
  1445. (defun org-html-example-block (example-block contents info)
  1446. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  1447. CONTENTS is nil. INFO is a plist holding contextual
  1448. information."
  1449. (if (org-export-read-attribute :attr_html example-block :textarea)
  1450. (org-html--textarea-block example-block)
  1451. (format "<pre class=\"example\">\n%s</pre>"
  1452. (org-html-format-code example-block info))))
  1453. ;;;; Export Snippet
  1454. (defun org-html-export-snippet (export-snippet contents info)
  1455. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  1456. CONTENTS is nil. INFO is a plist holding contextual
  1457. information."
  1458. (when (eq (org-export-snippet-backend export-snippet) 'html)
  1459. (org-element-property :value export-snippet)))
  1460. ;;;; Export Block
  1461. (defun org-html-export-block (export-block contents info)
  1462. "Transcode a EXPORT-BLOCK element from Org to HTML.
  1463. CONTENTS is nil. INFO is a plist holding contextual information."
  1464. (when (string= (org-element-property :type export-block) "HTML")
  1465. (org-remove-indentation (org-element-property :value export-block))))
  1466. ;;;; Fixed Width
  1467. (defun org-html-fixed-width (fixed-width contents info)
  1468. "Transcode a FIXED-WIDTH element from Org to HTML.
  1469. CONTENTS is nil. INFO is a plist holding contextual information."
  1470. (format "<pre class=\"example\">\n%s</pre>"
  1471. (org-html-do-format-code
  1472. (org-remove-indentation
  1473. (org-element-property :value fixed-width)))))
  1474. ;;;; Footnote Reference
  1475. (defun org-html-footnote-reference (footnote-reference contents info)
  1476. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  1477. CONTENTS is nil. INFO is a plist holding contextual information."
  1478. (concat
  1479. ;; Insert separator between two footnotes in a row.
  1480. (let ((prev (org-export-get-previous-element footnote-reference info)))
  1481. (when (eq (org-element-type prev) 'footnote-reference)
  1482. org-html-footnote-separator))
  1483. (cond
  1484. ((not (org-export-footnote-first-reference-p footnote-reference info))
  1485. (org-html-format-footnote-reference
  1486. (org-export-get-footnote-number footnote-reference info)
  1487. "IGNORED" 100))
  1488. ;; Inline definitions are secondary strings.
  1489. ((eq (org-element-property :type footnote-reference) 'inline)
  1490. (org-html-format-footnote-reference
  1491. (org-export-get-footnote-number footnote-reference info)
  1492. "IGNORED" 1))
  1493. ;; Non-inline footnotes definitions are full Org data.
  1494. (t (org-html-format-footnote-reference
  1495. (org-export-get-footnote-number footnote-reference info)
  1496. "IGNORED" 1)))))
  1497. ;;;; Headline
  1498. (defun org-html-format-headline--wrap (headline info
  1499. &optional format-function
  1500. &rest extra-keys)
  1501. "Transcode an HEADLINE element from Org to HTML.
  1502. CONTENTS holds the contents of the headline. INFO is a plist
  1503. holding contextual information."
  1504. (let* ((level (+ (org-export-get-relative-level headline info)
  1505. (1- org-html-toplevel-hlevel)))
  1506. (headline-number (org-export-get-headline-number headline info))
  1507. (section-number (and (not (org-export-low-level-p headline info))
  1508. (org-export-numbered-headline-p headline info)
  1509. (mapconcat 'number-to-string
  1510. headline-number ".")))
  1511. (todo (and (plist-get info :with-todo-keywords)
  1512. (let ((todo (org-element-property :todo-keyword headline)))
  1513. (and todo (org-export-data todo info)))))
  1514. (todo-type (and todo (org-element-property :todo-type headline)))
  1515. (priority (and (plist-get info :with-priority)
  1516. (org-element-property :priority headline)))
  1517. (text (org-export-data (org-element-property :title headline) info))
  1518. (tags (and (plist-get info :with-tags)
  1519. (org-export-get-tags headline info)))
  1520. (headline-label (or (org-element-property :custom-id headline)
  1521. (concat "sec-" (mapconcat 'number-to-string
  1522. headline-number "-"))))
  1523. (format-function (cond
  1524. ((functionp format-function) format-function)
  1525. ((functionp org-html-format-headline-function)
  1526. (function*
  1527. (lambda (todo todo-type priority text tags
  1528. &allow-other-keys)
  1529. (funcall org-html-format-headline-function
  1530. todo todo-type priority text tags))))
  1531. (t 'org-html-format-headline))))
  1532. (apply format-function
  1533. todo todo-type priority text tags
  1534. :headline-label headline-label :level level
  1535. :section-number section-number extra-keys)))
  1536. (defun org-html-headline (headline contents info)
  1537. "Transcode an HEADLINE element from Org to HTML.
  1538. CONTENTS holds the contents of the headline. INFO is a plist
  1539. holding contextual information."
  1540. ;; Empty contents?
  1541. (setq contents (or contents ""))
  1542. (let* ((numberedp (org-export-numbered-headline-p headline info))
  1543. (level (org-export-get-relative-level headline info))
  1544. (text (org-export-data (org-element-property :title headline) info))
  1545. (todo (and (plist-get info :with-todo-keywords)
  1546. (let ((todo (org-element-property :todo-keyword headline)))
  1547. (and todo (org-export-data todo info)))))
  1548. (todo-type (and todo (org-element-property :todo-type headline)))
  1549. (tags (and (plist-get info :with-tags)
  1550. (org-export-get-tags headline info)))
  1551. (priority (and (plist-get info :with-priority)
  1552. (org-element-property :priority headline)))
  1553. (section-number (and (org-export-numbered-headline-p headline info)
  1554. (mapconcat 'number-to-string
  1555. (org-export-get-headline-number
  1556. headline info) ".")))
  1557. ;; Create the headline text.
  1558. (full-text (org-html-format-headline--wrap headline info)))
  1559. (cond
  1560. ;; Case 1: This is a footnote section: ignore it.
  1561. ((org-element-property :footnote-section-p headline) nil)
  1562. ;; Case 2. This is a deep sub-tree: export it as a list item.
  1563. ;; Also export as items headlines for which no section
  1564. ;; format has been found.
  1565. ((org-export-low-level-p headline info)
  1566. ;; Build the real contents of the sub-tree.
  1567. (let* ((type (if numberedp 'ordered 'unordered))
  1568. (itemized-body (org-html-format-list-item
  1569. contents type nil nil full-text)))
  1570. (concat
  1571. (and (org-export-first-sibling-p headline info)
  1572. (org-html-begin-plain-list type))
  1573. itemized-body
  1574. (and (org-export-last-sibling-p headline info)
  1575. (org-html-end-plain-list type)))))
  1576. ;; Case 3. Standard headline. Export it as a section.
  1577. (t
  1578. (let* ((section-number (mapconcat 'number-to-string
  1579. (org-export-get-headline-number
  1580. headline info) "-"))
  1581. (ids (remove 'nil
  1582. (list (org-element-property :custom-id headline)
  1583. (concat "sec-" section-number)
  1584. (org-element-property :id headline))))
  1585. (preferred-id (car ids))
  1586. (extra-ids (cdr ids))
  1587. (extra-class (org-element-property :html-container-class headline))
  1588. (level1 (+ level (1- org-html-toplevel-hlevel))))
  1589. (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
  1590. (format "outline-container-%s"
  1591. (or (org-element-property :custom-id headline)
  1592. section-number))
  1593. (concat (format "outline-%d" level1) (and extra-class " ")
  1594. extra-class)
  1595. (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
  1596. level1
  1597. preferred-id
  1598. (mapconcat
  1599. (lambda (x)
  1600. (let ((id (org-export-solidify-link-text
  1601. (if (org-uuidgen-p x) (concat "ID-" x)
  1602. x))))
  1603. (org-html--anchor id)))
  1604. extra-ids "")
  1605. full-text
  1606. level1)
  1607. contents))))))
  1608. ;;;; Horizontal Rule
  1609. (defun org-html-horizontal-rule (horizontal-rule contents info)
  1610. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  1611. CONTENTS is nil. INFO is a plist holding contextual information."
  1612. "<hr/>")
  1613. ;;;; Inline Src Block
  1614. (defun org-html-inline-src-block (inline-src-block contents info)
  1615. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  1616. CONTENTS holds the contents of the item. INFO is a plist holding
  1617. contextual information."
  1618. (let* ((org-lang (org-element-property :language inline-src-block))
  1619. (code (org-element-property :value inline-src-block)))
  1620. (error "FIXME")))
  1621. ;;;; Inlinetask
  1622. (defun org-html-format-section (text class &optional id)
  1623. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  1624. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  1625. (defun org-html-inlinetask (inlinetask contents info)
  1626. "Transcode an INLINETASK element from Org to HTML.
  1627. CONTENTS holds the contents of the block. INFO is a plist
  1628. holding contextual information."
  1629. (cond
  1630. ;; If `org-html-format-inlinetask-function' is provided, call it
  1631. ;; with appropriate arguments.
  1632. ((functionp org-html-format-inlinetask-function)
  1633. (let ((format-function
  1634. (function*
  1635. (lambda (todo todo-type priority text tags
  1636. &key contents &allow-other-keys)
  1637. (funcall org-html-format-inlinetask-function
  1638. todo todo-type priority text tags contents)))))
  1639. (org-html-format-headline--wrap
  1640. inlinetask info format-function :contents contents)))
  1641. ;; Otherwise, use a default template.
  1642. (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
  1643. (org-html-format-headline--wrap inlinetask info)
  1644. contents))))
  1645. ;;;; Italic
  1646. (defun org-html-italic (italic contents info)
  1647. "Transcode ITALIC from Org to HTML.
  1648. CONTENTS is the text with italic markup. INFO is a plist holding
  1649. contextual information."
  1650. (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
  1651. ;;;; Item
  1652. (defun org-html-checkbox (checkbox)
  1653. (case checkbox (on "<code>[X]</code>")
  1654. (off "<code>[&nbsp;]</code>")
  1655. (trans "<code>[-]</code>")
  1656. (t "")))
  1657. (defun org-html-format-list-item (contents type checkbox
  1658. &optional term-counter-id
  1659. headline)
  1660. (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
  1661. (concat
  1662. (case type
  1663. (ordered
  1664. (let* ((counter term-counter-id)
  1665. (extra (if counter (format " value=\"%s\"" counter) "")))
  1666. (concat
  1667. (format "<li%s>" extra)
  1668. (when headline (concat headline "<br/>")))))
  1669. (unordered
  1670. (let* ((id term-counter-id)
  1671. (extra (if id (format " id=\"%s\"" id) "")))
  1672. (concat
  1673. (format "<li%s>" extra)
  1674. (when headline (concat headline "<br/>")))))
  1675. (descriptive
  1676. (let* ((term term-counter-id))
  1677. (setq term (or term "(no term)"))
  1678. ;; Check-boxes in descriptive lists are associated to tag.
  1679. (concat (format "<dt> %s </dt>"
  1680. (concat checkbox term))
  1681. "<dd>"))))
  1682. (unless (eq type 'descriptive) checkbox)
  1683. contents
  1684. (case type
  1685. (ordered "</li>")
  1686. (unordered "</li>")
  1687. (descriptive "</dd>")))))
  1688. (defun org-html-item (item contents info)
  1689. "Transcode an ITEM element from Org to HTML.
  1690. CONTENTS holds the contents of the item. INFO is a plist holding
  1691. contextual information."
  1692. (let* ((plain-list (org-export-get-parent item))
  1693. (type (org-element-property :type plain-list))
  1694. (counter (org-element-property :counter item))
  1695. (checkbox (org-element-property :checkbox item))
  1696. (tag (let ((tag (org-element-property :tag item)))
  1697. (and tag (org-export-data tag info)))))
  1698. (org-html-format-list-item
  1699. contents type checkbox (or tag counter))))
  1700. ;;;; Keyword
  1701. (defun org-html-keyword (keyword contents info)
  1702. "Transcode a KEYWORD element from Org to HTML.
  1703. CONTENTS is nil. INFO is a plist holding contextual information."
  1704. (let ((key (org-element-property :key keyword))
  1705. (value (org-element-property :value keyword)))
  1706. (cond
  1707. ((string= key "HTML") value)
  1708. ((string= key "INDEX") (format "\\index{%s}" value))
  1709. ;; Invisible targets.
  1710. ((string= key "TARGET") nil)
  1711. ((string= key "TOC")
  1712. (let ((value (downcase value)))
  1713. (cond
  1714. ((string-match "\\<headlines\\>" value)
  1715. (let ((depth (or (and (string-match "[0-9]+" value)
  1716. (string-to-number (match-string 0 value)))
  1717. (plist-get info :with-toc))))
  1718. (org-html-toc depth info)))
  1719. ((string= "tables" value) "\\listoftables")
  1720. ((string= "figures" value) "\\listoffigures")
  1721. ((string= "listings" value)
  1722. (cond
  1723. ;; At the moment, src blocks with a caption are wrapped
  1724. ;; into a figure environment.
  1725. (t "\\listoffigures")))))))))
  1726. ;;;; Latex Environment
  1727. (defun org-html-format-latex (latex-frag processing-type)
  1728. "Format LaTeX fragments into HTML."
  1729. (let ((cache-relpath "") (cache-dir "") bfn)
  1730. (unless (eq processing-type 'mathjax)
  1731. (setq bfn (buffer-file-name)
  1732. cache-relpath
  1733. (concat "ltxpng/"
  1734. (file-name-sans-extension
  1735. (file-name-nondirectory bfn)))
  1736. cache-dir (file-name-directory bfn)))
  1737. (with-temp-buffer
  1738. (insert latex-frag)
  1739. (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
  1740. nil nil processing-type)
  1741. (buffer-string))))
  1742. (defun org-html-latex-environment (latex-environment contents info)
  1743. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  1744. CONTENTS is nil. INFO is a plist holding contextual information."
  1745. (let ((processing-type (plist-get info :with-latex))
  1746. (latex-frag (org-remove-indentation
  1747. (org-element-property :value latex-environment)))
  1748. (caption (org-export-data
  1749. (org-export-get-caption latex-environment) info))
  1750. (attr nil) ; FIXME
  1751. (label (org-element-property :name latex-environment)))
  1752. (cond
  1753. ((memq processing-type '(t mathjax))
  1754. (org-html-format-latex latex-frag 'mathjax))
  1755. ((eq processing-type 'dvipng)
  1756. (let* ((formula-link (org-html-format-latex
  1757. latex-frag processing-type)))
  1758. (when (and formula-link
  1759. (string-match "file:\\([^]]*\\)" formula-link))
  1760. (org-html-format-inline-image
  1761. (match-string 1 formula-link) caption label attr t))))
  1762. (t latex-frag))))
  1763. ;;;; Latex Fragment
  1764. (defun org-html-latex-fragment (latex-fragment contents info)
  1765. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  1766. CONTENTS is nil. INFO is a plist holding contextual information."
  1767. (let ((latex-frag (org-element-property :value latex-fragment))
  1768. (processing-type (plist-get info :with-latex)))
  1769. (case processing-type
  1770. ((t mathjax)
  1771. (org-html-format-latex latex-frag 'mathjax))
  1772. (dvipng
  1773. (let* ((formula-link (org-html-format-latex
  1774. latex-frag processing-type)))
  1775. (when (and formula-link
  1776. (string-match "file:\\([^]]*\\)" formula-link))
  1777. (org-html-format-inline-image
  1778. (match-string 1 formula-link)))))
  1779. (t latex-frag))))
  1780. ;;;; Line Break
  1781. (defun org-html-line-break (line-break contents info)
  1782. "Transcode a LINE-BREAK object from Org to HTML.
  1783. CONTENTS is nil. INFO is a plist holding contextual information."
  1784. "<br/>\n")
  1785. ;;;; Link
  1786. (defun org-html-link--inline-image (link desc info)
  1787. "Return HTML code for an inline image.
  1788. LINK is the link pointing to the inline image. INFO is a plist
  1789. used as a communication channel."
  1790. (let* ((type (org-element-property :type link))
  1791. (raw-path (org-element-property :path link))
  1792. (path (cond ((member type '("http" "https"))
  1793. (concat type ":" raw-path))
  1794. ((file-name-absolute-p raw-path)
  1795. (expand-file-name raw-path))
  1796. (t raw-path)))
  1797. (parent (org-export-get-parent-element link))
  1798. (caption (org-export-data (org-export-get-caption parent) info))
  1799. (label (org-element-property :name parent))
  1800. ;; Retrieve latex attributes from the element around.
  1801. (attr (let ((raw-attr
  1802. (mapconcat #'identity
  1803. (org-element-property :attr_html parent)
  1804. " ")))
  1805. (unless (string= raw-attr "") raw-attr))))
  1806. ;; Now clear ATTR from any special keyword and set a default
  1807. ;; value if nothing is left.
  1808. (setq attr (if (not attr) "" (org-trim attr)))
  1809. ;; Return proper string, depending on DISPOSITION.
  1810. (org-html-format-inline-image
  1811. path caption label attr (org-html-standalone-image-p link info))))
  1812. (defvar org-html-standalone-image-predicate)
  1813. (defun org-html-standalone-image-p (element info &optional predicate)
  1814. "Test if ELEMENT is a standalone image for the purpose HTML export.
  1815. INFO is a plist holding contextual information.
  1816. Return non-nil, if ELEMENT is of type paragraph and it's sole
  1817. content, save for whitespaces, is a link that qualifies as an
  1818. inline image.
  1819. Return non-nil, if ELEMENT is of type link and it's containing
  1820. paragraph has no other content save for leading and trailing
  1821. whitespaces.
  1822. Return nil, otherwise.
  1823. Bind `org-html-standalone-image-predicate' to constrain
  1824. paragraph further. For example, to check for only captioned
  1825. standalone images, do the following.
  1826. \(setq org-html-standalone-image-predicate
  1827. \(lambda \(paragraph\)
  1828. \(org-element-property :caption paragraph\)\)\)"
  1829. (let ((paragraph (case (org-element-type element)
  1830. (paragraph element)
  1831. (link (and (org-export-inline-image-p
  1832. element org-html-inline-image-rules)
  1833. (org-export-get-parent element)))
  1834. (t nil))))
  1835. (when (eq (org-element-type paragraph) 'paragraph)
  1836. (when (or (not (and (boundp 'org-html-standalone-image-predicate)
  1837. (functionp org-html-standalone-image-predicate)))
  1838. (funcall org-html-standalone-image-predicate paragraph))
  1839. (let ((contents (org-element-contents paragraph)))
  1840. (loop for x in contents
  1841. with inline-image-count = 0
  1842. always (cond
  1843. ((eq (org-element-type x) 'plain-text)
  1844. (not (org-string-nw-p x)))
  1845. ((eq (org-element-type x) 'link)
  1846. (when (org-export-inline-image-p
  1847. x org-html-inline-image-rules)
  1848. (= (incf inline-image-count) 1)))
  1849. (t nil))))))))
  1850. (defun org-html-link (link desc info)
  1851. "Transcode a LINK object from Org to HTML.
  1852. DESC is the description part of the link, or the empty string.
  1853. INFO is a plist holding contextual information. See
  1854. `org-export-data'."
  1855. (let* ((--link-org-files-as-html-maybe
  1856. (function
  1857. (lambda (raw-path info)
  1858. "Treat links to `file.org' as links to `file.html', if needed.
  1859. See `org-html-link-org-files-as-html'."
  1860. (cond
  1861. ((and org-html-link-org-files-as-html
  1862. (string= ".org"
  1863. (downcase (file-name-extension raw-path "."))))
  1864. (concat (file-name-sans-extension raw-path) "."
  1865. (plist-get info :html-extension)))
  1866. (t raw-path)))))
  1867. (type (org-element-property :type link))
  1868. (raw-path (org-element-property :path link))
  1869. ;; Ensure DESC really exists, or set it to nil.
  1870. (desc (and (not (string= desc "")) desc))
  1871. (path (cond
  1872. ((member type '("http" "https" "ftp" "mailto"))
  1873. (concat type ":" raw-path))
  1874. ((string= type "file")
  1875. ;; Treat links to ".org" files as ".html", if needed.
  1876. (setq raw-path (funcall --link-org-files-as-html-maybe
  1877. raw-path info))
  1878. ;; If file path is absolute, prepend it with protocol
  1879. ;; component - "file://".
  1880. (if (not (file-name-absolute-p raw-path)) raw-path
  1881. (concat "file://" (expand-file-name raw-path))))
  1882. (t raw-path)))
  1883. attributes protocol)
  1884. ;; Extract attributes from parent's paragraph.
  1885. (and (setq attributes
  1886. (mapconcat
  1887. 'identity
  1888. (let ((att (org-element-property
  1889. :attr_html (org-export-get-parent-element link))))
  1890. (unless (and desc att (string-match (regexp-quote (car att)) desc)) att))
  1891. " "))
  1892. (setq attributes (concat " " attributes)))
  1893. (cond
  1894. ;; Image file.
  1895. ((and (or (eq t org-html-inline-images)
  1896. (and org-html-inline-images (not desc)))
  1897. (org-export-inline-image-p link org-html-inline-image-rules))
  1898. (org-html-link--inline-image link desc info))
  1899. ;; Radio target: Transcode target's contents and use them as
  1900. ;; link's description.
  1901. ((string= type "radio")
  1902. (let ((destination (org-export-resolve-radio-link link info)))
  1903. (when destination
  1904. (format "<a href=\"#%s\"%s>%s</a>"
  1905. (org-export-solidify-link-text path)
  1906. attributes
  1907. (org-export-data (org-element-contents destination) info)))))
  1908. ;; Links pointing to an headline: Find destination and build
  1909. ;; appropriate referencing command.
  1910. ((member type '("custom-id" "fuzzy" "id"))
  1911. (let ((destination (if (string= type "fuzzy")
  1912. (org-export-resolve-fuzzy-link link info)
  1913. (org-export-resolve-id-link link info))))
  1914. (case (org-element-type destination)
  1915. ;; ID link points to an external file.
  1916. (plain-text
  1917. (let ((fragment (concat "ID-" path))
  1918. ;; Treat links to ".org" files as ".html", if needed.
  1919. (path (funcall --link-org-files-as-html-maybe
  1920. destination info)))
  1921. (format "<a href=\"%s#%s\"%s>%s</a>"
  1922. path fragment attributes (or desc destination))))
  1923. ;; Fuzzy link points nowhere.
  1924. ((nil)
  1925. (format "<i>%s</i>"
  1926. (or desc
  1927. (org-export-data
  1928. (org-element-property :raw-link link) info))))
  1929. ;; Fuzzy link points to an invisible target.
  1930. (keyword nil)
  1931. ;; Link points to an headline.
  1932. (headline
  1933. (let ((href
  1934. ;; What href to use?
  1935. (cond
  1936. ;; Case 1: Headline is linked via it's CUSTOM_ID
  1937. ;; property. Use CUSTOM_ID.
  1938. ((string= type "custom-id")
  1939. (org-element-property :custom-id destination))
  1940. ;; Case 2: Headline is linked via it's ID property
  1941. ;; or through other means. Use the default href.
  1942. ((member type '("id" "fuzzy"))
  1943. (format "sec-%s"
  1944. (mapconcat 'number-to-string
  1945. (org-export-get-headline-number
  1946. destination info) "-")))
  1947. (t (error "Shouldn't reach here"))))
  1948. ;; What description to use?
  1949. (desc
  1950. ;; Case 1: Headline is numbered and LINK has no
  1951. ;; description or LINK's description matches
  1952. ;; headline's title. Display section number.
  1953. (if (and (org-export-numbered-headline-p destination info)
  1954. (or (not desc)
  1955. (string= desc (org-element-property
  1956. :raw-value destination))))
  1957. (mapconcat 'number-to-string
  1958. (org-export-get-headline-number
  1959. destination info) ".")
  1960. ;; Case 2: Either the headline is un-numbered or
  1961. ;; LINK has a custom description. Display LINK's
  1962. ;; description or headline's title.
  1963. (or desc (org-export-data (org-element-property
  1964. :title destination) info)))))
  1965. (format "<a href=\"#%s\"%s>%s</a>"
  1966. (org-export-solidify-link-text href) attributes desc)))
  1967. ;; Fuzzy link points to a target. Do as above.
  1968. (t
  1969. (let ((path (org-export-solidify-link-text path)) number)
  1970. (unless desc
  1971. (setq number (cond
  1972. ((org-html-standalone-image-p destination info)
  1973. (org-export-get-ordinal
  1974. (assoc 'link (org-element-contents destination))
  1975. info 'link 'org-html-standalone-image-p))
  1976. (t (org-export-get-ordinal destination info))))
  1977. (setq desc (when number
  1978. (if (atom number) (number-to-string number)
  1979. (mapconcat 'number-to-string number ".")))))
  1980. (format "<a href=\"#%s\"%s>%s</a>"
  1981. path attributes (or desc "FIXME")))))))
  1982. ;; Coderef: replace link with the reference name or the
  1983. ;; equivalent line number.
  1984. ((string= type "coderef")
  1985. (let ((fragment (concat "coderef-" path)))
  1986. (format "<a href=\"#%s\" %s%s>%s</a>"
  1987. fragment
  1988. (format (concat "class=\"coderef\""
  1989. " onmouseover=\"CodeHighlightOn(this, '%s');\""
  1990. " onmouseout=\"CodeHighlightOff(this, '%s');\"")
  1991. fragment fragment)
  1992. attributes
  1993. (format (org-export-get-coderef-format path desc)
  1994. (org-export-resolve-coderef path info)))))
  1995. ;; Link type is handled by a special function.
  1996. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  1997. (funcall protocol (org-link-unescape path) desc 'html))
  1998. ;; External link with a description part.
  1999. ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
  2000. ;; External link without a description part.
  2001. (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
  2002. ;; No path, only description. Try to do something useful.
  2003. (t (format "<i>%s</i>" desc)))))
  2004. ;;;; Paragraph
  2005. (defun org-html-paragraph (paragraph contents info)
  2006. "Transcode a PARAGRAPH element from Org to HTML.
  2007. CONTENTS is the contents of the paragraph, as a string. INFO is
  2008. the plist used as a communication channel."
  2009. (let* ((style nil) ; FIXME
  2010. (class (cdr (assoc style '((footnote . "footnote")
  2011. (verse . nil)))))
  2012. (extra (if class (format " class=\"%s\"" class) ""))
  2013. (parent (org-export-get-parent paragraph)))
  2014. (cond
  2015. ((and (eq (org-element-type parent) 'item)
  2016. (= (org-element-property :begin paragraph)
  2017. (org-element-property :contents-begin parent)))
  2018. ;; leading paragraph in a list item have no tags
  2019. contents)
  2020. ((org-html-standalone-image-p paragraph info)
  2021. ;; standalone image
  2022. contents)
  2023. (t (format "<p%s>\n%s</p>" extra contents)))))
  2024. ;;;; Plain List
  2025. (defun org-html-begin-plain-list (type &optional arg1)
  2026. (case type
  2027. (ordered
  2028. (format "<ol class=\"org-ol\"%s>" (if arg1 ; FIXME
  2029. (format " start=\"%d\"" arg1)
  2030. "")))
  2031. (unordered "<ul class=\"org-ul\">")
  2032. (descriptive "<dl class=\"org-dl\">")))
  2033. (defun org-html-end-plain-list (type)
  2034. (case type
  2035. (ordered "</ol>")
  2036. (unordered "</ul>")
  2037. (descriptive "</dl>")))
  2038. (defun org-html-plain-list (plain-list contents info)
  2039. "Transcode a PLAIN-LIST element from Org to HTML.
  2040. CONTENTS is the contents of the list. INFO is a plist holding
  2041. contextual information."
  2042. (let* (arg1 ;; FIXME
  2043. (type (org-element-property :type plain-list)))
  2044. (format "%s\n%s%s"
  2045. (org-html-begin-plain-list type)
  2046. contents (org-html-end-plain-list type))))
  2047. ;;;; Plain Text
  2048. (defun org-html-convert-special-strings (string)
  2049. "Convert special characters in STRING to HTML."
  2050. (let ((all org-html-special-string-regexps)
  2051. e a re rpl start)
  2052. (while (setq a (pop all))
  2053. (setq re (car a) rpl (cdr a) start 0)
  2054. (while (string-match re string start)
  2055. (setq string (replace-match rpl t nil string))))
  2056. string))
  2057. (defun org-html-encode-plain-text (text)
  2058. "Convert plain text characters to HTML equivalent.
  2059. Possible conversions are set in `org-export-html-protect-char-alist'."
  2060. (mapc
  2061. (lambda (pair)
  2062. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
  2063. org-html-protect-char-alist)
  2064. text)
  2065. (defun org-html-plain-text (text info)
  2066. "Transcode a TEXT string from Org to HTML.
  2067. TEXT is the string to transcode. INFO is a plist holding
  2068. contextual information."
  2069. (let ((output text))
  2070. ;; Protect following characters: <, >, &.
  2071. (setq output (org-html-encode-plain-text output))
  2072. ;; Handle smart quotes. Be sure to provide original string since
  2073. ;; OUTPUT may have been modified.
  2074. (when (plist-get info :with-smart-quotes)
  2075. (setq output (org-export-activate-smart-quotes output :html info text)))
  2076. ;; Handle special strings.
  2077. (when (plist-get info :with-special-strings)
  2078. (setq output (org-html-convert-special-strings output)))
  2079. ;; Handle break preservation if required.
  2080. (when (plist-get info :preserve-breaks)
  2081. (setq output
  2082. (replace-regexp-in-string
  2083. "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
  2084. ;; Return value.
  2085. output))
  2086. ;; Planning
  2087. (defun org-html-planning (planning contents info)
  2088. "Transcode a PLANNING element from Org to HTML.
  2089. CONTENTS is nil. INFO is a plist used as a communication
  2090. channel."
  2091. (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
  2092. (format
  2093. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  2094. (mapconcat
  2095. 'identity
  2096. (delq nil
  2097. (list
  2098. (let ((closed (org-element-property :closed planning)))
  2099. (when closed
  2100. (format span-fmt org-closed-string
  2101. (org-translate-time
  2102. (org-element-property :raw-value closed)))))
  2103. (let ((deadline (org-element-property :deadline planning)))
  2104. (when deadline
  2105. (format span-fmt org-deadline-string
  2106. (org-translate-time
  2107. (org-element-property :raw-value deadline)))))
  2108. (let ((scheduled (org-element-property :scheduled planning)))
  2109. (when scheduled
  2110. (format span-fmt org-scheduled-string
  2111. (org-translate-time
  2112. (org-element-property :raw-value scheduled)))))))
  2113. " "))))
  2114. ;;;; Property Drawer
  2115. (defun org-html-property-drawer (property-drawer contents info)
  2116. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2117. CONTENTS is nil. INFO is a plist holding contextual
  2118. information."
  2119. ;; The property drawer isn't exported but we want separating blank
  2120. ;; lines nonetheless.
  2121. "")
  2122. ;;;; Quote Block
  2123. (defun org-html-quote-block (quote-block contents info)
  2124. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2125. CONTENTS holds the contents of the block. INFO is a plist
  2126. holding contextual information."
  2127. (format "<blockquote>\n%s</blockquote>" contents))
  2128. ;;;; Quote Section
  2129. (defun org-html-quote-section (quote-section contents info)
  2130. "Transcode a QUOTE-SECTION element from Org to HTML.
  2131. CONTENTS is nil. INFO is a plist holding contextual information."
  2132. (let ((value (org-remove-indentation
  2133. (org-element-property :value quote-section))))
  2134. (when value (format "<pre>\n%s</pre>" value))))
  2135. ;;;; Section
  2136. (defun org-html-section (section contents info)
  2137. "Transcode a SECTION element from Org to HTML.
  2138. CONTENTS holds the contents of the section. INFO is a plist
  2139. holding contextual information."
  2140. (let ((parent (org-export-get-parent-headline section)))
  2141. ;; Before first headline: no container, just return CONTENTS.
  2142. (if (not parent) contents
  2143. ;; Get div's class and id references.
  2144. (let* ((class-num (+ (org-export-get-relative-level parent info)
  2145. (1- org-html-toplevel-hlevel)))
  2146. (section-number
  2147. (mapconcat
  2148. 'number-to-string
  2149. (org-export-get-headline-number parent info) "-")))
  2150. ;; Build return value.
  2151. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2152. class-num
  2153. (or (org-element-property :custom-id parent) section-number)
  2154. contents)))))
  2155. ;;;; Radio Target
  2156. (defun org-html-radio-target (radio-target text info)
  2157. "Transcode a RADIO-TARGET object from Org to HTML.
  2158. TEXT is the text of the target. INFO is a plist holding
  2159. contextual information."
  2160. (let ((id (org-export-solidify-link-text
  2161. (org-element-property :value radio-target))))
  2162. (org-html--anchor id text)))
  2163. ;;;; Special Block
  2164. (defun org-html-special-block (special-block contents info)
  2165. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2166. CONTENTS holds the contents of the block. INFO is a plist
  2167. holding contextual information."
  2168. (format "<div class=\"%s\">\n%s\n</div>"
  2169. (downcase (org-element-property :type special-block))
  2170. contents))
  2171. ;;;; Src Block
  2172. (defun org-html-src-block (src-block contents info)
  2173. "Transcode a SRC-BLOCK element from Org to HTML.
  2174. CONTENTS holds the contents of the item. INFO is a plist holding
  2175. contextual information."
  2176. (if (org-export-read-attribute :attr_html src-block :textarea)
  2177. (org-html--textarea-block src-block)
  2178. (let ((lang (org-element-property :language src-block))
  2179. (caption (org-export-get-caption src-block))
  2180. (code (org-html-format-code src-block info)))
  2181. (if (not lang) (format "<pre class=\"example\">\n%s</pre>" code)
  2182. (format "<div class=\"org-src-container\">\n%s%s\n</div>"
  2183. (if (not caption) ""
  2184. (format "<label class=\"org-src-name\">%s</label>"
  2185. (org-export-data caption info)))
  2186. (format "\n<pre class=\"src src-%s\">%s</pre>" lang code))))))
  2187. ;;;; Statistics Cookie
  2188. (defun org-html-statistics-cookie (statistics-cookie contents info)
  2189. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2190. CONTENTS is nil. INFO is a plist holding contextual information."
  2191. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2192. (format "<code>%s</code>" cookie-value)))
  2193. ;;;; Strike-Through
  2194. (defun org-html-strike-through (strike-through contents info)
  2195. "Transcode STRIKE-THROUGH from Org to HTML.
  2196. CONTENTS is the text with strike-through markup. INFO is a plist
  2197. holding contextual information."
  2198. (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
  2199. contents))
  2200. ;;;; Subscript
  2201. (defun org-html-subscript (subscript contents info)
  2202. "Transcode a SUBSCRIPT object from Org to HTML.
  2203. CONTENTS is the contents of the object. INFO is a plist holding
  2204. contextual information."
  2205. (format "<sub>%s</sub>" contents))
  2206. ;;;; Superscript
  2207. (defun org-html-superscript (superscript contents info)
  2208. "Transcode a SUPERSCRIPT object from Org to HTML.
  2209. CONTENTS is the contents of the object. INFO is a plist holding
  2210. contextual information."
  2211. (format "<sup>%s</sup>" contents))
  2212. ;;;; Tabel Cell
  2213. (defun org-html-table-cell (table-cell contents info)
  2214. "Transcode a TABLE-CELL element from Org to HTML.
  2215. CONTENTS is nil. INFO is a plist used as a communication
  2216. channel."
  2217. (let* ((table-row (org-export-get-parent table-cell))
  2218. (table (org-export-get-parent-table table-cell))
  2219. (cell-attrs
  2220. (if (not org-html-table-align-individual-fields) ""
  2221. (format (if (and (boundp 'org-html-format-table-no-css)
  2222. org-html-format-table-no-css)
  2223. " align=\"%s\"" " class=\"%s\"")
  2224. (org-export-table-cell-alignment table-cell info)))))
  2225. (when (or (not contents) (string= "" (org-trim contents)))
  2226. (setq contents "&nbsp;"))
  2227. (cond
  2228. ((and (org-export-table-has-header-p table info)
  2229. (= 1 (org-export-table-row-group table-row info)))
  2230. (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
  2231. contents (cdr org-html-table-header-tags)))
  2232. ((and org-html-table-use-header-tags-for-first-column
  2233. (zerop (cdr (org-export-table-cell-address table-cell info))))
  2234. (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
  2235. contents (cdr org-html-table-header-tags)))
  2236. (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
  2237. contents (cdr org-html-table-data-tags))))))
  2238. ;;;; Table Row
  2239. (defun org-html-table-row (table-row contents info)
  2240. "Transcode a TABLE-ROW element from Org to HTML.
  2241. CONTENTS is the contents of the row. INFO is a plist used as a
  2242. communication channel."
  2243. ;; Rules are ignored since table separators are deduced from
  2244. ;; borders of the current row.
  2245. (when (eq (org-element-property :type table-row) 'standard)
  2246. (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
  2247. (rowgroup-tags
  2248. (cond
  2249. ;; Case 1: Row belongs to second or subsequent rowgroups.
  2250. ((not (= 1 (org-export-table-row-group table-row info)))
  2251. '("<tbody>" . "\n</tbody>"))
  2252. ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
  2253. ((org-export-table-has-header-p
  2254. (org-export-get-parent-table table-row) info)
  2255. '("<thead>" . "\n</thead>"))
  2256. ;; Case 2: Row is from first and only row group.
  2257. (t '("<tbody>" . "\n</tbody>")))))
  2258. (concat
  2259. ;; Begin a rowgroup?
  2260. (when (org-export-table-row-starts-rowgroup-p table-row info)
  2261. (car rowgroup-tags))
  2262. ;; Actual table row
  2263. (concat "\n" (eval (car org-html-table-row-tags))
  2264. contents
  2265. "\n"
  2266. (eval (cdr org-html-table-row-tags)))
  2267. ;; End a rowgroup?
  2268. (when (org-export-table-row-ends-rowgroup-p table-row info)
  2269. (cdr rowgroup-tags))))))
  2270. ;;;; Table
  2271. (defun org-html-table-first-row-data-cells (table info)
  2272. (let ((table-row
  2273. (org-element-map table 'table-row
  2274. (lambda (row)
  2275. (unless (eq (org-element-property :type row) 'rule) row))
  2276. info 'first-match))
  2277. (special-column-p (org-export-table-has-special-column-p table)))
  2278. (if (not special-column-p) (org-element-contents table-row)
  2279. (cdr (org-element-contents table-row)))))
  2280. (defun org-html-table--table.el-table (table info)
  2281. (when (eq (org-element-property :type table) 'table.el)
  2282. (require 'table)
  2283. (let ((outbuf (with-current-buffer
  2284. (get-buffer-create "*org-export-table*")
  2285. (erase-buffer) (current-buffer))))
  2286. (with-temp-buffer
  2287. (insert (org-element-property :value table))
  2288. (goto-char 1)
  2289. (re-search-forward "^[ \t]*|[^|]" nil t)
  2290. (table-generate-source 'html outbuf))
  2291. (with-current-buffer outbuf
  2292. (prog1 (org-trim (buffer-string))
  2293. (kill-buffer) )))))
  2294. (defun org-html-table (table contents info)
  2295. "Transcode a TABLE element from Org to HTML.
  2296. CONTENTS is the contents of the table. INFO is a plist holding
  2297. contextual information."
  2298. (case (org-element-property :type table)
  2299. ;; Case 1: table.el table. Convert it using appropriate tools.
  2300. (table.el (org-html-table--table.el-table table info))
  2301. ;; Case 2: Standard table.
  2302. (t
  2303. (let* ((label (org-element-property :name table))
  2304. (caption (org-export-get-caption table))
  2305. (attributes (mapconcat #'identity
  2306. (org-element-property :attr_html table)
  2307. " "))
  2308. (alignspec
  2309. (if (and (boundp 'org-html-format-table-no-css)
  2310. org-html-format-table-no-css)
  2311. "align=\"%s\"" "class=\"%s\""))
  2312. (table-column-specs
  2313. (function
  2314. (lambda (table info)
  2315. (mapconcat
  2316. (lambda (table-cell)
  2317. (let ((alignment (org-export-table-cell-alignment
  2318. table-cell info)))
  2319. (concat
  2320. ;; Begin a colgroup?
  2321. (when (org-export-table-cell-starts-colgroup-p
  2322. table-cell info)
  2323. "\n<colgroup>")
  2324. ;; Add a column. Also specify it's alignment.
  2325. (format "\n<col %s/>" (format alignspec alignment))
  2326. ;; End a colgroup?
  2327. (when (org-export-table-cell-ends-colgroup-p
  2328. table-cell info)
  2329. "\n</colgroup>"))))
  2330. (org-html-table-first-row-data-cells table info) "\n"))))
  2331. (table-attributes
  2332. (let ((table-tag (plist-get info :html-table-tag)))
  2333. (concat
  2334. (and (string-match "<table\\(.*\\)>" table-tag)
  2335. (match-string 1 table-tag))
  2336. (and label (format " id=\"%s\""
  2337. (org-export-solidify-link-text label)))))))
  2338. ;; Remove last blank line.
  2339. (setq contents (substring contents 0 -1))
  2340. (format "<table%s>\n%s\n%s\n%s\n</table>"
  2341. table-attributes
  2342. (if (not caption) ""
  2343. (format "<caption>%s</caption>"
  2344. (org-export-data caption info)))
  2345. (funcall table-column-specs table info)
  2346. contents)))))
  2347. ;;;; Target
  2348. (defun org-html-target (target contents info)
  2349. "Transcode a TARGET object from Org to HTML.
  2350. CONTENTS is nil. INFO is a plist holding contextual
  2351. information."
  2352. (let ((id (org-export-solidify-link-text
  2353. (org-element-property :value target))))
  2354. (org-html--anchor id)))
  2355. ;;;; Timestamp
  2356. (defun org-html-timestamp (timestamp contents info)
  2357. "Transcode a TIMESTAMP object from Org to HTML.
  2358. CONTENTS is nil. INFO is a plist holding contextual
  2359. information."
  2360. (let ((value (org-html-plain-text
  2361. (org-timestamp-translate timestamp) info)))
  2362. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  2363. (replace-regexp-in-string "--" "&ndash;" value))))
  2364. ;;;; Underline
  2365. (defun org-html-underline (underline contents info)
  2366. "Transcode UNDERLINE from Org to HTML.
  2367. CONTENTS is the text with underline markup. INFO is a plist
  2368. holding contextual information."
  2369. (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
  2370. contents))
  2371. ;;;; Verbatim
  2372. (defun org-html-verbatim (verbatim contents info)
  2373. "Transcode VERBATIM from Org to HTML.
  2374. CONTENTS is nil. INFO is a plist holding contextual
  2375. information."
  2376. (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
  2377. (org-element-property :value verbatim)))
  2378. ;;;; Verse Block
  2379. (defun org-html-verse-block (verse-block contents info)
  2380. "Transcode a VERSE-BLOCK element from Org to HTML.
  2381. CONTENTS is verse block contents. INFO is a plist holding
  2382. contextual information."
  2383. ;; Replace each newline character with line break. Also replace
  2384. ;; each blank line with a line break.
  2385. (setq contents (replace-regexp-in-string
  2386. "^ *\\\\\\\\$" "<br/>\n"
  2387. (replace-regexp-in-string
  2388. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
  2389. ;; Replace each white space at beginning of a line with a
  2390. ;; non-breaking space.
  2391. (while (string-match "^[ \t]+" contents)
  2392. (let* ((num-ws (length (match-string 0 contents)))
  2393. (ws (let (out) (dotimes (i num-ws out)
  2394. (setq out (concat out "&nbsp;"))))))
  2395. (setq contents (replace-match ws nil t contents))))
  2396. (format "<p class=\"verse\">\n%s</p>" contents))
  2397. ;;; Filter Functions
  2398. (defun org-html-final-function (contents backend info)
  2399. (if (not org-html-pretty-output) contents
  2400. (with-temp-buffer
  2401. (html-mode)
  2402. (insert contents)
  2403. (indent-region (point-min) (point-max))
  2404. (buffer-substring-no-properties (point-min) (point-max)))))
  2405. ;;; End-user functions
  2406. ;;;###autoload
  2407. (defun org-html-export-as-html
  2408. (&optional async subtreep visible-only body-only ext-plist)
  2409. "Export current buffer to an HTML buffer.
  2410. If narrowing is active in the current buffer, only export its
  2411. narrowed part.
  2412. If a region is active, export that region.
  2413. A non-nil optional argument ASYNC means the process should happen
  2414. asynchronously. The resulting buffer should be accessible
  2415. through the `org-export-stack' interface.
  2416. When optional argument SUBTREEP is non-nil, export the sub-tree
  2417. at point, extracting information from the headline properties
  2418. first.
  2419. When optional argument VISIBLE-ONLY is non-nil, don't export
  2420. contents of hidden elements.
  2421. When optional argument BODY-ONLY is non-nil, only write code
  2422. between \"<body>\" and \"</body>\" tags.
  2423. EXT-PLIST, when provided, is a property list with external
  2424. parameters overriding Org default settings, but still inferior to
  2425. file-local settings.
  2426. Export is done in a buffer named \"*Org HTML Export*\", which
  2427. will be displayed when `org-export-show-temporary-export-buffer'
  2428. is non-nil."
  2429. (interactive)
  2430. (if async
  2431. (org-export-async-start
  2432. (lambda (output)
  2433. (with-current-buffer (get-buffer-create "*Org HTML Export*")
  2434. (erase-buffer)
  2435. (insert output)
  2436. (goto-char (point-min))
  2437. (funcall org-html-display-buffer-mode)
  2438. (org-export-add-to-stack (current-buffer) 'html)))
  2439. `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
  2440. (let ((outbuf (org-export-to-buffer
  2441. 'html "*Org HTML Export*"
  2442. subtreep visible-only body-only ext-plist)))
  2443. ;; Set major mode.
  2444. (with-current-buffer outbuf (funcall org-html-display-buffer-mode))
  2445. (when org-export-show-temporary-export-buffer
  2446. (switch-to-buffer-other-window outbuf)))))
  2447. ;;;###autoload
  2448. (defun org-html-export-to-html
  2449. (&optional async subtreep visible-only body-only ext-plist)
  2450. "Export current buffer to a HTML file.
  2451. If narrowing is active in the current buffer, only export its
  2452. narrowed part.
  2453. If a region is active, export that region.
  2454. A non-nil optional argument ASYNC means the process should happen
  2455. asynchronously. The resulting file should be accessible through
  2456. the `org-export-stack' interface.
  2457. When optional argument SUBTREEP is non-nil, export the sub-tree
  2458. at point, extracting information from the headline properties
  2459. first.
  2460. When optional argument VISIBLE-ONLY is non-nil, don't export
  2461. contents of hidden elements.
  2462. When optional argument BODY-ONLY is non-nil, only write code
  2463. between \"<body>\" and \"</body>\" tags.
  2464. EXT-PLIST, when provided, is a property list with external
  2465. parameters overriding Org default settings, but still inferior to
  2466. file-local settings.
  2467. Return output file's name."
  2468. (interactive)
  2469. (let* ((extension (concat "." org-html-extension))
  2470. (file (org-export-output-file-name extension subtreep))
  2471. (org-export-coding-system org-html-coding-system))
  2472. (if async
  2473. (org-export-async-start
  2474. (lambda (f) (org-export-add-to-stack f 'html))
  2475. (let ((org-export-coding-system org-html-coding-system))
  2476. `(expand-file-name
  2477. (org-export-to-file
  2478. 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
  2479. (let ((org-export-coding-system org-html-coding-system))
  2480. (org-export-to-file
  2481. 'html file subtreep visible-only body-only ext-plist)))))
  2482. ;;;###autoload
  2483. (defun org-html-publish-to-html (plist filename pub-dir)
  2484. "Publish an org file to HTML.
  2485. FILENAME is the filename of the Org file to be published. PLIST
  2486. is the property list for the given project. PUB-DIR is the
  2487. publishing directory.
  2488. Return output file name."
  2489. (org-publish-org-to 'html filename ".html" plist pub-dir))
  2490. ;;; FIXME
  2491. ;;;; org-format-table-html
  2492. ;;;; org-format-org-table-html
  2493. ;;;; org-format-table-table-html
  2494. ;;;; org-table-number-fraction
  2495. ;;;; org-table-number-regexp
  2496. ;;;; org-html-table-caption-above
  2497. ;;;; org-html-with-timestamp
  2498. ;;;; org-html-html-helper-timestamp
  2499. ;;;; org-export-as-html-and-open
  2500. ;;;; org-export-as-html-batch
  2501. ;;;; org-export-as-html-to-buffer
  2502. ;;;; org-replace-region-by-html
  2503. ;;;; org-export-region-as-html
  2504. ;;;; org-export-as-html
  2505. ;;;; (org-export-directory :html opt-plist)
  2506. ;;;; (plist-get opt-plist :html-extension)
  2507. ;;;; org-html-toplevel-hlevel
  2508. ;;;; org-html-special-string-regexps
  2509. ;;;; org-html-inline-images
  2510. ;;;; org-html-inline-image-extensions
  2511. ;;;; org-html-protect-char-alist
  2512. ;;;; org-html-table-use-header-tags-for-first-column
  2513. ;;;; org-html-todo-kwd-class-prefix
  2514. ;;;; org-html-tag-class-prefix
  2515. ;;;; org-html-footnote-separator
  2516. ;;;; org-export-preferred-target-alist
  2517. ;;;; org-export-solidify-link-text
  2518. ;;;; class for anchors
  2519. ;;;; org-export-with-section-numbers, body-only
  2520. ;;;; org-export-mark-todo-in-toc
  2521. ;;;; org-html-format-org-link
  2522. ;;;; (caption (and caption (org-xml-encode-org-text caption)))
  2523. ;;;; alt = (file-name-nondirectory path)
  2524. ;;;; org-export-time-stamp-file'
  2525. (provide 'ox-html)
  2526. ;; Local variables:
  2527. ;; generated-autoload-file: "org-loaddefs.el"
  2528. ;; End:
  2529. ;;; ox-html.el ends here