ox-html.el 130 KB

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