ox-html.el 124 KB

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