org-e-html.el 108 KB

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