org-e-html.el 109 KB

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