ox-html.el 143 KB

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