ox-html.el 130 KB

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