ox-html.el 124 KB

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