ox-html.el 139 KB

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