ox-html.el 132 KB

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