org-e-html.el 107 KB

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