org-e-html.el 103 KB

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