ox-html.el 144 KB

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