org-e-html.el 108 KB

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