org-e-html.el 108 KB

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