org-e-html.el 109 KB

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