org-e-html.el 107 KB

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