ox-html.el 104 KB

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