ox-html.el 143 KB

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