ox-html.el 130 KB

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