ox-html.el 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508
  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. <hgroup> is not included because it's currently impossible to
  148. wrap special blocks around multiple headlines. For other blocks
  149. that should contain headlines, use the HTML_CONTAINER property on
  150. the headline itself.")
  151. (defconst org-html-special-string-regexps
  152. '(("\\\\-" . "&#x00ad;") ; shy
  153. ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
  154. ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
  155. ("\\.\\.\\." . "&#x2026;")) ; hellip
  156. "Regular expressions for special string conversion.")
  157. (defconst org-html-scripts
  158. "<script type=\"text/javascript\">
  159. /*
  160. @licstart The following is the entire license notice for the
  161. JavaScript code in this tag.
  162. Copyright (C) 2012-2013 Free Software Foundation, Inc.
  163. The JavaScript code in this tag is free software: you can
  164. redistribute it and/or modify it under the terms of the GNU
  165. General Public License (GNU GPL) as published by the Free Software
  166. Foundation, either version 3 of the License, or (at your option)
  167. any later version. The code is distributed WITHOUT ANY WARRANTY;
  168. without even the implied warranty of MERCHANTABILITY or FITNESS
  169. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  170. As additional permission under GNU GPL version 3 section 7, you
  171. may distribute non-source (e.g., minimized or compacted) forms of
  172. that code without the copy of the GNU GPL normally required by
  173. section 4, provided you include this license notice and a URL
  174. through which recipients can access the Corresponding Source.
  175. @licend The above is the entire license notice
  176. for the JavaScript code in this tag.
  177. */
  178. <!--/*--><![CDATA[/*><!--*/
  179. function CodeHighlightOn(elem, id)
  180. {
  181. var target = document.getElementById(id);
  182. if(null != target) {
  183. elem.cacheClassElem = elem.className;
  184. elem.cacheClassTarget = target.className;
  185. target.className = \"code-highlighted\";
  186. elem.className = \"code-highlighted\";
  187. }
  188. }
  189. function CodeHighlightOff(elem, id)
  190. {
  191. var target = document.getElementById(id);
  192. if(elem.cacheClassElem)
  193. elem.className = elem.cacheClassElem;
  194. if(elem.cacheClassTarget)
  195. target.className = elem.cacheClassTarget;
  196. }
  197. /*]]>*///-->
  198. </script>"
  199. "Basic JavaScript that is needed by HTML files produced by Org mode.")
  200. (defconst org-html-style-default
  201. "<style type=\"text/css\">
  202. <!--/*--><![CDATA[/*><!--*/
  203. .title { text-align: center; }
  204. .todo { font-family: monospace; color: red; }
  205. .done { color: green; }
  206. .tag { background-color: #eee; font-family: monospace;
  207. padding: 2px; font-size: 80%; font-weight: normal; }
  208. .timestamp { color: #bebebe; }
  209. .timestamp-kwd { color: #5f9ea0; }
  210. .right { margin-left: auto; margin-right: 0px; text-align: right; }
  211. .left { margin-left: 0px; margin-right: auto; text-align: left; }
  212. .center { margin-left: auto; margin-right: auto; text-align: center; }
  213. .underline { text-decoration: underline; }
  214. #postamble p, #preamble p { font-size: 90%; margin: .2em; }
  215. p.verse { margin-left: 3%; }
  216. pre {
  217. border: 1px solid #ccc;
  218. box-shadow: 3px 3px 3px #eee;
  219. padding: 8pt;
  220. font-family: monospace;
  221. overflow: auto;
  222. margin: 1.2em;
  223. }
  224. pre.src {
  225. position: relative;
  226. overflow: visible;
  227. padding-top: 1.2em;
  228. }
  229. pre.src:before {
  230. display: none;
  231. position: absolute;
  232. background-color: white;
  233. top: -10px;
  234. right: 10px;
  235. padding: 3px;
  236. border: 1px solid black;
  237. }
  238. pre.src:hover:before { display: inline;}
  239. pre.src-sh:before { content: 'sh'; }
  240. pre.src-bash:before { content: 'sh'; }
  241. pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
  242. pre.src-R:before { content: 'R'; }
  243. pre.src-perl:before { content: 'Perl'; }
  244. pre.src-java:before { content: 'Java'; }
  245. pre.src-sql:before { content: 'SQL'; }
  246. table { border-collapse:collapse; }
  247. caption.t-above { caption-side: top; }
  248. caption.t-bottom { caption-side: bottom; }
  249. td, th { vertical-align:top; }
  250. th.right { text-align: center; }
  251. th.left { text-align: center; }
  252. th.center { text-align: center; }
  253. td.right { text-align: right; }
  254. td.left { text-align: left; }
  255. td.center { text-align: center; }
  256. dt { font-weight: bold; }
  257. .footpara:nth-child(2) { display: inline; }
  258. .footpara { display: block; }
  259. .footdef { margin-bottom: 1em; }
  260. .figure { padding: 1em; }
  261. .figure p { text-align: center; }
  262. .inlinetask {
  263. padding: 10px;
  264. border: 2px solid gray;
  265. margin: 10px;
  266. background: #ffffcc;
  267. }
  268. #org-div-home-and-up
  269. { text-align: right; font-size: 70%; white-space: nowrap; }
  270. textarea { overflow-x: auto; }
  271. .linenr { font-size: smaller }
  272. .code-highlighted { background-color: #ffff00; }
  273. .org-info-js_info-navigation { border-style: none; }
  274. #org-info-js_console-label
  275. { font-size: 10px; font-weight: bold; white-space: nowrap; }
  276. .org-info-js_search-highlight
  277. { background-color: #ffff00; color: #000000; font-weight: bold; }
  278. /*]]>*/-->
  279. </style>"
  280. "The default style specification for exported HTML files.
  281. You can use `org-html-head' and `org-html-head-extra' to add to
  282. this style. If you don't want to include this default style,
  283. customize `org-html-head-include-default-style'.")
  284. ;;; User Configuration Variables
  285. (defgroup org-export-html nil
  286. "Options for exporting Org mode files to HTML."
  287. :tag "Org Export HTML"
  288. :group 'org-export)
  289. ;;;; Handle infojs
  290. (defvar org-html-infojs-opts-table
  291. '((path PATH "http://orgmode.org/org-info.js")
  292. (view VIEW "info")
  293. (toc TOC :with-toc)
  294. (ftoc FIXED_TOC "0")
  295. (tdepth TOC_DEPTH "max")
  296. (sdepth SECTION_DEPTH "max")
  297. (mouse MOUSE_HINT "underline")
  298. (buttons VIEW_BUTTONS "0")
  299. (ltoc LOCAL_TOC "1")
  300. (up LINK_UP :html-link-up)
  301. (home LINK_HOME :html-link-home))
  302. "JavaScript options, long form for script, default values.")
  303. (defcustom org-html-use-infojs 'when-configured
  304. "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
  305. This option can be nil or t to never or always use the script.
  306. It can also be the symbol `when-configured', meaning that the
  307. script will be linked into the export file if and only if there
  308. is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
  309. `org-html-infojs-options'."
  310. :group 'org-export-html
  311. :version "24.4"
  312. :package-version '(Org . "8.0")
  313. :type '(choice
  314. (const :tag "Never" nil)
  315. (const :tag "When configured in buffer" when-configured)
  316. (const :tag "Always" t)))
  317. (defcustom org-html-infojs-options
  318. (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
  319. "Options settings for the INFOJS JavaScript.
  320. Each of the options must have an entry in `org-html-infojs-opts-table'.
  321. The value can either be a string that will be passed to the script, or
  322. a property. This property is then assumed to be a property that is defined
  323. by the Export/Publishing setup of Org.
  324. The `sdepth' and `tdepth' parameters can also be set to \"max\", which
  325. means to use the maximum value consistent with other options."
  326. :group 'org-export-html
  327. :version "24.4"
  328. :package-version '(Org . "8.0")
  329. :type
  330. `(set :greedy t :inline t
  331. ,@(mapcar
  332. (lambda (x)
  333. (list 'cons (list 'const (car x))
  334. '(choice
  335. (symbol :tag "Publishing/Export property")
  336. (string :tag "Value"))))
  337. org-html-infojs-opts-table)))
  338. (defcustom org-html-infojs-template
  339. "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
  340. /**
  341. *
  342. * @source: %SCRIPT_PATH
  343. *
  344. * @licstart The following is the entire license notice for the
  345. * JavaScript code in %SCRIPT_PATH.
  346. *
  347. * Copyright (C) 2012-2013 Free Software Foundation, Inc.
  348. *
  349. *
  350. * The JavaScript code in this tag is free software: you can
  351. * redistribute it and/or modify it under the terms of the GNU
  352. * General Public License (GNU GPL) as published by the Free Software
  353. * Foundation, either version 3 of the License, or (at your option)
  354. * any later version. The code is distributed WITHOUT ANY WARRANTY;
  355. * without even the implied warranty of MERCHANTABILITY or FITNESS
  356. * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  357. *
  358. * As additional permission under GNU GPL version 3 section 7, you
  359. * may distribute non-source (e.g., minimized or compacted) forms of
  360. * that code without the copy of the GNU GPL normally required by
  361. * section 4, provided you include this license notice and a URL
  362. * through which recipients can access the Corresponding Source.
  363. *
  364. * @licend The above is the entire license notice
  365. * for the JavaScript code in %SCRIPT_PATH.
  366. *
  367. */
  368. </script>
  369. <script type=\"text/javascript\">
  370. /*
  371. @licstart The following is the entire license notice for the
  372. JavaScript code in this tag.
  373. Copyright (C) 2012-2013 Free Software Foundation, Inc.
  374. The JavaScript code in this tag is free software: you can
  375. redistribute it and/or modify it under the terms of the GNU
  376. General Public License (GNU GPL) as published by the Free Software
  377. Foundation, either version 3 of the License, or (at your option)
  378. any later version. The code is distributed WITHOUT ANY WARRANTY;
  379. without even the implied warranty of MERCHANTABILITY or FITNESS
  380. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  381. As additional permission under GNU GPL version 3 section 7, you
  382. may distribute non-source (e.g., minimized or compacted) forms of
  383. that code without the copy of the GNU GPL normally required by
  384. section 4, provided you include this license notice and a URL
  385. through which recipients can access the Corresponding Source.
  386. @licend The above is the entire license notice
  387. for the JavaScript code in this tag.
  388. */
  389. <!--/*--><![CDATA[/*><!--*/
  390. %MANAGER_OPTIONS
  391. org_html_manager.setup(); // activate after the parameters are set
  392. /*]]>*///-->
  393. </script>"
  394. "The template for the export style additions when org-info.js is used.
  395. Option settings will replace the %MANAGER-OPTIONS cookie."
  396. :group 'org-export-html
  397. :version "24.4"
  398. :package-version '(Org . "8.0")
  399. :type 'string)
  400. (defun org-html-infojs-install-script (exp-plist backend)
  401. "Install script in export options when appropriate.
  402. EXP-PLIST is a plist containing export options. BACKEND is the
  403. export back-end currently used."
  404. (unless (or (memq 'body-only (plist-get exp-plist :export-options))
  405. (not org-html-use-infojs)
  406. (and (eq org-html-use-infojs 'when-configured)
  407. (or (not (plist-get exp-plist :infojs-opt))
  408. (string-match "\\<view:nil\\>"
  409. (plist-get exp-plist :infojs-opt)))))
  410. (let* ((template org-html-infojs-template)
  411. (ptoc (plist-get exp-plist :with-toc))
  412. (hlevels (plist-get exp-plist :headline-levels))
  413. (sdepth hlevels)
  414. (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
  415. (options (plist-get exp-plist :infojs-opt))
  416. (table org-html-infojs-opts-table)
  417. style)
  418. (dolist (entry table)
  419. (let* ((opt (car entry))
  420. (var (nth 1 entry))
  421. ;; Compute default values for script option OPT from
  422. ;; `org-html-infojs-options' variable.
  423. (default
  424. (let ((default (cdr (assq opt org-html-infojs-options))))
  425. (if (and (symbolp default) (not (memq default '(t nil))))
  426. (plist-get exp-plist default)
  427. default)))
  428. ;; Value set through INFOJS_OPT keyword has precedence
  429. ;; over the default one.
  430. (val (if (and options
  431. (string-match (format "\\<%s:\\(\\S-+\\)" opt)
  432. options))
  433. (match-string 1 options)
  434. default)))
  435. (case opt
  436. (path (setq template
  437. (replace-regexp-in-string
  438. "%SCRIPT_PATH" val template t t)))
  439. (sdepth (when (integerp (read val))
  440. (setq sdepth (min (read val) sdepth))))
  441. (tdepth (when (integerp (read val))
  442. (setq tdepth (min (read val) tdepth))))
  443. (otherwise (setq val
  444. (cond
  445. ((or (eq val t) (equal val "t")) "1")
  446. ((or (eq val nil) (equal val "nil")) "0")
  447. ((stringp val) val)
  448. (t (format "%s" val))))
  449. (push (cons var val) style)))))
  450. ;; Now we set the depth of the *generated* TOC to SDEPTH,
  451. ;; because the toc will actually determine the splitting. How
  452. ;; much of the toc will actually be displayed is governed by the
  453. ;; TDEPTH option.
  454. (setq exp-plist (plist-put exp-plist :with-toc sdepth))
  455. ;; The table of contents should not show more sections than we
  456. ;; generate.
  457. (setq tdepth (min tdepth sdepth))
  458. (push (cons "TOC_DEPTH" tdepth) style)
  459. ;; Build style string.
  460. (setq style (mapconcat
  461. (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
  462. (car x)
  463. (cdr x)))
  464. style "\n"))
  465. (when (and style (> (length style) 0))
  466. (and (string-match "%MANAGER_OPTIONS" template)
  467. (setq style (replace-match style t t template))
  468. (setq exp-plist
  469. (plist-put
  470. exp-plist :html-head-extra
  471. (concat (or (plist-get exp-plist :html-head-extra) "")
  472. "\n"
  473. style)))))
  474. ;; This script absolutely needs the table of contents, so we
  475. ;; change that setting.
  476. (unless (plist-get exp-plist :with-toc)
  477. (setq exp-plist (plist-put exp-plist :with-toc t)))
  478. ;; Return the modified property list.
  479. exp-plist)))
  480. ;;;; Bold, etc.
  481. (defcustom org-html-text-markup-alist
  482. '((bold . "<b>%s</b>")
  483. (code . "<code>%s</code>")
  484. (italic . "<i>%s</i>")
  485. (strike-through . "<del>%s</del>")
  486. (underline . "<span class=\"underline\">%s</span>")
  487. (verbatim . "<code>%s</code>"))
  488. "Alist of HTML expressions to convert text markup.
  489. The key must be a symbol among `bold', `code', `italic',
  490. `strike-through', `underline' and `verbatim'. The value is
  491. a formatting string to wrap fontified text with.
  492. If no association can be found for a given markup, text will be
  493. returned as-is."
  494. :group 'org-export-html
  495. :version "24.4"
  496. :package-version '(Org . "8.0")
  497. :type '(alist :key-type (symbol :tag "Markup type")
  498. :value-type (string :tag "Format string"))
  499. :options '(bold code italic strike-through underline verbatim))
  500. (defcustom org-html-indent nil
  501. "Non-nil means to indent the generated HTML.
  502. Warning: non-nil may break indentation of source code blocks."
  503. :group 'org-export-html
  504. :version "24.4"
  505. :package-version '(Org . "8.0")
  506. :type 'boolean)
  507. (defcustom org-html-use-unicode-chars nil
  508. "Non-nil means to use unicode characters instead of HTML entities."
  509. :group 'org-export-html
  510. :version "24.4"
  511. :package-version '(Org . "8.0")
  512. :type 'boolean)
  513. ;;;; Drawers
  514. (defcustom org-html-format-drawer-function
  515. (lambda (name contents) contents)
  516. "Function called to format a drawer in HTML code.
  517. The function must accept two parameters:
  518. NAME the drawer name, like \"LOGBOOK\"
  519. CONTENTS the contents of the drawer.
  520. The function should return the string to be exported.
  521. For example, the variable could be set to the following function
  522. in order to mimic default behaviour:
  523. The default value simply returns the value of CONTENTS."
  524. :group 'org-export-html
  525. :version "24.4"
  526. :package-version '(Org . "8.0")
  527. :type 'function)
  528. ;;;; Footnotes
  529. (defcustom org-html-footnotes-section "<div id=\"footnotes\">
  530. <h2 class=\"footnotes\">%s: </h2>
  531. <div id=\"text-footnotes\">
  532. %s
  533. </div>
  534. </div>"
  535. "Format for the footnotes section.
  536. Should contain a two instances of %s. The first will be replaced with the
  537. language-specific word for \"Footnotes\", the second one will be replaced
  538. by the footnotes themselves."
  539. :group 'org-export-html
  540. :type 'string)
  541. (defcustom org-html-footnote-format "<sup>%s</sup>"
  542. "The format for the footnote reference.
  543. %s will be replaced by the footnote reference itself."
  544. :group 'org-export-html
  545. :type 'string)
  546. (defcustom org-html-footnote-separator "<sup>, </sup>"
  547. "Text used to separate footnotes."
  548. :group 'org-export-html
  549. :type 'string)
  550. ;;;; Headline
  551. (defcustom org-html-toplevel-hlevel 2
  552. "The <H> level for level 1 headings in HTML export.
  553. This is also important for the classes that will be wrapped around headlines
  554. and outline structure. If this variable is 1, the top-level headlines will
  555. be <h1>, and the corresponding classes will be outline-1, section-number-1,
  556. and outline-text-1. If this is 2, all of these will get a 2 instead.
  557. The default for this variable is 2, because we use <h1> for formatting the
  558. document title."
  559. :group 'org-export-html
  560. :type 'integer)
  561. (defcustom org-html-format-headline-function 'ignore
  562. "Function to format headline text.
  563. This function will be called with 5 arguments:
  564. TODO the todo keyword (string or nil).
  565. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  566. PRIORITY the priority of the headline (integer or nil)
  567. TEXT the main headline text (string).
  568. TAGS the tags (string or nil).
  569. The function result will be used in the section format string."
  570. :group 'org-export-html
  571. :version "24.4"
  572. :package-version '(Org . "8.0")
  573. :type 'function)
  574. ;;;; HTML-specific
  575. (defcustom org-html-allow-name-attribute-in-anchors nil
  576. "When nil, do not set \"name\" attribute in anchors.
  577. By default, when appropriate, anchors are formatted with \"id\"
  578. but without \"name\" attribute."
  579. :group 'org-export-html
  580. :version "24.4"
  581. :package-version '(Org . "8.0")
  582. :type 'boolean)
  583. ;;;; Inlinetasks
  584. (defcustom org-html-format-inlinetask-function 'ignore
  585. "Function called to format an inlinetask in HTML code.
  586. The function must accept six parameters:
  587. TODO the todo keyword, as a string
  588. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  589. PRIORITY the inlinetask priority, as a string
  590. NAME the inlinetask name, as a string.
  591. TAGS the inlinetask tags, as a list of strings.
  592. CONTENTS the contents of the inlinetask, as a string.
  593. The function should return the string to be exported."
  594. :group 'org-export-html
  595. :version "24.4"
  596. :package-version '(Org . "8.0")
  597. :type 'function)
  598. ;;;; LaTeX
  599. (defcustom org-html-with-latex org-export-with-latex
  600. "Non-nil means process LaTeX math snippets.
  601. When set, the exporter will process LaTeX environments and
  602. fragments.
  603. This option can also be set with the +OPTIONS line,
  604. e.g. \"tex:mathjax\". Allowed values are:
  605. nil Ignore math snippets.
  606. `verbatim' Keep everything in verbatim
  607. `dvipng' Process the LaTeX fragments to images. This will also
  608. include processing of non-math environments.
  609. `imagemagick' Convert the LaTeX fragments to pdf files and use
  610. imagemagick to convert pdf files to png files.
  611. `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
  612. be loaded.
  613. t Synonym for `mathjax'."
  614. :group 'org-export-html
  615. :version "24.4"
  616. :package-version '(Org . "8.0")
  617. :type '(choice
  618. (const :tag "Do not process math in any way" nil)
  619. (const :tag "Use dvipng to make images" dvipng)
  620. (const :tag "Use imagemagick to make images" imagemagick)
  621. (const :tag "Use MathJax to display math" mathjax)
  622. (const :tag "Leave math verbatim" verbatim)))
  623. ;;;; Links :: Generic
  624. (defcustom org-html-link-org-files-as-html t
  625. "Non-nil means make file links to `file.org' point to `file.html'.
  626. When `org-mode' is exporting an `org-mode' file to HTML, links to
  627. non-html files are directly put into a href tag in HTML.
  628. However, links to other Org-mode files (recognized by the
  629. extension `.org.) should become links to the corresponding html
  630. file, assuming that the linked `org-mode' file will also be
  631. converted to HTML.
  632. When nil, the links still point to the plain `.org' file."
  633. :group 'org-export-html
  634. :type 'boolean)
  635. ;;;; Links :: Inline images
  636. (defcustom org-html-inline-images t
  637. "Non-nil means inline images into exported HTML pages.
  638. This is done using an <img> tag. When nil, an anchor with href is used to
  639. link to the image."
  640. :group 'org-export-html
  641. :version "24.4"
  642. :package-version '(Org . "8.1")
  643. :type 'boolean)
  644. (defcustom org-html-inline-image-rules
  645. '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
  646. ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
  647. ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
  648. "Rules characterizing image files that can be inlined into HTML.
  649. A rule consists in an association whose key is the type of link
  650. to consider, and value is a regexp that will be matched against
  651. link's path."
  652. :group 'org-export-html
  653. :version "24.4"
  654. :package-version '(Org . "8.0")
  655. :type '(alist :key-type (string :tag "Type")
  656. :value-type (regexp :tag "Path")))
  657. ;;;; Plain Text
  658. (defcustom org-html-protect-char-alist
  659. '(("&" . "&amp;")
  660. ("<" . "&lt;")
  661. (">" . "&gt;"))
  662. "Alist of characters to be converted by `org-html-protect'."
  663. :group 'org-export-html
  664. :type '(repeat (cons (string :tag "Character")
  665. (string :tag "HTML equivalent"))))
  666. ;;;; Src Block
  667. (defcustom org-html-htmlize-output-type 'inline-css
  668. "Output type to be used by htmlize when formatting code snippets.
  669. Choices are `css', to export the CSS selectors only, or `inline-css', to
  670. export the CSS attribute values inline in the HTML. We use as default
  671. `inline-css', in order to make the resulting HTML self-containing.
  672. However, this will fail when using Emacs in batch mode for export, because
  673. then no rich font definitions are in place. It will also not be good if
  674. people with different Emacs setup contribute HTML files to a website,
  675. because the fonts will represent the individual setups. In these cases,
  676. it is much better to let Org/Htmlize assign classes only, and to use
  677. a style file to define the look of these classes.
  678. To get a start for your css file, start Emacs session and make sure that
  679. all the faces you are interested in are defined, for example by loading files
  680. in all modes you want. Then, use the command
  681. \\[org-html-htmlize-generate-css] to extract class definitions."
  682. :group 'org-export-html
  683. :type '(choice (const css) (const inline-css)))
  684. (defcustom org-html-htmlize-font-prefix "org-"
  685. "The prefix for CSS class names for htmlize font specifications."
  686. :group 'org-export-html
  687. :type 'string)
  688. ;;;; Table
  689. (defcustom org-html-table-default-attributes
  690. '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
  691. "Default attributes and values which will be used in table tags.
  692. This is a plist where attributes are symbols, starting with
  693. colons, and values are strings.
  694. When exporting to HTML5, these values will be disregarded."
  695. :group 'org-export-html
  696. :version "24.4"
  697. :package-version '(Org . "8.0")
  698. :type '(plist :key-type (symbol :tag "Property")
  699. :value-type (string :tag "Value")))
  700. (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
  701. "The opening tag for table header fields.
  702. This is customizable so that alignment options can be specified.
  703. The first %s will be filled with the scope of the field, either row or col.
  704. The second %s will be replaced by a style entry to align the field.
  705. See also the variable `org-html-table-use-header-tags-for-first-column'.
  706. See also the variable `org-html-table-align-individual-fields'."
  707. :group 'org-export-html
  708. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  709. (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
  710. "The opening tag for table data fields.
  711. This is customizable so that alignment options can be specified.
  712. The first %s will be filled with the scope of the field, either row or col.
  713. The second %s will be replaced by a style entry to align the field.
  714. See also the variable `org-html-table-align-individual-fields'."
  715. :group 'org-export-html
  716. :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
  717. (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
  718. "The opening and ending tags for table rows.
  719. This is customizable so that alignment options can be specified.
  720. Instead of strings, these can be Lisp forms that will be
  721. evaluated for each row in order to construct the table row tags.
  722. During evaluation, these variables will be dynamically bound so that
  723. you can reuse them:
  724. `row-number': row number (0 is the first row)
  725. `rowgroup-number': group number of current row
  726. `start-rowgroup-p': non-nil means the row starts a group
  727. `end-rowgroup-p': non-nil means the row ends a group
  728. `top-row-p': non-nil means this is the top row
  729. `bottom-row-p': non-nil means this is the bottom row
  730. For example:
  731. \(setq org-html-table-row-tags
  732. (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
  733. (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
  734. (t (if (= (mod row-number 2) 1)
  735. \"<tr class=\\\"tr-odd\\\">\"
  736. \"<tr class=\\\"tr-even\\\">\")))
  737. \"</tr>\"))
  738. will use the \"tr-top\" and \"tr-bottom\" classes for the top row
  739. and the bottom row, and otherwise alternate between \"tr-odd\" and
  740. \"tr-even\" for odd and even rows."
  741. :group 'org-export-html
  742. :type '(cons
  743. (choice :tag "Opening tag"
  744. (string :tag "Specify")
  745. (sexp))
  746. (choice :tag "Closing tag"
  747. (string :tag "Specify")
  748. (sexp))))
  749. (defcustom org-html-table-align-individual-fields t
  750. "Non-nil means attach style attributes for alignment to each table field.
  751. When nil, alignment will only be specified in the column tags, but this
  752. is ignored by some browsers (like Firefox, Safari). Opera does it right
  753. though."
  754. :group 'org-export-html
  755. :type 'boolean)
  756. (defcustom org-html-table-use-header-tags-for-first-column nil
  757. "Non-nil means format column one in tables with header tags.
  758. When nil, also column one will use data tags."
  759. :group 'org-export-html
  760. :type 'boolean)
  761. (defcustom org-html-table-caption-above t
  762. "When non-nil, place caption string at the beginning of the table.
  763. Otherwise, place it near the end."
  764. :group 'org-export-html
  765. :type 'boolean)
  766. ;;;; Tags
  767. (defcustom org-html-tag-class-prefix ""
  768. "Prefix to class names for TODO keywords.
  769. Each tag gets a class given by the tag itself, with this prefix.
  770. The default prefix is empty because it is nice to just use the keyword
  771. as a class name. But if you get into conflicts with other, existing
  772. CSS classes, then this prefix can be very useful."
  773. :group 'org-export-html
  774. :type 'string)
  775. ;;;; Template :: Generic
  776. (defcustom org-html-extension "html"
  777. "The extension for exported HTML files."
  778. :group 'org-export-html
  779. :type 'string)
  780. (defcustom org-html-xml-declaration
  781. '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
  782. ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
  783. "The extension for exported HTML files.
  784. %s will be replaced with the charset of the exported file.
  785. This may be a string, or an alist with export extensions
  786. and corresponding declarations.
  787. This declaration only applies when exporting to XHTML."
  788. :group 'org-export-html
  789. :type '(choice
  790. (string :tag "Single declaration")
  791. (repeat :tag "Dependent on extension"
  792. (cons (string :tag "Extension")
  793. (string :tag "Declaration")))))
  794. (defcustom org-html-coding-system 'utf-8
  795. "Coding system for HTML export.
  796. Use utf-8 as the default value."
  797. :group 'org-export-html
  798. :version "24.4"
  799. :package-version '(Org . "8.0")
  800. :type 'coding-system)
  801. (defcustom org-html-doctype "xhtml-strict"
  802. "Document type definition to use for exported HTML files.
  803. Can be set with the in-buffer HTML_DOCTYPE property or for
  804. publishing, with :html-doctype."
  805. :group 'org-export-html
  806. :version "24.4"
  807. :package-version '(Org . "8.0")
  808. :type (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. (t
  1679. ;; Map language
  1680. (setq lang (or (assoc-default lang org-src-lang-modes) lang))
  1681. (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
  1682. (cond
  1683. ;; Case 1: Language is not associated with any Emacs mode
  1684. ((not (functionp lang-mode))
  1685. ;; Simple transcoding.
  1686. (org-html-encode-plain-text code))
  1687. ;; Case 2: Default. Fontify code.
  1688. (t
  1689. ;; htmlize
  1690. (setq code (with-temp-buffer
  1691. ;; Switch to language-specific mode.
  1692. (funcall lang-mode)
  1693. (insert code)
  1694. ;; Fontify buffer.
  1695. (font-lock-fontify-buffer)
  1696. ;; Remove formatting on newline characters.
  1697. (save-excursion
  1698. (let ((beg (point-min))
  1699. (end (point-max)))
  1700. (goto-char beg)
  1701. (while (progn (end-of-line) (< (point) end))
  1702. (put-text-property (point) (1+ (point)) 'face nil)
  1703. (forward-char 1))))
  1704. (org-src-mode)
  1705. (set-buffer-modified-p nil)
  1706. ;; Htmlize region.
  1707. (org-html-htmlize-region-for-paste
  1708. (point-min) (point-max))))
  1709. ;; Strip any enclosing <pre></pre> tags.
  1710. (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
  1711. (end (and beg (string-match "</pre>\\'" code))))
  1712. (if (and beg end) (substring code beg end) code)))))))))
  1713. (defun org-html-do-format-code
  1714. (code &optional lang refs retain-labels num-start)
  1715. "Format CODE string as source code.
  1716. Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
  1717. respectively, the language of the source code, as a string, an
  1718. alist between line numbers and references (as returned by
  1719. `org-export-unravel-code'), a boolean specifying if labels should
  1720. appear in the source code, and the number associated to the first
  1721. line of code."
  1722. (let* ((code-lines (org-split-string code "\n"))
  1723. (code-length (length code-lines))
  1724. (num-fmt
  1725. (and num-start
  1726. (format "%%%ds: "
  1727. (length (number-to-string (+ code-length num-start))))))
  1728. (code (org-html-fontify-code code lang)))
  1729. (org-export-format-code
  1730. code
  1731. (lambda (loc line-num ref)
  1732. (setq loc
  1733. (concat
  1734. ;; Add line number, if needed.
  1735. (when num-start
  1736. (format "<span class=\"linenr\">%s</span>"
  1737. (format num-fmt line-num)))
  1738. ;; Transcoded src line.
  1739. loc
  1740. ;; Add label, if needed.
  1741. (when (and ref retain-labels) (format " (%s)" ref))))
  1742. ;; Mark transcoded line as an anchor, if needed.
  1743. (if (not ref) loc
  1744. (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
  1745. ref loc)))
  1746. num-start refs)))
  1747. (defun org-html-format-code (element info)
  1748. "Format contents of ELEMENT as source code.
  1749. ELEMENT is either an example block or a src block. INFO is
  1750. a plist used as a communication channel."
  1751. (let* ((lang (org-element-property :language element))
  1752. ;; Extract code and references.
  1753. (code-info (org-export-unravel-code element))
  1754. (code (car code-info))
  1755. (refs (cdr code-info))
  1756. ;; Does the src block contain labels?
  1757. (retain-labels (org-element-property :retain-labels element))
  1758. ;; Does it have line numbers?
  1759. (num-start (case (org-element-property :number-lines element)
  1760. (continued (org-export-get-loc element info))
  1761. (new 0))))
  1762. (org-html-do-format-code code lang refs retain-labels num-start)))
  1763. ;;; Tables of Contents
  1764. (defun org-html-toc (depth info)
  1765. "Build a table of contents.
  1766. DEPTH is an integer specifying the depth of the table. INFO is a
  1767. plist used as a communication channel. Return the table of
  1768. contents as a string, or nil if it is empty."
  1769. (let ((toc-entries
  1770. (mapcar (lambda (headline)
  1771. (cons (org-html--format-toc-headline headline info)
  1772. (org-export-get-relative-level headline info)))
  1773. (org-export-collect-headlines info depth)))
  1774. (outer-tag (if (and (org-html-html5-p info)
  1775. (plist-get info :html-html5-fancy))
  1776. "nav"
  1777. "div")))
  1778. (when toc-entries
  1779. (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
  1780. (format "<h%d>%s</h%d>\n"
  1781. org-html-toplevel-hlevel
  1782. (org-html--translate "Table of Contents" info)
  1783. org-html-toplevel-hlevel)
  1784. "<div id=\"text-table-of-contents\">"
  1785. (org-html--toc-text toc-entries)
  1786. "</div>\n"
  1787. (format "</%s>\n" outer-tag)))))
  1788. (defun org-html--toc-text (toc-entries)
  1789. "Return innards of a table of contents, as a string.
  1790. TOC-ENTRIES is an alist where key is an entry title, as a string,
  1791. and value is its relative level, as an integer."
  1792. (let* ((prev-level (1- (cdar toc-entries)))
  1793. (start-level prev-level))
  1794. (concat
  1795. (mapconcat
  1796. (lambda (entry)
  1797. (let ((headline (car entry))
  1798. (level (cdr entry)))
  1799. (concat
  1800. (let* ((cnt (- level prev-level))
  1801. (times (if (> cnt 0) (1- cnt) (- cnt)))
  1802. rtn)
  1803. (setq prev-level level)
  1804. (concat
  1805. (org-html--make-string
  1806. times (cond ((> cnt 0) "\n<ul>\n<li>")
  1807. ((< cnt 0) "</li>\n</ul>\n")))
  1808. (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
  1809. headline)))
  1810. toc-entries "")
  1811. (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
  1812. (defun org-html--format-toc-headline (headline info)
  1813. "Return an appropriate table of contents entry for HEADLINE.
  1814. INFO is a plist used as a communication channel."
  1815. (let* ((headline-number (org-export-get-headline-number headline info))
  1816. (todo (and (plist-get info :with-todo-keywords)
  1817. (let ((todo (org-element-property :todo-keyword headline)))
  1818. (and todo (org-export-data todo info)))))
  1819. (todo-type (and todo (org-element-property :todo-type headline)))
  1820. (priority (and (plist-get info :with-priority)
  1821. (org-element-property :priority headline)))
  1822. (text (org-export-data-with-backend
  1823. (org-export-get-alt-title headline info)
  1824. ;; Create an anonymous back-end that will ignore any
  1825. ;; footnote-reference, link, radio-target and target
  1826. ;; in table of contents.
  1827. (org-export-create-backend
  1828. :parent 'html
  1829. :transcoders '((footnote-reference . ignore)
  1830. (link . (lambda (object c i) c))
  1831. (radio-target . (lambda (object c i) c))
  1832. (target . ignore)))
  1833. info))
  1834. (tags (and (eq (plist-get info :with-tags) t)
  1835. (org-export-get-tags headline info))))
  1836. (format "<a href=\"#%s\">%s</a>"
  1837. ;; Label.
  1838. (org-export-solidify-link-text
  1839. (or (org-element-property :CUSTOM_ID headline)
  1840. (concat "sec-"
  1841. (mapconcat #'number-to-string headline-number "-"))))
  1842. ;; Body.
  1843. (concat
  1844. (and (not (org-export-low-level-p headline info))
  1845. (org-export-numbered-headline-p headline info)
  1846. (concat (mapconcat #'number-to-string headline-number ".")
  1847. ". "))
  1848. (apply (if (not (eq org-html-format-headline-function 'ignore))
  1849. (lambda (todo todo-type priority text tags &rest ignore)
  1850. (funcall org-html-format-headline-function
  1851. todo todo-type priority text tags))
  1852. #'org-html-format-headline)
  1853. todo todo-type priority text tags :section-number nil)))))
  1854. (defun org-html-list-of-listings (info)
  1855. "Build a list of listings.
  1856. INFO is a plist used as a communication channel. Return the list
  1857. of listings as a string, or nil if it is empty."
  1858. (let ((lol-entries (org-export-collect-listings info)))
  1859. (when lol-entries
  1860. (concat "<div id=\"list-of-listings\">\n"
  1861. (format "<h%d>%s</h%d>\n"
  1862. org-html-toplevel-hlevel
  1863. (org-html--translate "List of Listings" info)
  1864. org-html-toplevel-hlevel)
  1865. "<div id=\"text-list-of-listings\">\n<ul>\n"
  1866. (let ((count 0)
  1867. (initial-fmt (format "<span class=\"listing-number\">%s</span>"
  1868. (org-html--translate "Listing %d:" info))))
  1869. (mapconcat
  1870. (lambda (entry)
  1871. (let ((label (org-element-property :name entry))
  1872. (title (org-trim
  1873. (org-export-data
  1874. (or (org-export-get-caption entry t)
  1875. (org-export-get-caption entry))
  1876. info))))
  1877. (concat
  1878. "<li>"
  1879. (if (not label)
  1880. (concat (format initial-fmt (incf count)) " " title)
  1881. (format "<a href=\"#%s\">%s %s</a>"
  1882. (org-export-solidify-link-text label)
  1883. (format initial-fmt (incf count))
  1884. title))
  1885. "</li>")))
  1886. lol-entries "\n"))
  1887. "\n</ul>\n</div>\n</div>"))))
  1888. (defun org-html-list-of-tables (info)
  1889. "Build a list of tables.
  1890. INFO is a plist used as a communication channel. Return the list
  1891. of tables as a string, or nil if it is empty."
  1892. (let ((lol-entries (org-export-collect-tables info)))
  1893. (when lol-entries
  1894. (concat "<div id=\"list-of-tables\">\n"
  1895. (format "<h%d>%s</h%d>\n"
  1896. org-html-toplevel-hlevel
  1897. (org-html--translate "List of Tables" info)
  1898. org-html-toplevel-hlevel)
  1899. "<div id=\"text-list-of-tables\">\n<ul>\n"
  1900. (let ((count 0)
  1901. (initial-fmt (format "<span class=\"table-number\">%s</span>"
  1902. (org-html--translate "Table %d:" info))))
  1903. (mapconcat
  1904. (lambda (entry)
  1905. (let ((label (org-element-property :name entry))
  1906. (title (org-trim
  1907. (org-export-data
  1908. (or (org-export-get-caption entry t)
  1909. (org-export-get-caption entry))
  1910. info))))
  1911. (concat
  1912. "<li>"
  1913. (if (not label)
  1914. (concat (format initial-fmt (incf count)) " " title)
  1915. (format "<a href=\"#%s\">%s %s</a>"
  1916. (org-export-solidify-link-text label)
  1917. (format initial-fmt (incf count))
  1918. title))
  1919. "</li>")))
  1920. lol-entries "\n"))
  1921. "\n</ul>\n</div>\n</div>"))))
  1922. ;;; Transcode Functions
  1923. ;;;; Bold
  1924. (defun org-html-bold (bold contents info)
  1925. "Transcode BOLD from Org to HTML.
  1926. CONTENTS is the text with bold markup. INFO is a plist holding
  1927. contextual information."
  1928. (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
  1929. contents))
  1930. ;;;; Center Block
  1931. (defun org-html-center-block (center-block contents info)
  1932. "Transcode a CENTER-BLOCK element from Org to HTML.
  1933. CONTENTS holds the contents of the block. INFO is a plist
  1934. holding contextual information."
  1935. (format "<div class=\"center\">\n%s</div>" contents))
  1936. ;;;; Clock
  1937. (defun org-html-clock (clock contents info)
  1938. "Transcode a CLOCK element from Org to HTML.
  1939. CONTENTS is nil. INFO is a plist used as a communication
  1940. channel."
  1941. (format "<p>
  1942. <span class=\"timestamp-wrapper\">
  1943. <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
  1944. </span>
  1945. </p>"
  1946. org-clock-string
  1947. (org-translate-time
  1948. (org-element-property :raw-value
  1949. (org-element-property :value clock)))
  1950. (let ((time (org-element-property :duration clock)))
  1951. (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
  1952. ;;;; Code
  1953. (defun org-html-code (code contents info)
  1954. "Transcode CODE from Org to HTML.
  1955. CONTENTS is nil. INFO is a plist holding contextual
  1956. information."
  1957. (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
  1958. (org-html-encode-plain-text (org-element-property :value code))))
  1959. ;;;; Drawer
  1960. (defun org-html-drawer (drawer contents info)
  1961. "Transcode a DRAWER element from Org to HTML.
  1962. CONTENTS holds the contents of the block. INFO is a plist
  1963. holding contextual information."
  1964. (if (functionp org-html-format-drawer-function)
  1965. (funcall org-html-format-drawer-function
  1966. (org-element-property :drawer-name drawer)
  1967. contents)
  1968. ;; If there's no user defined function: simply
  1969. ;; display contents of the drawer.
  1970. contents))
  1971. ;;;; Dynamic Block
  1972. (defun org-html-dynamic-block (dynamic-block contents info)
  1973. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  1974. CONTENTS holds the contents of the block. INFO is a plist
  1975. holding contextual information. See `org-export-data'."
  1976. contents)
  1977. ;;;; Entity
  1978. (defun org-html-entity (entity contents info)
  1979. "Transcode an ENTITY object from Org to HTML.
  1980. CONTENTS are the definition itself. INFO is a plist holding
  1981. contextual information."
  1982. (org-element-property :html entity))
  1983. ;;;; Example Block
  1984. (defun org-html-example-block (example-block contents info)
  1985. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  1986. CONTENTS is nil. INFO is a plist holding contextual
  1987. information."
  1988. (if (org-export-read-attribute :attr_html example-block :textarea)
  1989. (org-html--textarea-block example-block)
  1990. (format "<pre class=\"example\">\n%s</pre>"
  1991. (org-html-format-code example-block info))))
  1992. ;;;; Export Snippet
  1993. (defun org-html-export-snippet (export-snippet contents info)
  1994. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  1995. CONTENTS is nil. INFO is a plist holding contextual
  1996. information."
  1997. (when (eq (org-export-snippet-backend export-snippet) 'html)
  1998. (org-element-property :value export-snippet)))
  1999. ;;;; Export Block
  2000. (defun org-html-export-block (export-block contents info)
  2001. "Transcode a EXPORT-BLOCK element from Org to HTML.
  2002. CONTENTS is nil. INFO is a plist holding contextual information."
  2003. (when (string= (org-element-property :type export-block) "HTML")
  2004. (org-remove-indentation (org-element-property :value export-block))))
  2005. ;;;; Fixed Width
  2006. (defun org-html-fixed-width (fixed-width contents info)
  2007. "Transcode a FIXED-WIDTH element from Org to HTML.
  2008. CONTENTS is nil. INFO is a plist holding contextual information."
  2009. (format "<pre class=\"example\">\n%s</pre>"
  2010. (org-html-do-format-code
  2011. (org-remove-indentation
  2012. (org-element-property :value fixed-width)))))
  2013. ;;;; Footnote Reference
  2014. (defun org-html-footnote-reference (footnote-reference contents info)
  2015. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  2016. CONTENTS is nil. INFO is a plist holding contextual information."
  2017. (concat
  2018. ;; Insert separator between two footnotes in a row.
  2019. (let ((prev (org-export-get-previous-element footnote-reference info)))
  2020. (when (eq (org-element-type prev) 'footnote-reference)
  2021. org-html-footnote-separator))
  2022. (cond
  2023. ((not (org-export-footnote-first-reference-p footnote-reference info))
  2024. (org-html-format-footnote-reference
  2025. (org-export-get-footnote-number footnote-reference info)
  2026. "IGNORED" 100))
  2027. ;; Inline definitions are secondary strings.
  2028. ((eq (org-element-property :type footnote-reference) 'inline)
  2029. (org-html-format-footnote-reference
  2030. (org-export-get-footnote-number footnote-reference info)
  2031. "IGNORED" 1))
  2032. ;; Non-inline footnotes definitions are full Org data.
  2033. (t (org-html-format-footnote-reference
  2034. (org-export-get-footnote-number footnote-reference info)
  2035. "IGNORED" 1)))))
  2036. ;;;; Headline
  2037. (defun org-html-format-headline--wrap
  2038. (headline info &optional format-function &rest extra-keys)
  2039. "Transcode a HEADLINE element from Org to HTML.
  2040. CONTENTS holds the contents of the headline. INFO is a plist
  2041. holding contextual information."
  2042. (let* ((level (+ (org-export-get-relative-level headline info)
  2043. (1- org-html-toplevel-hlevel)))
  2044. (headline-number (org-export-get-headline-number headline info))
  2045. (section-number (and (not (org-export-low-level-p headline info))
  2046. (org-export-numbered-headline-p headline info)
  2047. (mapconcat 'number-to-string
  2048. headline-number ".")))
  2049. (todo (and (plist-get info :with-todo-keywords)
  2050. (let ((todo (org-element-property :todo-keyword headline)))
  2051. (and todo (org-export-data todo info)))))
  2052. (todo-type (and todo (org-element-property :todo-type headline)))
  2053. (priority (and (plist-get info :with-priority)
  2054. (org-element-property :priority headline)))
  2055. (text (org-export-data (org-element-property :title headline) info))
  2056. (tags (and (plist-get info :with-tags)
  2057. (org-export-get-tags headline info)))
  2058. (headline-label (or (org-element-property :CUSTOM_ID headline)
  2059. (concat "sec-" (mapconcat 'number-to-string
  2060. headline-number "-"))))
  2061. (format-function
  2062. (cond ((functionp format-function) format-function)
  2063. ((not (eq org-html-format-headline-function 'ignore))
  2064. (lambda (todo todo-type priority text tags &rest ignore)
  2065. (funcall org-html-format-headline-function
  2066. todo todo-type priority text tags)))
  2067. (t 'org-html-format-headline))))
  2068. (apply format-function
  2069. todo todo-type priority text tags
  2070. :headline-label headline-label :level level
  2071. :section-number section-number extra-keys)))
  2072. (defun org-html-headline (headline contents info)
  2073. "Transcode a HEADLINE element from Org to HTML.
  2074. CONTENTS holds the contents of the headline. INFO is a plist
  2075. holding contextual information."
  2076. ;; Empty contents?
  2077. (setq contents (or contents ""))
  2078. (let* ((numberedp (org-export-numbered-headline-p headline info))
  2079. (level (org-export-get-relative-level headline info))
  2080. (text (org-export-data (org-element-property :title headline) info))
  2081. (todo (and (plist-get info :with-todo-keywords)
  2082. (let ((todo (org-element-property :todo-keyword headline)))
  2083. (and todo (org-export-data todo info)))))
  2084. (todo-type (and todo (org-element-property :todo-type headline)))
  2085. (tags (and (plist-get info :with-tags)
  2086. (org-export-get-tags headline info)))
  2087. (priority (and (plist-get info :with-priority)
  2088. (org-element-property :priority headline)))
  2089. (section-number (and (org-export-numbered-headline-p headline info)
  2090. (mapconcat 'number-to-string
  2091. (org-export-get-headline-number
  2092. headline info) ".")))
  2093. ;; Create the headline text.
  2094. (full-text (org-html-format-headline--wrap headline info)))
  2095. (cond
  2096. ;; Case 1: This is a footnote section: ignore it.
  2097. ((org-element-property :footnote-section-p headline) nil)
  2098. ;; Case 2. This is a deep sub-tree: export it as a list item.
  2099. ;; Also export as items headlines for which no section
  2100. ;; format has been found.
  2101. ((org-export-low-level-p headline info)
  2102. ;; Build the real contents of the sub-tree.
  2103. (let* ((type (if numberedp 'ordered 'unordered))
  2104. (itemized-body (org-html-format-list-item
  2105. contents type nil info nil full-text)))
  2106. (concat
  2107. (and (org-export-first-sibling-p headline info)
  2108. (org-html-begin-plain-list type))
  2109. itemized-body
  2110. (and (org-export-last-sibling-p headline info)
  2111. (org-html-end-plain-list type)))))
  2112. ;; Case 3. Standard headline. Export it as a section.
  2113. (t
  2114. (let* ((section-number (mapconcat 'number-to-string
  2115. (org-export-get-headline-number
  2116. headline info) "-"))
  2117. (ids (remove 'nil
  2118. (list (org-element-property :CUSTOM_ID headline)
  2119. (concat "sec-" section-number)
  2120. (org-element-property :ID headline))))
  2121. (preferred-id (car ids))
  2122. (extra-ids (cdr ids))
  2123. (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
  2124. (level1 (+ level (1- org-html-toplevel-hlevel)))
  2125. (first-content (car (org-element-contents headline))))
  2126. (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
  2127. (org-html--container headline info)
  2128. (format "outline-container-%s"
  2129. (or (org-element-property :CUSTOM_ID headline)
  2130. (concat "sec-" section-number)))
  2131. (concat (format "outline-%d" level1) (and extra-class " ")
  2132. extra-class)
  2133. (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
  2134. level1
  2135. preferred-id
  2136. (mapconcat
  2137. (lambda (x)
  2138. (let ((id (org-export-solidify-link-text
  2139. (if (org-uuidgen-p x) (concat "ID-" x)
  2140. x))))
  2141. (org-html--anchor id)))
  2142. extra-ids "")
  2143. full-text
  2144. level1)
  2145. ;; When there is no section, pretend there is an empty
  2146. ;; one to get the correct <div class="outline- ...>
  2147. ;; which is needed by `org-info.js'.
  2148. (if (not (eq (org-element-type first-content) 'section))
  2149. (concat (org-html-section first-content "" info)
  2150. contents)
  2151. contents)
  2152. (org-html--container headline info)))))))
  2153. (defun org-html--container (headline info)
  2154. (or (org-element-property :HTML_CONTAINER headline)
  2155. (if (= 1 (org-export-get-relative-level headline info))
  2156. (plist-get info :html-container)
  2157. "div")))
  2158. ;;;; Horizontal Rule
  2159. (defun org-html-horizontal-rule (horizontal-rule contents info)
  2160. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  2161. CONTENTS is nil. INFO is a plist holding contextual information."
  2162. (org-html-close-tag "hr" nil info))
  2163. ;;;; Inline Src Block
  2164. (defun org-html-inline-src-block (inline-src-block contents info)
  2165. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  2166. CONTENTS holds the contents of the item. INFO is a plist holding
  2167. contextual information."
  2168. (let* ((org-lang (org-element-property :language inline-src-block))
  2169. (code (org-element-property :value inline-src-block)))
  2170. (error "Cannot export inline src block")))
  2171. ;;;; Inlinetask
  2172. (defun org-html-format-section (text class &optional id)
  2173. "Format a section with TEXT into a HTML div with CLASS and ID."
  2174. (let ((extra (concat (when id (format " id=\"%s\"" id)))))
  2175. (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
  2176. (defun org-html-inlinetask (inlinetask contents info)
  2177. "Transcode an INLINETASK element from Org to HTML.
  2178. CONTENTS holds the contents of the block. INFO is a plist
  2179. holding contextual information."
  2180. (cond
  2181. ;; If `org-html-format-inlinetask-function' is not 'ignore, call it
  2182. ;; with appropriate arguments.
  2183. ((not (eq org-html-format-inlinetask-function 'ignore))
  2184. (let ((format-function
  2185. (function*
  2186. (lambda (todo todo-type priority text tags
  2187. &key contents &allow-other-keys)
  2188. (funcall org-html-format-inlinetask-function
  2189. todo todo-type priority text tags contents)))))
  2190. (org-html-format-headline--wrap
  2191. inlinetask info format-function :contents contents)))
  2192. ;; Otherwise, use a default template.
  2193. (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
  2194. (org-html-format-headline--wrap inlinetask info)
  2195. (org-html-close-tag "br" nil info)
  2196. contents))))
  2197. ;;;; Italic
  2198. (defun org-html-italic (italic contents info)
  2199. "Transcode ITALIC from Org to HTML.
  2200. CONTENTS is the text with italic markup. INFO is a plist holding
  2201. contextual information."
  2202. (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
  2203. ;;;; Item
  2204. (defun org-html-checkbox (checkbox info)
  2205. "Format CHECKBOX into HTML.
  2206. INFO is a plist holding contextual information. See
  2207. `org-html-checkbox-type' for customization options."
  2208. (cdr (assq checkbox
  2209. (cdr (assq org-html-checkbox-type org-html-checkbox-types)))))
  2210. (defun org-html-format-list-item (contents type checkbox info
  2211. &optional term-counter-id
  2212. headline)
  2213. "Format a list item into HTML."
  2214. (let ((checkbox (concat (org-html-checkbox checkbox info)
  2215. (and checkbox " ")))
  2216. (br (org-html-close-tag "br" nil info)))
  2217. (concat
  2218. (case type
  2219. (ordered
  2220. (let* ((counter term-counter-id)
  2221. (extra (if counter (format " value=\"%s\"" counter) "")))
  2222. (concat
  2223. (format "<li%s>" extra)
  2224. (when headline (concat headline br)))))
  2225. (unordered
  2226. (let* ((id term-counter-id)
  2227. (extra (if id (format " id=\"%s\"" id) "")))
  2228. (concat
  2229. (format "<li%s>" extra)
  2230. (when headline (concat headline br)))))
  2231. (descriptive
  2232. (let* ((term term-counter-id))
  2233. (setq term (or term "(no term)"))
  2234. ;; Check-boxes in descriptive lists are associated to tag.
  2235. (concat (format "<dt> %s </dt>"
  2236. (concat checkbox term))
  2237. "<dd>"))))
  2238. (unless (eq type 'descriptive) checkbox)
  2239. contents
  2240. (case type
  2241. (ordered "</li>")
  2242. (unordered "</li>")
  2243. (descriptive "</dd>")))))
  2244. (defun org-html-item (item contents info)
  2245. "Transcode an ITEM element from Org to HTML.
  2246. CONTENTS holds the contents of the item. INFO is a plist holding
  2247. contextual information."
  2248. (let* ((plain-list (org-export-get-parent item))
  2249. (type (org-element-property :type plain-list))
  2250. (counter (org-element-property :counter item))
  2251. (checkbox (org-element-property :checkbox item))
  2252. (tag (let ((tag (org-element-property :tag item)))
  2253. (and tag (org-export-data tag info)))))
  2254. (org-html-format-list-item
  2255. contents type checkbox info (or tag counter))))
  2256. ;;;; Keyword
  2257. (defun org-html-keyword (keyword contents info)
  2258. "Transcode a KEYWORD element from Org to HTML.
  2259. CONTENTS is nil. INFO is a plist holding contextual information."
  2260. (let ((key (org-element-property :key keyword))
  2261. (value (org-element-property :value keyword)))
  2262. (cond
  2263. ((string= key "HTML") value)
  2264. ((string= key "TOC")
  2265. (let ((value (downcase value)))
  2266. (cond
  2267. ((string-match "\\<headlines\\>" value)
  2268. (let ((depth (or (and (string-match "[0-9]+" value)
  2269. (string-to-number (match-string 0 value)))
  2270. (plist-get info :with-toc))))
  2271. (org-html-toc depth info)))
  2272. ((string= "listings" value) (org-html-list-of-listings info))
  2273. ((string= "tables" value) (org-html-list-of-tables info))))))))
  2274. ;;;; Latex Environment
  2275. (defun org-html-format-latex (latex-frag processing-type info)
  2276. "Format a LaTeX fragment LATEX-FRAG into HTML.
  2277. PROCESSING-TYPE designates the tool used for conversion. It is
  2278. a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
  2279. and t. See `org-html-with-latex' for more information. INFO is
  2280. a plist containing export properties."
  2281. (let ((cache-relpath "") (cache-dir ""))
  2282. (unless (eq processing-type 'mathjax)
  2283. (let ((bfn (or (buffer-file-name)
  2284. (make-temp-name
  2285. (expand-file-name "latex" temporary-file-directory))))
  2286. (latex-header
  2287. (let ((header (plist-get info :latex-header)))
  2288. (and header
  2289. (concat (mapconcat
  2290. (lambda (line) (concat "#+LATEX_HEADER: " line))
  2291. (org-split-string header "\n")
  2292. "\n")
  2293. "\n")))))
  2294. (setq cache-relpath
  2295. (concat "ltxpng/"
  2296. (file-name-sans-extension
  2297. (file-name-nondirectory bfn)))
  2298. cache-dir (file-name-directory bfn))
  2299. ;; Re-create LaTeX environment from original buffer in
  2300. ;; temporary buffer so that dvipng/imagemagick can properly
  2301. ;; turn the fragment into an image.
  2302. (setq latex-frag (concat latex-header latex-frag))))
  2303. (with-temp-buffer
  2304. (insert latex-frag)
  2305. (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
  2306. nil nil processing-type)
  2307. (buffer-string))))
  2308. (defun org-html-latex-environment (latex-environment contents info)
  2309. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  2310. CONTENTS is nil. INFO is a plist holding contextual information."
  2311. (let ((processing-type (plist-get info :with-latex))
  2312. (latex-frag (org-remove-indentation
  2313. (org-element-property :value latex-environment)))
  2314. (attributes (org-export-read-attribute :attr_html latex-environment)))
  2315. (case processing-type
  2316. ((t mathjax)
  2317. (org-html-format-latex latex-frag 'mathjax info))
  2318. ((dvipng imagemagick)
  2319. (let ((formula-link
  2320. (org-html-format-latex latex-frag processing-type info)))
  2321. (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
  2322. ;; Do not provide a caption or a name to be consistent with
  2323. ;; `mathjax' handling.
  2324. (org-html--wrap-image
  2325. (org-html--format-image
  2326. (match-string 1 formula-link) attributes info) info))))
  2327. (t latex-frag))))
  2328. ;;;; Latex Fragment
  2329. (defun org-html-latex-fragment (latex-fragment contents info)
  2330. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2331. CONTENTS is nil. INFO is a plist holding contextual information."
  2332. (let ((latex-frag (org-element-property :value latex-fragment))
  2333. (processing-type (plist-get info :with-latex)))
  2334. (case processing-type
  2335. ((t mathjax)
  2336. (org-html-format-latex latex-frag 'mathjax info))
  2337. ((dvipng imagemagick)
  2338. (let ((formula-link
  2339. (org-html-format-latex latex-frag processing-type info)))
  2340. (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
  2341. (org-html--format-image (match-string 1 formula-link) nil info))))
  2342. (t latex-frag))))
  2343. ;;;; Line Break
  2344. (defun org-html-line-break (line-break contents info)
  2345. "Transcode a LINE-BREAK object from Org to HTML.
  2346. CONTENTS is nil. INFO is a plist holding contextual information."
  2347. (concat (org-html-close-tag "br" nil info) "\n"))
  2348. ;;;; Link
  2349. (defun org-html-inline-image-p (link info)
  2350. "Non-nil when LINK is meant to appear as an image.
  2351. INFO is a plist used as a communication channel. LINK is an
  2352. inline image when it has no description and targets an image
  2353. file (see `org-html-inline-image-rules' for more information), or
  2354. if its description is a single link targeting an image file."
  2355. (if (not (org-element-contents link))
  2356. (org-export-inline-image-p link org-html-inline-image-rules)
  2357. (not
  2358. (let ((link-count 0))
  2359. (org-element-map (org-element-contents link)
  2360. (cons 'plain-text org-element-all-objects)
  2361. (lambda (obj)
  2362. (case (org-element-type obj)
  2363. (plain-text (org-string-nw-p obj))
  2364. (link (if (= link-count 1) t
  2365. (incf link-count)
  2366. (not (org-export-inline-image-p
  2367. obj org-html-inline-image-rules))))
  2368. (otherwise t)))
  2369. info t)))))
  2370. (defvar org-html-standalone-image-predicate)
  2371. (defun org-html-standalone-image-p (element info)
  2372. "Test if ELEMENT is a standalone image.
  2373. INFO is a plist holding contextual information.
  2374. Return non-nil, if ELEMENT is of type paragraph and its sole
  2375. content, save for white spaces, is a link that qualifies as an
  2376. inline image.
  2377. Return non-nil, if ELEMENT is of type link and its containing
  2378. paragraph has no other content save white spaces.
  2379. Return nil, otherwise.
  2380. Bind `org-html-standalone-image-predicate' to constrain paragraph
  2381. further. For example, to check for only captioned standalone
  2382. images, set it to:
  2383. \(lambda (paragraph) (org-element-property :caption paragraph))"
  2384. (let ((paragraph (case (org-element-type element)
  2385. (paragraph element)
  2386. (link (org-export-get-parent element)))))
  2387. (and (eq (org-element-type paragraph) 'paragraph)
  2388. (or (not (and (boundp 'org-html-standalone-image-predicate)
  2389. (functionp org-html-standalone-image-predicate)))
  2390. (funcall org-html-standalone-image-predicate paragraph))
  2391. (not (let ((link-count 0))
  2392. (org-element-map (org-element-contents paragraph)
  2393. (cons 'plain-text org-element-all-objects)
  2394. (lambda (obj) (case (org-element-type obj)
  2395. (plain-text (org-string-nw-p obj))
  2396. (link
  2397. (or (> (incf link-count) 1)
  2398. (not (org-html-inline-image-p obj info))))
  2399. (otherwise t)))
  2400. info 'first-match 'link))))))
  2401. (defun org-html-link (link desc info)
  2402. "Transcode a LINK object from Org to HTML.
  2403. DESC is the description part of the link, or the empty string.
  2404. INFO is a plist holding contextual information. See
  2405. `org-export-data'."
  2406. (let* ((home (when (plist-get info :html-link-home)
  2407. (org-trim (plist-get info :html-link-home))))
  2408. (use-abs-url (plist-get info :html-link-use-abs-url))
  2409. (link-org-files-as-html-maybe
  2410. (function
  2411. (lambda (raw-path info)
  2412. "Treat links to `file.org' as links to `file.html', if needed.
  2413. See `org-html-link-org-files-as-html'."
  2414. (cond
  2415. ((and org-html-link-org-files-as-html
  2416. (string= ".org"
  2417. (downcase (file-name-extension raw-path "."))))
  2418. (concat (file-name-sans-extension raw-path) "."
  2419. (plist-get info :html-extension)))
  2420. (t raw-path)))))
  2421. (type (org-element-property :type link))
  2422. (raw-path (org-element-property :path link))
  2423. ;; Ensure DESC really exists, or set it to nil.
  2424. (desc (org-string-nw-p desc))
  2425. (path
  2426. (cond
  2427. ((member type '("http" "https" "ftp" "mailto"))
  2428. (org-link-escape
  2429. (org-link-unescape
  2430. (concat type ":" raw-path)) org-link-escape-chars-browser))
  2431. ((string= type "file")
  2432. ;; Treat links to ".org" files as ".html", if needed.
  2433. (setq raw-path
  2434. (funcall link-org-files-as-html-maybe raw-path info))
  2435. ;; If file path is absolute, prepend it with protocol
  2436. ;; component - "file://".
  2437. (cond ((file-name-absolute-p raw-path)
  2438. (setq raw-path
  2439. (concat "file://" (expand-file-name
  2440. raw-path))))
  2441. ((and home use-abs-url)
  2442. (setq raw-path (concat (file-name-as-directory home) raw-path))))
  2443. ;; Add search option, if any. A search option can be
  2444. ;; relative to a custom-id or a headline title. Append
  2445. ;; a hash sign to any unresolved option, as it might point
  2446. ;; to a target.
  2447. (let ((option (org-element-property :search-option link)))
  2448. (cond ((not option) raw-path)
  2449. ((eq (aref option 0) ?#) (concat raw-path option))
  2450. (t
  2451. (let ((destination
  2452. (org-publish-resolve-external-fuzzy-link
  2453. (org-element-property :path link) option)))
  2454. (concat raw-path
  2455. (if (not destination) (concat "#" option)
  2456. (concat "#sec-"
  2457. (mapconcat #'number-to-string
  2458. destination "-")))))))))
  2459. (t raw-path)))
  2460. ;; Extract attributes from parent's paragraph. HACK: Only do
  2461. ;; this for the first link in parent (inner image link for
  2462. ;; inline images). This is needed as long as attributes
  2463. ;; cannot be set on a per link basis.
  2464. (attributes-plist
  2465. (let* ((parent (org-export-get-parent-element link))
  2466. (link (let ((container (org-export-get-parent link)))
  2467. (if (and (eq (org-element-type container) 'link)
  2468. (org-html-inline-image-p link info))
  2469. container
  2470. link))))
  2471. (and (eq (org-element-map parent 'link 'identity info t) link)
  2472. (org-export-read-attribute :attr_html parent))))
  2473. (attributes
  2474. (let ((attr (org-html--make-attribute-string attributes-plist)))
  2475. (if (org-string-nw-p attr) (concat " " attr) "")))
  2476. protocol)
  2477. (cond
  2478. ;; Image file.
  2479. ((and org-html-inline-images
  2480. (org-export-inline-image-p link org-html-inline-image-rules))
  2481. (org-html--format-image path attributes-plist info))
  2482. ;; Radio target: Transcode target's contents and use them as
  2483. ;; link's description.
  2484. ((string= type "radio")
  2485. (let ((destination (org-export-resolve-radio-link link info)))
  2486. (when destination
  2487. (format "<a href=\"#%s\"%s>%s</a>"
  2488. (org-export-solidify-link-text path)
  2489. attributes
  2490. (org-export-data (org-element-contents destination) info)))))
  2491. ;; Links pointing to a headline: Find destination and build
  2492. ;; appropriate referencing command.
  2493. ((member type '("custom-id" "fuzzy" "id"))
  2494. (let ((destination (if (string= type "fuzzy")
  2495. (org-export-resolve-fuzzy-link link info)
  2496. (org-export-resolve-id-link link info))))
  2497. (case (org-element-type destination)
  2498. ;; ID link points to an external file.
  2499. (plain-text
  2500. (let ((fragment (concat "ID-" path))
  2501. ;; Treat links to ".org" files as ".html", if needed.
  2502. (path (funcall link-org-files-as-html-maybe
  2503. destination info)))
  2504. (format "<a href=\"%s#%s\"%s>%s</a>"
  2505. path fragment attributes (or desc destination))))
  2506. ;; Fuzzy link points nowhere.
  2507. ((nil)
  2508. (format "<i>%s</i>"
  2509. (or desc
  2510. (org-export-data
  2511. (org-element-property :raw-link link) info))))
  2512. ;; Link points to a headline.
  2513. (headline
  2514. (let ((href
  2515. ;; What href to use?
  2516. (cond
  2517. ;; Case 1: Headline is linked via it's CUSTOM_ID
  2518. ;; property. Use CUSTOM_ID.
  2519. ((string= type "custom-id")
  2520. (org-element-property :CUSTOM_ID destination))
  2521. ;; Case 2: Headline is linked via it's ID property
  2522. ;; or through other means. Use the default href.
  2523. ((member type '("id" "fuzzy"))
  2524. (format "sec-%s"
  2525. (mapconcat 'number-to-string
  2526. (org-export-get-headline-number
  2527. destination info) "-")))
  2528. (t (error "Shouldn't reach here"))))
  2529. ;; What description to use?
  2530. (desc
  2531. ;; Case 1: Headline is numbered and LINK has no
  2532. ;; description. Display section number.
  2533. (if (and (org-export-numbered-headline-p destination info)
  2534. (not desc))
  2535. (mapconcat 'number-to-string
  2536. (org-export-get-headline-number
  2537. destination info) ".")
  2538. ;; Case 2: Either the headline is un-numbered or
  2539. ;; LINK has a custom description. Display LINK's
  2540. ;; description or headline's title.
  2541. (or desc (org-export-data (org-element-property
  2542. :title destination) info)))))
  2543. (format "<a href=\"#%s\"%s>%s</a>"
  2544. (org-export-solidify-link-text href) attributes desc)))
  2545. ;; Fuzzy link points to a target or an element.
  2546. (t
  2547. (let* ((path (org-export-solidify-link-text path))
  2548. (org-html-standalone-image-predicate 'org-html--has-caption-p)
  2549. (number (cond
  2550. (desc nil)
  2551. ((org-html-standalone-image-p destination info)
  2552. (org-export-get-ordinal
  2553. (org-element-map destination 'link
  2554. 'identity info t)
  2555. info 'link 'org-html-standalone-image-p))
  2556. (t (org-export-get-ordinal
  2557. destination info nil 'org-html--has-caption-p))))
  2558. (desc (cond (desc)
  2559. ((not number) "No description for this link")
  2560. ((numberp number) (number-to-string number))
  2561. (t (mapconcat 'number-to-string number ".")))))
  2562. (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
  2563. ;; Coderef: replace link with the reference name or the
  2564. ;; equivalent line number.
  2565. ((string= type "coderef")
  2566. (let ((fragment (concat "coderef-" path)))
  2567. (format "<a href=\"#%s\"%s%s>%s</a>"
  2568. fragment
  2569. (org-trim
  2570. (format (concat "class=\"coderef\""
  2571. " onmouseover=\"CodeHighlightOn(this, '%s');\""
  2572. " onmouseout=\"CodeHighlightOff(this, '%s');\"")
  2573. fragment fragment))
  2574. attributes
  2575. (format (org-export-get-coderef-format path desc)
  2576. (org-export-resolve-coderef path info)))))
  2577. ;; Link type is handled by a special function.
  2578. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2579. (funcall protocol (org-link-unescape path) desc 'html))
  2580. ;; External link with a description part.
  2581. ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
  2582. ;; External link without a description part.
  2583. (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
  2584. ;; No path, only description. Try to do something useful.
  2585. (t (format "<i>%s</i>" desc)))))
  2586. ;;;; Node Property
  2587. (defun org-html-node-property (node-property contents info)
  2588. "Transcode a NODE-PROPERTY element from Org to HTML.
  2589. CONTENTS is nil. INFO is a plist holding contextual
  2590. information."
  2591. (format "%s:%s"
  2592. (org-element-property :key node-property)
  2593. (let ((value (org-element-property :value node-property)))
  2594. (if value (concat " " value) ""))))
  2595. ;;;; Paragraph
  2596. (defun org-html-paragraph (paragraph contents info)
  2597. "Transcode a PARAGRAPH element from Org to HTML.
  2598. CONTENTS is the contents of the paragraph, as a string. INFO is
  2599. the plist used as a communication channel."
  2600. (let* ((parent (org-export-get-parent paragraph))
  2601. (parent-type (org-element-type parent))
  2602. (style '((footnote-definition " class=\"footpara\"")))
  2603. (extra (or (cadr (assoc parent-type style)) "")))
  2604. (cond
  2605. ((and (eq (org-element-type parent) 'item)
  2606. (= (org-element-property :begin paragraph)
  2607. (org-element-property :contents-begin parent)))
  2608. ;; Leading paragraph in a list item have no tags.
  2609. contents)
  2610. ((org-html-standalone-image-p paragraph info)
  2611. ;; Standalone image.
  2612. (let ((caption
  2613. (let ((raw (org-export-data
  2614. (org-export-get-caption paragraph) info))
  2615. (org-html-standalone-image-predicate
  2616. 'org-html--has-caption-p))
  2617. (if (not (org-string-nw-p raw)) raw
  2618. (concat
  2619. "<span class=\"figure-number\">"
  2620. (format (org-html--translate "Figure %d:" info)
  2621. (org-export-get-ordinal
  2622. (org-element-map paragraph 'link
  2623. 'identity info t)
  2624. info nil 'org-html-standalone-image-p))
  2625. "</span> " raw))))
  2626. (label (org-element-property :name paragraph)))
  2627. (org-html--wrap-image contents info caption label)))
  2628. ;; Regular paragraph.
  2629. (t (format "<p%s>\n%s</p>" extra contents)))))
  2630. ;;;; Plain List
  2631. ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
  2632. ;; the correct value for the item counter
  2633. (defun org-html-begin-plain-list (type &optional arg1)
  2634. "Insert the beginning of the HTML list depending on TYPE.
  2635. When ARG1 is a string, use it as the start parameter for ordered
  2636. lists."
  2637. (case type
  2638. (ordered
  2639. (format "<ol class=\"org-ol\"%s>"
  2640. (if arg1 (format " start=\"%d\"" arg1) "")))
  2641. (unordered "<ul class=\"org-ul\">")
  2642. (descriptive "<dl class=\"org-dl\">")))
  2643. (defun org-html-end-plain-list (type)
  2644. "Insert the end of the HTML list depending on TYPE."
  2645. (case type
  2646. (ordered "</ol>")
  2647. (unordered "</ul>")
  2648. (descriptive "</dl>")))
  2649. (defun org-html-plain-list (plain-list contents info)
  2650. "Transcode a PLAIN-LIST element from Org to HTML.
  2651. CONTENTS is the contents of the list. INFO is a plist holding
  2652. contextual information."
  2653. (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
  2654. (type (org-element-property :type plain-list)))
  2655. (format "%s\n%s%s"
  2656. (org-html-begin-plain-list type)
  2657. contents (org-html-end-plain-list type))))
  2658. ;;;; Plain Text
  2659. (defun org-html-convert-special-strings (string)
  2660. "Convert special characters in STRING to HTML."
  2661. (let ((all org-html-special-string-regexps)
  2662. e a re rpl start)
  2663. (while (setq a (pop all))
  2664. (setq re (car a) rpl (cdr a) start 0)
  2665. (while (string-match re string start)
  2666. (setq string (replace-match rpl t nil string))))
  2667. string))
  2668. (defun org-html-encode-plain-text (text)
  2669. "Convert plain text characters from TEXT to HTML equivalent.
  2670. Possible conversions are set in `org-html-protect-char-alist'."
  2671. (mapc
  2672. (lambda (pair)
  2673. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
  2674. org-html-protect-char-alist)
  2675. text)
  2676. (defun org-html-plain-text (text info)
  2677. "Transcode a TEXT string from Org to HTML.
  2678. TEXT is the string to transcode. INFO is a plist holding
  2679. contextual information."
  2680. (let ((output text))
  2681. ;; Protect following characters: <, >, &.
  2682. (setq output (org-html-encode-plain-text output))
  2683. ;; Handle smart quotes. Be sure to provide original string since
  2684. ;; OUTPUT may have been modified.
  2685. (when (plist-get info :with-smart-quotes)
  2686. (setq output (org-export-activate-smart-quotes output :html info text)))
  2687. ;; Handle special strings.
  2688. (when (plist-get info :with-special-strings)
  2689. (setq output (org-html-convert-special-strings output)))
  2690. ;; Handle break preservation if required.
  2691. (when (plist-get info :preserve-breaks)
  2692. (setq output
  2693. (replace-regexp-in-string
  2694. "\\(\\\\\\\\\\)?[ \t]*\n"
  2695. (concat (org-html-close-tag "br" nil info) "\n") output)))
  2696. ;; Return value.
  2697. output))
  2698. ;; Planning
  2699. (defun org-html-planning (planning contents info)
  2700. "Transcode a PLANNING element from Org to HTML.
  2701. CONTENTS is nil. INFO is a plist used as a communication
  2702. channel."
  2703. (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
  2704. (format
  2705. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  2706. (mapconcat
  2707. 'identity
  2708. (delq nil
  2709. (list
  2710. (let ((closed (org-element-property :closed planning)))
  2711. (when closed
  2712. (format span-fmt org-closed-string
  2713. (org-translate-time
  2714. (org-element-property :raw-value closed)))))
  2715. (let ((deadline (org-element-property :deadline planning)))
  2716. (when deadline
  2717. (format span-fmt org-deadline-string
  2718. (org-translate-time
  2719. (org-element-property :raw-value deadline)))))
  2720. (let ((scheduled (org-element-property :scheduled planning)))
  2721. (when scheduled
  2722. (format span-fmt org-scheduled-string
  2723. (org-translate-time
  2724. (org-element-property :raw-value scheduled)))))))
  2725. " "))))
  2726. ;;;; Property Drawer
  2727. (defun org-html-property-drawer (property-drawer contents info)
  2728. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2729. CONTENTS holds the contents of the drawer. INFO is a plist
  2730. holding contextual information."
  2731. (and (org-string-nw-p contents)
  2732. (format "<pre class=\"example\">\n%s</pre>" contents)))
  2733. ;;;; Quote Block
  2734. (defun org-html-quote-block (quote-block contents info)
  2735. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2736. CONTENTS holds the contents of the block. INFO is a plist
  2737. holding contextual information."
  2738. (format "<blockquote>\n%s</blockquote>" contents))
  2739. ;;;; Section
  2740. (defun org-html-section (section contents info)
  2741. "Transcode a SECTION element from Org to HTML.
  2742. CONTENTS holds the contents of the section. INFO is a plist
  2743. holding contextual information."
  2744. (let ((parent (org-export-get-parent-headline section)))
  2745. ;; Before first headline: no container, just return CONTENTS.
  2746. (if (not parent) contents
  2747. ;; Get div's class and id references.
  2748. (let* ((class-num (+ (org-export-get-relative-level parent info)
  2749. (1- org-html-toplevel-hlevel)))
  2750. (section-number
  2751. (mapconcat
  2752. 'number-to-string
  2753. (org-export-get-headline-number parent info) "-")))
  2754. ;; Build return value.
  2755. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2756. class-num
  2757. (or (org-element-property :CUSTOM_ID parent) section-number)
  2758. contents)))))
  2759. ;;;; Radio Target
  2760. (defun org-html-radio-target (radio-target text info)
  2761. "Transcode a RADIO-TARGET object from Org to HTML.
  2762. TEXT is the text of the target. INFO is a plist holding
  2763. contextual information."
  2764. (let ((id (org-export-solidify-link-text
  2765. (org-element-property :value radio-target))))
  2766. (org-html--anchor id text)))
  2767. ;;;; Special Block
  2768. (defun org-html-special-block (special-block contents info)
  2769. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2770. CONTENTS holds the contents of the block. INFO is a plist
  2771. holding contextual information."
  2772. (let* ((block-type (downcase
  2773. (org-element-property :type special-block)))
  2774. (contents (or contents ""))
  2775. (html5-fancy (and (org-html-html5-p info)
  2776. (plist-get info :html-html5-fancy)
  2777. (member block-type org-html-html5-elements)))
  2778. (attributes (org-export-read-attribute :attr_html special-block)))
  2779. (unless html5-fancy
  2780. (let ((class (plist-get attributes :class)))
  2781. (setq attributes (plist-put attributes :class
  2782. (if class (concat class " " block-type)
  2783. block-type)))))
  2784. (setq attributes (org-html--make-attribute-string attributes))
  2785. (when (not (equal attributes ""))
  2786. (setq attributes (concat " " attributes)))
  2787. (if html5-fancy
  2788. (format "<%s%s>\n%s</%s>" block-type attributes
  2789. contents block-type)
  2790. (format "<div%s>\n%s\n</div>" attributes contents))))
  2791. ;;;; Src Block
  2792. (defun org-html-src-block (src-block contents info)
  2793. "Transcode a SRC-BLOCK element from Org to HTML.
  2794. CONTENTS holds the contents of the item. INFO is a plist holding
  2795. contextual information."
  2796. (if (org-export-read-attribute :attr_html src-block :textarea)
  2797. (org-html--textarea-block src-block)
  2798. (let ((lang (org-element-property :language src-block))
  2799. (caption (org-export-get-caption src-block))
  2800. (code (org-html-format-code src-block info))
  2801. (label (let ((lbl (org-element-property :name src-block)))
  2802. (if (not lbl) ""
  2803. (format " id=\"%s\""
  2804. (org-export-solidify-link-text lbl))))))
  2805. (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
  2806. (format
  2807. "<div class=\"org-src-container\">\n%s%s\n</div>"
  2808. (if (not caption) ""
  2809. (format "<label class=\"org-src-name\">%s</label>"
  2810. (org-export-data caption info)))
  2811. (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
  2812. ;;;; Statistics Cookie
  2813. (defun org-html-statistics-cookie (statistics-cookie contents info)
  2814. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2815. CONTENTS is nil. INFO is a plist holding contextual information."
  2816. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2817. (format "<code>%s</code>" cookie-value)))
  2818. ;;;; Strike-Through
  2819. (defun org-html-strike-through (strike-through contents info)
  2820. "Transcode STRIKE-THROUGH from Org to HTML.
  2821. CONTENTS is the text with strike-through markup. INFO is a plist
  2822. holding contextual information."
  2823. (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
  2824. contents))
  2825. ;;;; Subscript
  2826. (defun org-html-subscript (subscript contents info)
  2827. "Transcode a SUBSCRIPT object from Org to HTML.
  2828. CONTENTS is the contents of the object. INFO is a plist holding
  2829. contextual information."
  2830. (format "<sub>%s</sub>" contents))
  2831. ;;;; Superscript
  2832. (defun org-html-superscript (superscript contents info)
  2833. "Transcode a SUPERSCRIPT object from Org to HTML.
  2834. CONTENTS is the contents of the object. INFO is a plist holding
  2835. contextual information."
  2836. (format "<sup>%s</sup>" contents))
  2837. ;;;; Table Cell
  2838. (defun org-html-table-cell (table-cell contents info)
  2839. "Transcode a TABLE-CELL element from Org to HTML.
  2840. CONTENTS is nil. INFO is a plist used as a communication
  2841. channel."
  2842. (let* ((table-row (org-export-get-parent table-cell))
  2843. (table (org-export-get-parent-table table-cell))
  2844. (cell-attrs
  2845. (if (not org-html-table-align-individual-fields) ""
  2846. (format (if (and (boundp 'org-html-format-table-no-css)
  2847. org-html-format-table-no-css)
  2848. " align=\"%s\"" " class=\"%s\"")
  2849. (org-export-table-cell-alignment table-cell info)))))
  2850. (when (or (not contents) (string= "" (org-trim contents)))
  2851. (setq contents "&#xa0;"))
  2852. (cond
  2853. ((and (org-export-table-has-header-p table info)
  2854. (= 1 (org-export-table-row-group table-row info)))
  2855. (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
  2856. contents (cdr org-html-table-header-tags)))
  2857. ((and org-html-table-use-header-tags-for-first-column
  2858. (zerop (cdr (org-export-table-cell-address table-cell info))))
  2859. (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
  2860. contents (cdr org-html-table-header-tags)))
  2861. (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
  2862. contents (cdr org-html-table-data-tags))))))
  2863. ;;;; Table Row
  2864. (defun org-html-table-row (table-row contents info)
  2865. "Transcode a TABLE-ROW element from Org to HTML.
  2866. CONTENTS is the contents of the row. INFO is a plist used as a
  2867. communication channel."
  2868. ;; Rules are ignored since table separators are deduced from
  2869. ;; borders of the current row.
  2870. (when (eq (org-element-property :type table-row) 'standard)
  2871. (let* ((rowgroup-number (org-export-table-row-group table-row info))
  2872. (row-number (org-export-table-row-number table-row info))
  2873. (start-rowgroup-p
  2874. (org-export-table-row-starts-rowgroup-p table-row info))
  2875. (end-rowgroup-p
  2876. (org-export-table-row-ends-rowgroup-p table-row info))
  2877. ;; `top-row-p' and `end-rowgroup-p' are not used directly
  2878. ;; but should be set so that `org-html-table-row-tags' can
  2879. ;; use them (see the docstring of this variable.)
  2880. (top-row-p (and (equal start-rowgroup-p '(top))
  2881. (equal end-rowgroup-p '(below top))))
  2882. (bottom-row-p (and (equal start-rowgroup-p '(above))
  2883. (equal end-rowgroup-p '(bottom above))))
  2884. (rowgroup-tags
  2885. (cond
  2886. ;; Case 1: Row belongs to second or subsequent rowgroups.
  2887. ((not (= 1 rowgroup-number))
  2888. '("<tbody>" . "\n</tbody>"))
  2889. ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
  2890. ((org-export-table-has-header-p
  2891. (org-export-get-parent-table table-row) info)
  2892. '("<thead>" . "\n</thead>"))
  2893. ;; Case 2: Row is from first and only row group.
  2894. (t '("<tbody>" . "\n</tbody>")))))
  2895. (concat
  2896. ;; Begin a rowgroup?
  2897. (when start-rowgroup-p (car rowgroup-tags))
  2898. ;; Actual table row
  2899. (concat "\n" (eval (car org-html-table-row-tags))
  2900. contents
  2901. "\n"
  2902. (eval (cdr org-html-table-row-tags)))
  2903. ;; End a rowgroup?
  2904. (when end-rowgroup-p (cdr rowgroup-tags))))))
  2905. ;;;; Table
  2906. (defun org-html-table-first-row-data-cells (table info)
  2907. "Transcode the first row of TABLE.
  2908. INFO is a plist used as a communication channel."
  2909. (let ((table-row
  2910. (org-element-map table 'table-row
  2911. (lambda (row)
  2912. (unless (eq (org-element-property :type row) 'rule) row))
  2913. info 'first-match))
  2914. (special-column-p (org-export-table-has-special-column-p table)))
  2915. (if (not special-column-p) (org-element-contents table-row)
  2916. (cdr (org-element-contents table-row)))))
  2917. (defun org-html-table--table.el-table (table info)
  2918. "Format table.el tables into HTML.
  2919. INFO is a plist used as a communication channel."
  2920. (when (eq (org-element-property :type table) 'table.el)
  2921. (require 'table)
  2922. (let ((outbuf (with-current-buffer
  2923. (get-buffer-create "*org-export-table*")
  2924. (erase-buffer) (current-buffer))))
  2925. (with-temp-buffer
  2926. (insert (org-element-property :value table))
  2927. (goto-char 1)
  2928. (re-search-forward "^[ \t]*|[^|]" nil t)
  2929. (table-generate-source 'html outbuf))
  2930. (with-current-buffer outbuf
  2931. (prog1 (org-trim (buffer-string))
  2932. (kill-buffer) )))))
  2933. (defun org-html-table (table contents info)
  2934. "Transcode a TABLE element from Org to HTML.
  2935. CONTENTS is the contents of the table. INFO is a plist holding
  2936. contextual information."
  2937. (case (org-element-property :type table)
  2938. ;; Case 1: table.el table. Convert it using appropriate tools.
  2939. (table.el (org-html-table--table.el-table table info))
  2940. ;; Case 2: Standard table.
  2941. (t
  2942. (let* ((label (org-element-property :name table))
  2943. (caption (org-export-get-caption table))
  2944. (number (org-export-get-ordinal
  2945. table info nil 'org-html--has-caption-p))
  2946. (attributes
  2947. (org-html--make-attribute-string
  2948. (org-combine-plists
  2949. (and label (list :id (org-export-solidify-link-text label)))
  2950. (and (not (org-html-html5-p info))
  2951. (plist-get info :html-table-attributes))
  2952. (org-export-read-attribute :attr_html table))))
  2953. (alignspec
  2954. (if (and (boundp 'org-html-format-table-no-css)
  2955. org-html-format-table-no-css)
  2956. "align=\"%s\"" "class=\"%s\""))
  2957. (table-column-specs
  2958. (function
  2959. (lambda (table info)
  2960. (mapconcat
  2961. (lambda (table-cell)
  2962. (let ((alignment (org-export-table-cell-alignment
  2963. table-cell info)))
  2964. (concat
  2965. ;; Begin a colgroup?
  2966. (when (org-export-table-cell-starts-colgroup-p
  2967. table-cell info)
  2968. "\n<colgroup>")
  2969. ;; Add a column. Also specify it's alignment.
  2970. (format "\n%s"
  2971. (org-html-close-tag
  2972. "col" (concat " " (format alignspec alignment)) info))
  2973. ;; End a colgroup?
  2974. (when (org-export-table-cell-ends-colgroup-p
  2975. table-cell info)
  2976. "\n</colgroup>"))))
  2977. (org-html-table-first-row-data-cells table info) "\n")))))
  2978. (format "<table%s>\n%s\n%s\n%s</table>"
  2979. (if (equal attributes "") "" (concat " " attributes))
  2980. (if (not caption) ""
  2981. (format (if org-html-table-caption-above
  2982. "<caption class=\"t-above\">%s</caption>"
  2983. "<caption class=\"t-bottom\">%s</caption>")
  2984. (concat
  2985. "<span class=\"table-number\">"
  2986. (format (org-html--translate "Table %d:" info) number)
  2987. "</span> " (org-export-data caption info))))
  2988. (funcall table-column-specs table info)
  2989. contents)))))
  2990. ;;;; Target
  2991. (defun org-html-target (target contents info)
  2992. "Transcode a TARGET object from Org to HTML.
  2993. CONTENTS is nil. INFO is a plist holding contextual
  2994. information."
  2995. (let ((id (org-export-solidify-link-text
  2996. (org-element-property :value target))))
  2997. (org-html--anchor id)))
  2998. ;;;; Timestamp
  2999. (defun org-html-timestamp (timestamp contents info)
  3000. "Transcode a TIMESTAMP object from Org to HTML.
  3001. CONTENTS is nil. INFO is a plist holding contextual
  3002. information."
  3003. (let ((value (org-html-plain-text
  3004. (org-timestamp-translate timestamp) info)))
  3005. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  3006. (replace-regexp-in-string "--" "&#x2013;" value))))
  3007. ;;;; Underline
  3008. (defun org-html-underline (underline contents info)
  3009. "Transcode UNDERLINE from Org to HTML.
  3010. CONTENTS is the text with underline markup. INFO is a plist
  3011. holding contextual information."
  3012. (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
  3013. contents))
  3014. ;;;; Verbatim
  3015. (defun org-html-verbatim (verbatim contents info)
  3016. "Transcode VERBATIM from Org to HTML.
  3017. CONTENTS is nil. INFO is a plist holding contextual
  3018. information."
  3019. (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
  3020. (org-html-encode-plain-text (org-element-property :value verbatim))))
  3021. ;;;; Verse Block
  3022. (defun org-html-verse-block (verse-block contents info)
  3023. "Transcode a VERSE-BLOCK element from Org to HTML.
  3024. CONTENTS is verse block contents. INFO is a plist holding
  3025. contextual information."
  3026. ;; Replace each newline character with line break. Also replace
  3027. ;; each blank line with a line break.
  3028. (setq contents (replace-regexp-in-string
  3029. "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
  3030. (replace-regexp-in-string
  3031. "\\(\\\\\\\\\\)?[ \t]*\n"
  3032. (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
  3033. ;; Replace each white space at beginning of a line with a
  3034. ;; non-breaking space.
  3035. (while (string-match "^[ \t]+" contents)
  3036. (let* ((num-ws (length (match-string 0 contents)))
  3037. (ws (let (out) (dotimes (i num-ws out)
  3038. (setq out (concat out "&#xa0;"))))))
  3039. (setq contents (replace-match ws nil t contents))))
  3040. (format "<p class=\"verse\">\n%s</p>" contents))
  3041. ;;; Filter Functions
  3042. (defun org-html-final-function (contents backend info)
  3043. "Filter to indent the HTML and convert HTML entities."
  3044. (with-temp-buffer
  3045. (insert contents)
  3046. (set-auto-mode t)
  3047. (if org-html-indent
  3048. (indent-region (point-min) (point-max)))
  3049. (when org-html-use-unicode-chars
  3050. (require 'mm-url)
  3051. (mm-url-decode-entities))
  3052. (buffer-substring-no-properties (point-min) (point-max))))
  3053. ;;; End-user functions
  3054. ;;;###autoload
  3055. (defun org-html-export-as-html
  3056. (&optional async subtreep visible-only body-only ext-plist)
  3057. "Export current buffer to an HTML buffer.
  3058. If narrowing is active in the current buffer, only export its
  3059. narrowed part.
  3060. If a region is active, export that region.
  3061. A non-nil optional argument ASYNC means the process should happen
  3062. asynchronously. The resulting buffer should be accessible
  3063. through the `org-export-stack' interface.
  3064. When optional argument SUBTREEP is non-nil, export the sub-tree
  3065. at point, extracting information from the headline properties
  3066. first.
  3067. When optional argument VISIBLE-ONLY is non-nil, don't export
  3068. contents of hidden elements.
  3069. When optional argument BODY-ONLY is non-nil, only write code
  3070. between \"<body>\" and \"</body>\" tags.
  3071. EXT-PLIST, when provided, is a property list with external
  3072. parameters overriding Org default settings, but still inferior to
  3073. file-local settings.
  3074. Export is done in a buffer named \"*Org HTML Export*\", which
  3075. will be displayed when `org-export-show-temporary-export-buffer'
  3076. is non-nil."
  3077. (interactive)
  3078. (org-export-to-buffer 'html "*Org HTML Export*"
  3079. async subtreep visible-only body-only ext-plist
  3080. (lambda () (set-auto-mode t))))
  3081. ;;;###autoload
  3082. (defun org-html-convert-region-to-html ()
  3083. "Assume the current region has org-mode syntax, and convert it to HTML.
  3084. This can be used in any buffer. For example, you can write an
  3085. itemized list in org-mode syntax in an HTML buffer and use this
  3086. command to convert it."
  3087. (interactive)
  3088. (org-export-replace-region-by 'html))
  3089. ;;;###autoload
  3090. (defun org-html-export-to-html
  3091. (&optional async subtreep visible-only body-only ext-plist)
  3092. "Export current buffer to a HTML file.
  3093. If narrowing is active in the current buffer, only export its
  3094. narrowed part.
  3095. If a region is active, export that region.
  3096. A non-nil optional argument ASYNC means the process should happen
  3097. asynchronously. The resulting file should be accessible through
  3098. the `org-export-stack' interface.
  3099. When optional argument SUBTREEP is non-nil, export the sub-tree
  3100. at point, extracting information from the headline properties
  3101. first.
  3102. When optional argument VISIBLE-ONLY is non-nil, don't export
  3103. contents of hidden elements.
  3104. When optional argument BODY-ONLY is non-nil, only write code
  3105. between \"<body>\" and \"</body>\" tags.
  3106. EXT-PLIST, when provided, is a property list with external
  3107. parameters overriding Org default settings, but still inferior to
  3108. file-local settings.
  3109. Return output file's name."
  3110. (interactive)
  3111. (let* ((extension (concat "." org-html-extension))
  3112. (file (org-export-output-file-name extension subtreep))
  3113. (org-export-coding-system org-html-coding-system))
  3114. (org-export-to-file 'html file
  3115. async subtreep visible-only body-only ext-plist)))
  3116. ;;;###autoload
  3117. (defun org-html-publish-to-html (plist filename pub-dir)
  3118. "Publish an org file to HTML.
  3119. FILENAME is the filename of the Org file to be published. PLIST
  3120. is the property list for the given project. PUB-DIR is the
  3121. publishing directory.
  3122. Return output file name."
  3123. (org-publish-org-to 'html filename
  3124. (concat "." (or (plist-get plist :html-extension)
  3125. org-html-extension "html"))
  3126. plist pub-dir))
  3127. (provide 'ox-html)
  3128. ;; Local variables:
  3129. ;; generated-autoload-file: "org-loaddefs.el"
  3130. ;; End:
  3131. ;;; ox-html.el ends here