ox-html.el 125 KB

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