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