ox-html.el 132 KB

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