ox-html.el 145 KB

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