org-e-html.el 110 KB

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