ox-html.el 106 KB

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