ox-html.el 142 KB

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