ox-html.el 124 KB

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