org-e-html.el 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234
  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. "Alist between export properties and ways to set them.
  100. The car of the alist is the property name, and the cdr is a list
  101. like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
  102. KEYWORD is a string representing a buffer keyword, or nil.
  103. OPTION is a string that could be found in an #+OPTIONS: line.
  104. DEFAULT is the default value for the property.
  105. BEHAVIOUR determine how Org should handle multiple keywords for
  106. the same property. It is a symbol among:
  107. nil Keep old value and discard the new one.
  108. t Replace old value with the new one.
  109. `space' Concatenate the values, separating them with a space.
  110. `newline' Concatenate the values, separating them with
  111. a newline.
  112. `split' Split values at white spaces, and cons them to the
  113. previous list.
  114. KEYWORD and OPTION have precedence over DEFAULT.
  115. All these properties should be back-end agnostic. For back-end
  116. specific properties, define a similar variable named
  117. `org-BACKEND-option-alist', replacing BACKEND with the name of
  118. the appropriate back-end. You can also redefine properties
  119. there, as they have precedence over these.")
  120. (defvar html-table-tag nil) ; dynamically scoped into this.
  121. ;; FIXME: it already exists in org-e-html.el
  122. (defconst org-e-html-cvt-link-fn
  123. nil
  124. "Function to convert link URLs to exportable URLs.
  125. Takes two arguments, TYPE and PATH.
  126. Returns exportable url as (TYPE PATH), or nil to signal that it
  127. didn't handle this case.
  128. Intended to be locally bound around a call to `org-export-as-html'." )
  129. (defvar org-e-html-format-table-no-css)
  130. (defvar htmlize-buffer-places) ; from htmlize.el
  131. (defvar body-only) ; dynamically scoped into this.
  132. (defvar org-e-html-table-rowgrp-open)
  133. (defvar org-e-html-table-rownum)
  134. (defvar org-e-html-table-cur-rowgrp-is-hdr)
  135. (defvar org-lparse-table-is-styled)
  136. (defvar org-e-html-headline-formatter
  137. (lambda (level snumber todo todo-type priority
  138. title tags target extra-targets extra-class)
  139. (concat snumber " " title)))
  140. ;;; User Configuration Variables
  141. (defgroup org-export-e-html nil
  142. "Options for exporting Org mode files to HTML."
  143. :tag "Org Export HTML"
  144. :group 'org-export)
  145. ;;;; Debugging
  146. (defcustom org-e-html-pretty-output t
  147. "Enable this to generate pretty HTML."
  148. :group 'org-export-e-html
  149. :type 'boolean)
  150. ;;;; Document
  151. (defcustom org-e-html-extension "html"
  152. "The extension for exported HTML files."
  153. :group 'org-export-e-html
  154. :type 'string)
  155. (defcustom org-e-html-xml-declaration
  156. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  157. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  158. "The extension for exported HTML files.
  159. %s will be replaced with the charset of the exported file.
  160. This may be a string, or an alist with export extensions
  161. and corresponding declarations."
  162. :group 'org-export-e-html
  163. :type '(choice
  164. (string :tag "Single declaration")
  165. (repeat :tag "Dependent on extension"
  166. (cons (string :tag "Extension")
  167. (string :tag "Declaration")))))
  168. (defcustom org-e-html-coding-system nil
  169. "Coding system for HTML export, defaults to `buffer-file-coding-system'."
  170. :group 'org-export-e-html
  171. :type 'coding-system)
  172. (defvar org-e-html-content-div "content"
  173. "The name of the container DIV that holds all the page contents.
  174. This variable is obsolete since Org version 7.7.
  175. Please set `org-e-html-divs' instead.")
  176. (defcustom org-e-html-divs '("preamble" "content" "postamble")
  177. "The name of the main divs for HTML export.
  178. This is a list of three strings, the first one for the preamble
  179. DIV, the second one for the content DIV and the third one for the
  180. postamble DIV."
  181. :group 'org-export-e-html
  182. :type '(list
  183. (string :tag " Div for the preamble:")
  184. (string :tag " Div for the content:")
  185. (string :tag "Div for the postamble:")))
  186. ;;;; Document Header (Styles)
  187. (defconst org-e-html-style-default
  188. "<style type=\"text/css\">
  189. <!--/*--><![CDATA[/*><!--*/
  190. html { font-family: Times, serif; font-size: 12pt; }
  191. .title { text-align: center; }
  192. .todo { color: red; }
  193. .done { color: green; }
  194. .tag { background-color: #add8e6; font-weight:normal }
  195. .target { }
  196. .timestamp { color: #bebebe; }
  197. .timestamp-kwd { color: #5f9ea0; }
  198. .right {margin-left:auto; margin-right:0px; text-align:right;}
  199. .left {margin-left:0px; margin-right:auto; text-align:left;}
  200. .center {margin-left:auto; margin-right:auto; text-align:center;}
  201. p.verse { margin-left: 3% }
  202. pre {
  203. border: 1pt solid #AEBDCC;
  204. background-color: #F3F5F7;
  205. padding: 5pt;
  206. font-family: courier, monospace;
  207. font-size: 90%;
  208. overflow:auto;
  209. }
  210. table { border-collapse: collapse; }
  211. td, th { vertical-align: top; }
  212. th.right { text-align:center; }
  213. th.left { text-align:center; }
  214. th.center { text-align:center; }
  215. td.right { text-align:right; }
  216. td.left { text-align:left; }
  217. td.center { text-align:center; }
  218. dt { font-weight: bold; }
  219. div.figure { padding: 0.5em; }
  220. div.figure p { text-align: center; }
  221. div.inlinetask {
  222. padding:10px;
  223. border:2px solid gray;
  224. margin:10px;
  225. background: #ffffcc;
  226. }
  227. textarea { overflow-x: auto; }
  228. .linenr { font-size:smaller }
  229. .code-highlighted {background-color:#ffff00;}
  230. .org-info-js_info-navigation { border-style:none; }
  231. #org-info-js_console-label { font-size:10px; font-weight:bold;
  232. white-space:nowrap; }
  233. .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
  234. font-weight:bold; }
  235. /*]]>*/-->
  236. </style>"
  237. "The default style specification for exported HTML files.
  238. Please use the variables `org-e-html-style' and
  239. `org-e-html-style-extra' to add to this style. If you wish to not
  240. have the default style included, customize the variable
  241. `org-e-html-style-include-default'.")
  242. (defcustom org-e-html-style-include-default t
  243. "Non-nil means include the default style in exported HTML files.
  244. The actual style is defined in `org-e-html-style-default' and should
  245. not be modified. Use the variables `org-e-html-style' to add
  246. your own style information."
  247. :group 'org-export-e-html
  248. :type 'boolean)
  249. ;;;###autoload
  250. (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
  251. (defcustom org-e-html-style ""
  252. "Org-wide style definitions for exported HTML files.
  253. This variable needs to contain the full HTML structure to provide a style,
  254. including the surrounding HTML tags. If you set the value of this variable,
  255. you should consider to include definitions for the following classes:
  256. title, todo, done, timestamp, timestamp-kwd, tag, target.
  257. For example, a valid value would be:
  258. <style type=\"text/css\">
  259. <![CDATA[
  260. p { font-weight: normal; color: gray; }
  261. h1 { color: black; }
  262. .title { text-align: center; }
  263. .todo, .timestamp-kwd { color: red; }
  264. .done { color: green; }
  265. ]]>
  266. </style>
  267. If you'd like to refer to an external style file, use something like
  268. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  269. As the value of this option simply gets inserted into the HTML <head> header,
  270. you can \"misuse\" it to add arbitrary text to the header.
  271. See also the variable `org-e-html-style-extra'."
  272. :group 'org-export-e-html
  273. :type 'string)
  274. ;;;###autoload
  275. (put 'org-e-html-style 'safe-local-variable 'stringp)
  276. (defcustom org-e-html-style-extra ""
  277. "Additional style information for HTML export.
  278. The value of this variable is inserted into the HTML buffer right after
  279. the value of `org-e-html-style'. Use this variable for per-file
  280. settings of style information, and do not forget to surround the style
  281. settings with <style>...</style> tags."
  282. :group 'org-export-e-html
  283. :type 'string)
  284. ;;;###autoload
  285. (put 'org-e-html-style-extra 'safe-local-variable 'stringp)
  286. (defcustom org-e-html-mathjax-options
  287. '((path "http://orgmode.org/mathjax/MathJax.js")
  288. (scale "100")
  289. (align "center")
  290. (indent "2em")
  291. (mathml nil))
  292. "Options for MathJax setup.
  293. path The path where to find MathJax
  294. scale Scaling for the HTML-CSS backend, usually between 100 and 133
  295. align How to align display math: left, center, or right
  296. indent If align is not center, how far from the left/right side?
  297. mathml Should a MathML player be used if available?
  298. This is faster and reduces bandwidth use, but currently
  299. sometimes has lower spacing quality. Therefore, the default is
  300. nil. When browsers get better, this switch can be flipped.
  301. You can also customize this for each buffer, using something like
  302. #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
  303. :group 'org-export-e-html
  304. :type '(list :greedy t
  305. (list :tag "path (the path from where to load MathJax.js)"
  306. (const :format " " path) (string))
  307. (list :tag "scale (scaling for the displayed math)"
  308. (const :format " " scale) (string))
  309. (list :tag "align (alignment of displayed equations)"
  310. (const :format " " align) (string))
  311. (list :tag "indent (indentation with left or right alignment)"
  312. (const :format " " indent) (string))
  313. (list :tag "mathml (should MathML display be used is possible)"
  314. (const :format " " mathml) (boolean))))
  315. ;;;; Document Header (Scripts)
  316. (defcustom org-e-html-style-include-scripts t
  317. "Non-nil means include the JavaScript snippets in exported HTML files.
  318. The actual script is defined in `org-e-html-scripts' and should
  319. not be modified."
  320. :group 'org-export-e-html
  321. :type 'boolean)
  322. (defconst org-e-html-scripts
  323. "<script type=\"text/javascript\">
  324. <!--/*--><![CDATA[/*><!--*/
  325. function CodeHighlightOn(elem, id)
  326. {
  327. var target = document.getElementById(id);
  328. if(null != target) {
  329. elem.cacheClassElem = elem.className;
  330. elem.cacheClassTarget = target.className;
  331. target.className = \"code-highlighted\";
  332. elem.className = \"code-highlighted\";
  333. }
  334. }
  335. function CodeHighlightOff(elem, id)
  336. {
  337. var target = document.getElementById(id);
  338. if(elem.cacheClassElem)
  339. elem.className = elem.cacheClassElem;
  340. if(elem.cacheClassTarget)
  341. target.className = elem.cacheClassTarget;
  342. }
  343. /*]]>*///-->
  344. </script>"
  345. "Basic JavaScript that is needed by HTML files produced by Org-mode.")
  346. ;;;; Document Header (Mathjax)
  347. (defcustom org-e-html-mathjax-template
  348. "<script type=\"text/javascript\" src=\"%PATH\">
  349. <!--/*--><![CDATA[/*><!--*/
  350. MathJax.Hub.Config({
  351. // Only one of the two following lines, depending on user settings
  352. // First allows browser-native MathML display, second forces HTML/CSS
  353. :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
  354. :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
  355. extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
  356. \"TeX/noUndefined.js\"],
  357. tex2jax: {
  358. inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
  359. displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
  360. skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
  361. ignoreClass: \"tex2jax_ignore\",
  362. processEscapes: false,
  363. processEnvironments: true,
  364. preview: \"TeX\"
  365. },
  366. showProcessingMessages: true,
  367. displayAlign: \"%ALIGN\",
  368. displayIndent: \"%INDENT\",
  369. \"HTML-CSS\": {
  370. scale: %SCALE,
  371. availableFonts: [\"STIX\",\"TeX\"],
  372. preferredFont: \"TeX\",
  373. webFont: \"TeX\",
  374. imageFont: \"TeX\",
  375. showMathMenu: true,
  376. },
  377. MMLorHTML: {
  378. prefer: {
  379. MSIE: \"MML\",
  380. Firefox: \"MML\",
  381. Opera: \"HTML\",
  382. other: \"HTML\"
  383. }
  384. }
  385. });
  386. /*]]>*///-->
  387. </script>"
  388. "The MathJax setup for XHTML files."
  389. :group 'org-export-e-html
  390. :type 'string)
  391. ;;;; Preamble
  392. (defcustom org-e-html-preamble t
  393. "Non-nil means insert a preamble in HTML export.
  394. When `t', insert a string as defined by one of the formatting
  395. strings in `org-e-html-preamble-format'. When set to a
  396. string, this string overrides `org-e-html-preamble-format'.
  397. When set to a function, apply this function and insert the
  398. returned string. The function takes the property list of export
  399. options as its only argument.
  400. Setting :html-preamble in publishing projects will take
  401. precedence over this variable."
  402. :group 'org-export-e-html
  403. :type '(choice (const :tag "No preamble" nil)
  404. (const :tag "Default preamble" t)
  405. (string :tag "Custom formatting string")
  406. (function :tag "Function (must return a string)")))
  407. (defcustom org-e-html-preamble-format '(("en" ""))
  408. "The format for the HTML preamble.
  409. %t stands for the title.
  410. %a stands for the author's name.
  411. %e stands for the author's email.
  412. %d stands for the date.
  413. If you need to use a \"%\" character, you need to escape it
  414. like that: \"%%\"."
  415. :group 'org-export-e-html
  416. :type 'string)
  417. (defcustom org-e-html-home/up-format
  418. "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
  419. <a accesskey=\"h\" href=\"%s\"> UP </a>
  420. |
  421. <a accesskey=\"H\" href=\"%s\"> HOME </a>
  422. </div>"
  423. "Snippet used to insert the HOME and UP links.
  424. This is a format string, the first %s will receive the UP link,
  425. the second the HOME link. If both `org-e-html-link-up' and
  426. `org-e-html-link-home' are empty, the entire snippet will be
  427. ignored."
  428. :group 'org-export-e-html
  429. :type 'string)
  430. ;;;; Postamble
  431. (defcustom org-e-html-postamble 'auto
  432. "Non-nil means insert a postamble in HTML export.
  433. When `t', insert a string as defined by the formatting string in
  434. `org-e-html-postamble-format'. When set to a string, this
  435. string overrides `org-e-html-postamble-format'. When set to
  436. 'auto, discard `org-e-html-postamble-format' and honor
  437. `org-export-author/email/creator-info' variables. When set to a
  438. function, apply this function and insert the returned string.
  439. The function takes the property list of export options as its
  440. only argument.
  441. Setting :html-postamble in publishing projects will take
  442. precedence over this variable."
  443. :group 'org-export-e-html
  444. :type '(choice (const :tag "No postamble" nil)
  445. (const :tag "Auto preamble" 'auto)
  446. (const :tag "Default formatting string" t)
  447. (string :tag "Custom formatting string")
  448. (function :tag "Function (must return a string)")))
  449. (defcustom org-e-html-postamble-format
  450. '(("en" "<p class=\"author\">Author: %a (%e)</p>
  451. <p class=\"date\">Date: %d</p>
  452. <p class=\"creator\">Generated by %c</p>
  453. <p class=\"xhtml-validation\">%v</p>
  454. "))
  455. "The format for the HTML postamble.
  456. %a stands for the author's name.
  457. %e stands for the author's email.
  458. %d stands for the date.
  459. %c will be replaced by information about Org/Emacs versions.
  460. %v will be replaced by `org-e-html-validation-link'.
  461. If you need to use a \"%\" character, you need to escape it
  462. like that: \"%%\"."
  463. :group 'org-export-e-html
  464. :type 'string)
  465. (defcustom org-e-html-validation-link
  466. "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
  467. "Link to HTML validation service."
  468. :group 'org-export-e-html
  469. :type 'string)
  470. ;; FIXME Obsolete since Org 7.7
  471. ;; Use the :timestamp option or `org-export-time-stamp-file' instead
  472. ;;;; Emphasis
  473. (defcustom org-e-html-protect-char-alist
  474. '(("&" . "&amp;")
  475. ("<" . "&lt;")
  476. (">" . "&gt;"))
  477. "Alist of characters to be converted by `org-e-html-protect'."
  478. :group 'org-export-e-html
  479. :type '(repeat (cons (string :tag "Character")
  480. (string :tag "HTML equivalent"))))
  481. (defconst org-e-html-special-string-regexps
  482. '(("\\\\-" . "&shy;")
  483. ("---\\([^-]\\)" . "&mdash;\\1")
  484. ("--\\([^-]\\)" . "&ndash;\\1")
  485. ("\\.\\.\\." . "&hellip;"))
  486. "Regular expressions for special string conversion.")
  487. ;;;; Todos
  488. (defcustom org-e-html-todo-kwd-class-prefix ""
  489. "Prefix to class names for TODO keywords.
  490. Each TODO keyword gets a class given by the keyword itself, with this prefix.
  491. The default prefix is empty because it is nice to just use the keyword
  492. as a class name. But if you get into conflicts with other, existing
  493. CSS classes, then this prefix can be very useful."
  494. :group 'org-export-e-html
  495. :type 'string)
  496. ;;;; Tags
  497. (defcustom org-e-html-tag-class-prefix ""
  498. "Prefix to class names for TODO keywords.
  499. Each tag gets a class given by the tag itself, with this prefix.
  500. The default prefix is empty because it is nice to just use the keyword
  501. as a class name. But if you get into conflicts with other, existing
  502. CSS classes, then this prefix can be very useful."
  503. :group 'org-export-e-html
  504. :type 'string)
  505. ;;;; Time-stamps
  506. ;;;; Statistics Cookie
  507. ;;;; Subscript
  508. ;;;; Superscript
  509. ;;;; Inline images
  510. (defcustom org-e-html-inline-images 'maybe
  511. "Non-nil means inline images into exported HTML pages.
  512. This is done using an <img> tag. When nil, an anchor with href is used to
  513. link to the image. If this option is `maybe', then images in links with
  514. an empty description will be inlined, while images with a description will
  515. be linked only."
  516. :group 'org-export-e-html
  517. :type '(choice (const :tag "Never" nil)
  518. (const :tag "Always" t)
  519. (const :tag "When there is no description" maybe)))
  520. (defcustom org-e-html-inline-image-extensions
  521. '("png" "jpeg" "jpg" "gif" "svg")
  522. "Extensions of image files that can be inlined into HTML."
  523. :group 'org-export-e-html
  524. :type '(repeat (string :tag "Extension")))
  525. ;;;; Block
  526. ;;;; Comment
  527. ;;;; Comment Block
  528. ;;;; Drawer
  529. ;;;; Dynamic Block
  530. ;;;; Emphasis
  531. ;;;; Entity
  532. ;;;; Example Block
  533. ;;;; Export Snippet
  534. ;;;; Export Block
  535. ;;;; Fixed Width
  536. ;;;; Footnotes
  537. (defcustom org-e-html-footnotes-section "<div id=\"footnotes\">
  538. <h2 class=\"footnotes\">%s: </h2>
  539. <div id=\"text-footnotes\">
  540. %s
  541. </div>
  542. </div>"
  543. "Format for the footnotes section.
  544. Should contain a two instances of %s. The first will be replaced with the
  545. language-specific word for \"Footnotes\", the second one will be replaced
  546. by the footnotes themselves."
  547. :group 'org-export-e-html
  548. :type 'string)
  549. (defcustom org-e-html-footnote-format "<sup>%s</sup>"
  550. "The format for the footnote reference.
  551. %s will be replaced by the footnote reference itself."
  552. :group 'org-export-e-html
  553. :type 'string)
  554. (defcustom org-e-html-footnote-separator "<sup>, </sup>"
  555. "Text used to separate footnotes."
  556. :group 'org-export-e-html
  557. :type 'string)
  558. ;;;; Headline
  559. ;;;; Horizontal Rule
  560. ;;;; Inline Babel Call
  561. ;;;; Inline Src Block
  562. ;;;; Inlinetask
  563. ;;;; Item
  564. ;;;; Keyword
  565. ;;;; Latex Environment
  566. ;;;; Latex Fragment
  567. ;;;; Line Break
  568. ;;;; Link
  569. ;;;; Babel Call
  570. ;;;; Macro
  571. ;;;; Paragraph
  572. ;;;; Plain List
  573. ;;;; Plain Text
  574. ;;;; Property Drawer
  575. ;;;; Quote Block
  576. ;;;; Quote Section
  577. ;;;; Section
  578. ;;;; Radio Target
  579. ;;;; Special Block
  580. ;;;; Src Block
  581. (defgroup org-export-e-htmlize nil
  582. "Options for processing examples with htmlize.el."
  583. :tag "Org Export Htmlize"
  584. :group 'org-export-e-html)
  585. (defcustom org-export-e-htmlize-output-type 'inline-css
  586. "Output type to be used by htmlize when formatting code snippets.
  587. Choices are `css', to export the CSS selectors only, or `inline-css', to
  588. export the CSS attribute values inline in the HTML. We use as default
  589. `inline-css', in order to make the resulting HTML self-containing.
  590. However, this will fail when using Emacs in batch mode for export, because
  591. then no rich font definitions are in place. It will also not be good if
  592. people with different Emacs setup contribute HTML files to a website,
  593. because the fonts will represent the individual setups. In these cases,
  594. it is much better to let Org/Htmlize assign classes only, and to use
  595. a style file to define the look of these classes.
  596. To get a start for your css file, start Emacs session and make sure that
  597. all the faces you are interested in are defined, for example by loading files
  598. in all modes you want. Then, use the command
  599. \\[org-export-e-htmlize-generate-css] to extract class definitions."
  600. :group 'org-export-e-htmlize
  601. :type '(choice (const css) (const inline-css)))
  602. (defcustom org-export-e-htmlize-css-font-prefix "org-"
  603. "The prefix for CSS class names for htmlize font specifications."
  604. :group 'org-export-e-htmlize
  605. :type 'string)
  606. (defcustom org-export-e-htmlized-org-css-url nil
  607. "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
  608. Normally when creating an htmlized version of an Org buffer, htmlize will
  609. create CSS to define the font colors. However, this does not work when
  610. converting in batch mode, and it also can look bad if different people
  611. with different fontification setup work on the same website.
  612. When this variable is non-nil, creating an htmlized version of an Org buffer
  613. using `org-export-as-org' will remove the internal CSS section and replace it
  614. with a link to this URL."
  615. :group 'org-export-e-htmlize
  616. :type '(choice
  617. (const :tag "Keep internal css" nil)
  618. (string :tag "URL or local href")))
  619. ;;;; Table
  620. (defcustom org-e-html-table-tag
  621. "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
  622. "The HTML tag that is used to start a table.
  623. This must be a <table> tag, but you may change the options like
  624. borders and spacing."
  625. :group 'org-export-e-html
  626. :type 'string)
  627. (defcustom org-e-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  628. "The opening tag for table header fields.
  629. This is customizable so that alignment options can be specified.
  630. The first %s will be filled with the scope of the field, either row or col.
  631. The second %s will be replaced by a style entry to align the field.
  632. See also the variable `org-e-html-table-use-header-tags-for-first-column'.
  633. See also the variable `org-e-html-table-align-individual-fields'."
  634. :group 'org-export-tables ; FIXME: change group?
  635. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  636. (defcustom org-e-html-table-data-tags '("<td%s>" . "</td>")
  637. "The opening tag for table data fields.
  638. This is customizable so that alignment options can be specified.
  639. The first %s will be filled with the scope of the field, either row or col.
  640. The second %s will be replaced by a style entry to align the field.
  641. See also the variable `org-e-html-table-align-individual-fields'."
  642. :group 'org-export-tables
  643. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  644. (defcustom org-e-html-table-row-tags '("<tr>" . "</tr>")
  645. "The opening tag for table data fields.
  646. This is customizable so that alignment options can be specified.
  647. Instead of strings, these can be Lisp forms that will be evaluated
  648. for each row in order to construct the table row tags. During evaluation,
  649. the variable `head' will be true when this is a header line, nil when this
  650. is a body line. And the variable `nline' will contain the line number,
  651. starting from 1 in the first header line. For example
  652. (setq org-e-html-table-row-tags
  653. (cons '(if head
  654. \"<tr>\"
  655. (if (= (mod nline 2) 1)
  656. \"<tr class=\\\"tr-odd\\\">\"
  657. \"<tr class=\\\"tr-even\\\">\"))
  658. \"</tr>\"))
  659. will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
  660. :group 'org-export-tables
  661. :type '(cons
  662. (choice :tag "Opening tag"
  663. (string :tag "Specify")
  664. (sexp))
  665. (choice :tag "Closing tag"
  666. (string :tag "Specify")
  667. (sexp))))
  668. (defcustom org-e-html-table-align-individual-fields t
  669. "Non-nil means attach style attributes for alignment to each table field.
  670. When nil, alignment will only be specified in the column tags, but this
  671. is ignored by some browsers (like Firefox, Safari). Opera does it right
  672. though."
  673. :group 'org-export-tables
  674. :type 'boolean)
  675. (defcustom org-e-html-table-use-header-tags-for-first-column nil
  676. "Non-nil means format column one in tables with header tags.
  677. When nil, also column one will use data tags."
  678. :group 'org-export-tables
  679. :type 'boolean)
  680. ;;;; Target
  681. ;;;; Time-stamp
  682. ;;;; Verbatim
  683. ;;;; Verse Block
  684. ;;;; Headline
  685. (defcustom org-e-html-toplevel-hlevel 2
  686. "The <H> level for level 1 headings in HTML export.
  687. This is also important for the classes that will be wrapped around headlines
  688. and outline structure. If this variable is 1, the top-level headlines will
  689. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  690. and outline-text-1. If this is 2, all of these will get a 2 instead.
  691. The default for this variable is 2, because we use <h1> for formatting the
  692. document title."
  693. :group 'org-export-e-html
  694. :type 'string)
  695. ;;;; Links
  696. ;;;; Drawers
  697. ;;;; Inlinetasks
  698. ;;;; Publishing
  699. (defcustom org-e-html-link-org-files-as-html t
  700. "Non-nil means make file links to `file.org' point to `file.html'.
  701. When org-mode is exporting an org-mode file to HTML, links to
  702. non-html files are directly put into a href tag in HTML.
  703. However, links to other Org-mode files (recognized by the
  704. extension `.org.) should become links to the corresponding html
  705. file, assuming that the linked org-mode file will also be
  706. converted to HTML.
  707. When nil, the links still point to the plain `.org' file."
  708. :group 'org-export-e-html
  709. :type 'boolean)
  710. ;;;; Compilation
  711. ;;; User Configurable Variables (MAYBE)
  712. ;;;; Preamble
  713. (defcustom org-e-html-date-format
  714. "\\today"
  715. "Format string for \\date{...}."
  716. :group 'org-export-e-html
  717. :type 'boolean)
  718. ;;;; Headline
  719. (defcustom org-e-html-format-headline-function nil
  720. "Function to format headline text.
  721. This function will be called with 5 arguments:
  722. TODO the todo keyword \(string or nil\).
  723. TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
  724. PRIORITY the priority of the headline \(integer or nil\)
  725. TEXT the main headline text \(string\).
  726. TAGS the tags string, separated with colons \(string or nil\).
  727. The function result will be used in the section format string.
  728. As an example, one could set the variable to the following, in
  729. order to reproduce the default set-up:
  730. \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
  731. \"Default format function for an headline.\"
  732. \(concat \(when todo
  733. \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
  734. \(when priority
  735. \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  736. text
  737. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
  738. :group 'org-export-e-html
  739. :type 'function)
  740. ;;;; Emphasis
  741. (defcustom org-e-html-emphasis-alist
  742. '(("*" . "<b>%s</b>")
  743. ("/" . "<i>%s</i>")
  744. ("_" . "<span style=\"text-decoration:underline;\">%s</span>")
  745. ("+" . "<del>%s</del>")
  746. ("=" . "<code>%s</code>")
  747. ("~" . "<code>%s</code>"))
  748. "Alist of HTML expressions to convert emphasis fontifiers.
  749. The key is the character used as a marker for fontification. The
  750. value is a formatting string to wrap fontified text with.
  751. Value can also be set to the following symbols: `verb' and
  752. `protectedtexttt'. For the former, Org will use \"\\verb\" to
  753. create a format string and select a delimiter character that
  754. isn't in the string. For the latter, Org will use \"\\texttt\"
  755. to typeset and try to protect special characters."
  756. :group 'org-export-e-html
  757. :type 'alist)
  758. ;;;; Footnotes
  759. (defcustom org-e-html-footnote-separator "<sup>, </sup>"
  760. "Text used to separate footnotes."
  761. :group 'org-export-e-html
  762. :type 'string)
  763. ;;;; Time-stamps
  764. (defcustom org-e-html-active-timestamp-format "\\textit{%s}"
  765. "A printf format string to be applied to active time-stamps."
  766. :group 'org-export-e-html
  767. :type 'string)
  768. (defcustom org-e-html-inactive-timestamp-format "\\textit{%s}"
  769. "A printf format string to be applied to inactive time-stamps."
  770. :group 'org-export-e-html
  771. :type 'string)
  772. (defcustom org-e-html-diary-timestamp-format "\\textit{%s}"
  773. "A printf format string to be applied to diary time-stamps."
  774. :group 'org-export-e-html
  775. :type 'string)
  776. ;;;; Links
  777. (defcustom org-e-html-image-default-option "width=.9\\linewidth"
  778. "Default option for images."
  779. :group 'org-export-e-html
  780. :type 'string)
  781. (defcustom org-e-html-default-figure-position "htb"
  782. "Default position for latex figures."
  783. :group 'org-export-e-html
  784. :type 'string)
  785. (defcustom org-e-html-inline-image-rules
  786. '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
  787. "Rules characterizing image files that can be inlined into HTML.
  788. A rule consists in an association whose key is the type of link
  789. to consider, and value is a regexp that will be matched against
  790. link's path.
  791. Note that, by default, the image extension *actually* allowed
  792. depend on the way the HTML file is processed. When used with
  793. pdflatex, pdf, jpg and png images are OK. When processing
  794. through dvi to Postscript, only ps and eps are allowed. The
  795. default we use here encompasses both."
  796. :group 'org-export-e-html
  797. :type '(alist :key-type (string :tag "Type")
  798. :value-type (regexp :tag "Path")))
  799. ;;;; Tables
  800. (defcustom org-e-html-table-caption-above t
  801. "When non-nil, place caption string at the beginning of the table.
  802. Otherwise, place it near the end."
  803. :group 'org-export-e-html
  804. :type 'boolean)
  805. ;;;; Drawers
  806. (defcustom org-e-html-format-drawer-function nil
  807. "Function called to format a drawer in HTML code.
  808. The function must accept two parameters:
  809. NAME the drawer name, like \"LOGBOOK\"
  810. CONTENTS the contents of the drawer.
  811. The function should return the string to be exported.
  812. For example, the variable could be set to the following function
  813. in order to mimic default behaviour:
  814. \(defun org-e-html-format-drawer-default \(name contents\)
  815. \"Format a drawer element for HTML export.\"
  816. contents\)"
  817. :group 'org-export-e-html
  818. :type 'function)
  819. ;;;; Inlinetasks
  820. (defcustom org-e-html-format-inlinetask-function nil
  821. "Function called to format an inlinetask in HTML code.
  822. The function must accept six parameters:
  823. TODO the todo keyword, as a string
  824. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  825. PRIORITY the inlinetask priority, as a string
  826. NAME the inlinetask name, as a string.
  827. TAGS the inlinetask tags, as a string.
  828. CONTENTS the contents of the inlinetask, as a string.
  829. The function should return the string to be exported.
  830. For example, the variable could be set to the following function
  831. in order to mimic default behaviour:
  832. \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
  833. \"Format an inline task element for HTML export.\"
  834. \(let \(\(full-title
  835. \(concat
  836. \(when todo
  837. \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
  838. \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
  839. title
  840. \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
  841. \(format \(concat \"\\\\begin{center}\\n\"
  842. \"\\\\fbox{\\n\"
  843. \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
  844. \"%s\\n\\n\"
  845. \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
  846. \"%s\"
  847. \"\\\\end{minipage}}\"
  848. \"\\\\end{center}\"\)
  849. full-title contents\)\)"
  850. :group 'org-export-e-html
  851. :type 'function)
  852. ;; Src blocks
  853. ;;;; Plain text
  854. (defcustom org-e-html-quotes
  855. '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
  856. ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
  857. "Alist for quotes to use when converting english double-quotes.
  858. The CAR of each item in this alist is the language code.
  859. The CDR of each item in this alist is a list of three CONS:
  860. - the first CONS defines the opening quote;
  861. - the second CONS defines the closing quote;
  862. - the last CONS defines single quotes.
  863. For each item in a CONS, the first string is a regexp
  864. for allowed characters before/after the quote, the second
  865. string defines the replacement string for this quote."
  866. :group 'org-export-e-html
  867. :type '(list
  868. (cons :tag "Opening quote"
  869. (string :tag "Regexp for char before")
  870. (string :tag "Replacement quote "))
  871. (cons :tag "Closing quote"
  872. (string :tag "Regexp for char after ")
  873. (string :tag "Replacement quote "))
  874. (cons :tag "Single quote"
  875. (string :tag "Regexp for char before")
  876. (string :tag "Replacement quote "))))
  877. ;;;; Compilation
  878. ;;; Internal Functions (HTML)
  879. (defun org-e-html-cvt-org-as-html (opt-plist type path)
  880. "Convert an org filename to an equivalent html filename.
  881. If TYPE is not file, just return `nil'.
  882. See variable `org-e-html-link-org-files-as-html'"
  883. (save-match-data
  884. (and
  885. org-e-html-link-org-files-as-html
  886. (string= type "file")
  887. (string-match "\\.org$" path)
  888. (progn
  889. (list
  890. "file"
  891. (concat
  892. (substring path 0 (match-beginning 0))
  893. "."
  894. (plist-get opt-plist :html-extension)))))))
  895. (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
  896. descp)
  897. "Make an HTML link.
  898. OPT-PLIST is an options list.
  899. TYPE is the device-type of the link (THIS://foo.html).
  900. PATH is the path of the link (http://THIS#location).
  901. FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
  902. DESC is the link description, if any.
  903. ATTR is a string of other attributes of the \"a\" element."
  904. (declare (special org-lparse-par-open))
  905. (save-match-data
  906. (when (string= type-1 "coderef")
  907. (let ((ref fragment))
  908. (setq desc (format (org-export-get-coderef-format ref (and descp desc))
  909. (cdr (assoc ref org-export-code-refs)))
  910. fragment (concat "coderef-" ref)
  911. attr (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
  912. fragment fragment))))
  913. (let* ((may-inline-p
  914. (and (member type-1 '("http" "https" "file"))
  915. (org-lparse-should-inline-p path descp)
  916. (not fragment)))
  917. (type (if (equal type-1 "id") "file" type-1))
  918. (filename path)
  919. ;;First pass. Just sanity stuff.
  920. (components-1
  921. (cond
  922. ((string= type "file")
  923. (list
  924. type
  925. ;;Substitute just if original path was absolute.
  926. ;;(Otherwise path must remain relative)
  927. (if (file-name-absolute-p path)
  928. (concat "file://" (expand-file-name path))
  929. path)))
  930. ((string= type "")
  931. (list nil path))
  932. (t (list type path))))
  933. ;;Second pass. Components converted so they can refer
  934. ;;to a remote site.
  935. (components-2
  936. (or
  937. (and org-e-html-cvt-link-fn
  938. (apply org-e-html-cvt-link-fn
  939. opt-plist components-1))
  940. (apply #'org-e-html-cvt-org-as-html
  941. opt-plist components-1)
  942. components-1))
  943. (type (first components-2))
  944. (thefile (second components-2)))
  945. ;;Third pass. Build final link except for leading type
  946. ;;spec.
  947. (cond
  948. ((or
  949. (not type)
  950. (string= type "http")
  951. (string= type "https")
  952. (string= type "file")
  953. (string= type "coderef"))
  954. (if fragment
  955. (setq thefile (concat thefile "#" fragment))))
  956. (t))
  957. ;;Final URL-build, for all types.
  958. (setq thefile
  959. (let
  960. ((str (org-xml-format-href thefile)))
  961. (if (and type (not (or (string= "file" type)
  962. (string= "coderef" type))))
  963. (concat type ":" str)
  964. str)))
  965. (if may-inline-p
  966. (org-e-html-format-image thefile)
  967. (org-lparse-format
  968. 'LINK (org-xml-format-desc desc) thefile attr)))))
  969. (defun org-e-html-format-inline-image (path &optional caption label attr)
  970. ;; FIXME: alt text missing here?
  971. (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
  972. path (file-name-nondirectory path))))
  973. (if (not label) inline-image
  974. (org-e-html-format-section inline-image "figure" label))))
  975. (defun org-e-html-format-image (src)
  976. "Create image tag with source and attributes."
  977. (save-match-data
  978. (let* ((caption (org-find-text-property-in-string 'org-caption src))
  979. (attr (org-find-text-property-in-string 'org-attributes src))
  980. (label (org-find-text-property-in-string 'org-label src))
  981. (caption (and caption (org-xml-encode-org-text caption)))
  982. (img-extras (if (string-match "^ltxpng/" src)
  983. (format " alt=\"%s\""
  984. (org-find-text-property-in-string
  985. 'org-latex-src src))
  986. (if (string-match "\\<alt=" (or attr ""))
  987. (concat " " attr )
  988. (concat " " attr " alt=\"" src "\""))))
  989. (img (format "<img src=\"%s\"%s />" src img-extras))
  990. (extra (concat
  991. (and label
  992. (format "id=\"%s\" " (org-solidify-link-text label)))
  993. "class=\"figure\"")))
  994. (if caption
  995. (with-temp-buffer
  996. (with-org-lparse-preserve-paragraph-state
  997. (insert
  998. (org-lparse-format
  999. '("<div %s>" . "\n</div>")
  1000. (concat
  1001. (org-lparse-format '("\n<p>" . "</p>") img)
  1002. (org-lparse-format '("\n<p>" . "</p>") caption))
  1003. extra)))
  1004. (buffer-string))
  1005. img))))
  1006. ;;;; Bibliography
  1007. (defun org-e-html-bibliography ()
  1008. "Find bibliography, cut it out and return it."
  1009. (catch 'exit
  1010. (let (beg end (cnt 1) bib)
  1011. (save-excursion
  1012. (goto-char (point-min))
  1013. (when (re-search-forward
  1014. "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
  1015. (setq beg (match-beginning 0))
  1016. (while (re-search-forward "</?div\\>" nil t)
  1017. (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
  1018. (when (= cnt 0)
  1019. (and (looking-at ">") (forward-char 1))
  1020. (setq bib (buffer-substring beg (point)))
  1021. (delete-region beg (point))
  1022. (throw 'exit bib))))
  1023. nil))))
  1024. ;;;; Table
  1025. (defun org-e-html-format-table (lines olines)
  1026. (let ((org-e-html-format-table-no-css nil))
  1027. (org-lparse-format-table lines olines)))
  1028. (defun org-e-html-splice-attributes (tag attributes)
  1029. "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
  1030. (if (not attributes)
  1031. tag
  1032. (let (oldatt newatt)
  1033. (setq oldatt (org-extract-attributes-from-string tag)
  1034. tag (pop oldatt)
  1035. newatt (cdr (org-extract-attributes-from-string attributes)))
  1036. (while newatt
  1037. (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
  1038. (if (string-match ">" tag)
  1039. (setq tag
  1040. (replace-match (concat (org-attributes-to-string oldatt) ">")
  1041. t t tag)))
  1042. tag)))
  1043. (defun org-export-splice-style (style extra)
  1044. "Splice EXTRA into STYLE, just before \"</style>\"."
  1045. (if (and (stringp extra)
  1046. (string-match "\\S-" extra)
  1047. (string-match "</style>" style))
  1048. (concat (substring style 0 (match-beginning 0))
  1049. "\n" extra "\n"
  1050. (substring style (match-beginning 0)))
  1051. style))
  1052. (defun org-export-e-htmlize-region-for-paste (beg end)
  1053. "Convert the region to HTML, using htmlize.el.
  1054. This is much like `htmlize-region-for-paste', only that it uses
  1055. the settings define in the org-... variables."
  1056. (let* ((htmlize-output-type org-export-e-htmlize-output-type)
  1057. (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
  1058. (htmlbuf (htmlize-region beg end)))
  1059. (unwind-protect
  1060. (with-current-buffer htmlbuf
  1061. (buffer-substring (plist-get htmlize-buffer-places 'content-start)
  1062. (plist-get htmlize-buffer-places 'content-end)))
  1063. (kill-buffer htmlbuf))))
  1064. ;;;###autoload
  1065. (defun org-export-e-htmlize-generate-css ()
  1066. "Create the CSS for all font definitions in the current Emacs session.
  1067. Use this to create face definitions in your CSS style file that can then
  1068. be used by code snippets transformed by htmlize.
  1069. This command just produces a buffer that contains class definitions for all
  1070. faces used in the current Emacs session. You can copy and paste the ones you
  1071. need into your CSS file.
  1072. If you then set `org-export-e-htmlize-output-type' to `css', calls to
  1073. the function `org-export-e-htmlize-region-for-paste' will produce code
  1074. that uses these same face definitions."
  1075. (interactive)
  1076. (require 'htmlize)
  1077. (and (get-buffer "*html*") (kill-buffer "*html*"))
  1078. (with-temp-buffer
  1079. (let ((fl (face-list))
  1080. (htmlize-css-name-prefix "org-")
  1081. (htmlize-output-type 'css)
  1082. f i)
  1083. (while (setq f (pop fl)
  1084. i (and f (face-attribute f :inherit)))
  1085. (when (and (symbolp f) (or (not i) (not (listp i))))
  1086. (insert (org-add-props (copy-sequence "1") nil 'face f))))
  1087. (htmlize-region (point-min) (point-max))))
  1088. (org-pop-to-buffer-same-window "*html*")
  1089. (goto-char (point-min))
  1090. (if (re-search-forward "<style" nil t)
  1091. (delete-region (point-min) (match-beginning 0)))
  1092. (if (re-search-forward "</style>" nil t)
  1093. (delete-region (1+ (match-end 0)) (point-max)))
  1094. (beginning-of-line 1)
  1095. (if (looking-at " +") (replace-match ""))
  1096. (goto-char (point-min)))
  1097. (defun org-e-html-format-toc-entry (snumber todo headline tags href)
  1098. (setq headline (concat
  1099. ;; section number
  1100. (and org-export-with-section-numbers (concat snumber " "))
  1101. ;; headline
  1102. headline
  1103. ;; tags
  1104. (and tags (concat
  1105. "&nbsp;&nbsp;&nbsp;"
  1106. (format "<span class=\"tag\">%s</span>" tags)))))
  1107. ;; fontify headline based on TODO keyword
  1108. (when todo
  1109. (setq headline (format "<span class=\"todo\">%s</span>" headline)))
  1110. (format "<a href=\"#%s\">%s</a>" href headline))
  1111. (defun org-e-html-toc-entry-formatter
  1112. (level snumber todo todo-type priority
  1113. headline tags target extra-targets extra-class)
  1114. (org-e-html-format-toc-entry snumber todo headline tags target))
  1115. (defun org-e-html-make-string (n string)
  1116. (let (out) (dotimes (i n out) (setq out (concat string out)))))
  1117. (defun org-e-html-toc-text (toc-entries)
  1118. (let* ((prev-level (1- (nth 1 (car toc-entries))))
  1119. (start-level prev-level))
  1120. (concat
  1121. (mapconcat
  1122. (lambda (entry)
  1123. (let ((headline (nth 0 entry))
  1124. (level (nth 1 entry)))
  1125. (concat
  1126. (let* ((cnt (- level prev-level))
  1127. (times (if (> cnt 0) (1- cnt) (- cnt)))
  1128. rtn)
  1129. (setq prev-level level)
  1130. (concat
  1131. (org-e-html-make-string
  1132. times (cond ((> cnt 0) "\n<ul>\n<li>")
  1133. ((< cnt 0) "</li>\n</ul>\n")))
  1134. (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
  1135. headline)))
  1136. toc-entries "")
  1137. (org-e-html-make-string
  1138. (- prev-level start-level) "</li>\n</ul>\n"))))
  1139. (defun org-e-html-toc (depth info)
  1140. (assert (wholenump depth))
  1141. (let* ((headlines (org-export-collect-headlines info depth))
  1142. (toc-entries
  1143. (loop for headline in headlines collect
  1144. (list (org-e-html-headline-text
  1145. headline info 'org-e-html-toc-entry-formatter)
  1146. (org-export-get-relative-level headline info)))))
  1147. (when toc-entries
  1148. (let* ((lang-specific-heading
  1149. (nth 3 (or (assoc (plist-get info :language)
  1150. org-export-language-setup)
  1151. (assoc "en" org-export-language-setup)))))
  1152. (concat
  1153. "<div id=\"table-of-contents\">\n"
  1154. (format "<h%d>%s</h%d>\n"
  1155. org-e-html-toplevel-hlevel
  1156. lang-specific-heading
  1157. org-e-html-toplevel-hlevel)
  1158. "<div id=\"text-table-of-contents\">"
  1159. (org-e-html-toc-text toc-entries)
  1160. "</div>\n"
  1161. "</div>\n")))))
  1162. ;; (defun org-e-html-format-line (line)
  1163. ;; (case org-lparse-dyn-current-environment
  1164. ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
  1165. ;; (t (concat line "\n"))))
  1166. (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
  1167. "Turn todo keyword into a valid class name.
  1168. Replaces invalid characters with \"_\"."
  1169. (save-match-data
  1170. (while (string-match "[^a-zA-Z0-9_]" kwd)
  1171. (setq kwd (replace-match "_" t t kwd))))
  1172. kwd)
  1173. (defun org-e-html-format-footnote-reference (n def refcnt)
  1174. (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
  1175. (format org-e-html-footnote-format
  1176. (format
  1177. "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
  1178. n extra n n))))
  1179. (defun org-e-html-format-footnotes-section (section-name definitions)
  1180. (if (not definitions) ""
  1181. (format org-e-html-footnotes-section section-name definitions)))
  1182. (defun org-e-html-format-footnote-definition (fn)
  1183. (let ((n (car fn)) (def (cdr fn)))
  1184. (format
  1185. "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
  1186. (format
  1187. (format org-e-html-footnote-format
  1188. "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
  1189. n n n) def)))
  1190. (defun org-e-html-footnote-section (info)
  1191. (let* ((fn-alist (org-export-collect-footnote-definitions
  1192. (plist-get info :parse-tree) info))
  1193. (fn-alist
  1194. (loop for (n type raw) in fn-alist collect
  1195. (cons n (if (equal (org-element-type raw) 'org-data)
  1196. (org-trim (org-export-data raw 'e-html info))
  1197. (format "<p>%s</p>"
  1198. (org-trim (org-export-secondary-string
  1199. raw 'e-html info))))))))
  1200. (when fn-alist
  1201. (org-e-html-format-footnotes-section
  1202. (nth 4 (or (assoc (plist-get info :language)
  1203. org-export-language-setup)
  1204. (assoc "en" org-export-language-setup)))
  1205. (format
  1206. "<table>\n%s\n</table>\n"
  1207. (mapconcat 'org-e-html-format-footnote-definition fn-alist "\n"))))))
  1208. (defun org-e-html-get-coding-system-for-write ()
  1209. (or org-e-html-coding-system
  1210. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1211. (defun org-e-html-get-coding-system-for-save ()
  1212. (or org-e-html-coding-system
  1213. (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
  1214. (defun org-e-html-format-date (info)
  1215. (let ((date (plist-get info :date)))
  1216. (cond
  1217. ((and date (string-match "%" date))
  1218. (format-time-string date))
  1219. (date date)
  1220. (t (format-time-string "%Y-%m-%d %T %Z")))))
  1221. ;;; Internal Functions (Ngz)
  1222. (defun org-e-html--caption/label-string (caption label info)
  1223. "Return caption and label HTML string for floats.
  1224. CAPTION is a cons cell of secondary strings, the car being the
  1225. standard caption and the cdr its short form. LABEL is a string
  1226. representing the label. INFO is a plist holding contextual
  1227. information.
  1228. If there's no caption nor label, return the empty string.
  1229. For non-floats, see `org-e-html--wrap-label'."
  1230. (setq label nil) ;; FIXME
  1231. (let ((label-str (if label (format "\\label{%s}" label) "")))
  1232. (cond
  1233. ((and (not caption) (not label)) "")
  1234. ((not caption) (format "\\label{%s}\n" label))
  1235. ;; Option caption format with short name.
  1236. ((cdr caption)
  1237. (format "\\caption[%s]{%s%s}\n"
  1238. (org-export-secondary-string (cdr caption) 'e-html info)
  1239. label-str
  1240. (org-export-secondary-string (car caption) 'e-html info)))
  1241. ;; Standard caption format.
  1242. ;; (t (format "\\caption{%s%s}\n"
  1243. ;; label-str
  1244. ;; (org-export-secondary-string (car caption) 'e-html info)))
  1245. (t (org-export-secondary-string (car caption) 'e-html info)))))
  1246. (defun org-e-html--find-verb-separator (s)
  1247. "Return a character not used in string S.
  1248. This is used to choose a separator for constructs like \\verb."
  1249. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1250. (loop for c across ll
  1251. when (not (string-match (regexp-quote (char-to-string c)) s))
  1252. return (char-to-string c))))
  1253. (defun org-e-html--make-option-string (options)
  1254. "Return a comma separated string of keywords and values.
  1255. OPTIONS is an alist where the key is the options keyword as
  1256. a string, and the value a list containing the keyword value, or
  1257. nil."
  1258. (mapconcat (lambda (pair)
  1259. (concat (first pair)
  1260. (when (> (length (second pair)) 0)
  1261. (concat "=" (second pair)))))
  1262. options
  1263. ","))
  1264. (defun org-e-html--quotation-marks (text info)
  1265. "Export quotation marks depending on language conventions.
  1266. TEXT is a string containing quotation marks to be replaced. INFO
  1267. is a plist used as a communication channel."
  1268. (mapc (lambda(l)
  1269. (let ((start 0))
  1270. (while (setq start (string-match (car l) text start))
  1271. (let ((new-quote (concat (match-string 1 text) (cdr l))))
  1272. (setq text (replace-match new-quote t t text))))))
  1273. (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
  1274. ;; Falls back on English.
  1275. (assoc "en" org-e-html-quotes))))
  1276. text)
  1277. (defun org-e-html--wrap-label (element output)
  1278. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  1279. This function shouldn't be used for floats. See
  1280. `org-e-html--caption/label-string'."
  1281. ;; (let ((label (org-element-property :name element)))
  1282. ;; (if (or (not output) (not label) (string= output "") (string= label ""))
  1283. ;; output
  1284. ;; (concat (format "\\label{%s}\n" label) output)))
  1285. output)
  1286. ;;; Template
  1287. (defun org-e-html-meta-info (info)
  1288. (let* ((title (org-export-secondary-string
  1289. (plist-get info :title) 'e-html info))
  1290. (author (and (plist-get info :with-author)
  1291. (let ((auth (plist-get info :author)))
  1292. (and auth (org-export-secondary-string
  1293. auth 'e-html info)))))
  1294. (description (plist-get info :description))
  1295. (keywords (plist-get info :keywords)))
  1296. (concat
  1297. (format "<title>%s</title>\n" title)
  1298. (format
  1299. "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
  1300. (and coding-system-for-write
  1301. (fboundp 'coding-system-get)
  1302. (coding-system-get coding-system-for-write
  1303. 'mime-charset)))
  1304. (format "<meta name=\"title\" content=\"%s\"/>\n" title)
  1305. (format "<meta name=\"generator\" content=\"Org-mode\"/>")
  1306. (format "<meta name=\"generated\" content=\"%s\"/>\n"
  1307. (org-e-html-format-date info))
  1308. (format "<meta name=\"author\" content=\"%s\"/>\n" author)
  1309. (format "<meta name=\"description\" content=\"%s\"/>\n" description)
  1310. (format " <meta name=\"keywords\" content=\"%s\"/>\n" keywords))))
  1311. (defun org-e-html-style (info)
  1312. (concat
  1313. (when (plist-get info :style-include-default)
  1314. org-e-html-style-default)
  1315. (plist-get info :style)
  1316. (plist-get info :style-extra)
  1317. "\n"
  1318. (when (plist-get info :style-include-scripts)
  1319. org-e-html-scripts)))
  1320. (defun org-e-html-mathjax-config (template options in-buffer)
  1321. "Insert the user setup into the matchjax template."
  1322. (let (name val (yes " ") (no "// ") x)
  1323. (mapc
  1324. (lambda (e)
  1325. (setq name (car e) val (nth 1 e))
  1326. (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
  1327. (setq val (car (read-from-string
  1328. (substring in-buffer (match-end 0))))))
  1329. (if (not (stringp val)) (setq val (format "%s" val)))
  1330. (if (string-match (concat "%" (upcase (symbol-name name))) template)
  1331. (setq template (replace-match val t t template))))
  1332. options)
  1333. (setq val (nth 1 (assq 'mathml options)))
  1334. (if (string-match (concat "\\<mathml:") in-buffer)
  1335. (setq val (car (read-from-string
  1336. (substring in-buffer (match-end 0))))))
  1337. ;; Exchange prefixes depending on mathml setting
  1338. (if (not val) (setq x yes yes no no x))
  1339. ;; Replace cookies to turn on or off the config/jax lines
  1340. (if (string-match ":MMLYES:" template)
  1341. (setq template (replace-match yes t t template)))
  1342. (if (string-match ":MMLNO:" template)
  1343. (setq template (replace-match no t t template)))
  1344. ;; Return the modified template
  1345. template))
  1346. (defun org-e-html-mathjax (info)
  1347. (when (or (eq (plist-get info :HTML-fragments) 'mathjax)
  1348. (and org-export-have-math
  1349. (eq (plist-get info :HTML-fragments) t)))
  1350. (org-e-html-mathjax-config
  1351. org-e-html-mathjax-template
  1352. org-e-html-mathjax-options
  1353. (or (plist-get info :mathjax) ""))))
  1354. (defun org-e-html-preamble (info)
  1355. (when (plist-get info :html-preamble)
  1356. (let* ((title (plist-get info :title))
  1357. (date (org-e-html-format-date info))
  1358. (author (plist-get info :author))
  1359. (lang-words (or (assoc (plist-get info :language)
  1360. org-export-language-setup)
  1361. (assoc "en" org-export-language-setup)))
  1362. (email (plist-get info :email))
  1363. (html-pre-real-contents
  1364. (cond
  1365. ((functionp (plist-get info :html-preamble))
  1366. (with-temp-buffer
  1367. (funcall (plist-get info :html-preamble))
  1368. (buffer-string)))
  1369. ((stringp (plist-get info :html-preamble))
  1370. (format-spec (plist-get info :html-preamble)
  1371. `((?t . ,title) (?a . ,author)
  1372. (?d . ,date) (?e . ,email))))
  1373. (t
  1374. (format-spec
  1375. (or (cadr (assoc (nth 0 lang-words)
  1376. org-e-html-preamble-format))
  1377. (cadr (assoc "en" org-e-html-preamble-format)))
  1378. `((?t . ,title) (?a . ,author)
  1379. (?d . ,date) (?e . ,email)))))))
  1380. (when (not (equal html-pre-real-contents ""))
  1381. (concat
  1382. (format "
  1383. <div id=\"%s\"> " (nth 0 org-e-html-divs))
  1384. "
  1385. "
  1386. html-pre-real-contents
  1387. "
  1388. </div>")))))
  1389. (defun org-e-html-postamble (info)
  1390. (concat
  1391. (when (and (not body-only)
  1392. (plist-get info :html-postamble))
  1393. (let* ((html-post (plist-get info :html-postamble))
  1394. (date (org-e-html-format-date info))
  1395. (author (plist-get info :author))
  1396. (email (plist-get info :email))
  1397. (lang-words (or (assoc (plist-get info :language)
  1398. org-export-language-setup)
  1399. (assoc "en" org-export-language-setup)))
  1400. (email
  1401. (mapconcat (lambda(e)
  1402. (format "<a href=\"mailto:%s\">%s</a>" e e))
  1403. (split-string email ",+ *")
  1404. ", "))
  1405. (html-validation-link (or org-e-html-validation-link ""))
  1406. (creator-info
  1407. (concat "Org version " org-version " with Emacs version "
  1408. (number-to-string emacs-major-version))))
  1409. (concat
  1410. ;; begin postamble
  1411. "
  1412. <div id=\"" (nth 2 org-e-html-divs) "\">"
  1413. (cond
  1414. ;; auto postamble
  1415. ((eq (plist-get info :html-postamble) 'auto)
  1416. (concat
  1417. (when (plist-get info :time-stamp-file)
  1418. (format "
  1419. <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
  1420. (when (and (plist-get info :with-author) author)
  1421. (format "
  1422. <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
  1423. (when (and (plist-get info :with-email) email)
  1424. (format "
  1425. <p class=\"email\"> %s </p>" email))
  1426. (when (plist-get info :with-creator)
  1427. (format "
  1428. <p class=\"creator\"> %s </p>" creator-info))
  1429. html-validation-link "\n"))
  1430. ;; postamble from a string
  1431. ((stringp (plist-get info :html-postamble))
  1432. (format-spec (plist-get info :html-postamble)
  1433. `((?a . ,author) (?e . ,email)
  1434. (?d . ,date) (?c . ,creator-info)
  1435. (?v . ,html-validation-link))))
  1436. ;; postamble from a function
  1437. ((functionp (plist-get info :html-postamble))
  1438. (with-temp-buffer
  1439. (funcall (plist-get info :html-postamble))
  1440. (buffer-string)))
  1441. ;; default postamble
  1442. (t
  1443. (format-spec
  1444. (or (cadr (assoc (nth 0 lang-words)
  1445. org-e-html-postamble-format))
  1446. (cadr (assoc "en" org-e-html-postamble-format)))
  1447. `((?a . ,author) (?e . ,email)
  1448. (?d . ,date) (?c . ,creator-info)
  1449. (?v . ,html-validation-link)))))
  1450. "
  1451. </div>")))
  1452. ;; org-e-html-html-helper-timestamp
  1453. ))
  1454. (defun org-e-html-template (contents info)
  1455. "Return complete document string after HTML conversion.
  1456. CONTENTS is the transcoded contents string. RAW-DATA is the
  1457. original parsed data. INFO is a plist holding export options."
  1458. (concat
  1459. (format
  1460. (or (and (stringp org-e-html-xml-declaration)
  1461. org-e-html-xml-declaration)
  1462. (cdr (assoc (plist-get info :html-extension)
  1463. org-e-html-xml-declaration))
  1464. (cdr (assoc "html" org-e-html-xml-declaration))
  1465. "")
  1466. (or (and coding-system-for-write
  1467. (fboundp 'coding-system-get)
  1468. (coding-system-get coding-system-for-write
  1469. 'mime-charset))
  1470. "iso-8859-1"))
  1471. "
  1472. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  1473. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
  1474. (format "
  1475. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
  1476. (plist-get info :language) (plist-get info :language))
  1477. "
  1478. <head>"
  1479. (org-e-html-meta-info info) ; meta
  1480. (org-e-html-style info) ; style
  1481. (org-e-html-mathjax info) ; mathjax
  1482. "
  1483. </head>"
  1484. "
  1485. <body>"
  1486. (let ((link-up (and (plist-get info :link-up)
  1487. (string-match "\\S-" (plist-get info :link-up))
  1488. (plist-get info :link-up)))
  1489. (link-home (and (plist-get info :link-home)
  1490. (string-match "\\S-" (plist-get info :link-home))
  1491. (plist-get info :link-home))))
  1492. (when (or link-up link-home)
  1493. (format org-e-html-home/up-format
  1494. (or link-up link-home)
  1495. (or link-home link-up))))
  1496. ;; preamble
  1497. (org-e-html-preamble info)
  1498. ;; begin content
  1499. (format "
  1500. <div id=\"%s\">" (or org-e-html-content-div
  1501. (nth 1 org-e-html-divs)))
  1502. ;; document title
  1503. (format "
  1504. <h1 class=\"title\"> %s </h1>\n" (plist-get info :title))
  1505. ;; table of contents
  1506. (let ((depth (plist-get info :with-toc)))
  1507. (when (wholenump depth) (org-e-html-toc depth info)))
  1508. ;; document contents
  1509. contents
  1510. ;; footnotes section
  1511. (org-e-html-footnote-section info)
  1512. ;; bibliography
  1513. (org-e-html-bibliography)
  1514. ;; end content
  1515. (unless body-only
  1516. "
  1517. </div>")
  1518. ;; postamble
  1519. (org-e-html-postamble info)
  1520. (unless body-only
  1521. "
  1522. </body>")
  1523. "
  1524. </html>"))
  1525. ;;; Transcode Functions
  1526. ;;;; Block
  1527. (defun org-e-html-center-block (center-block contents info)
  1528. "Transcode a CENTER-BLOCK element from Org to HTML.
  1529. CONTENTS holds the contents of the block. INFO is a plist
  1530. holding contextual information."
  1531. (org-e-html--wrap-label
  1532. center-block
  1533. (format "<div style=\"text-align: center\">\n%s</div>" contents)))
  1534. ;;;; Comment
  1535. ;; Comments are ignored.
  1536. ;;;; Comment Block
  1537. ;; Comment Blocks are ignored.
  1538. ;;;; Drawer
  1539. (defun org-e-html-drawer (drawer contents info)
  1540. "Transcode a DRAWER element from Org to HTML.
  1541. CONTENTS holds the contents of the block. INFO is a plist
  1542. holding contextual information."
  1543. (let* ((name (org-element-property :drawer-name drawer))
  1544. (output (if (functionp org-e-html-format-drawer-function)
  1545. (funcall org-e-html-format-drawer-function
  1546. name contents)
  1547. ;; If there's no user defined function: simply
  1548. ;; display contents of the drawer.
  1549. contents)))
  1550. (org-e-html--wrap-label drawer output)))
  1551. ;;;; Dynamic Block
  1552. (defun org-e-html-dynamic-block (dynamic-block contents info)
  1553. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1554. CONTENTS holds the contents of the block. INFO is a plist
  1555. holding contextual information. See
  1556. `org-export-data'."
  1557. (org-e-html--wrap-label dynamic-block contents))
  1558. ;;;; Emphasis
  1559. (defun org-e-html-emphasis (emphasis contents info)
  1560. "Transcode EMPHASIS from Org to HTML.
  1561. CONTENTS is the contents of the emphasized text. INFO is a plist
  1562. holding contextual information.."
  1563. (let* ((marker (org-element-property :marker emphasis)))
  1564. (format (cdr (assoc marker org-e-html-emphasis-alist)) contents)))
  1565. ;;;; Entity
  1566. (defun org-e-html-entity (entity contents info)
  1567. "Transcode an ENTITY object from Org to HTML.
  1568. CONTENTS are the definition itself. INFO is a plist holding
  1569. contextual information."
  1570. ;; (let ((ent (org-element-property :latex entity)))
  1571. ;; (if (org-element-property :latex-math-p entity)
  1572. ;; (format "$%s$" ent)
  1573. ;; ent))
  1574. (org-element-property :html entity))
  1575. ;;;; Example Block
  1576. ;; (defun org-odt-format-source-code-or-example-colored
  1577. ;; (lines lang caption textareap cols rows num cont rpllbl fmt))
  1578. (defun org-e-html-format-source-code-or-example-plain
  1579. (lines lang caption textareap cols rows num cont rpllbl fmt)
  1580. (setq lines
  1581. (concat
  1582. "<pre class=\"example\">\n"
  1583. (cond
  1584. (textareap
  1585. (concat
  1586. (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
  1587. cols rows)
  1588. lines "</textarea>\n</p>\n"))
  1589. (t
  1590. (with-temp-buffer
  1591. (insert lines)
  1592. (goto-char (point-min))
  1593. (while (re-search-forward "[<>&]" nil t)
  1594. (replace-match (cdr (assq (char-before)
  1595. '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
  1596. t t))
  1597. (buffer-string))))
  1598. "</pre>\n"))
  1599. (unless textareap
  1600. (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
  1601. ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
  1602. ;; (setq lines (replace-match "\\1" t nil lines)))
  1603. lines)
  1604. (defun org-e-html-format-source-code-or-example-colored
  1605. (lines lang caption textareap cols rows num cont rpllbl fmt)
  1606. (let* ((lang-m (when lang
  1607. (or (cdr (assoc lang org-src-lang-modes))
  1608. lang)))
  1609. (mode (and lang-m (intern
  1610. (concat
  1611. (if (symbolp lang-m)
  1612. (symbol-name lang-m)
  1613. lang-m)
  1614. "-mode"))))
  1615. (org-inhibit-startup t)
  1616. (org-startup-folded nil))
  1617. (setq lines
  1618. (with-temp-buffer
  1619. (insert lines)
  1620. (if (functionp mode)
  1621. (funcall mode)
  1622. (fundamental-mode))
  1623. (font-lock-fontify-buffer)
  1624. ;; markup each line separately
  1625. (org-remove-formatting-on-newlines-in-region
  1626. (point-min) (point-max))
  1627. (org-src-mode)
  1628. (set-buffer-modified-p nil)
  1629. (org-export-e-htmlize-region-for-paste
  1630. (point-min) (point-max))))
  1631. (when (string-match "<pre\\([^>]*\\)>\n*" lines)
  1632. (setq lines (replace-match
  1633. (format "<pre class=\"src src-%s\">\n" lang) t t lines)))
  1634. (when caption
  1635. (setq lines
  1636. (concat
  1637. "<div class=\"org-src-container\">"
  1638. (format "<label class=\"org-src-name\">%s</label>" caption)
  1639. lines "</div>")))
  1640. (unless textareap
  1641. (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
  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)))
  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. (format (org-export-get-coderef-format path (or desc ""))
  2241. (org-export-resolve-coderef path info)))
  2242. ;; Link type is handled by a special function.
  2243. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2244. (funcall protocol (org-link-unescape path) desc 'html))
  2245. ;; External link with a description part.
  2246. ((and path desc) (format "<a href=\"%s\">%s</a>" path desc))
  2247. ;; External link without a description part.
  2248. (path (format "<a href=\"%s\">%s</a>" path path))
  2249. ;; No path, only description. Try to do something useful.
  2250. (t (format "<i>%s</i>" desc)))))
  2251. ;;;; Babel Call
  2252. ;; Babel Calls are ignored.
  2253. ;;;; Macro
  2254. (defun org-e-html-macro (macro contents info)
  2255. "Transcode a MACRO element from Org to HTML.
  2256. CONTENTS is nil. INFO is a plist holding contextual information."
  2257. ;; Use available tools.
  2258. (org-export-expand-macro macro info))
  2259. ;;;; Paragraph
  2260. (defun org-e-html-paragraph (paragraph contents info)
  2261. "Transcode a PARAGRAPH element from Org to HTML.
  2262. CONTENTS is the contents of the paragraph, as a string. INFO is
  2263. the plist used as a communication channel."
  2264. (let* ((style nil) ; FIXME
  2265. (class (cdr (assoc style '((footnote . "footnote")
  2266. (verse . nil)))))
  2267. (extra (if class (format " class=\"%s\"" class) ""))
  2268. (parent (car (org-export-get-genealogy paragraph info))))
  2269. (cond
  2270. ((and (equal (car parent) 'item)
  2271. (= (org-element-property :begin paragraph)
  2272. (org-element-property :contents-begin parent)))
  2273. ;; leading paragraph in a list item have no tags
  2274. contents)
  2275. (t (format "\n<p%s>\n%s\n</p>" extra contents)))))
  2276. ;;;; Plain List
  2277. (defun org-e-html-begin-plain-list (type &optional arg1)
  2278. (case type
  2279. (ordered
  2280. (format "<ol%s>" (if arg1 ; FIXME
  2281. (format " start=\"%d\"" arg1)
  2282. "")))
  2283. (unordered "<ul>")
  2284. (descriptive "<dl>")))
  2285. (defun org-e-html-end-plain-list (type)
  2286. (case type
  2287. (ordered "</ol>")
  2288. (unordered "</ul>")
  2289. (descriptive "</dl>")))
  2290. (defun org-e-html-plain-list (plain-list contents info)
  2291. "Transcode a PLAIN-LIST element from Org to HTML.
  2292. CONTENTS is the contents of the list. INFO is a plist holding
  2293. contextual information."
  2294. (let* (arg1 ;; FIXME
  2295. (type (org-element-property :type plain-list))
  2296. (attr (mapconcat #'identity
  2297. (org-element-property :attr_html plain-list)
  2298. " ")))
  2299. (org-e-html--wrap-label
  2300. plain-list (format "%s\n%s%s"
  2301. (org-e-html-begin-plain-list type)
  2302. contents (org-e-html-end-plain-list type)))))
  2303. ;;;; Plain Text
  2304. (defun org-e-html-convert-special-strings (string)
  2305. "Convert special characters in STRING to HTML."
  2306. (let ((all org-e-html-special-string-regexps)
  2307. e a re rpl start)
  2308. (while (setq a (pop all))
  2309. (setq re (car a) rpl (cdr a) start 0)
  2310. (while (string-match re string start)
  2311. (setq string (replace-match rpl t nil string))))
  2312. string))
  2313. (defun org-e-html-encode-plain-text (s)
  2314. "Convert plain text characters to HTML equivalent.
  2315. Possible conversions are set in `org-export-html-protect-char-alist'."
  2316. (let ((cl org-e-html-protect-char-alist) c)
  2317. (while (setq c (pop cl))
  2318. (let ((start 0))
  2319. (while (string-match (car c) s start)
  2320. (setq s (replace-match (cdr c) t t s)
  2321. start (1+ (match-beginning 0))))))
  2322. s))
  2323. (defun org-e-html-plain-text (text info)
  2324. "Transcode a TEXT string from Org to HTML.
  2325. TEXT is the string to transcode. INFO is a plist holding
  2326. contextual information."
  2327. (setq text (org-e-html-encode-plain-text text))
  2328. ;; Protect %, #, &, $, ~, ^, _, { and }.
  2329. ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
  2330. ;; (setq text
  2331. ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
  2332. ;; Protect \
  2333. ;; (setq text (replace-regexp-in-string
  2334. ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
  2335. ;; "$\\backslash$" text nil t 1))
  2336. ;; HTML into \HTML{} and TeX into \TeX{}.
  2337. ;; (let ((case-fold-search nil)
  2338. ;; (start 0))
  2339. ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
  2340. ;; (setq text (replace-match
  2341. ;; (format "\\%s{}" (match-string 1 text)) nil t text)
  2342. ;; start (match-end 0))))
  2343. ;; Handle quotation marks
  2344. ;; (setq text (org-e-html--quotation-marks text info))
  2345. ;; Convert special strings.
  2346. ;; (when (plist-get info :with-special-strings)
  2347. ;; (while (string-match (regexp-quote "...") text)
  2348. ;; (setq text (replace-match "\\ldots{}" nil t text))))
  2349. (when (plist-get info :with-special-strings)
  2350. (setq text (org-e-html-convert-special-strings text)))
  2351. ;; Handle break preservation if required.
  2352. (when (plist-get info :preserve-breaks)
  2353. (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
  2354. text)))
  2355. ;; Return value.
  2356. text)
  2357. ;;;; Property Drawer
  2358. (defun org-e-html-property-drawer (property-drawer contents info)
  2359. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2360. CONTENTS is nil. INFO is a plist holding contextual
  2361. information."
  2362. ;; The property drawer isn't exported but we want separating blank
  2363. ;; lines nonetheless.
  2364. "")
  2365. ;;;; Quote Block
  2366. (defun org-e-html-quote-block (quote-block contents info)
  2367. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2368. CONTENTS holds the contents of the block. INFO is a plist
  2369. holding contextual information."
  2370. (org-e-html--wrap-label
  2371. quote-block (format "<blockquote>\n%s</blockquote>" contents)))
  2372. ;;;; Quote Section
  2373. (defun org-e-html-quote-section (quote-section contents info)
  2374. "Transcode a QUOTE-SECTION element from Org to HTML.
  2375. CONTENTS is nil. INFO is a plist holding contextual information."
  2376. (let ((value (org-remove-indentation
  2377. (org-element-property :value quote-section))))
  2378. (when value (format "<pre>\n%s</pre>" value))))
  2379. ;;;; Section
  2380. (defun org-e-html-section (section contents info) ; FIXME
  2381. "Transcode a SECTION element from Org to HTML.
  2382. CONTENTS holds the contents of the section. INFO is a plist
  2383. holding contextual information."
  2384. (let ((parent (org-export-get-parent-headline section info)))
  2385. ;; Before first headline: no container, just return CONTENTS.
  2386. (if (not parent) contents
  2387. ;; Get div's class and id references.
  2388. (let ((class-num (+ (org-export-get-relative-level parent info)
  2389. (1- org-e-html-toplevel-hlevel)))
  2390. (id-num
  2391. (mapconcat
  2392. 'number-to-string
  2393. (org-export-get-headline-number parent info) "-")))
  2394. ;; Build return value.
  2395. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2396. class-num id-num contents)))))
  2397. ;;;; Radio Target
  2398. (defun org-e-html-radio-target (radio-target text info)
  2399. "Transcode a RADIO-TARGET object from Org to HTML.
  2400. TEXT is the text of the target. INFO is a plist holding
  2401. contextual information."
  2402. (let ((id (org-export-solidify-link-text
  2403. (org-element-property :raw-value radio-target))))
  2404. (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text)))
  2405. ;;;; Special Block
  2406. (defun org-e-html-special-block (special-block contents info)
  2407. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2408. CONTENTS holds the contents of the block. INFO is a plist
  2409. holding contextual information."
  2410. (let ((type (downcase (org-element-property :type special-block))))
  2411. (org-e-html--wrap-label
  2412. special-block
  2413. (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
  2414. ;;;; Src Block
  2415. (defun org-e-html-src-block (src-block contents info)
  2416. "Transcode a SRC-BLOCK element from Org to HTML.
  2417. CONTENTS holds the contents of the item. INFO is a plist holding
  2418. contextual information."
  2419. (let* ((lang (org-element-property :language src-block))
  2420. (code (org-export-handle-code src-block info))
  2421. (caption (org-element-property :caption src-block))
  2422. (label (org-element-property :name src-block)))
  2423. ;; FIXME: Handle caption
  2424. ;; caption-str (when caption)
  2425. ;; (main (org-export-secondary-string (car caption) 'e-html info))
  2426. ;; (secondary (org-export-secondary-string (cdr caption) 'e-html info))
  2427. ;; (caption-str (org-e-html--caption/label-string caption label info))
  2428. (org-e-html-format-source-code-or-example lang code)))
  2429. ;;;; Statistics Cookie
  2430. (defun org-e-html-statistics-cookie (statistics-cookie contents info)
  2431. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2432. CONTENTS is nil. INFO is a plist holding contextual information."
  2433. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2434. (format "<code>%s</code>" cookie-value)))
  2435. ;;;; Subscript
  2436. (defun org-e-html-subscript (subscript contents info)
  2437. "Transcode a SUBSCRIPT object from Org to HTML.
  2438. CONTENTS is the contents of the object. INFO is a plist holding
  2439. contextual information."
  2440. (format "<sub>%s</sub>" contents))
  2441. ;;;; Superscript
  2442. (defun org-e-html-superscript (superscript contents info)
  2443. "Transcode a SUPERSCRIPT object from Org to HTML.
  2444. CONTENTS is the contents of the object. INFO is a plist holding
  2445. contextual information."
  2446. (format "<sup>%s</sup>" contents))
  2447. ;;;; Table
  2448. (defun org-e-html-begin-table (caption label attributes)
  2449. (let* ((html-table-tag (or (plist-get info :html-table-tag) ; FIXME
  2450. org-e-html-table-tag))
  2451. (html-table-tag
  2452. (org-e-html-splice-attributes html-table-tag attributes)))
  2453. (when label
  2454. (setq html-table-tag
  2455. (org-e-html-splice-attributes
  2456. html-table-tag
  2457. (format "id=\"%s\"" (org-solidify-link-text label)))))
  2458. (concat "\n" html-table-tag
  2459. (format "\n<caption>%s</caption>" (or caption "")))))
  2460. (defun org-e-html-end-table ()
  2461. "</table>\n")
  2462. (defun org-e-html-format-table-cell (text r c horiz-span)
  2463. (let ((cell-style-cookie
  2464. (if org-e-html-table-align-individual-fields
  2465. (format (if (and (boundp 'org-e-html-format-table-no-css)
  2466. org-e-html-format-table-no-css)
  2467. " align=\"%s\"" " class=\"%s\"")
  2468. (or (aref (plist-get table-info :alignment) c) "left")) ""))) ;; FIXME
  2469. (cond
  2470. (org-e-html-table-cur-rowgrp-is-hdr
  2471. (concat
  2472. (format (car org-e-html-table-header-tags) "col" cell-style-cookie)
  2473. text (cdr org-e-html-table-header-tags)))
  2474. ((and (= c 0) org-e-html-table-use-header-tags-for-first-column)
  2475. (concat
  2476. (format (car org-e-html-table-header-tags) "row" cell-style-cookie)
  2477. text (cdr org-e-html-table-header-tags)))
  2478. (t
  2479. (concat
  2480. (format (car org-e-html-table-data-tags) cell-style-cookie)
  2481. text (cdr org-e-html-table-data-tags))))))
  2482. (defun org-e-html-format-table-row (row)
  2483. (concat (eval (car org-e-html-table-row-tags)) row
  2484. (eval (cdr org-e-html-table-row-tags))))
  2485. (defun org-e-html-table-row (fields &optional text-for-empty-fields)
  2486. (incf org-e-html-table-rownum)
  2487. (let ((i -1))
  2488. (org-e-html-format-table-row
  2489. (mapconcat
  2490. (lambda (x)
  2491. (when (and (string= x "") text-for-empty-fields)
  2492. (setq x text-for-empty-fields))
  2493. (incf i)
  2494. (let (horiz-span)
  2495. (org-e-html-format-table-cell
  2496. x org-e-html-table-rownum i (or horiz-span 0))))
  2497. fields "\n"))))
  2498. (defun org-e-html-end-table-rowgroup ()
  2499. (when org-e-html-table-rowgrp-open
  2500. (setq org-e-html-table-rowgrp-open nil)
  2501. (if org-e-html-table-cur-rowgrp-is-hdr "</thead>" "</tbody>")))
  2502. (defun org-e-html-begin-table-rowgroup (&optional is-header-row)
  2503. (concat
  2504. (when org-e-html-table-rowgrp-open
  2505. (org-e-html-end-table-rowgroup))
  2506. (progn
  2507. (setq org-e-html-table-rowgrp-open t)
  2508. (setq org-e-html-table-cur-rowgrp-is-hdr is-header-row)
  2509. (if is-header-row "<thead>" "<tbody>"))))
  2510. (defun org-e-html-table-preamble ()
  2511. (let ((colgroup-vector (plist-get table-info :column-groups)) ;; FIXME
  2512. c gr colgropen preamble)
  2513. (unless (aref colgroup-vector 0)
  2514. (setf (aref colgroup-vector 0) 'start))
  2515. (dotimes (c columns-number preamble)
  2516. (setq gr (aref colgroup-vector c))
  2517. (setq preamble
  2518. (concat
  2519. preamble
  2520. (when (memq gr '(start start-end))
  2521. (prog1 (if colgropen "</colgroup>\n<colgroup>" "\n<colgroup>")
  2522. (setq colgropen t)))
  2523. (let* ((colalign-vector (plist-get table-info :alignment)) ;; FIXME
  2524. (align (cdr (assoc (aref colalign-vector c)
  2525. '(("l" . "left")
  2526. ("r" . "right")
  2527. ("c" . "center")))))
  2528. (alignspec (if (and (boundp 'org-e-html-format-table-no-css)
  2529. org-e-html-format-table-no-css)
  2530. " align=\"%s\"" " class=\"%s\""))
  2531. (extra (format alignspec align)))
  2532. (format "<col%s />" extra))
  2533. (when (memq gr '(end start-end))
  2534. (setq colgropen nil)
  2535. "</colgroup>"))))
  2536. (concat preamble (if colgropen "</colgroup>"))))
  2537. (defun org-e-html-list-table (lines caption label attributes)
  2538. (setq lines (org-e-html-org-table-to-list-table lines))
  2539. (let* ((splice nil) head
  2540. (org-e-html-table-rownum -1)
  2541. i (cnt 0)
  2542. fields line
  2543. org-e-html-table-cur-rowgrp-is-hdr
  2544. org-e-html-table-rowgrp-open
  2545. n
  2546. (org-lparse-table-style 'org-table)
  2547. org-lparse-table-is-styled)
  2548. (cond
  2549. (splice
  2550. (setq org-lparse-table-is-styled nil)
  2551. (mapconcat 'org-e-html-table-row lines "\n"))
  2552. (t
  2553. (setq org-lparse-table-is-styled t)
  2554. (concat
  2555. (org-e-html-begin-table caption label attributes)
  2556. (org-e-html-table-preamble)
  2557. (org-e-html-begin-table-rowgroup head)
  2558. (mapconcat
  2559. (lambda (line)
  2560. (cond
  2561. ((equal line 'hline) (org-e-html-begin-table-rowgroup))
  2562. (t (org-e-html-table-row line))))
  2563. lines "\n")
  2564. (org-e-html-end-table-rowgroup)
  2565. (org-e-html-end-table))))))
  2566. (defun org-e-html-transcode-table-row (row)
  2567. (if (string-match org-table-hline-regexp row) 'hline
  2568. (mapcar
  2569. (lambda (cell)
  2570. (org-export-secondary-string
  2571. (let ((cell (org-element-parse-secondary-string
  2572. cell
  2573. (cdr (assq 'table org-element-string-restrictions)))))
  2574. cell)
  2575. 'e-html info))
  2576. (org-split-string row "[ \t]*|[ \t]*"))))
  2577. (defun org-e-html-org-table-to-list-table (lines &optional splice)
  2578. "Convert org-table to list-table.
  2579. LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
  2580. element is a `string' representing a single row of org-table.
  2581. Thus each ROW has vertical separators \"|\" separating the table
  2582. fields. A ROW could also be a row-group separator of the form
  2583. \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
  2584. ...). ROW could either be symbol `'hline' or a list of the
  2585. form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
  2586. (let (line lines-1)
  2587. (cond
  2588. (splice
  2589. (while (setq line (pop lines))
  2590. (unless (string-match "^[ \t]*|-" line)
  2591. (push (org-e-html-transcode-table-row line) lines-1))))
  2592. (t (while (setq line (pop lines))
  2593. (cond
  2594. ((string-match "^[ \t]*|-" line)
  2595. (when lines (push 'hline lines-1)))
  2596. (t (push (org-e-html-transcode-table-row line) lines-1))))))
  2597. (nreverse lines-1)))
  2598. (defun org-e-html-table-table (raw-table)
  2599. (require 'table)
  2600. (with-current-buffer (get-buffer-create "*org-export-table*")
  2601. (erase-buffer))
  2602. (let ((output (with-temp-buffer
  2603. (insert raw-table)
  2604. (goto-char 1)
  2605. (re-search-forward "^[ \t]*|[^|]" nil t)
  2606. (table-generate-source 'html "*org-export-table*")
  2607. (with-current-buffer "*org-export-table*"
  2608. (org-trim (buffer-string))))))
  2609. (kill-buffer (get-buffer "*org-export-table*"))
  2610. output))
  2611. (defun org-e-html-table (table contents info)
  2612. "Transcode a TABLE element from Org to HTML.
  2613. CONTENTS is nil. INFO is a plist holding contextual information."
  2614. (let* ((label (org-element-property :name table))
  2615. (caption (org-e-html--caption/label-string
  2616. (org-element-property :caption table) label info))
  2617. (attr (mapconcat #'identity
  2618. (org-element-property :attr_html table)
  2619. " "))
  2620. (raw-table (org-element-property :raw-table table))
  2621. (table-type (org-element-property :type table)))
  2622. (case table-type
  2623. (table.el
  2624. (org-e-html-table-table raw-table))
  2625. (t
  2626. (let* ((table-info (org-export-table-format-info raw-table))
  2627. (columns-number (length (plist-get table-info :alignment)))
  2628. (lines (org-split-string
  2629. (org-export-clean-table
  2630. raw-table (plist-get table-info :special-column-p)) "\n")))
  2631. (org-e-html-list-table lines caption label attr))))))
  2632. ;;;; Target
  2633. (defun org-e-html-target (target text info)
  2634. "Transcode a TARGET object from Org to HTML.
  2635. TEXT is the text of the target. INFO is a plist holding
  2636. contextual information."
  2637. (let ((id (org-export-solidify-link-text
  2638. (org-element-property :raw-value target))))
  2639. (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text)))
  2640. ;;;; Time-stamp
  2641. (defun org-e-html-time-stamp (time-stamp contents info)
  2642. "Transcode a TIME-STAMP object from Org to HTML.
  2643. CONTENTS is nil. INFO is a plist holding contextual
  2644. information."
  2645. (let ((value (org-element-property :value time-stamp))
  2646. (type (org-element-property :type time-stamp))
  2647. (appt-type (org-element-property :appt-type time-stamp)))
  2648. (setq value (org-translate-time
  2649. (org-export-secondary-string value 'e-html info)))
  2650. (setq appt-type (case appt-type
  2651. (scheduled org-scheduled-string)
  2652. (deadline org-deadline-string)
  2653. (closed org-closed-string)))
  2654. (format "<span class=\"timestamp-wrapper\">%s%s</span>"
  2655. (if (not appt-type) ""
  2656. (format "<span class=\"timestamp-kwd\">%s</span> " appt-type))
  2657. (format "<span class=\"timestamp\">%s</span>" value))))
  2658. ;;;; Verbatim
  2659. (defun org-e-html-verbatim (verbatim contents info)
  2660. "Transcode a VERBATIM object from Org to HTML.
  2661. CONTENTS is nil. INFO is a plist used as a communication
  2662. channel."
  2663. (org-e-html-emphasis
  2664. verbatim (org-element-property :value verbatim) info))
  2665. ;;;; Verse Block
  2666. (defun org-e-html-verse-block (verse-block contents info)
  2667. "Transcode a VERSE-BLOCK element from Org to HTML.
  2668. CONTENTS is nil. INFO is a plist holding contextual information."
  2669. ;; Replace each newline character with line break. Also replace
  2670. ;; each blank line with a line break.
  2671. (setq contents (replace-regexp-in-string
  2672. "^ *\\\\\\\\$" "<br/>\n"
  2673. (replace-regexp-in-string
  2674. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
  2675. (org-remove-indentation
  2676. (org-export-secondary-string
  2677. (org-element-property :value verse-block)
  2678. 'e-html info)))))
  2679. ;; Replace each white space at beginning of a line with a
  2680. ;; non-breaking space.
  2681. (while (string-match "^[ \t]+" contents)
  2682. (let* ((num-ws (length (match-string 0 contents)))
  2683. (ws (let (out) (dotimes (i num-ws out)
  2684. (setq out (concat out "&nbsp;"))))))
  2685. (setq contents (replace-match ws nil t contents))))
  2686. (org-e-html--wrap-label
  2687. verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
  2688. ;;; Filter Functions
  2689. ;;;; Filter Settings
  2690. (defconst org-e-html-filters-alist
  2691. '((:filter-final-output . org-e-html-final-function))
  2692. "Alist between filters keywords and back-end specific filters.
  2693. See `org-export-filters-alist' for more information.")
  2694. ;;;; Filters
  2695. (defun org-e-html-final-function (contents backend info)
  2696. (if (not org-e-html-pretty-output) contents
  2697. (with-temp-buffer
  2698. (nxml-mode)
  2699. (insert contents)
  2700. (indent-region (point-min) (point-max))
  2701. (buffer-substring-no-properties (point-min) (point-max)))))
  2702. ;;; Interactive functions
  2703. (defun org-e-html-export-to-html
  2704. (&optional subtreep visible-only body-only ext-plist pub-dir)
  2705. "Export current buffer to a HTML file.
  2706. If narrowing is active in the current buffer, only export its
  2707. narrowed part.
  2708. If a region is active, export that region.
  2709. When optional argument SUBTREEP is non-nil, export the sub-tree
  2710. at point, extracting information from the headline properties
  2711. first.
  2712. When optional argument VISIBLE-ONLY is non-nil, don't export
  2713. contents of hidden elements.
  2714. When optional argument BODY-ONLY is non-nil, only write code
  2715. between \"\\begin{document}\" and \"\\end{document}\".
  2716. EXT-PLIST, when provided, is a property list with external
  2717. parameters overriding Org default settings, but still inferior to
  2718. file-local settings.
  2719. When optional argument PUB-DIR is set, use it as the publishing
  2720. directory.
  2721. Return output file's name."
  2722. (interactive)
  2723. ;; FIXME
  2724. (with-current-buffer (get-buffer-create "*debug*")
  2725. (erase-buffer))
  2726. (let ((outfile (org-export-output-file-name ".html" subtreep pub-dir)))
  2727. (org-export-to-file
  2728. 'e-html outfile subtreep visible-only body-only ext-plist)))
  2729. ;;; FIXMES, TODOS, FOR REVIEW etc
  2730. ;;;; org-format-table-html
  2731. ;;;; org-format-org-table-html
  2732. ;;;; org-format-table-table-html
  2733. ;;;; org-table-number-fraction
  2734. ;;;; org-table-number-regexp
  2735. ;;;; org-e-html-table-caption-above
  2736. ;;;; org-whitespace
  2737. ;;;; "<span style=\"visibility:hidden;\">%s</span>"
  2738. ;;;; Remove display properties
  2739. ;;;; org-e-html-final-hook
  2740. ;;;; org-e-html-with-timestamp
  2741. ;;;; org-e-html-html-helper-timestamp
  2742. ;;;; org-export-as-html-and-open
  2743. ;;;; org-export-as-html-batch
  2744. ;;;; org-export-as-html-to-buffer
  2745. ;;;; org-replace-region-by-html
  2746. ;;;; org-export-region-as-html
  2747. ;;;; org-export-as-html
  2748. ;;;; (org-export-directory :html opt-plist)
  2749. ;;;; (plist-get opt-plist :html-extension)
  2750. ;;;; org-e-html-toplevel-hlevel
  2751. ;;;; org-e-html-special-string-regexps
  2752. ;;;; org-e-html-coding-system
  2753. ;;;; org-e-html-coding-system
  2754. ;;;; org-e-html-inline-images
  2755. ;;;; org-e-html-inline-image-extensions
  2756. ;;;; org-e-html-protect-char-alist
  2757. ;;;; org-e-html-table-use-header-tags-for-first-column
  2758. ;;;; org-e-html-todo-kwd-class-prefix
  2759. ;;;; org-e-html-tag-class-prefix
  2760. ;;;; org-e-html-footnote-separator
  2761. ;;;; org-export-preferred-target-alist
  2762. ;;;; org-solidify-link-text
  2763. ;;;; class for anchors
  2764. ;;;; org-export-with-section-numbers, body-only
  2765. (provide 'org-e-html)
  2766. ;;; org-e-html.el ends here