org-e-html.el 108 KB

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