ox-html.el 125 KB

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