org-e-html.el 110 KB

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