org-e-html.el 108 KB

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