ox-html.el 129 KB

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