ox-html.el 143 KB

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