org-e-html.el 110 KB

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