ox-html.el 132 KB

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