org-e-html.el 107 KB

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