org-e-html.el 107 KB

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