ox-html.el 132 KB

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