org-e-html.el 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212
  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 (org-export-data (plist-get info :date) info)))
  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. "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
  1691. cols rows code)))
  1692. (t (format "<pre class=\"example\">\n%s</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 "<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/>")))
  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. "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</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. (let ((checkbox (concat (org-e-html-checkbox checkbox) (and checkbox " "))))
  1912. (concat
  1913. (case type
  1914. (ordered
  1915. (let* ((counter term-counter-id)
  1916. (extra (if counter (format " value=\"%s\"" counter) "")))
  1917. (format "<li%s>" extra)))
  1918. (unordered
  1919. (let* ((id term-counter-id)
  1920. (extra (if id (format " id=\"%s\"" id) "")))
  1921. (concat
  1922. (format "<li%s>" extra)
  1923. (when headline (concat headline "<br/>")))))
  1924. (descriptive
  1925. (let* ((term term-counter-id))
  1926. (setq term (or term "(no term)"))
  1927. ;; Check-boxes in descriptive lists are associated to tag.
  1928. (concat (format "<dt> %s </dt>"
  1929. (concat checkbox term))
  1930. "<dd>"))))
  1931. (unless (eq type 'descriptive) checkbox)
  1932. contents
  1933. (case type
  1934. (ordered "</li>")
  1935. (unordered "</li>")
  1936. (descriptive "</dd>")))))
  1937. (defun org-e-html-item (item contents info)
  1938. "Transcode an ITEM element from Org to HTML.
  1939. CONTENTS holds the contents of the item. INFO is a plist holding
  1940. contextual information."
  1941. (let* ((plain-list (org-export-get-parent item))
  1942. (type (org-element-property :type plain-list))
  1943. (counter (org-element-property :counter item))
  1944. (checkbox (org-element-property :checkbox item))
  1945. (tag (let ((tag (org-element-property :tag item)))
  1946. (and tag (org-export-data tag info)))))
  1947. (org-e-html-format-list-item
  1948. contents type checkbox (or tag counter))))
  1949. ;;;; Keyword
  1950. (defun org-e-html-keyword (keyword contents info)
  1951. "Transcode a KEYWORD element from Org to HTML.
  1952. CONTENTS is nil. INFO is a plist holding contextual information."
  1953. (let ((key (org-element-property :key keyword))
  1954. (value (org-element-property :value keyword)))
  1955. (cond
  1956. ((string= key "LATEX") value)
  1957. ((string= key "INDEX") (format "\\index{%s}" value))
  1958. ;; Invisible targets.
  1959. ((string= key "TARGET") nil) ; FIXME
  1960. ((string= key "TOC")
  1961. (let ((value (downcase value)))
  1962. (cond
  1963. ((string-match "\\<headlines\\>" value)
  1964. (let ((depth (or (and (string-match "[0-9]+" value)
  1965. (string-to-number (match-string 0 value)))
  1966. (plist-get info :with-toc))))
  1967. (when (wholenump depth) (org-e-html-toc depth info))))
  1968. ((string= "tables" value) "\\listoftables")
  1969. ((string= "figures" value) "\\listoffigures")
  1970. ((string= "listings" value)
  1971. (cond
  1972. ;; At the moment, src blocks with a caption are wrapped
  1973. ;; into a figure environment.
  1974. (t "\\listoffigures")))))))))
  1975. ;;;; Latex Environment
  1976. (defun org-e-html-format-latex (latex-frag processing-type)
  1977. (let* ((cache-relpath
  1978. (concat "ltxpng/" (file-name-sans-extension
  1979. (file-name-nondirectory (buffer-file-name)))))
  1980. (cache-dir (file-name-directory (buffer-file-name )))
  1981. (display-msg "Creating LaTeX Image..."))
  1982. (with-temp-buffer
  1983. (insert latex-frag)
  1984. (org-format-latex cache-relpath cache-dir nil display-msg
  1985. nil nil processing-type)
  1986. (buffer-string))))
  1987. (defun org-e-html-latex-environment (latex-environment contents info)
  1988. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  1989. CONTENTS is nil. INFO is a plist holding contextual information."
  1990. (org-e-html--wrap-label
  1991. latex-environment
  1992. (let ((processing-type (plist-get info :LaTeX-fragments))
  1993. (latex-frag (org-remove-indentation
  1994. (org-element-property :value latex-environment)))
  1995. (caption (org-e-html--caption/label-string
  1996. (org-element-property :caption latex-environment)
  1997. (org-element-property :name latex-environment)
  1998. info))
  1999. (attr nil) ; FIXME
  2000. (label (org-element-property :name latex-environment)))
  2001. (cond
  2002. ((member processing-type '(t mathjax))
  2003. (org-e-html-format-latex latex-frag 'mathjax))
  2004. ((equal processing-type 'dvipng)
  2005. (let* ((formula-link (org-e-html-format-latex
  2006. latex-frag processing-type)))
  2007. (when (and formula-link
  2008. (string-match "file:\\([^]]*\\)" formula-link))
  2009. (org-e-html-format-inline-image
  2010. (match-string 1 formula-link) caption label attr t))))
  2011. (t latex-frag)))))
  2012. ;;;; Latex Fragment
  2013. (defun org-e-html-latex-fragment (latex-fragment contents info)
  2014. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2015. CONTENTS is nil. INFO is a plist holding contextual information."
  2016. (let ((latex-frag (org-element-property :value latex-fragment))
  2017. (processing-type (plist-get info :LaTeX-fragments)))
  2018. (case processing-type
  2019. ((t mathjax)
  2020. (org-e-html-format-latex latex-frag 'mathjax))
  2021. (dvipng
  2022. (let* ((formula-link (org-e-html-format-latex
  2023. latex-frag processing-type)))
  2024. (when (and formula-link
  2025. (string-match "file:\\([^]]*\\)" formula-link))
  2026. (org-e-html-format-inline-image
  2027. (match-string 1 formula-link)))))
  2028. (t latex-frag))))
  2029. ;;;; Line Break
  2030. (defun org-e-html-line-break (line-break contents info)
  2031. "Transcode a LINE-BREAK object from Org to HTML.
  2032. CONTENTS is nil. INFO is a plist holding contextual information."
  2033. "<br/>")
  2034. ;;;; Link
  2035. (defun org-e-html-link--inline-image (link desc info)
  2036. "Return HTML code for an inline image.
  2037. LINK is the link pointing to the inline image. INFO is a plist
  2038. used as a communication channel."
  2039. (let* ((type (org-element-property :type link))
  2040. (raw-path (org-element-property :path link))
  2041. (path (cond ((member type '("http" "https"))
  2042. (concat type ":" raw-path))
  2043. ((file-name-absolute-p raw-path)
  2044. (expand-file-name raw-path))
  2045. (t raw-path)))
  2046. (parent (org-export-get-parent-element link))
  2047. (caption (org-e-html--caption/label-string
  2048. (org-element-property :caption parent)
  2049. (org-element-property :name parent)
  2050. info))
  2051. (label (org-element-property :name parent))
  2052. ;; Retrieve latex attributes from the element around.
  2053. (attr (let ((raw-attr
  2054. (mapconcat #'identity
  2055. (org-element-property :attr_html parent)
  2056. " ")))
  2057. (unless (string= raw-attr "") raw-attr))))
  2058. ;; Now clear ATTR from any special keyword and set a default
  2059. ;; value if nothing is left.
  2060. (setq attr (if (not attr) "" (org-trim attr)))
  2061. ;; Return proper string, depending on DISPOSITION.
  2062. (org-e-html-format-inline-image
  2063. path caption label attr (org-e-html-standalone-image-p link info))))
  2064. (defvar org-e-html-standalone-image-predicate)
  2065. (defun org-e-html-standalone-image-p (element info &optional predicate)
  2066. "Test if ELEMENT is a standalone image for the purpose HTML export.
  2067. INFO is a plist holding contextual information.
  2068. Return non-nil, if ELEMENT is of type paragraph and it's sole
  2069. content, save for whitespaces, is a link that qualifies as an
  2070. inline image.
  2071. Return non-nil, if ELEMENT is of type link and it's containing
  2072. paragraph has no other content save for leading and trailing
  2073. whitespaces.
  2074. Return nil, otherwise.
  2075. Bind `org-e-html-standalone-image-predicate' to constrain
  2076. paragraph further. For example, to check for only captioned
  2077. standalone images, do the following.
  2078. \(setq org-e-html-standalone-image-predicate
  2079. \(lambda \(paragraph\)
  2080. \(org-element-property :caption paragraph\)\)\)
  2081. "
  2082. (let ((paragraph (case (org-element-type element)
  2083. (paragraph element)
  2084. (link (and (org-export-inline-image-p
  2085. element org-e-html-inline-image-rules)
  2086. (org-export-get-parent element)))
  2087. (t nil))))
  2088. (when paragraph
  2089. (assert (eq (org-element-type paragraph) 'paragraph))
  2090. (when (or (not (and (boundp 'org-e-html-standalone-image-predicate)
  2091. (functionp org-e-html-standalone-image-predicate)))
  2092. (funcall org-e-html-standalone-image-predicate paragraph))
  2093. (let ((contents (org-element-contents paragraph)))
  2094. (loop for x in contents
  2095. with inline-image-count = 0
  2096. always (cond
  2097. ((eq (org-element-type x) 'plain-text)
  2098. (not (org-string-nw-p x)))
  2099. ((eq (org-element-type x) 'link)
  2100. (when (org-export-inline-image-p
  2101. x org-e-html-inline-image-rules)
  2102. (= (incf inline-image-count) 1)))
  2103. (t nil))))))))
  2104. (defun org-e-html-link (link desc info)
  2105. "Transcode a LINK object from Org to HTML.
  2106. DESC is the description part of the link, or the empty string.
  2107. INFO is a plist holding contextual information. See
  2108. `org-export-data'."
  2109. (let* ((type (org-element-property :type link))
  2110. (raw-path (org-element-property :path link))
  2111. ;; Ensure DESC really exists, or set it to nil.
  2112. (desc (and (not (string= desc "")) desc))
  2113. (path (cond
  2114. ((member type '("http" "https" "ftp" "mailto"))
  2115. (concat type ":" raw-path))
  2116. ((string= type "file")
  2117. ;; Extract just the file path and strip all other
  2118. ;; components.
  2119. (when (string-match "\\(.+\\)::.+" raw-path)
  2120. (setq raw-path (match-string 1 raw-path)))
  2121. ;; If the link points to "*.org" file, rewrite it as
  2122. ;; though it were a link to the corresponding
  2123. ;; "*.html" file, if needed.
  2124. (when (and org-e-html-link-org-files-as-html
  2125. (string= ".org" (downcase (file-name-extension
  2126. raw-path "."))))
  2127. (setq raw-path (concat
  2128. (file-name-sans-extension raw-path) "."
  2129. (plist-get info :html-extension))))
  2130. ;; If file path is absolute, prepend it with protocol
  2131. ;; component - "file://".
  2132. (if (not (file-name-absolute-p raw-path)) raw-path
  2133. (concat "file://" (expand-file-name raw-path))))
  2134. (t raw-path)))
  2135. ;; Extract attributes from parent's paragraph.
  2136. (attributes
  2137. (let ((attr (mapconcat
  2138. 'identity
  2139. (org-element-property
  2140. :attr_html (org-export-get-parent-element link))
  2141. " ")))
  2142. (if attr (concat " " attr) "")))
  2143. protocol)
  2144. (cond
  2145. ;; Image file.
  2146. ((and (or (eq t org-e-html-inline-images)
  2147. (and org-e-html-inline-images (not desc)))
  2148. (org-export-inline-image-p link org-e-html-inline-image-rules))
  2149. (org-e-html-link--inline-image link desc info))
  2150. ;; Radio target: Transcode target's contents and use them as
  2151. ;; link's description.
  2152. ((string= type "radio")
  2153. (let ((destination (org-export-resolve-radio-link link info)))
  2154. (when destination
  2155. (format "<a href=\"#%s\"%s>%s</a>"
  2156. (org-export-solidify-link-text path)
  2157. attributes
  2158. (org-export-data (org-element-contents destination) info)))))
  2159. ;; Links pointing to an headline: Find destination and build
  2160. ;; appropriate referencing command.
  2161. ((member type '("custom-id" "fuzzy" "id"))
  2162. (let ((destination (if (string= type "fuzzy")
  2163. (org-export-resolve-fuzzy-link link info)
  2164. (org-export-resolve-id-link link info))))
  2165. (case (org-element-type destination)
  2166. ;; Fuzzy link points nowhere.
  2167. ((nil)
  2168. (format "<i>%s</i>"
  2169. (or desc
  2170. (org-export-data
  2171. (org-element-property :raw-link link) info))))
  2172. ;; Fuzzy link points to an invisible target.
  2173. (keyword nil)
  2174. ;; Link points to an headline.
  2175. (headline
  2176. (let ((href
  2177. ;; What href to use?
  2178. (cond
  2179. ;; Case 1: Headline is linked via it's CUSTOM_ID
  2180. ;; property. Use CUSTOM_ID.
  2181. ((string= type "custom-id")
  2182. (org-element-property :custom-id destination))
  2183. ;; Case 2: Headline is linked via it's ID property
  2184. ;; or through other means. Use the default href.
  2185. ((member type '("id" "fuzzy"))
  2186. (format "sec-%s"
  2187. (mapconcat 'number-to-string
  2188. (org-export-get-headline-number
  2189. destination info) "-")))
  2190. (t (error "Shouldn't reach here"))))
  2191. (desc
  2192. ;; What description to use?
  2193. (cond
  2194. ;; Case 1: Link already has a description. Use it.
  2195. (desc desc)
  2196. ;; Case 2: Link has no description and headline is
  2197. ;; numbered. Use the section number.
  2198. ((org-export-numbered-headline-p destination info)
  2199. (mapconcat 'number-to-string
  2200. (org-export-get-headline-number
  2201. destination info) "."))
  2202. ;; Case 3: Link has no description and headline is
  2203. ;; un-numbered. Use the headline title.
  2204. (t (org-export-data
  2205. (org-element-property :title destination) info)))))
  2206. (format "<a href=\"#%s\"%s>%s</a>"
  2207. (org-solidify-link-text href) attributes desc)))
  2208. ;; Fuzzy link points to a target. Do as above.
  2209. (t
  2210. (let ((path (org-export-solidify-link-text path)) number)
  2211. (unless desc
  2212. (setq number (cond
  2213. ((org-e-html-standalone-image-p destination info)
  2214. (org-export-get-ordinal
  2215. (assoc 'link (org-element-contents destination))
  2216. info 'link 'org-e-html-standalone-image-p))
  2217. (t (org-export-get-ordinal destination info))))
  2218. (setq desc (when number
  2219. (if (atom number) (number-to-string number)
  2220. (mapconcat 'number-to-string number ".")))))
  2221. (format "<a href=\"#%s\"%s>%s</a>"
  2222. path attributes (or desc "FIXME")))))))
  2223. ;; Coderef: replace link with the reference name or the
  2224. ;; equivalent line number.
  2225. ((string= type "coderef")
  2226. (let ((fragment (concat "coderef-" path)))
  2227. (format "<a href=\"#%s\" %s%s>%s</a>"
  2228. fragment
  2229. (format (concat "class=\"coderef\""
  2230. " onmouseover=\"CodeHighlightOn(this, '%s');\""
  2231. " onmouseout=\"CodeHighlightOff(this, '%s');\"")
  2232. fragment fragment)
  2233. attributes
  2234. (format (org-export-get-coderef-format path desc)
  2235. (org-export-resolve-coderef path info)))))
  2236. ;; Link type is handled by a special function.
  2237. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2238. (funcall protocol (org-link-unescape path) desc 'html))
  2239. ;; External link with a description part.
  2240. ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
  2241. ;; External link without a description part.
  2242. (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
  2243. ;; No path, only description. Try to do something useful.
  2244. (t (format "<i>%s</i>" desc)))))
  2245. ;;;; Babel Call
  2246. ;; Babel Calls are ignored.
  2247. ;;;; Macro
  2248. (defun org-e-html-macro (macro contents info)
  2249. "Transcode a MACRO element from Org to HTML.
  2250. CONTENTS is nil. INFO is a plist holding contextual information."
  2251. ;; Use available tools.
  2252. (org-export-expand-macro macro info))
  2253. ;;;; Paragraph
  2254. (defun org-e-html-paragraph (paragraph contents info)
  2255. "Transcode a PARAGRAPH element from Org to HTML.
  2256. CONTENTS is the contents of the paragraph, as a string. INFO is
  2257. the plist used as a communication channel."
  2258. (let* ((style nil) ; FIXME
  2259. (class (cdr (assoc style '((footnote . "footnote")
  2260. (verse . nil)))))
  2261. (extra (if class (format " class=\"%s\"" class) ""))
  2262. (parent (org-export-get-parent paragraph)))
  2263. (cond
  2264. ((and (equal (org-element-type parent) 'item)
  2265. (= (org-element-property :begin paragraph)
  2266. (org-element-property :contents-begin parent)))
  2267. ;; leading paragraph in a list item have no tags
  2268. contents)
  2269. ((org-e-html-standalone-image-p paragraph info)
  2270. ;; standalone image
  2271. contents)
  2272. (t (format "<p%s>\n%s</p>" extra contents)))))
  2273. ;;;; Plain List
  2274. (defun org-e-html-begin-plain-list (type &optional arg1)
  2275. (case type
  2276. (ordered
  2277. (format "<ol%s>" (if arg1 ; FIXME
  2278. (format " start=\"%d\"" arg1)
  2279. "")))
  2280. (unordered "<ul>")
  2281. (descriptive "<dl>")))
  2282. (defun org-e-html-end-plain-list (type)
  2283. (case type
  2284. (ordered "</ol>")
  2285. (unordered "</ul>")
  2286. (descriptive "</dl>")))
  2287. (defun org-e-html-plain-list (plain-list contents info)
  2288. "Transcode a PLAIN-LIST element from Org to HTML.
  2289. CONTENTS is the contents of the list. INFO is a plist holding
  2290. contextual information."
  2291. (let* (arg1 ;; FIXME
  2292. (type (org-element-property :type plain-list))
  2293. (attr (mapconcat #'identity
  2294. (org-element-property :attr_html plain-list)
  2295. " ")))
  2296. (org-e-html--wrap-label
  2297. plain-list (format "%s\n%s%s"
  2298. (org-e-html-begin-plain-list type)
  2299. contents (org-e-html-end-plain-list type)))))
  2300. ;;;; Plain Text
  2301. (defun org-e-html-convert-special-strings (string)
  2302. "Convert special characters in STRING to HTML."
  2303. (let ((all org-e-html-special-string-regexps)
  2304. e a re rpl start)
  2305. (while (setq a (pop all))
  2306. (setq re (car a) rpl (cdr a) start 0)
  2307. (while (string-match re string start)
  2308. (setq string (replace-match rpl t nil string))))
  2309. string))
  2310. (defun org-e-html-encode-plain-text (s)
  2311. "Convert plain text characters to HTML equivalent.
  2312. Possible conversions are set in `org-export-html-protect-char-alist'."
  2313. (let ((cl org-e-html-protect-char-alist) c)
  2314. (while (setq c (pop cl))
  2315. (let ((start 0))
  2316. (while (string-match (car c) s start)
  2317. (setq s (replace-match (cdr c) t t s)
  2318. start (1+ (match-beginning 0))))))
  2319. s))
  2320. (defun org-e-html-plain-text (text info)
  2321. "Transcode a TEXT string from Org to HTML.
  2322. TEXT is the string to transcode. INFO is a plist holding
  2323. contextual information."
  2324. (setq text (org-e-html-encode-plain-text text))
  2325. ;; Protect %, #, &, $, ~, ^, _, { and }.
  2326. ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
  2327. ;; (setq text
  2328. ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
  2329. ;; Protect \
  2330. ;; (setq text (replace-regexp-in-string
  2331. ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
  2332. ;; "$\\backslash$" text nil t 1))
  2333. ;; HTML into \HTML{} and TeX into \TeX{}.
  2334. ;; (let ((case-fold-search nil)
  2335. ;; (start 0))
  2336. ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
  2337. ;; (setq text (replace-match
  2338. ;; (format "\\%s{}" (match-string 1 text)) nil t text)
  2339. ;; start (match-end 0))))
  2340. ;; Handle quotation marks
  2341. ;; (setq text (org-e-html--quotation-marks text info))
  2342. ;; Convert special strings.
  2343. ;; (when (plist-get info :with-special-strings)
  2344. ;; (while (string-match (regexp-quote "...") text)
  2345. ;; (setq text (replace-match "\\ldots{}" nil t text))))
  2346. (when (plist-get info :with-special-strings)
  2347. (setq text (org-e-html-convert-special-strings text)))
  2348. ;; Handle break preservation if required.
  2349. (when (plist-get info :preserve-breaks)
  2350. (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
  2351. text)))
  2352. ;; Return value.
  2353. text)
  2354. ;; Planning
  2355. (defun org-e-html-planning (planning contents info)
  2356. "Transcode a PLANNING element from Org to HTML.
  2357. CONTENTS is nil. INFO is a plist used as a communication
  2358. channel."
  2359. (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
  2360. (format
  2361. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  2362. (mapconcat
  2363. 'identity
  2364. (delq nil
  2365. (list
  2366. (let ((closed (org-element-property :closed planning)))
  2367. (when closed
  2368. (format span-fmt org-closed-string
  2369. (org-translate-time closed))))
  2370. (let ((deadline (org-element-property :deadline planning)))
  2371. (when deadline
  2372. (format span-fmt org-deadline-string
  2373. (org-translate-time deadline))))
  2374. (let ((scheduled (org-element-property :scheduled planning)))
  2375. (when scheduled
  2376. (format span-fmt org-scheduled-string
  2377. (org-translate-time scheduled))))))
  2378. " "))))
  2379. ;;;; Property Drawer
  2380. (defun org-e-html-property-drawer (property-drawer contents info)
  2381. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2382. CONTENTS is nil. INFO is a plist holding contextual
  2383. information."
  2384. ;; The property drawer isn't exported but we want separating blank
  2385. ;; lines nonetheless.
  2386. "")
  2387. ;;;; Quote Block
  2388. (defun org-e-html-quote-block (quote-block contents info)
  2389. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2390. CONTENTS holds the contents of the block. INFO is a plist
  2391. holding contextual information."
  2392. (org-e-html--wrap-label
  2393. quote-block (format "<blockquote>\n%s</blockquote>" contents)))
  2394. ;;;; Quote Section
  2395. (defun org-e-html-quote-section (quote-section contents info)
  2396. "Transcode a QUOTE-SECTION element from Org to HTML.
  2397. CONTENTS is nil. INFO is a plist holding contextual information."
  2398. (let ((value (org-remove-indentation
  2399. (org-element-property :value quote-section))))
  2400. (when value (format "<pre>\n%s</pre>" value))))
  2401. ;;;; Section
  2402. (defun org-e-html-section (section contents info) ; FIXME
  2403. "Transcode a SECTION element from Org to HTML.
  2404. CONTENTS holds the contents of the section. INFO is a plist
  2405. holding contextual information."
  2406. (let ((parent (org-export-get-parent-headline section)))
  2407. ;; Before first headline: no container, just return CONTENTS.
  2408. (if (not parent) contents
  2409. ;; Get div's class and id references.
  2410. (let* ((class-num (+ (org-export-get-relative-level parent info)
  2411. (1- org-e-html-toplevel-hlevel)))
  2412. (section-number
  2413. (mapconcat
  2414. 'number-to-string
  2415. (org-export-get-headline-number parent info) "-"))
  2416. (ids (remove 'nil
  2417. (list (org-element-property :custom-id parent)
  2418. (org-element-property :id parent)
  2419. (concat "sec-" section-number))))
  2420. (preferred-id (car ids))
  2421. (extra-ids (cdr ids)))
  2422. ;; Build return value.
  2423. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2424. class-num
  2425. (if (zerop (length extra-ids)) section-number preferred-id)
  2426. contents)))))
  2427. ;;;; Radio Target
  2428. (defun org-e-html-radio-target (radio-target text info)
  2429. "Transcode a RADIO-TARGET object from Org to HTML.
  2430. TEXT is the text of the target. INFO is a plist holding
  2431. contextual information."
  2432. (let ((id (org-export-solidify-link-text
  2433. (org-element-property :value radio-target))))
  2434. (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text)))
  2435. ;;;; Special Block
  2436. (defun org-e-html-special-block (special-block contents info)
  2437. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2438. CONTENTS holds the contents of the block. INFO is a plist
  2439. holding contextual information."
  2440. (let ((type (downcase (org-element-property :type special-block))))
  2441. (org-e-html--wrap-label
  2442. special-block
  2443. (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
  2444. ;;;; Src Block
  2445. (defun org-e-html-src-block (src-block contents info)
  2446. "Transcode a SRC-BLOCK element from Org to HTML.
  2447. CONTENTS holds the contents of the item. INFO is a plist holding
  2448. contextual information."
  2449. (let* ((lang (org-element-property :language src-block))
  2450. (caption (org-element-property :caption src-block))
  2451. (label (org-element-property :name src-block))
  2452. (caption-str (org-e-html--caption/label-string caption label info))
  2453. (attr (mapconcat #'identity
  2454. (org-element-property :attr_html src-block)
  2455. " "))
  2456. ;; (switches (org-element-property :switches src-block))
  2457. (switches nil) ; FIXME
  2458. (textarea-p (and switches (string-match "-t\\>" switches)))
  2459. (code (org-e-html-format-code src-block info)))
  2460. (cond
  2461. (lang (format
  2462. "<div class=\"org-src-container\">\n%s%s\n</div>"
  2463. (if (not caption) ""
  2464. (format "<label class=\"org-src-name\">%s</label>" caption-str))
  2465. (format "\n<pre class=\"src src-%s\">%s</pre>" lang code)))
  2466. (textarea-p
  2467. (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
  2468. 80 (string-to-number (match-string 1 switches))))
  2469. (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
  2470. (string-to-number (match-string 1 switches))
  2471. (org-count-lines code))))
  2472. (format
  2473. "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
  2474. cols rows code)))
  2475. (t (format "<pre class=\"example\">\n%s</pre>" code)))))
  2476. ;;;; Statistics Cookie
  2477. (defun org-e-html-statistics-cookie (statistics-cookie contents info)
  2478. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2479. CONTENTS is nil. INFO is a plist holding contextual information."
  2480. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2481. (format "<code>%s</code>" cookie-value)))
  2482. ;;;; Strike-Through
  2483. (defun org-e-html-strike-through (strike-through contents info)
  2484. "Transcode STRIKE-THROUGH from Org to HTML.
  2485. CONTENTS is the text with strike-through markup. INFO is a plist
  2486. holding contextual information."
  2487. (format (or (cdr (assq 'strike-through org-e-html-text-markup-alist)) "%s")
  2488. contents))
  2489. ;;;; Subscript
  2490. (defun org-e-html-subscript (subscript contents info)
  2491. "Transcode a SUBSCRIPT object from Org to HTML.
  2492. CONTENTS is the contents of the object. INFO is a plist holding
  2493. contextual information."
  2494. (format "<sub>%s</sub>" contents))
  2495. ;;;; Superscript
  2496. (defun org-e-html-superscript (superscript contents info)
  2497. "Transcode a SUPERSCRIPT object from Org to HTML.
  2498. CONTENTS is the contents of the object. INFO is a plist holding
  2499. contextual information."
  2500. (format "<sup>%s</sup>" contents))
  2501. ;;;; Tabel Cell
  2502. (defun org-e-html-table-cell (table-cell contents info)
  2503. "Transcode a TABLE-CELL element from Org to HTML.
  2504. CONTENTS is nil. INFO is a plist used as a communication
  2505. channel."
  2506. (let* ((table-row (org-export-get-parent table-cell))
  2507. (table (org-export-get-parent-table table-cell))
  2508. (cell-attrs
  2509. (if (not org-e-html-table-align-individual-fields) ""
  2510. (format (if (and (boundp 'org-e-html-format-table-no-css)
  2511. org-e-html-format-table-no-css)
  2512. " align=\"%s\"" " class=\"%s\"")
  2513. (org-export-table-cell-alignment table-cell info)))))
  2514. (when (or (not contents) (string= "" (org-trim contents)))
  2515. (setq contents "&nbsp;"))
  2516. (cond
  2517. ((and (org-export-table-has-header-p table info)
  2518. (= 1 (org-export-table-row-group table-row info)))
  2519. (concat "\n" (format (car org-e-html-table-header-tags) "col" cell-attrs)
  2520. contents (cdr org-e-html-table-header-tags)))
  2521. ((and org-e-html-table-use-header-tags-for-first-column
  2522. (zerop (cdr (org-export-table-cell-address table-cell info))))
  2523. (concat "\n" (format (car org-e-html-table-header-tags) "row" cell-attrs)
  2524. contents (cdr org-e-html-table-header-tags)))
  2525. (t (concat "\n" (format (car org-e-html-table-data-tags) cell-attrs)
  2526. contents (cdr org-e-html-table-data-tags))))))
  2527. ;;;; Table Row
  2528. (defun org-e-html-table-row (table-row contents info)
  2529. "Transcode a TABLE-ROW element from Org to HTML.
  2530. CONTENTS is the contents of the row. INFO is a plist used as a
  2531. communication channel."
  2532. ;; Rules are ignored since table separators are deduced from
  2533. ;; borders of the current row.
  2534. (when (eq (org-element-property :type table-row) 'standard)
  2535. (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
  2536. (rowgroup-tags
  2537. (cond
  2538. ;; Case 1: Row belongs to second or subsequent rowgroups.
  2539. ((not (= 1 (org-export-table-row-group table-row info)))
  2540. '("<tbody>" . "\n</tbody>"))
  2541. ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
  2542. ((org-export-table-has-header-p
  2543. (org-export-get-parent-table table-row) info)
  2544. '("<thead>" . "\n</thead>"))
  2545. ;; Case 2: Row is from first and only row group.
  2546. (t '("<tbody>" . "\n</tbody>")))))
  2547. (concat
  2548. ;; Begin a rowgroup?
  2549. (when (org-export-table-row-starts-rowgroup-p table-row info)
  2550. (car rowgroup-tags))
  2551. ;; Actual table row
  2552. (concat "\n" (eval (car org-e-html-table-row-tags))
  2553. contents
  2554. "\n"
  2555. (eval (cdr org-e-html-table-row-tags)))
  2556. ;; End a rowgroup?
  2557. (when (org-export-table-row-ends-rowgroup-p table-row info)
  2558. (cdr rowgroup-tags))))))
  2559. ;;;; Table
  2560. (defun org-e-html-table-first-row-data-cells (table info)
  2561. (let ((table-row
  2562. (org-element-map
  2563. table 'table-row
  2564. (lambda (row)
  2565. (unless (eq (org-element-property :type row) 'rule) row))
  2566. info 'first-match))
  2567. (special-column-p (org-export-table-has-special-column-p table)))
  2568. (if (not special-column-p) (org-element-contents table-row)
  2569. (cdr (org-element-contents table-row)))))
  2570. (defun org-e-html-table--table.el-table (table info)
  2571. (when (eq (org-element-property :type table) 'table.el)
  2572. (require 'table)
  2573. (let ((outbuf (with-current-buffer
  2574. (get-buffer-create "*org-export-table*")
  2575. (erase-buffer) (current-buffer))))
  2576. (with-temp-buffer
  2577. (insert (org-element-property :value table))
  2578. (goto-char 1)
  2579. (re-search-forward "^[ \t]*|[^|]" nil t)
  2580. (table-generate-source 'html outbuf))
  2581. (with-current-buffer outbuf
  2582. (prog1 (org-trim (buffer-string))
  2583. (kill-buffer) )))))
  2584. (defun org-e-html-table (table contents info)
  2585. "Transcode a TABLE element from Org to HTML.
  2586. CONTENTS is the contents of the table. INFO is a plist holding
  2587. contextual information."
  2588. (case (org-element-property :type table)
  2589. ;; Case 1: table.el table. Convert it using appropriate tools.
  2590. (table.el (org-e-html-table--table.el-table table info))
  2591. ;; Case 2: Standard table.
  2592. (t
  2593. (let* ((label (org-element-property :name table))
  2594. (caption (org-e-html--caption/label-string
  2595. (org-element-property :caption table) label info))
  2596. (attributes (mapconcat #'identity
  2597. (org-element-property :attr_html table)
  2598. " "))
  2599. (alignspec
  2600. (if (and (boundp 'org-e-html-format-table-no-css)
  2601. org-e-html-format-table-no-css)
  2602. "align=\"%s\"" "class=\"%s\""))
  2603. (table-column-specs
  2604. (function
  2605. (lambda (table info)
  2606. (mapconcat
  2607. (lambda (table-cell)
  2608. (let ((alignment (org-export-table-cell-alignment
  2609. table-cell info)))
  2610. (concat
  2611. ;; Begin a colgroup?
  2612. (when (org-export-table-cell-starts-colgroup-p
  2613. table-cell info)
  2614. "\n<colgroup>")
  2615. ;; Add a column. Also specify it's alignment.
  2616. (format "\n<col %s/>" (format alignspec alignment))
  2617. ;; End a colgroup?
  2618. (when (org-export-table-cell-ends-colgroup-p
  2619. table-cell info)
  2620. "\n</colgroup>"))))
  2621. (org-e-html-table-first-row-data-cells table info) "\n"))))
  2622. (table-attributes
  2623. (let ((table-tag (plist-get info :html-table-tag)))
  2624. (concat
  2625. (and (string-match "<table\\(.*\\)>" table-tag)
  2626. (match-string 1 table-tag))
  2627. (and label (format " id=\"%s\""
  2628. (org-solidify-link-text label)))))))
  2629. ;; Remove last blank line.
  2630. (setq contents (substring contents 0 -1))
  2631. ;; FIXME: splice
  2632. (format "<table%s>\n<caption>%s</caption>\n%s\n%s\n</table>"
  2633. table-attributes
  2634. (or caption "")
  2635. (funcall table-column-specs table info)
  2636. contents)))))
  2637. ;;;; Target
  2638. (defun org-e-html-target (target contents info)
  2639. "Transcode a TARGET object from Org to HTML.
  2640. CONTENTS is nil. INFO is a plist holding contextual
  2641. information."
  2642. (let ((id (org-export-solidify-link-text
  2643. (org-element-property :value target))))
  2644. (format "<a id=\"%s\" name=\"%s\"></a>" id id)))
  2645. ;;;; Timestamp
  2646. (defun org-e-html-timestamp (timestamp contents info)
  2647. "Transcode a TIMESTAMP object from Org to HTML.
  2648. CONTENTS is nil. INFO is a plist holding contextual
  2649. information."
  2650. (let ((value (org-translate-time (org-element-property :value timestamp))))
  2651. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  2652. value)))
  2653. ;;;; Underline
  2654. (defun org-e-html-underline (underline contents info)
  2655. "Transcode UNDERLINE from Org to HTML.
  2656. CONTENTS is the text with underline markup. INFO is a plist
  2657. holding contextual information."
  2658. (format (or (cdr (assq 'underline org-e-html-text-markup-alist)) "%s")
  2659. contents))
  2660. ;;;; Verbatim
  2661. (defun org-e-html-verbatim (verbatim contents info)
  2662. "Transcode VERBATIM from Org to HTML.
  2663. CONTENTS is nil. INFO is a plist holding contextual
  2664. information."
  2665. (format (or (cdr (assq 'verbatim org-e-html-text-markup-alist)) "%s")
  2666. (org-element-property :value verbatim)))
  2667. ;;;; Verse Block
  2668. (defun org-e-html-verse-block (verse-block contents info)
  2669. "Transcode a VERSE-BLOCK element from Org to HTML.
  2670. CONTENTS is verse block contents. INFO is a plist holding
  2671. contextual information."
  2672. ;; Replace each newline character with line break. Also replace
  2673. ;; each blank line with a line break.
  2674. (setq contents (replace-regexp-in-string
  2675. "^ *\\\\\\\\$" "<br/>\n"
  2676. (replace-regexp-in-string
  2677. "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
  2678. ;; Replace each white space at beginning of a line with a
  2679. ;; non-breaking space.
  2680. (while (string-match "^[ \t]+" contents)
  2681. (let* ((num-ws (length (match-string 0 contents)))
  2682. (ws (let (out) (dotimes (i num-ws out)
  2683. (setq out (concat out "&nbsp;"))))))
  2684. (setq contents (replace-match ws nil t contents))))
  2685. (org-e-html--wrap-label
  2686. verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
  2687. ;;; Filter Functions
  2688. (defun org-e-html-final-function (contents backend info)
  2689. (if (not org-e-html-pretty-output) contents
  2690. (with-temp-buffer
  2691. (nxml-mode)
  2692. (insert contents)
  2693. (indent-region (point-min) (point-max))
  2694. (buffer-substring-no-properties (point-min) (point-max)))))
  2695. ;;; Interactive functions
  2696. ;;;###autoload
  2697. (defun org-e-html-export-to-html
  2698. (&optional subtreep visible-only body-only ext-plist pub-dir)
  2699. "Export current buffer to a HTML file.
  2700. If narrowing is active in the current buffer, only export its
  2701. narrowed part.
  2702. If a region is active, export that region.
  2703. When optional argument SUBTREEP is non-nil, export the sub-tree
  2704. at point, extracting information from the headline properties
  2705. first.
  2706. When optional argument VISIBLE-ONLY is non-nil, don't export
  2707. contents of hidden elements.
  2708. When optional argument BODY-ONLY is non-nil, only write code
  2709. between \"\\begin{document}\" and \"\\end{document}\".
  2710. EXT-PLIST, when provided, is a property list with external
  2711. parameters overriding Org default settings, but still inferior to
  2712. file-local settings.
  2713. When optional argument PUB-DIR is set, use it as the publishing
  2714. directory.
  2715. Return output file's name."
  2716. (interactive)
  2717. (setq debug-on-error t) ; FIXME
  2718. (let* ((extension (concat "." org-e-html-extension))
  2719. (file (org-export-output-file-name extension subtreep pub-dir))
  2720. (org-export-coding-system org-e-html-coding-system))
  2721. (org-export-to-file
  2722. 'e-html file subtreep visible-only body-only ext-plist)))
  2723. ;;; FIXMES, TODOS, FOR REVIEW etc
  2724. ;;;; org-format-table-html
  2725. ;;;; org-format-org-table-html
  2726. ;;;; org-format-table-table-html
  2727. ;;;; org-table-number-fraction
  2728. ;;;; org-table-number-regexp
  2729. ;;;; org-e-html-table-caption-above
  2730. ;;;; org-whitespace
  2731. ;;;; "<span style=\"visibility:hidden;\">%s</span>"
  2732. ;;;; Remove display properties
  2733. ;;;; org-e-html-with-timestamp
  2734. ;;;; org-e-html-html-helper-timestamp
  2735. ;;;; org-export-as-html-and-open
  2736. ;;;; org-export-as-html-batch
  2737. ;;;; org-export-as-html-to-buffer
  2738. ;;;; org-replace-region-by-html
  2739. ;;;; org-export-region-as-html
  2740. ;;;; org-export-as-html
  2741. ;;;; (org-export-directory :html opt-plist)
  2742. ;;;; (plist-get opt-plist :html-extension)
  2743. ;;;; org-e-html-toplevel-hlevel
  2744. ;;;; org-e-html-special-string-regexps
  2745. ;;;; org-e-html-inline-images
  2746. ;;;; org-e-html-inline-image-extensions
  2747. ;;;; org-e-html-protect-char-alist
  2748. ;;;; org-e-html-table-use-header-tags-for-first-column
  2749. ;;;; org-e-html-todo-kwd-class-prefix
  2750. ;;;; org-e-html-tag-class-prefix
  2751. ;;;; org-e-html-footnote-separator
  2752. ;;;; org-export-preferred-target-alist
  2753. ;;;; org-solidify-link-text
  2754. ;;;; class for anchors
  2755. ;;;; org-export-with-section-numbers, body-only
  2756. ;;;; org-export-mark-todo-in-toc
  2757. (provide 'org-e-html)
  2758. ;;; org-e-html.el ends here