org-e-html.el 110 KB

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