org-e-html.el 107 KB

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