ox-html.el 123 KB

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