ox-html.el 123 KB

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