org-e-html.el 103 KB

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