ox-html.el 132 KB

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