org-e-html.el 105 KB

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