org-e-html.el 111 KB

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