ox-html.el 130 KB

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