org-e-html.el 110 KB

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