ox-html.el 128 KB

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