org-e-html.el 107 KB

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