org-e-html.el 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181
  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. 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 (plist-get info :author))
  1392. (email (plist-get info :email))
  1393. (lang-words (or (assoc (plist-get info :language)
  1394. org-export-language-setup)
  1395. (assoc "en" org-export-language-setup)))
  1396. (email
  1397. (mapconcat (lambda(e)
  1398. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1399. (split-string email ",+ *")
  1400. ", "))
  1401. (html-validation-link (or org-e-html-validation-link ""))
  1402. (creator-info org-export-creator-string))
  1403. (concat
  1404. ;; begin postamble
  1405. "
  1406. <div id=\"" (nth 2 org-e-html-divs) "\">"
  1407. (cond
  1408. ;; auto postamble
  1409. ((eq (plist-get info :html-postamble) 'auto)
  1410. (concat
  1411. (when (plist-get info :time-stamp-file)
  1412. (format "
  1413. <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
  1414. (when (and (plist-get info :with-author) author)
  1415. (format "
  1416. <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
  1417. (when (and (plist-get info :with-email) email)
  1418. (format "
  1419. <p class=\"email\"> %s </p>" email))
  1420. (when (plist-get info :with-creator)
  1421. (format "
  1422. <p class=\"creator\"> %s </p>" creator-info))
  1423. html-validation-link "\n"))
  1424. ;; postamble from a string
  1425. ((stringp (plist-get info :html-postamble))
  1426. (format-spec (plist-get info :html-postamble)
  1427. `((?a . ,author) (?e . ,email)
  1428. (?d . ,date) (?c . ,creator-info)
  1429. (?v . ,html-validation-link))))
  1430. ;; postamble from a function
  1431. ((functionp (plist-get info :html-postamble))
  1432. (with-temp-buffer
  1433. (funcall (plist-get info :html-postamble))
  1434. (buffer-string)))
  1435. ;; default postamble
  1436. (t
  1437. (format-spec
  1438. (or (cadr (assoc (nth 0 lang-words)
  1439. org-e-html-postamble-format))
  1440. (cadr (assoc "en" org-e-html-postamble-format)))
  1441. `((?a . ,author) (?e . ,email)
  1442. (?d . ,date) (?c . ,creator-info)
  1443. (?v . ,html-validation-link)))))
  1444. "
  1445. </div>")))
  1446. ;; org-e-html-html-helper-timestamp
  1447. ))
  1448. (defun org-e-html-template (contents info)
  1449. "Return complete document string after HTML conversion.
  1450. CONTENTS is the transcoded contents string. RAW-DATA is the
  1451. original parsed data. INFO is a plist holding export options."
  1452. (concat
  1453. (format
  1454. (or (and (stringp org-e-html-xml-declaration)
  1455. org-e-html-xml-declaration)
  1456. (cdr (assoc (plist-get info :html-extension)
  1457. org-e-html-xml-declaration))
  1458. (cdr (assoc "html" org-e-html-xml-declaration))
  1459. "")
  1460. (or (and org-e-html-coding-system
  1461. (fboundp 'coding-system-get)
  1462. (coding-system-get org-e-html-coding-system
  1463. 'mime-charset))
  1464. "iso-8859-1"))
  1465. "
  1466. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1467. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
  1468. (format "
  1469. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
  1470. (plist-get info :language) (plist-get info :language))
  1471. "
  1472. <head>"
  1473. (org-e-html-meta-info info) ; meta
  1474. (org-e-html-style info) ; style
  1475. (org-e-html-mathjax-config info) ; mathjax
  1476. "
  1477. </head>"
  1478. "
  1479. <body>"
  1480. (let ((link-up (org-trim (plist-get info :link-up)))
  1481. (link-home (org-trim (plist-get info :link-home))))
  1482. (unless (and (string= link-up "") (string= link-up ""))
  1483. (format org-e-html-home/up-format
  1484. (or link-up link-home)
  1485. (or link-home link-up))))
  1486. ;; preamble
  1487. (org-e-html-preamble info)
  1488. ;; begin content
  1489. (format "
  1490. <div id=\"%s\">" (or org-e-html-content-div
  1491. (nth 1 org-e-html-divs)))
  1492. ;; document title
  1493. (format "
  1494. <h1 class=\"title\">%s</h1>\n" (org-export-data (plist-get info :title) info))
  1495. ;; table of contents
  1496. (let ((depth (plist-get info :with-toc)))
  1497. (when (wholenump depth) (org-e-html-toc depth info)))
  1498. ;; document contents
  1499. contents
  1500. ;; footnotes section
  1501. (org-e-html-footnote-section info)
  1502. ;; bibliography
  1503. (org-e-html-bibliography)
  1504. ;; end content
  1505. (unless body-only
  1506. "
  1507. </div>")
  1508. ;; postamble
  1509. (org-e-html-postamble info)
  1510. (unless body-only
  1511. "
  1512. </body>")
  1513. "
  1514. </html>"))
  1515. ;;; Transcode Helpers
  1516. ;;;; Todo
  1517. (defun org-e-html--todo (todo)
  1518. (when todo
  1519. (format "<span class=\"%s %s%s\">%s</span>"
  1520. (if (member todo org-done-keywords) "done" "todo")
  1521. org-e-html-todo-kwd-class-prefix (org-e-html-fix-class-name todo)
  1522. todo)))
  1523. ;;;; Tags
  1524. (defun org-e-html--tags (tags)
  1525. (when tags
  1526. (format "<span class=\"tag\">%s</span>"
  1527. (mapconcat
  1528. (lambda (tag)
  1529. (format "<span class=\"%s\">%s</span>"
  1530. (concat org-e-html-tag-class-prefix
  1531. (org-e-html-fix-class-name tag))
  1532. tag))
  1533. tags "&nbsp;"))))
  1534. ;;;; Headline
  1535. (defun* org-e-html-format-headline
  1536. (todo todo-type priority text tags
  1537. &key level section-number headline-label &allow-other-keys)
  1538. (let ((section-number
  1539. (when section-number
  1540. (format "<span class=\"section-number-%d\">%s</span> "
  1541. level section-number)))
  1542. (todo (org-e-html--todo todo))
  1543. (tags (org-e-html--tags tags)))
  1544. (concat section-number todo (and todo " ") text
  1545. (and tags "&nbsp;&nbsp;&nbsp;") tags)))
  1546. ;;;; Src Code
  1547. (defun org-e-html-fontify-code (code lang)
  1548. (when code
  1549. (cond
  1550. ;; Case 1: No lang. Possibly an example block.
  1551. ((not lang)
  1552. ;; Simple transcoding.
  1553. (org-e-html-encode-plain-text code))
  1554. ;; Case 2: No htmlize or an inferior version of htmlize
  1555. ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
  1556. ;; Emit a warning.
  1557. (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
  1558. ;; Simple transcoding.
  1559. (org-e-html-encode-plain-text code))
  1560. (t
  1561. ;; Map language
  1562. (setq lang (or (assoc-default lang org-src-lang-modes) lang))
  1563. (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
  1564. (cond
  1565. ;; Case 1: Language is not associated with any Emacs mode
  1566. ((not (functionp lang-mode))
  1567. ;; Simple transcoding.
  1568. (org-e-html-encode-plain-text code))
  1569. ;; Case 2: Default. Fotify code.
  1570. (t
  1571. ;; htmlize
  1572. (setq code (with-temp-buffer
  1573. (insert code)
  1574. (funcall lang-mode)
  1575. (font-lock-fontify-buffer)
  1576. ;; markup each line separately
  1577. (org-remove-formatting-on-newlines-in-region
  1578. (point-min) (point-max))
  1579. (org-src-mode)
  1580. (set-buffer-modified-p nil)
  1581. (org-export-e-htmlize-region-for-paste
  1582. (point-min) (point-max))))
  1583. ;; Strip any encolosing <pre></pre> tags
  1584. (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
  1585. (match-string 1 code)
  1586. code))))))))
  1587. (defun org-e-html-do-format-code
  1588. (code &optional lang refs retain-labels num-start textarea-p)
  1589. (when textarea-p
  1590. (setq num-start nil refs nil lang nil))
  1591. (let* ((code-lines (org-split-string code "\n"))
  1592. (code-length (length code-lines))
  1593. (num-fmt
  1594. (and num-start
  1595. (format "%%%ds: "
  1596. (length (number-to-string (+ code-length num-start))))))
  1597. (code (org-e-html-fontify-code code lang)))
  1598. (assert (= code-length (length (org-split-string code "\n"))))
  1599. (org-export-format-code
  1600. code
  1601. (lambda (loc line-num ref)
  1602. (setq loc
  1603. (concat
  1604. ;; Add line number, if needed.
  1605. (when num-start
  1606. (format "<span class=\"linenr\">%s</span>"
  1607. (format num-fmt line-num)))
  1608. ;; Transcoded src line.
  1609. loc
  1610. ;; Add label, if needed.
  1611. (when (and ref retain-labels) (format " (%s)" ref))))
  1612. ;; Mark transcoded line as an anchor, if needed.
  1613. (if (not ref) loc
  1614. (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
  1615. ref loc)))
  1616. num-start refs)))
  1617. (defun org-e-html-format-code (element info)
  1618. (let* ((lang (org-element-property :language element))
  1619. ;; (switches (org-element-property :switches element))
  1620. (switches nil) ; FIXME
  1621. (textarea-p (and switches (string-match "-t\\>" switches)))
  1622. ;; Extract code and references.
  1623. (code-info (org-export-unravel-code element))
  1624. (code (car code-info))
  1625. (refs (cdr code-info))
  1626. ;; Does the src block contain labels?
  1627. (retain-labels (org-element-property :retain-labels element))
  1628. ;; Does it have line numbers?
  1629. (num-start (case (org-element-property :number-lines element)
  1630. (continued (org-export-get-loc element info))
  1631. (new 0))))
  1632. (org-e-html-do-format-code
  1633. code lang refs retain-labels num-start textarea-p)))
  1634. ;;; Transcode Functions
  1635. ;;;; Bold
  1636. (defun org-e-html-bold (bold contents info)
  1637. "Transcode BOLD from Org to HTML.
  1638. CONTENTS is the text with bold markup. INFO is a plist holding
  1639. contextual information."
  1640. (format (or (cdr (assq 'bold org-e-html-text-markup-alist)) "%s")
  1641. contents))
  1642. ;;;; Center Block
  1643. (defun org-e-html-center-block (center-block contents info)
  1644. "Transcode a CENTER-BLOCK element from Org to HTML.
  1645. CONTENTS holds the contents of the block. INFO is a plist
  1646. holding contextual information."
  1647. (org-e-html--wrap-label
  1648. center-block
  1649. (format "<div style=\"text-align: center\">\n%s</div>" contents)))
  1650. ;;;; Clock
  1651. (defun org-e-html-clock (clock contents info)
  1652. "Transcode a CLOCK element from Org to HTML.
  1653. CONTENTS is nil. INFO is a plist used as a communication
  1654. channel."
  1655. (format "<p>
  1656. <span class=\"timestamp-wrapper\">
  1657. <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
  1658. </span>
  1659. </p>"
  1660. org-clock-string
  1661. (org-translate-time (org-element-property :value clock))
  1662. (let ((time (org-element-property :time clock)))
  1663. (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
  1664. ;;;; Code
  1665. (defun org-e-html-code (code contents info)
  1666. "Transcode CODE from Org to HTML.
  1667. CONTENTS is nil. INFO is a plist holding contextual
  1668. information."
  1669. (format (or (cdr (assq 'code org-e-html-text-markup-alist)) "%s")
  1670. (org-element-property :value code)))
  1671. ;;;; Comment
  1672. ;; Comments are ignored.
  1673. ;;;; Comment Block
  1674. ;; Comment Blocks are ignored.
  1675. ;;;; Drawer
  1676. (defun org-e-html-drawer (drawer contents info)
  1677. "Transcode a DRAWER element from Org to HTML.
  1678. CONTENTS holds the contents of the block. INFO is a plist
  1679. holding contextual information."
  1680. (let* ((name (org-element-property :drawer-name drawer))
  1681. (output (if (functionp org-e-html-format-drawer-function)
  1682. (funcall org-e-html-format-drawer-function
  1683. name contents)
  1684. ;; If there's no user defined function: simply
  1685. ;; display contents of the drawer.
  1686. contents)))
  1687. (org-e-html--wrap-label drawer output)))
  1688. ;;;; Dynamic Block
  1689. (defun org-e-html-dynamic-block (dynamic-block contents info)
  1690. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1691. CONTENTS holds the contents of the block. INFO is a plist
  1692. holding contextual information. See `org-export-data'."
  1693. (org-e-html--wrap-label dynamic-block contents))
  1694. ;;;; Entity
  1695. (defun org-e-html-entity (entity contents info)
  1696. "Transcode an ENTITY object from Org to HTML.
  1697. CONTENTS are the definition itself. INFO is a plist holding
  1698. contextual information."
  1699. (org-element-property :html entity))
  1700. ;;;; Example Block
  1701. (defun org-e-html-example-block (example-block contents info)
  1702. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  1703. CONTENTS is nil. INFO is a plist holding contextual information."
  1704. (let* ((options (or (org-element-property :options example-block) ""))
  1705. (lang (org-element-property :language example-block))
  1706. (caption (org-element-property :caption example-block))
  1707. (label (org-element-property :name example-block))
  1708. (caption-str (org-e-html--caption/label-string caption label info))
  1709. (attr (mapconcat #'identity
  1710. (org-element-property :attr_html example-block)
  1711. " "))
  1712. ;; (switches (org-element-property :switches example-block))
  1713. (switches nil) ; FIXME
  1714. (textarea-p (and switches (string-match "-t\\>" switches)))
  1715. (code (org-e-html-format-code example-block info)))
  1716. (cond
  1717. (textarea-p
  1718. (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
  1719. 80 (string-to-number (match-string 1 switches))))
  1720. (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
  1721. (string-to-number (match-string 1 switches))
  1722. (org-count-lines code))))
  1723. (format
  1724. "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
  1725. cols rows code)))
  1726. (t (format "\n<pre class=\"example\">\n%s\n</pre>" code)))))
  1727. ;;;; Export Snippet
  1728. (defun org-e-html-export-snippet (export-snippet contents info)
  1729. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  1730. CONTENTS is nil. INFO is a plist holding contextual information."
  1731. (when (eq (org-export-snippet-backend export-snippet) 'e-html)
  1732. (org-element-property :value export-snippet)))
  1733. ;;;; Export Block
  1734. (defun org-e-html-export-block (export-block contents info)
  1735. "Transcode a EXPORT-BLOCK element from Org to HTML.
  1736. CONTENTS is nil. INFO is a plist holding contextual information."
  1737. (when (string= (org-element-property :type export-block) "HTML")
  1738. (org-remove-indentation (org-element-property :value export-block))))
  1739. ;;;; Fixed Width
  1740. (defun org-e-html-fixed-width (fixed-width contents info)
  1741. "Transcode a FIXED-WIDTH element from Org to HTML.
  1742. CONTENTS is nil. INFO is a plist holding contextual information."
  1743. (org-e-html--wrap-label
  1744. fixed-width
  1745. (format "\n<pre class=\"example\">\n%s</pre>"
  1746. (org-e-html-do-format-code
  1747. (org-remove-indentation
  1748. (org-element-property :value fixed-width))))))
  1749. ;;;; Footnote Definition
  1750. ;; Footnote Definitions are ignored.
  1751. ;;;; Footnote Reference
  1752. (defun org-e-html-footnote-reference (footnote-reference contents info)
  1753. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  1754. CONTENTS is nil. INFO is a plist holding contextual information."
  1755. (concat
  1756. ;; Insert separator between two footnotes in a row.
  1757. (let ((prev (org-export-get-previous-element footnote-reference info)))
  1758. (when (eq (org-element-type prev) 'footnote-reference)
  1759. org-e-html-footnote-separator))
  1760. (cond
  1761. ((not (org-export-footnote-first-reference-p footnote-reference info))
  1762. (org-e-html-format-footnote-reference
  1763. (org-export-get-footnote-number footnote-reference info)
  1764. "IGNORED" 100))
  1765. ;; Inline definitions are secondary strings.
  1766. ((eq (org-element-property :type footnote-reference) 'inline)
  1767. (org-e-html-format-footnote-reference
  1768. (org-export-get-footnote-number footnote-reference info)
  1769. "IGNORED" 1))
  1770. ;; Non-inline footnotes definitions are full Org data.
  1771. (t (org-e-html-format-footnote-reference
  1772. (org-export-get-footnote-number footnote-reference info)
  1773. "IGNORED" 1)))))
  1774. ;;;; Headline
  1775. (defun org-e-html-format-headline--wrap (headline info
  1776. &optional format-function
  1777. &rest extra-keys)
  1778. "Transcode an HEADLINE element from Org to HTML.
  1779. CONTENTS holds the contents of the headline. INFO is a plist
  1780. holding contextual information."
  1781. (let* ((level (+ (org-export-get-relative-level headline info)
  1782. (1- org-e-html-toplevel-hlevel)))
  1783. (headline-number (org-export-get-headline-number headline info))
  1784. (section-number (and (org-export-numbered-headline-p headline info)
  1785. (mapconcat 'number-to-string
  1786. headline-number ".")))
  1787. (todo (and (plist-get info :with-todo-keywords)
  1788. (let ((todo (org-element-property :todo-keyword headline)))
  1789. (and todo (org-export-data todo info)))))
  1790. (todo-type (and todo (org-element-property :todo-type headline)))
  1791. (priority (and (plist-get info :with-priority)
  1792. (org-element-property :priority headline)))
  1793. (text (org-export-data (org-element-property :title headline) info))
  1794. (tags (and (plist-get info :with-tags)
  1795. (org-export-get-tags headline info)))
  1796. (headline-label (concat "sec-" (mapconcat 'number-to-string
  1797. headline-number "-")))
  1798. (format-function (cond
  1799. ((functionp format-function) format-function)
  1800. ((functionp org-e-html-format-headline-function)
  1801. (function*
  1802. (lambda (todo todo-type priority text tags
  1803. &allow-other-keys)
  1804. (funcall org-e-html-format-headline-function
  1805. todo todo-type priority text tags))))
  1806. (t 'org-e-html-format-headline))))
  1807. (apply format-function
  1808. todo todo-type priority text tags
  1809. :headline-label headline-label :level level
  1810. :section-number section-number extra-keys)))
  1811. (defun org-e-html-headline (headline contents info)
  1812. "Transcode an HEADLINE element from Org to HTML.
  1813. CONTENTS holds the contents of the headline. INFO is a plist
  1814. holding contextual information."
  1815. (let* ((numberedp (org-export-numbered-headline-p headline info))
  1816. (level (org-export-get-relative-level headline info))
  1817. (text (org-export-data (org-element-property :title headline) info))
  1818. (todo (and (plist-get info :with-todo-keywords)
  1819. (let ((todo (org-element-property :todo-keyword headline)))
  1820. (and todo (org-export-data todo info)))))
  1821. (todo-type (and todo (org-element-property :todo-type headline)))
  1822. (tags (and (plist-get info :with-tags)
  1823. (org-export-get-tags headline info)))
  1824. (priority (and (plist-get info :with-priority)
  1825. (org-element-property :priority headline)))
  1826. (section-number (and (org-export-numbered-headline-p headline info)
  1827. (mapconcat 'number-to-string
  1828. (org-export-get-headline-number
  1829. headline info) ".")))
  1830. ;; Create the headline text.
  1831. (full-text (org-e-html-format-headline--wrap headline info)))
  1832. (cond
  1833. ;; Case 1: This is a footnote section: ignore it.
  1834. ((org-element-property :footnote-section-p headline) nil)
  1835. ;; Case 2. This is a deep sub-tree: export it as a list item.
  1836. ;; Also export as items headlines for which no section
  1837. ;; format has been found.
  1838. ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
  1839. ;; Build the real contents of the sub-tree.
  1840. (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
  1841. (itemized-body (org-e-html-format-list-item
  1842. contents type nil nil full-text)))
  1843. (concat
  1844. (and (org-export-first-sibling-p headline info)
  1845. (org-e-html-begin-plain-list type))
  1846. itemized-body
  1847. (and (org-export-last-sibling-p headline info)
  1848. (org-e-html-end-plain-list type)))))
  1849. ;; Case 3. Standard headline. Export it as a section.
  1850. (t
  1851. (let* ((extra-class (org-element-property :html-container-class headline))
  1852. (extra-ids (list (org-element-property :custom-id headline)
  1853. (org-element-property :id headline)))
  1854. (extra-ids
  1855. (mapconcat
  1856. (lambda (x)
  1857. (when x
  1858. (let ((id (org-solidify-link-text
  1859. (if (org-uuidgen-p x) (concat "ID-" x) x))))
  1860. (format "<a id=\"%s\" name=\"%s\"/>" id id))))
  1861. extra-ids ""))
  1862. (level1 (+ level (1- org-e-html-toplevel-hlevel)))
  1863. (id (mapconcat 'number-to-string
  1864. (org-export-get-headline-number headline info) "-")))
  1865. (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
  1866. (format "outline-container-%s" id)
  1867. (concat (format "outline-%d" level1) (and extra-class " ")
  1868. extra-class)
  1869. (format "\n<h%d id=\"sec-%s\">%s%s</h%d>\n"
  1870. level1 id extra-ids full-text level1)
  1871. contents))))))
  1872. ;;;; Horizontal Rule
  1873. (defun org-e-html-horizontal-rule (horizontal-rule contents info)
  1874. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  1875. CONTENTS is nil. INFO is a plist holding contextual information."
  1876. (let ((attr (mapconcat #'identity
  1877. (org-element-property :attr_html horizontal-rule)
  1878. " ")))
  1879. (org-e-html--wrap-label horizontal-rule "<hr/>\n")))
  1880. ;;;; Inline Babel Call
  1881. ;; Inline Babel Calls are ignored.
  1882. ;;;; Inline Src Block
  1883. (defun org-e-html-inline-src-block (inline-src-block contents info)
  1884. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  1885. CONTENTS holds the contents of the item. INFO is a plist holding
  1886. contextual information."
  1887. (let* ((org-lang (org-element-property :language inline-src-block))
  1888. (code (org-element-property :value inline-src-block))
  1889. (separator (org-e-html--find-verb-separator code)))
  1890. (error "FIXME")))
  1891. ;;;; Inlinetask
  1892. (defun org-e-html-format-section (text class &optional id)
  1893. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  1894. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  1895. (defun org-e-html-inlinetask (inlinetask contents info)
  1896. "Transcode an INLINETASK element from Org to HTML.
  1897. CONTENTS holds the contents of the block. INFO is a plist
  1898. holding contextual information."
  1899. (cond
  1900. ;; If `org-e-html-format-inlinetask-function' is provided, call it
  1901. ;; with appropriate arguments.
  1902. ((functionp org-e-html-format-inlinetask-function)
  1903. (let ((format-function
  1904. (function*
  1905. (lambda (todo todo-type priority text tags
  1906. &key contents &allow-other-keys)
  1907. (funcall org-e-html-format-inlinetask-function
  1908. todo todo-type priority text tags contents)))))
  1909. (org-e-html-format-headline--wrap
  1910. inlinetask info format-function :contents contents)))
  1911. ;; Otherwise, use a default template.
  1912. (t (org-e-html--wrap-label
  1913. inlinetask
  1914. (format
  1915. "\n<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s\n</div>"
  1916. (org-e-html-format-headline--wrap inlinetask info)
  1917. contents)))))
  1918. ;;;; Italic
  1919. (defun org-e-html-italic (italic contents info)
  1920. "Transcode ITALIC from Org to HTML.
  1921. CONTENTS is the text with italic markup. INFO is a plist holding
  1922. contextual information."
  1923. (format (or (cdr (assq 'italic org-e-html-text-markup-alist)) "%s") contents))
  1924. ;;;; Item
  1925. (defun org-e-html-checkbox (checkbox)
  1926. (case checkbox (on "<code>[X]</code>")
  1927. (off "<code>[&nbsp;]</code>")
  1928. (trans "<code>[-]</code>")
  1929. (t "")))
  1930. (defun org-e-html-format-list-item (contents type checkbox
  1931. &optional term-counter-id
  1932. headline)
  1933. (concat
  1934. (case type
  1935. (ordered
  1936. (let* ((counter term-counter-id)
  1937. (extra (if counter (format " value=\"%s\"" counter) "")))
  1938. (format "<li%s>" extra)))
  1939. (unordered
  1940. (let* ((id term-counter-id)
  1941. (extra (if id (format " id=\"%s\"" id) "")))
  1942. (concat
  1943. (format "<li%s>" extra)
  1944. (when headline (concat headline "<br/>")))))
  1945. (descriptive
  1946. (let* ((term term-counter-id))
  1947. (setq term (or term "(no term)"))
  1948. (concat (format "<dt> %s </dt>" term) "<dd>"))))
  1949. (org-e-html-checkbox checkbox) (and checkbox " ")
  1950. contents
  1951. (case type
  1952. (ordered "</li>")
  1953. (unordered "</li>")
  1954. (descriptive "</dd>"))))
  1955. (defun org-e-html-item (item contents info)
  1956. "Transcode an ITEM element from Org to HTML.
  1957. CONTENTS holds the contents of the item. INFO is a plist holding
  1958. contextual information."
  1959. (let* ((plain-list (org-export-get-parent item info))
  1960. (type (org-element-property :type plain-list))
  1961. (counter (org-element-property :counter item))
  1962. (checkbox (org-element-property :checkbox item))
  1963. (tag (let ((tag (org-element-property :tag item)))
  1964. (and tag (org-export-data tag info)))))
  1965. (org-e-html-format-list-item
  1966. contents type checkbox (or tag counter))))
  1967. ;;;; Keyword
  1968. (defun org-e-html-keyword (keyword contents info)
  1969. "Transcode a KEYWORD element from Org to HTML.
  1970. CONTENTS is nil. INFO is a plist holding contextual information."
  1971. (let ((key (org-element-property :key keyword))
  1972. (value (org-element-property :value keyword)))
  1973. (cond
  1974. ((string= key "LATEX") value)
  1975. ((string= key "INDEX") (format "\\index{%s}" value))
  1976. ;; Invisible targets.
  1977. ((string= key "TARGET") nil) ; FIXME
  1978. ((string= key "TOC")
  1979. (let ((value (downcase value)))
  1980. (cond
  1981. ((string-match "\\<headlines\\>" value)
  1982. (let ((depth (or (and (string-match "[0-9]+" value)
  1983. (string-to-number (match-string 0 value)))
  1984. (plist-get info :with-toc))))
  1985. (when (wholenump depth) (org-e-html-toc depth info))))
  1986. ((string= "tables" value) "\\listoftables")
  1987. ((string= "figures" value) "\\listoffigures")
  1988. ((string= "listings" value)
  1989. (cond
  1990. ;; At the moment, src blocks with a caption are wrapped
  1991. ;; into a figure environment.
  1992. (t "\\listoffigures")))))))))
  1993. ;;;; Latex Environment
  1994. (defun org-e-html-format-latex (latex-frag processing-type)
  1995. (let* ((cache-relpath
  1996. (concat "ltxpng/" (file-name-sans-extension
  1997. (file-name-nondirectory (buffer-file-name)))))
  1998. (cache-dir (file-name-directory (buffer-file-name )))
  1999. (display-msg "Creating LaTeX Image..."))
  2000. (with-temp-buffer
  2001. (insert latex-frag)
  2002. (org-format-latex cache-relpath cache-dir nil display-msg
  2003. nil nil processing-type)
  2004. (buffer-string))))
  2005. (defun org-e-html-latex-environment (latex-environment contents info)
  2006. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  2007. CONTENTS is nil. INFO is a plist holding contextual information."
  2008. (org-e-html--wrap-label
  2009. latex-environment
  2010. (let ((processing-type (plist-get info :LaTeX-fragments))
  2011. (latex-frag (org-remove-indentation
  2012. (org-element-property :value latex-environment)))
  2013. (caption (org-e-html--caption/label-string
  2014. (org-element-property :caption latex-environment)
  2015. (org-element-property :name latex-environment)
  2016. info))
  2017. (attr nil) ; FIXME
  2018. (label (org-element-property :name latex-environment)))
  2019. (cond
  2020. ((member processing-type '(t mathjax))
  2021. (org-e-html-format-latex latex-frag 'mathjax))
  2022. ((equal processing-type 'dvipng)
  2023. (let* ((formula-link (org-e-html-format-latex
  2024. latex-frag processing-type)))
  2025. (when (and formula-link
  2026. (string-match "file:\\([^]]*\\)" formula-link))
  2027. (org-e-html-format-inline-image
  2028. (match-string 1 formula-link) caption label attr t))))
  2029. (t latex-frag)))))
  2030. ;;;; Latex Fragment
  2031. (defun org-e-html-latex-fragment (latex-fragment contents info)
  2032. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2033. CONTENTS is nil. INFO is a plist holding contextual information."
  2034. (let ((latex-frag (org-element-property :value latex-fragment))
  2035. (processing-type (plist-get info :LaTeX-fragments)))
  2036. (case processing-type
  2037. ((t mathjax)
  2038. (org-e-html-format-latex latex-frag 'mathjax))
  2039. (dvipng
  2040. (let* ((formula-link (org-e-html-format-latex
  2041. latex-frag processing-type)))
  2042. (when (and formula-link
  2043. (string-match "file:\\([^]]*\\)" formula-link))
  2044. (org-e-html-format-inline-image
  2045. (match-string 1 formula-link)))))
  2046. (t latex-frag))))
  2047. ;;;; Line Break
  2048. (defun org-e-html-line-break (line-break contents info)
  2049. "Transcode a LINE-BREAK object from Org to HTML.
  2050. CONTENTS is nil. INFO is a plist holding contextual information."
  2051. "<br/>")
  2052. ;;;; Link
  2053. (defun org-e-html-link--inline-image (link desc info)
  2054. "Return HTML code for an inline image.
  2055. LINK is the link pointing to the inline image. INFO is a plist
  2056. used as a communication channel."
  2057. (let* ((type (org-element-property :type link))
  2058. (raw-path (org-element-property :path link))
  2059. (path (cond ((member type '("http" "https"))
  2060. (concat type ":" raw-path))
  2061. ((file-name-absolute-p raw-path)
  2062. (expand-file-name raw-path))
  2063. (t raw-path)))
  2064. (parent (org-export-get-parent-paragraph link info))
  2065. (caption (org-e-html--caption/label-string
  2066. (org-element-property :caption parent)
  2067. (org-element-property :name parent)
  2068. info))
  2069. (label (org-element-property :name parent))
  2070. ;; Retrieve latex attributes from the element around.
  2071. (attr (let ((raw-attr
  2072. (mapconcat #'identity
  2073. (org-element-property :attr_html parent)
  2074. " ")))
  2075. (unless (string= raw-attr "") raw-attr))))
  2076. ;; Now clear ATTR from any special keyword and set a default
  2077. ;; value if nothing is left.
  2078. (setq attr (if (not attr) "" (org-trim attr)))
  2079. ;; Return proper string, depending on DISPOSITION.
  2080. (org-e-html-format-inline-image
  2081. path caption label attr (org-e-html-standalone-image-p link info))))
  2082. (defvar org-e-html-standalone-image-predicate)
  2083. (defun org-e-html-standalone-image-p (element info &optional predicate)
  2084. "Test if ELEMENT is a standalone image for the purpose HTML export.
  2085. INFO is a plist holding contextual information.
  2086. Return non-nil, if ELEMENT is of type paragraph and it's sole
  2087. content, save for whitespaces, is a link that qualifies as an
  2088. inline image.
  2089. Return non-nil, if ELEMENT is of type link and it's containing
  2090. paragraph has no other content save for leading and trailing
  2091. whitespaces.
  2092. Return nil, otherwise.
  2093. Bind `org-e-html-standalone-image-predicate' to constrain
  2094. paragraph further. For example, to check for only captioned
  2095. standalone images, do the following.
  2096. \(setq org-e-html-standalone-image-predicate
  2097. \(lambda \(paragraph\)
  2098. \(org-element-property :caption paragraph\)\)\)
  2099. "
  2100. (let ((paragraph (case (org-element-type element)
  2101. (paragraph element)
  2102. (link (and (org-export-inline-image-p
  2103. element org-e-html-inline-image-rules)
  2104. (org-export-get-parent element info)))
  2105. (t nil))))
  2106. (when paragraph
  2107. (assert (eq (org-element-type paragraph) 'paragraph))
  2108. (when (or (not (and (boundp 'org-e-html-standalone-image-predicate)
  2109. (functionp org-e-html-standalone-image-predicate)))
  2110. (funcall org-e-html-standalone-image-predicate paragraph))
  2111. (let ((contents (org-element-contents paragraph)))
  2112. (loop for x in contents
  2113. with inline-image-count = 0
  2114. always (cond
  2115. ((eq (org-element-type x) 'plain-text)
  2116. (not (org-string-nw-p x)))
  2117. ((eq (org-element-type x) 'link)
  2118. (when (org-export-inline-image-p
  2119. x org-e-html-inline-image-rules)
  2120. (= (incf inline-image-count) 1)))
  2121. (t nil))))))))
  2122. (defun org-e-html-link (link desc info)
  2123. "Transcode a LINK object from Org to HTML.
  2124. DESC is the description part of the link, or the empty string.
  2125. INFO is a plist holding contextual information. See
  2126. `org-export-data'."
  2127. (let* ((type (org-element-property :type link))
  2128. (raw-path (org-element-property :path link))
  2129. ;; Ensure DESC really exists, or set it to nil.
  2130. (desc (and (not (string= desc "")) desc))
  2131. (path (cond
  2132. ((member type '("http" "https" "ftp" "mailto"))
  2133. (concat type ":" raw-path))
  2134. ((string= type "file")
  2135. (when (string-match "\\(.+\\)::.+" raw-path)
  2136. (setq raw-path (match-string 1 raw-path)))
  2137. (if (file-name-absolute-p raw-path)
  2138. (concat "file://" (expand-file-name raw-path))
  2139. (concat "file://" raw-path)))
  2140. (t raw-path)))
  2141. protocol)
  2142. (cond
  2143. ;; Image file.
  2144. ((and (or (eq t org-e-html-inline-images)
  2145. (and org-e-html-inline-images (not desc)))
  2146. (org-export-inline-image-p link org-e-html-inline-image-rules))
  2147. (org-e-html-link--inline-image link desc info))
  2148. ;; Radio target: Transcode target's contents and use them as
  2149. ;; link's description.
  2150. ((string= type "radio")
  2151. (let ((destination (org-export-resolve-radio-link link info)))
  2152. (when destination
  2153. (format "<a href=\"#%s\">%s</a>"
  2154. (org-export-solidify-link-text path)
  2155. (org-export-data (org-element-contents destination) info)))))
  2156. ;; Links pointing to an headline: Find destination and build
  2157. ;; appropriate referencing command.
  2158. ((member type '("custom-id" "fuzzy" "id"))
  2159. (let ((destination (if (string= type "fuzzy")
  2160. (org-export-resolve-fuzzy-link link info)
  2161. (org-export-resolve-id-link link info))))
  2162. (case (org-element-type destination)
  2163. ;; Fuzzy link points nowhere.
  2164. ('nil
  2165. (format "<i>%s</i>"
  2166. (or desc
  2167. (org-export-data
  2168. (org-element-property :raw-link link) info))))
  2169. ;; Fuzzy link points to an invisible target.
  2170. (keyword nil)
  2171. ;; LINK points to an headline. If headlines are numbered
  2172. ;; and the link has no description, display headline's
  2173. ;; number. Otherwise, display description or headline's
  2174. ;; title.
  2175. (headline
  2176. (let* ((headline-no (org-export-get-headline-number destination info))
  2177. (label (format "sec-%s" (mapconcat 'number-to-string
  2178. headline-no "-")))
  2179. (section-no (mapconcat 'number-to-string headline-no ".")))
  2180. (setq desc
  2181. (cond
  2182. (desc desc)
  2183. ((plist-get info :section-numbers) section-no)
  2184. (t (org-export-data
  2185. (org-element-property :title destination) info))))
  2186. (format "<a href=\"#%s\">%s</a>" label desc)))
  2187. ;; Fuzzy link points to a target. Do as above.
  2188. (otherwise
  2189. (let ((path (org-export-solidify-link-text path)) number)
  2190. (unless desc
  2191. (setq number (cond
  2192. ((org-e-html-standalone-image-p destination info)
  2193. (org-export-get-ordinal
  2194. (assoc 'link (org-element-contents destination))
  2195. info 'link 'org-e-html-standalone-image-p))
  2196. (t (org-export-get-ordinal destination info))))
  2197. (setq desc (when number
  2198. (if (atom number) (number-to-string number)
  2199. (mapconcat 'number-to-string number ".")))))
  2200. (format "<a href=\"#%s\">%s</a>" path (or desc "FIXME")))))))
  2201. ;; Coderef: replace link with the reference name or the
  2202. ;; equivalent line number.
  2203. ((string= type "coderef")
  2204. (let ((fragment (concat "coderef-" path)))
  2205. (format "<a href=\"#%s\" %s>%s</a>" fragment
  2206. (format (concat "class=\"coderef\""
  2207. " onmouseover=\"CodeHighlightOn(this, '%s');\""
  2208. " onmouseout=\"CodeHighlightOff(this, '%s');\"")
  2209. fragment fragment)
  2210. (format (org-export-get-coderef-format path desc)
  2211. (org-export-resolve-coderef path info)))))
  2212. ;; Link type is handled by a special function.
  2213. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2214. (funcall protocol (org-link-unescape path) desc 'html))
  2215. ;; External link with a description part.
  2216. ((and path desc) (format "<a href=\"%s\">%s</a>" path desc))
  2217. ;; External link without a description part.
  2218. (path (format "<a href=\"%s\">%s</a>" path path))
  2219. ;; No path, only description. Try to do something useful.
  2220. (t (format "<i>%s</i>" desc)))))
  2221. ;;;; Babel Call
  2222. ;; Babel Calls are ignored.
  2223. ;;;; Macro
  2224. (defun org-e-html-macro (macro contents info)
  2225. "Transcode a MACRO element from Org to HTML.
  2226. CONTENTS is nil. INFO is a plist holding contextual information."
  2227. ;; Use available tools.
  2228. (org-export-expand-macro macro info))
  2229. ;;;; Paragraph
  2230. (defun org-e-html-paragraph (paragraph contents info)
  2231. "Transcode a PARAGRAPH element from Org to HTML.
  2232. CONTENTS is the contents of the paragraph, as a string. INFO is
  2233. the plist used as a communication channel."
  2234. (let* ((style nil) ; FIXME
  2235. (class (cdr (assoc style '((footnote . "footnote")
  2236. (verse . nil)))))
  2237. (extra (if class (format " class=\"%s\"" class) ""))
  2238. (parent (org-export-get-parent paragraph info)))
  2239. (cond
  2240. ((and (equal (car parent) 'item)
  2241. (= (org-element-property :begin paragraph)
  2242. (org-element-property :contents-begin parent)))
  2243. ;; leading paragraph in a list item have no tags
  2244. contents)
  2245. ((org-e-html-standalone-image-p paragraph info)
  2246. ;; standalone image
  2247. contents)
  2248. (t (format "\n<p%s>\n%s\n</p>" extra contents)))))
  2249. ;;;; Plain List
  2250. (defun org-e-html-begin-plain-list (type &optional arg1)
  2251. (case type
  2252. (ordered
  2253. (format "<ol%s>" (if arg1 ; FIXME
  2254. (format " start=\"%d\"" arg1)
  2255. "")))
  2256. (unordered "<ul>")
  2257. (descriptive "<dl>")))
  2258. (defun org-e-html-end-plain-list (type)
  2259. (case type
  2260. (ordered "</ol>")
  2261. (unordered "</ul>")
  2262. (descriptive "</dl>")))
  2263. (defun org-e-html-plain-list (plain-list contents info)
  2264. "Transcode a PLAIN-LIST element from Org to HTML.
  2265. CONTENTS is the contents of the list. INFO is a plist holding
  2266. contextual information."
  2267. (let* (arg1 ;; FIXME
  2268. (type (org-element-property :type plain-list))
  2269. (attr (mapconcat #'identity
  2270. (org-element-property :attr_html plain-list)
  2271. " ")))
  2272. (org-e-html--wrap-label
  2273. plain-list (format "%s\n%s%s"
  2274. (org-e-html-begin-plain-list type)
  2275. contents (org-e-html-end-plain-list type)))))
  2276. ;;;; Plain Text
  2277. (defun org-e-html-convert-special-strings (string)
  2278. "Convert special characters in STRING to HTML."
  2279. (let ((all org-e-html-special-string-regexps)
  2280. e a re rpl start)
  2281. (while (setq a (pop all))
  2282. (setq re (car a) rpl (cdr a) start 0)
  2283. (while (string-match re string start)
  2284. (setq string (replace-match rpl t nil string))))
  2285. string))
  2286. (defun org-e-html-encode-plain-text (s)
  2287. "Convert plain text characters to HTML equivalent.
  2288. Possible conversions are set in `org-export-html-protect-char-alist'."
  2289. (let ((cl org-e-html-protect-char-alist) c)
  2290. (while (setq c (pop cl))
  2291. (let ((start 0))
  2292. (while (string-match (car c) s start)
  2293. (setq s (replace-match (cdr c) t t s)
  2294. start (1+ (match-beginning 0))))))
  2295. s))
  2296. (defun org-e-html-plain-text (text info)
  2297. "Transcode a TEXT string from Org to HTML.
  2298. TEXT is the string to transcode. INFO is a plist holding
  2299. contextual information."
  2300. (setq text (org-e-html-encode-plain-text text))
  2301. ;; Protect %, #, &, $, ~, ^, _, { and }.
  2302. ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
  2303. ;; (setq text
  2304. ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
  2305. ;; Protect \
  2306. ;; (setq text (replace-regexp-in-string
  2307. ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
  2308. ;; "$\\backslash$" text nil t 1))
  2309. ;; HTML into \HTML{} and TeX into \TeX{}.
  2310. ;; (let ((case-fold-search nil)
  2311. ;; (start 0))
  2312. ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
  2313. ;; (setq text (replace-match
  2314. ;; (format "\\%s{}" (match-string 1 text)) nil t text)
  2315. ;; start (match-end 0))))
  2316. ;; Handle quotation marks
  2317. ;; (setq text (org-e-html--quotation-marks text info))
  2318. ;; Convert special strings.
  2319. ;; (when (plist-get info :with-special-strings)
  2320. ;; (while (string-match (regexp-quote "...") text)
  2321. ;; (setq text (replace-match "\\ldots{}" nil t text))))
  2322. (when (plist-get info :with-special-strings)
  2323. (setq text (org-e-html-convert-special-strings text)))
  2324. ;; Handle break preservation if required.
  2325. (when (plist-get info :preserve-breaks)
  2326. (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
  2327. text)))
  2328. ;; Return value.
  2329. text)
  2330. ;; Planning
  2331. (defun org-e-html-planning (planning contents info)
  2332. "Transcode a PLANNING element from Org to HTML.
  2333. CONTENTS is nil. INFO is a plist used as a communication
  2334. channel."
  2335. (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
  2336. (format
  2337. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  2338. (mapconcat
  2339. 'identity
  2340. (delq nil
  2341. (list
  2342. (let ((closed (org-element-property :closed planning)))
  2343. (when closed
  2344. (format span-fmt org-closed-string
  2345. (org-translate-time closed))))
  2346. (let ((deadline (org-element-property :deadline planning)))
  2347. (when deadline
  2348. (format span-fmt org-deadline-string
  2349. (org-translate-time deadline))))
  2350. (let ((scheduled (org-element-property :scheduled planning)))
  2351. (when scheduled
  2352. (format span-fmt org-scheduled-string
  2353. (org-translate-time scheduled))))))
  2354. " "))))
  2355. ;;;; Property Drawer
  2356. (defun org-e-html-property-drawer (property-drawer contents info)
  2357. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2358. CONTENTS is nil. INFO is a plist holding contextual
  2359. information."
  2360. ;; The property drawer isn't exported but we want separating blank
  2361. ;; lines nonetheless.
  2362. "")
  2363. ;;;; Quote Block
  2364. (defun org-e-html-quote-block (quote-block contents info)
  2365. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2366. CONTENTS holds the contents of the block. INFO is a plist
  2367. holding contextual information."
  2368. (org-e-html--wrap-label
  2369. quote-block (format "<blockquote>\n%s</blockquote>" contents)))
  2370. ;;;; Quote Section
  2371. (defun org-e-html-quote-section (quote-section contents info)
  2372. "Transcode a QUOTE-SECTION element from Org to HTML.
  2373. CONTENTS is nil. INFO is a plist holding contextual information."
  2374. (let ((value (org-remove-indentation
  2375. (org-element-property :value quote-section))))
  2376. (when value (format "<pre>\n%s</pre>" value))))
  2377. ;;;; Section
  2378. (defun org-e-html-section (section contents info) ; FIXME
  2379. "Transcode a SECTION element from Org to HTML.
  2380. CONTENTS holds the contents of the section. INFO is a plist
  2381. holding contextual information."
  2382. (let ((parent (org-export-get-parent-headline section info)))
  2383. ;; Before first headline: no container, just return CONTENTS.
  2384. (if (not parent) contents
  2385. ;; Get div's class and id references.
  2386. (let ((class-num (+ (org-export-get-relative-level parent info)
  2387. (1- org-e-html-toplevel-hlevel)))
  2388. (id-num
  2389. (mapconcat
  2390. 'number-to-string
  2391. (org-export-get-headline-number parent info) "-")))
  2392. ;; Build return value.
  2393. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2394. class-num id-num contents)))))
  2395. ;;;; Radio Target
  2396. (defun org-e-html-radio-target (radio-target text info)
  2397. "Transcode a RADIO-TARGET object from Org to HTML.
  2398. TEXT is the text of the target. INFO is a plist holding
  2399. contextual information."
  2400. (let ((id (org-export-solidify-link-text
  2401. (org-element-property :value radio-target))))
  2402. (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text)))
  2403. ;;;; Special Block
  2404. (defun org-e-html-special-block (special-block contents info)
  2405. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2406. CONTENTS holds the contents of the block. INFO is a plist
  2407. holding contextual information."
  2408. (let ((type (downcase (org-element-property :type special-block))))
  2409. (org-e-html--wrap-label
  2410. special-block
  2411. (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
  2412. ;;;; Src Block
  2413. (defun org-e-html-src-block (src-block contents info)
  2414. "Transcode a SRC-BLOCK element from Org to HTML.
  2415. CONTENTS holds the contents of the item. INFO is a plist holding
  2416. contextual information."
  2417. (let* ((lang (org-element-property :language src-block))
  2418. (caption (org-element-property :caption src-block))
  2419. (label (org-element-property :name src-block))
  2420. (caption-str (org-e-html--caption/label-string caption label info))
  2421. (attr (mapconcat #'identity
  2422. (org-element-property :attr_html src-block)
  2423. " "))
  2424. ;; (switches (org-element-property :switches src-block))
  2425. (switches nil) ; FIXME
  2426. (textarea-p (and switches (string-match "-t\\>" switches)))
  2427. (code (org-e-html-format-code src-block info)))
  2428. (cond
  2429. (lang (format
  2430. "\n<div class=\"org-src-container\">\n%s%s\n</div>"
  2431. (if (not caption) ""
  2432. (format "<label class=\"org-src-name\">%s</label>" caption-str))
  2433. (format "\n<pre class=\"src src-%s\">%s\n</pre>" lang code)))
  2434. (textarea-p
  2435. (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
  2436. 80 (string-to-number (match-string 1 switches))))
  2437. (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
  2438. (string-to-number (match-string 1 switches))
  2439. (org-count-lines code))))
  2440. (format
  2441. "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
  2442. cols rows code)))
  2443. (t (format "\n<pre class=\"example\">\n%s\n</pre>" code)))))
  2444. ;;;; Statistics Cookie
  2445. (defun org-e-html-statistics-cookie (statistics-cookie contents info)
  2446. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2447. CONTENTS is nil. INFO is a plist holding contextual information."
  2448. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2449. (format "<code>%s</code>" cookie-value)))
  2450. ;;;; Strike-Through
  2451. (defun org-e-html-strike-through (strike-through contents info)
  2452. "Transcode STRIKE-THROUGH from Org to HTML.
  2453. CONTENTS is the text with strike-through markup. INFO is a plist
  2454. holding contextual information."
  2455. (format (or (cdr (assq 'strike-through org-e-html-text-markup-alist)) "%s")
  2456. contents))
  2457. ;;;; Subscript
  2458. (defun org-e-html-subscript (subscript contents info)
  2459. "Transcode a SUBSCRIPT object from Org to HTML.
  2460. CONTENTS is the contents of the object. INFO is a plist holding
  2461. contextual information."
  2462. (format "<sub>%s</sub>" contents))
  2463. ;;;; Superscript
  2464. (defun org-e-html-superscript (superscript contents info)
  2465. "Transcode a SUPERSCRIPT object from Org to HTML.
  2466. CONTENTS is the contents of the object. INFO is a plist holding
  2467. contextual information."
  2468. (format "<sup>%s</sup>" contents))
  2469. ;;;; Tabel Cell
  2470. (defun org-e-html-table-cell (table-cell contents info)
  2471. "Transcode a TABLE-CELL element from Org to HTML.
  2472. CONTENTS is nil. INFO is a plist used as a communication
  2473. channel."
  2474. (let* ((table-row (org-export-get-parent table-cell info))
  2475. (table (org-export-get-parent-table table-cell info))
  2476. (cell-attrs
  2477. (if (not org-e-html-table-align-individual-fields) ""
  2478. (format (if (and (boundp 'org-e-html-format-table-no-css)
  2479. org-e-html-format-table-no-css)
  2480. " align=\"%s\"" " class=\"%s\"")
  2481. (org-export-table-cell-alignment table-cell info)))))
  2482. (when (or (not contents) (string= "" (org-trim contents)))
  2483. (setq contents "&nbsp;"))
  2484. (cond
  2485. ((and (org-export-table-has-header-p table info)
  2486. (= 1 (org-export-table-row-group table-row info)))
  2487. (concat "\n" (format (car org-e-html-table-header-tags) "col" cell-attrs)
  2488. contents (cdr org-e-html-table-header-tags)))
  2489. ((and org-e-html-table-use-header-tags-for-first-column
  2490. (zerop (cdr (org-export-table-cell-address table-cell info))))
  2491. (concat "\n" (format (car org-e-html-table-header-tags) "row" cell-attrs)
  2492. contents (cdr org-e-html-table-header-tags)))
  2493. (t (concat "\n" (format (car org-e-html-table-data-tags) cell-attrs)
  2494. contents (cdr org-e-html-table-data-tags))))))
  2495. ;;;; Table Row
  2496. (defun org-e-html-table-row (table-row contents info)
  2497. "Transcode a TABLE-ROW element from Org to HTML.
  2498. CONTENTS is the contents of the row. INFO is a plist used as a
  2499. communication channel."
  2500. ;; Rules are ignored since table separators are deduced from
  2501. ;; borders of the current row.
  2502. (when (eq (org-element-property :type table-row) 'standard)
  2503. (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
  2504. (rowgroup-tags
  2505. (cond
  2506. ;; Case 1: Row belongs to second or subsequent rowgroups.
  2507. ((not (= 1 (org-export-table-row-group table-row info)))
  2508. '("\n<tbody>" . "\n</tbody>"))
  2509. ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
  2510. ((org-export-table-has-header-p
  2511. (org-export-get-parent-table table-row info) info)
  2512. '("\n<thead>" . "\n</thead>"))
  2513. ;; Case 2: Row is from first and only row group.
  2514. (t '("\n<tbody>" . "\n</tbody>")))))
  2515. (concat
  2516. ;; Begin a rowgroup?
  2517. (when (org-export-table-row-starts-rowgroup-p table-row info)
  2518. (car rowgroup-tags))
  2519. ;; Actual table row
  2520. (concat "\n" (eval (car org-e-html-table-row-tags))
  2521. contents (eval (cdr org-e-html-table-row-tags)))
  2522. ;; End a rowgroup?
  2523. (when (org-export-table-row-ends-rowgroup-p table-row info)
  2524. (cdr rowgroup-tags))))))
  2525. ;;;; Table
  2526. (defun org-e-html-table-first-row-data-cells (table info)
  2527. (let ((table-row
  2528. (org-element-map
  2529. table 'table-row
  2530. (lambda (row)
  2531. (unless (eq (org-element-property :type row) 'rule) row))
  2532. info 'first-match))
  2533. (special-column-p (org-export-table-has-special-column-p table)))
  2534. (if (not special-column-p) (org-element-contents table-row)
  2535. (cdr (org-element-contents table-row)))))
  2536. (defun org-e-html-table--table.el-table (table info)
  2537. (when (eq (org-element-property :type table) 'table.el)
  2538. (require 'table)
  2539. (let ((outbuf (with-current-buffer
  2540. (get-buffer-create "*org-export-table*")
  2541. (erase-buffer) (current-buffer))))
  2542. (with-temp-buffer
  2543. (insert (org-element-property :value table))
  2544. (goto-char 1)
  2545. (re-search-forward "^[ \t]*|[^|]" nil t)
  2546. (table-generate-source 'html outbuf))
  2547. (with-current-buffer outbuf
  2548. (prog1 (org-trim (buffer-string))
  2549. (kill-buffer) )))))
  2550. (defun org-e-html-table (table contents info)
  2551. "Transcode a TABLE element from Org to HTML.
  2552. CONTENTS is the contents of the table. INFO is a plist holding
  2553. contextual information."
  2554. (case (org-element-property :type table)
  2555. ;; Case 1: table.el table. Convert it using appropriate tools.
  2556. (table.el (org-e-html-table--table.el-table table info))
  2557. ;; Case 2: Standard table.
  2558. (t
  2559. (let* ((label (org-element-property :name table))
  2560. (caption (org-e-html--caption/label-string
  2561. (org-element-property :caption table) label info))
  2562. (attributes (mapconcat #'identity
  2563. (org-element-property :attr_html table)
  2564. " "))
  2565. (alignspec
  2566. (if (and (boundp 'org-e-html-format-table-no-css)
  2567. org-e-html-format-table-no-css)
  2568. "align=\"%s\"" "class=\"%s\""))
  2569. (table-column-specs
  2570. (function
  2571. (lambda (table info)
  2572. (mapconcat
  2573. (lambda (table-cell)
  2574. (let ((alignment (org-export-table-cell-alignment
  2575. table-cell info)))
  2576. (concat
  2577. ;; Begin a colgroup?
  2578. (when (org-export-table-cell-starts-colgroup-p
  2579. table-cell info)
  2580. "\n<colgroup>")
  2581. ;; Add a column. Also specify it's alignment.
  2582. (format "\n<col %s/>" (format alignspec alignment))
  2583. ;; End a colgroup?
  2584. (when (org-export-table-cell-ends-colgroup-p
  2585. table-cell info)
  2586. "\n</colgroup>"))))
  2587. (org-e-html-table-first-row-data-cells table info) "\n"))))
  2588. (table-attributes
  2589. (let ((table-tag (plist-get info :html-table-tag)))
  2590. (concat
  2591. (and (string-match "<table\\(.*\\)>" table-tag)
  2592. (match-string 1 table-tag))
  2593. (and label (format " id=\"%s\""
  2594. (org-solidify-link-text label)))))))
  2595. ;; Remove last blank line.
  2596. (setq contents (substring contents 0 -1))
  2597. ;; FIXME: splice
  2598. (format "\n<table%s>\n<caption>%s</caption>\n%s\n%s\n</table>"
  2599. table-attributes
  2600. (or caption "")
  2601. (funcall table-column-specs table info)
  2602. contents)))))
  2603. ;;;; Target
  2604. (defun org-e-html-target (target contents info)
  2605. "Transcode a TARGET object from Org to HTML.
  2606. CONTENTS is nil. INFO is a plist holding contextual
  2607. information."
  2608. (let ((id (org-export-solidify-link-text
  2609. (org-element-property :value target))))
  2610. (format "<a id=\"%s\" name=\"%s\"/>" id id)))
  2611. ;;;; Timestamp
  2612. (defun org-e-html-timestamp (timestamp contents info)
  2613. "Transcode a TIMESTAMP object from Org to HTML.
  2614. CONTENTS is nil. INFO is a plist holding contextual
  2615. information."
  2616. (let ((value (org-translate-time (org-element-property :value timestamp))))
  2617. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  2618. value)))
  2619. ;;;; Underline
  2620. (defun org-e-html-underline (underline contents info)
  2621. "Transcode UNDERLINE from Org to HTML.
  2622. CONTENTS is the text with underline markup. INFO is a plist
  2623. holding contextual information."
  2624. (format (or (cdr (assq 'underline org-e-html-text-markup-alist)) "%s")
  2625. contents))
  2626. ;;;; Verbatim
  2627. (defun org-e-html-verbatim (verbatim contents info)
  2628. "Transcode VERBATIM from Org to HTML.
  2629. CONTENTS is nil. INFO is a plist holding contextual
  2630. information."
  2631. (format (or (cdr (assq 'verbatim org-e-html-text-markup-alist)) "%s")
  2632. (org-element-property :value verbatim)))
  2633. ;;;; Verse Block
  2634. (defun org-e-html-verse-block (verse-block contents info)
  2635. "Transcode a VERSE-BLOCK element from Org to HTML.
  2636. CONTENTS is verse block contents. INFO is a plist holding
  2637. contextual information."
  2638. ;; Replace each newline character with line break. Also replace
  2639. ;; each blank line with a line break.
  2640. (setq contents (replace-regexp-in-string
  2641. "^ *\\\\\\\\$" "<br/>\n"
  2642. (replace-regexp-in-string
  2643. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
  2644. ;; Replace each white space at beginning of a line with a
  2645. ;; non-breaking space.
  2646. (while (string-match "^[ \t]+" contents)
  2647. (let* ((num-ws (length (match-string 0 contents)))
  2648. (ws (let (out) (dotimes (i num-ws out)
  2649. (setq out (concat out "&nbsp;"))))))
  2650. (setq contents (replace-match ws nil t contents))))
  2651. (org-e-html--wrap-label
  2652. verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
  2653. ;;; Filter Functions
  2654. (defun org-e-html-final-function (contents backend info)
  2655. (if (not org-e-html-pretty-output) contents
  2656. (with-temp-buffer
  2657. (nxml-mode)
  2658. (insert contents)
  2659. (indent-region (point-min) (point-max))
  2660. (buffer-substring-no-properties (point-min) (point-max)))))
  2661. ;;; Interactive functions
  2662. ;;;###autoload
  2663. (defun org-e-html-export-to-html
  2664. (&optional subtreep visible-only body-only ext-plist pub-dir)
  2665. "Export current buffer to a HTML file.
  2666. If narrowing is active in the current buffer, only export its
  2667. narrowed part.
  2668. If a region is active, export that region.
  2669. When optional argument SUBTREEP is non-nil, export the sub-tree
  2670. at point, extracting information from the headline properties
  2671. first.
  2672. When optional argument VISIBLE-ONLY is non-nil, don't export
  2673. contents of hidden elements.
  2674. When optional argument BODY-ONLY is non-nil, only write code
  2675. between \"\\begin{document}\" and \"\\end{document}\".
  2676. EXT-PLIST, when provided, is a property list with external
  2677. parameters overriding Org default settings, but still inferior to
  2678. file-local settings.
  2679. When optional argument PUB-DIR is set, use it as the publishing
  2680. directory.
  2681. Return output file's name."
  2682. (interactive)
  2683. (setq debug-on-error t) ; FIXME
  2684. (let* ((extension (concat "." org-e-html-extension))
  2685. (file (org-export-output-file-name extension subtreep pub-dir))
  2686. (org-export-coding-system org-e-html-coding-system))
  2687. (org-export-to-file
  2688. 'e-html file subtreep visible-only body-only ext-plist)))
  2689. ;;; FIXMES, TODOS, FOR REVIEW etc
  2690. ;;;; org-format-table-html
  2691. ;;;; org-format-org-table-html
  2692. ;;;; org-format-table-table-html
  2693. ;;;; org-table-number-fraction
  2694. ;;;; org-table-number-regexp
  2695. ;;;; org-e-html-table-caption-above
  2696. ;;;; org-whitespace
  2697. ;;;; "<span style=\"visibility:hidden;\">%s</span>"
  2698. ;;;; Remove display properties
  2699. ;;;; org-e-html-with-timestamp
  2700. ;;;; org-e-html-html-helper-timestamp
  2701. ;;;; org-export-as-html-and-open
  2702. ;;;; org-export-as-html-batch
  2703. ;;;; org-export-as-html-to-buffer
  2704. ;;;; org-replace-region-by-html
  2705. ;;;; org-export-region-as-html
  2706. ;;;; org-export-as-html
  2707. ;;;; (org-export-directory :html opt-plist)
  2708. ;;;; (plist-get opt-plist :html-extension)
  2709. ;;;; org-e-html-toplevel-hlevel
  2710. ;;;; org-e-html-special-string-regexps
  2711. ;;;; org-e-html-inline-images
  2712. ;;;; org-e-html-inline-image-extensions
  2713. ;;;; org-e-html-protect-char-alist
  2714. ;;;; org-e-html-table-use-header-tags-for-first-column
  2715. ;;;; org-e-html-todo-kwd-class-prefix
  2716. ;;;; org-e-html-tag-class-prefix
  2717. ;;;; org-e-html-footnote-separator
  2718. ;;;; org-export-preferred-target-alist
  2719. ;;;; org-solidify-link-text
  2720. ;;;; class for anchors
  2721. ;;;; org-export-with-section-numbers, body-only
  2722. ;;;; org-export-mark-todo-in-toc
  2723. (provide 'org-e-html)
  2724. ;;; org-e-html.el ends here