ox-html.el 125 KB

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