ox-html.el 144 KB

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