ox-html.el 106 KB

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