ox-html.el 132 KB

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