ox-html.el 136 KB

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