ox-html.el 130 KB

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