ox-html.el 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521
  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-protect'.")
  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-translate-time
  1982. (org-element-property :raw-value
  1983. (org-element-property :value clock)))
  1984. (let ((time (org-element-property :duration clock)))
  1985. (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
  1986. ;;;; Code
  1987. (defun org-html-code (code contents info)
  1988. "Transcode CODE from Org to HTML.
  1989. CONTENTS is nil. INFO is a plist holding contextual
  1990. information."
  1991. (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
  1992. (org-html-encode-plain-text (org-element-property :value code))))
  1993. ;;;; Drawer
  1994. (defun org-html-drawer (drawer contents info)
  1995. "Transcode a DRAWER element from Org to HTML.
  1996. CONTENTS holds the contents of the block. INFO is a plist
  1997. holding contextual information."
  1998. (funcall (plist-get info :html-format-drawer-function)
  1999. (org-element-property :drawer-name drawer)
  2000. contents))
  2001. ;;;; Dynamic Block
  2002. (defun org-html-dynamic-block (dynamic-block contents info)
  2003. "Transcode a DYNAMIC-BLOCK element from Org to HTML.
  2004. CONTENTS holds the contents of the block. INFO is a plist
  2005. holding contextual information. See `org-export-data'."
  2006. contents)
  2007. ;;;; Entity
  2008. (defun org-html-entity (entity contents info)
  2009. "Transcode an ENTITY object from Org to HTML.
  2010. CONTENTS are the definition itself. INFO is a plist holding
  2011. contextual information."
  2012. (org-element-property :html entity))
  2013. ;;;; Example Block
  2014. (defun org-html-example-block (example-block contents info)
  2015. "Transcode a EXAMPLE-BLOCK element from Org to HTML.
  2016. CONTENTS is nil. INFO is a plist holding contextual
  2017. information."
  2018. (if (org-export-read-attribute :attr_html example-block :textarea)
  2019. (org-html--textarea-block example-block)
  2020. (format "<pre class=\"example\">\n%s</pre>"
  2021. (org-html-format-code example-block info))))
  2022. ;;;; Export Snippet
  2023. (defun org-html-export-snippet (export-snippet contents info)
  2024. "Transcode a EXPORT-SNIPPET object from Org to HTML.
  2025. CONTENTS is nil. INFO is a plist holding contextual
  2026. information."
  2027. (when (eq (org-export-snippet-backend export-snippet) 'html)
  2028. (org-element-property :value export-snippet)))
  2029. ;;;; Export Block
  2030. (defun org-html-export-block (export-block contents info)
  2031. "Transcode a EXPORT-BLOCK element from Org to HTML.
  2032. CONTENTS is nil. INFO is a plist holding contextual information."
  2033. (when (string= (org-element-property :type export-block) "HTML")
  2034. (org-remove-indentation (org-element-property :value export-block))))
  2035. ;;;; Fixed Width
  2036. (defun org-html-fixed-width (fixed-width contents info)
  2037. "Transcode a FIXED-WIDTH element from Org to HTML.
  2038. CONTENTS is nil. INFO is a plist holding contextual information."
  2039. (format "<pre class=\"example\">\n%s</pre>"
  2040. (org-html-do-format-code
  2041. (org-remove-indentation
  2042. (org-element-property :value fixed-width)))))
  2043. ;;;; Footnote Reference
  2044. (defun org-html-footnote-reference (footnote-reference contents info)
  2045. "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
  2046. CONTENTS is nil. INFO is a plist holding contextual information."
  2047. (concat
  2048. ;; Insert separator between two footnotes in a row.
  2049. (let ((prev (org-export-get-previous-element footnote-reference info)))
  2050. (when (eq (org-element-type prev) 'footnote-reference)
  2051. (plist-get info :html-footnote-separator)))
  2052. (let* ((n (org-export-get-footnote-number footnote-reference info))
  2053. (id (format "fnr.%d%s"
  2054. n
  2055. (if (org-export-footnote-first-reference-p
  2056. footnote-reference info)
  2057. ""
  2058. ".100"))))
  2059. (format
  2060. (plist-get info :html-footnote-format)
  2061. (org-html--anchor
  2062. id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
  2063. ;;;; Headline
  2064. (defun org-html-headline (headline contents info)
  2065. "Transcode a HEADLINE element from Org to HTML.
  2066. CONTENTS holds the contents of the headline. INFO is a plist
  2067. holding contextual information."
  2068. (unless (org-element-property :footnote-section-p headline)
  2069. (let* ((numberedp (org-export-numbered-headline-p headline info))
  2070. (numbers (org-export-get-headline-number headline info))
  2071. (section-number (and numbers
  2072. (mapconcat #'number-to-string numbers "-")))
  2073. (level (+ (org-export-get-relative-level headline info)
  2074. (1- (plist-get info :html-toplevel-hlevel))))
  2075. (todo (and (plist-get info :with-todo-keywords)
  2076. (let ((todo (org-element-property :todo-keyword headline)))
  2077. (and todo (org-export-data todo info)))))
  2078. (todo-type (and todo (org-element-property :todo-type headline)))
  2079. (priority (and (plist-get info :with-priority)
  2080. (org-element-property :priority headline)))
  2081. (text (org-export-data (org-element-property :title headline) info))
  2082. (tags (and (plist-get info :with-tags)
  2083. (org-export-get-tags headline info)))
  2084. (full-text (funcall (plist-get info :html-format-headline-function)
  2085. todo todo-type priority text tags info))
  2086. (contents (or contents ""))
  2087. (ids (delq nil
  2088. (list (org-element-property :CUSTOM_ID headline)
  2089. (org-export-get-headline-id headline info)
  2090. (org-element-property :ID headline))))
  2091. (preferred-id (car ids))
  2092. (extra-ids (mapconcat
  2093. (lambda (id)
  2094. (org-html--anchor
  2095. (org-export-solidify-link-text
  2096. (if (org-uuidgen-p id) (concat "ID-" id) id))
  2097. nil nil info))
  2098. (cdr ids) "")))
  2099. (if (org-export-low-level-p headline info)
  2100. ;; This is a deep sub-tree: export it as a list item.
  2101. (let* ((type (if numberedp 'ordered 'unordered))
  2102. (itemized-body
  2103. (org-html-format-list-item
  2104. contents type nil info nil
  2105. (concat (org-html--anchor preferred-id nil nil info)
  2106. extra-ids
  2107. full-text))))
  2108. (concat (and (org-export-first-sibling-p headline info)
  2109. (org-html-begin-plain-list type))
  2110. itemized-body
  2111. (and (org-export-last-sibling-p headline info)
  2112. (org-html-end-plain-list type))))
  2113. (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
  2114. (first-content (car (org-element-contents headline))))
  2115. ;; Standard headline. Export it as a section.
  2116. (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
  2117. (org-html--container headline info)
  2118. (format "outline-container-%s"
  2119. (or (org-element-property :CUSTOM_ID headline)
  2120. (org-export-get-headline-id headline info)))
  2121. (concat (format "outline-%d" level)
  2122. (and extra-class " ")
  2123. extra-class)
  2124. (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
  2125. level
  2126. preferred-id
  2127. extra-ids
  2128. (concat
  2129. (and numberedp
  2130. (format
  2131. "<span class=\"section-number-%d\">%s</span> "
  2132. level
  2133. (mapconcat #'number-to-string numbers ".")))
  2134. full-text)
  2135. level)
  2136. ;; When there is no section, pretend there is an
  2137. ;; empty one to get the correct <div
  2138. ;; class="outline-...> which is needed by
  2139. ;; `org-info.js'.
  2140. (if (eq (org-element-type first-content) 'section) contents
  2141. (concat (org-html-section first-content "" info) contents))
  2142. (org-html--container headline info)))))))
  2143. (defun org-html-format-headline-default-function
  2144. (todo todo-type priority text tags info)
  2145. "Default format function for a headline.
  2146. See `org-html-format-headline-function' for details."
  2147. (let ((todo (org-html--todo todo info))
  2148. (tags (org-html--tags tags info)))
  2149. (concat todo (and todo " ") text (and tags "&#xa0;&#xa0;&#xa0;") tags)))
  2150. (defun org-html--container (headline info)
  2151. (or (org-element-property :HTML_CONTAINER headline)
  2152. (if (= 1 (org-export-get-relative-level headline info))
  2153. (plist-get info :html-container)
  2154. "div")))
  2155. ;;;; Horizontal Rule
  2156. (defun org-html-horizontal-rule (horizontal-rule contents info)
  2157. "Transcode an HORIZONTAL-RULE object from Org to HTML.
  2158. CONTENTS is nil. INFO is a plist holding contextual information."
  2159. (org-html-close-tag "hr" nil info))
  2160. ;;;; Inline Src Block
  2161. (defun org-html-inline-src-block (inline-src-block contents info)
  2162. "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
  2163. CONTENTS holds the contents of the item. INFO is a plist holding
  2164. contextual information."
  2165. (let* ((org-lang (org-element-property :language inline-src-block))
  2166. (code (org-element-property :value inline-src-block)))
  2167. (let ((lang (org-element-property :language inline-src-block))
  2168. (code (org-html-format-code inline-src-block info))
  2169. (label (let ((lbl (org-element-property :name inline-src-block)))
  2170. (if (not lbl) ""
  2171. (format " id=\"%s\""
  2172. (org-export-solidify-link-text lbl))))))
  2173. (format "<code class=\"src src-%s\"%s>%s</code>" lang label code))))
  2174. ;;;; Inlinetask
  2175. (defun org-html-inlinetask (inlinetask contents info)
  2176. "Transcode an INLINETASK element from Org to HTML.
  2177. CONTENTS holds the contents of the block. INFO is a plist
  2178. holding contextual information."
  2179. (let* ((todo (and (plist-get info :with-todo-keywords)
  2180. (let ((todo (org-element-property :todo-keyword inlinetask)))
  2181. (and todo (org-export-data todo info)))))
  2182. (todo-type (and todo (org-element-property :todo-type inlinetask)))
  2183. (priority (and (plist-get info :with-priority)
  2184. (org-element-property :priority inlinetask)))
  2185. (text (org-export-data (org-element-property :title inlinetask) info))
  2186. (tags (and (plist-get info :with-tags)
  2187. (org-export-get-tags inlinetask info))))
  2188. (funcall (plist-get info :html-format-inlinetask-function)
  2189. todo todo-type priority text tags contents info)))
  2190. (defun org-html-format-inlinetask-default-function
  2191. (todo todo-type priority text tags contents info)
  2192. "Default format function for a inlinetasks.
  2193. See `org-html-format-inlinetask-function' for details."
  2194. (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
  2195. (org-html-format-headline-default-function
  2196. todo todo-type priority text tags info)
  2197. (org-html-close-tag "br" nil info)
  2198. contents))
  2199. ;;;; Italic
  2200. (defun org-html-italic (italic contents info)
  2201. "Transcode ITALIC from Org to HTML.
  2202. CONTENTS is the text with italic markup. INFO is a plist holding
  2203. contextual information."
  2204. (format
  2205. (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
  2206. contents))
  2207. ;;;; Item
  2208. (defun org-html-checkbox (checkbox info)
  2209. "Format CHECKBOX into HTML.
  2210. INFO is a plist holding contextual information. See
  2211. `org-html-checkbox-type' for customization options."
  2212. (cdr (assq checkbox
  2213. (cdr (assq (plist-get info :html-checkbox-type)
  2214. org-html-checkbox-types)))))
  2215. (defun org-html-format-list-item (contents type checkbox info
  2216. &optional term-counter-id
  2217. headline)
  2218. "Format a list item into HTML."
  2219. (let ((class (if checkbox
  2220. (format " class=\"%s\""
  2221. (symbol-name checkbox)) ""))
  2222. (checkbox (concat (org-html-checkbox checkbox info)
  2223. (and checkbox " ")))
  2224. (br (org-html-close-tag "br" nil info)))
  2225. (concat
  2226. (case type
  2227. (ordered
  2228. (let* ((counter term-counter-id)
  2229. (extra (if counter (format " value=\"%s\"" counter) "")))
  2230. (concat
  2231. (format "<li%s%s>" class extra)
  2232. (when headline (concat headline br)))))
  2233. (unordered
  2234. (let* ((id term-counter-id)
  2235. (extra (if id (format " id=\"%s\"" id) "")))
  2236. (concat
  2237. (format "<li%s%s>" class extra)
  2238. (when headline (concat headline br)))))
  2239. (descriptive
  2240. (let* ((term term-counter-id))
  2241. (setq term (or term "(no term)"))
  2242. ;; Check-boxes in descriptive lists are associated to tag.
  2243. (concat (format "<dt%s>%s</dt>"
  2244. class (concat checkbox term))
  2245. "<dd>"))))
  2246. (unless (eq type 'descriptive) checkbox)
  2247. contents
  2248. (case type
  2249. (ordered "</li>")
  2250. (unordered "</li>")
  2251. (descriptive "</dd>")))))
  2252. (defun org-html-item (item contents info)
  2253. "Transcode an ITEM element from Org to HTML.
  2254. CONTENTS holds the contents of the item. INFO is a plist holding
  2255. contextual information."
  2256. (let* ((plain-list (org-export-get-parent item))
  2257. (type (org-element-property :type plain-list))
  2258. (counter (org-element-property :counter item))
  2259. (checkbox (org-element-property :checkbox item))
  2260. (tag (let ((tag (org-element-property :tag item)))
  2261. (and tag (org-export-data tag info)))))
  2262. (org-html-format-list-item
  2263. contents type checkbox info (or tag counter))))
  2264. ;;;; Keyword
  2265. (defun org-html-keyword (keyword contents info)
  2266. "Transcode a KEYWORD element from Org to HTML.
  2267. CONTENTS is nil. INFO is a plist holding contextual information."
  2268. (let ((key (org-element-property :key keyword))
  2269. (value (org-element-property :value keyword)))
  2270. (cond
  2271. ((string= key "HTML") value)
  2272. ((string= key "TOC")
  2273. (let ((value (downcase value)))
  2274. (cond
  2275. ((string-match "\\<headlines\\>" value)
  2276. (let ((depth (or (and (string-match "[0-9]+" value)
  2277. (string-to-number (match-string 0 value)))
  2278. (plist-get info :with-toc))))
  2279. (org-html-toc depth info)))
  2280. ((string= "listings" value) (org-html-list-of-listings info))
  2281. ((string= "tables" value) (org-html-list-of-tables info))))))))
  2282. ;;;; Latex Environment
  2283. (defun org-html-format-latex (latex-frag processing-type info)
  2284. "Format a LaTeX fragment LATEX-FRAG into HTML.
  2285. PROCESSING-TYPE designates the tool used for conversion. It is
  2286. a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
  2287. and t. See `org-html-with-latex' for more information. INFO is
  2288. a plist containing export properties."
  2289. (let ((cache-relpath "") (cache-dir ""))
  2290. (unless (eq processing-type 'mathjax)
  2291. (let ((bfn (or (buffer-file-name)
  2292. (make-temp-name
  2293. (expand-file-name "latex" temporary-file-directory))))
  2294. (latex-header
  2295. (let ((header (plist-get info :latex-header)))
  2296. (and header
  2297. (concat (mapconcat
  2298. (lambda (line) (concat "#+LATEX_HEADER: " line))
  2299. (org-split-string header "\n")
  2300. "\n")
  2301. "\n")))))
  2302. (setq cache-relpath
  2303. (concat "ltxpng/"
  2304. (file-name-sans-extension
  2305. (file-name-nondirectory bfn)))
  2306. cache-dir (file-name-directory bfn))
  2307. ;; Re-create LaTeX environment from original buffer in
  2308. ;; temporary buffer so that dvipng/imagemagick can properly
  2309. ;; turn the fragment into an image.
  2310. (setq latex-frag (concat latex-header latex-frag))))
  2311. (with-temp-buffer
  2312. (insert latex-frag)
  2313. (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
  2314. nil processing-type)
  2315. (buffer-string))))
  2316. (defun org-html-latex-environment (latex-environment contents info)
  2317. "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
  2318. CONTENTS is nil. INFO is a plist holding contextual information."
  2319. (let ((processing-type (plist-get info :with-latex))
  2320. (latex-frag (org-remove-indentation
  2321. (org-element-property :value latex-environment)))
  2322. (attributes (org-export-read-attribute :attr_html latex-environment)))
  2323. (case processing-type
  2324. ((t mathjax)
  2325. (org-html-format-latex latex-frag 'mathjax info))
  2326. ((dvipng imagemagick)
  2327. (let ((formula-link
  2328. (org-html-format-latex latex-frag processing-type info)))
  2329. (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
  2330. ;; Do not provide a caption or a name to be consistent with
  2331. ;; `mathjax' handling.
  2332. (org-html--wrap-image
  2333. (org-html--format-image
  2334. (match-string 1 formula-link) attributes info) info))))
  2335. (t latex-frag))))
  2336. ;;;; Latex Fragment
  2337. (defun org-html-latex-fragment (latex-fragment contents info)
  2338. "Transcode a LATEX-FRAGMENT object from Org to HTML.
  2339. CONTENTS is nil. INFO is a plist holding contextual information."
  2340. (let ((latex-frag (org-element-property :value latex-fragment))
  2341. (processing-type (plist-get info :with-latex)))
  2342. (case processing-type
  2343. ((t mathjax)
  2344. (org-html-format-latex latex-frag 'mathjax info))
  2345. ((dvipng imagemagick)
  2346. (let ((formula-link
  2347. (org-html-format-latex latex-frag processing-type info)))
  2348. (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
  2349. (org-html--format-image (match-string 1 formula-link) nil info))))
  2350. (t latex-frag))))
  2351. ;;;; Line Break
  2352. (defun org-html-line-break (line-break contents info)
  2353. "Transcode a LINE-BREAK object from Org to HTML.
  2354. CONTENTS is nil. INFO is a plist holding contextual information."
  2355. (concat (org-html-close-tag "br" nil info) "\n"))
  2356. ;;;; Link
  2357. (defun org-html-inline-image-p (link info)
  2358. "Non-nil when LINK is meant to appear as an image.
  2359. INFO is a plist used as a communication channel. LINK is an
  2360. inline image when it has no description and targets an image
  2361. file (see `org-html-inline-image-rules' for more information), or
  2362. if its description is a single link targeting an image file."
  2363. (if (not (org-element-contents link))
  2364. (org-export-inline-image-p
  2365. link (plist-get info :html-inline-image-rules))
  2366. (not
  2367. (let ((link-count 0))
  2368. (org-element-map (org-element-contents link)
  2369. (cons 'plain-text org-element-all-objects)
  2370. (lambda (obj)
  2371. (case (org-element-type obj)
  2372. (plain-text (org-string-nw-p obj))
  2373. (link (if (= link-count 1) t
  2374. (incf link-count)
  2375. (not (org-export-inline-image-p
  2376. obj (plist-get info :html-inline-image-rules)))))
  2377. (otherwise t)))
  2378. info t)))))
  2379. (defvar org-html-standalone-image-predicate)
  2380. (defun org-html-standalone-image-p (element info)
  2381. "Non-nil if ELEMENT is a standalone image.
  2382. INFO is a plist holding contextual information.
  2383. An element or object is a standalone image when
  2384. - its type is `paragraph' and its sole content, save for white
  2385. spaces, is a link that qualifies as an inline image;
  2386. - its type is `link' and its containing paragraph has no other
  2387. content save white spaces.
  2388. Bind `org-html-standalone-image-predicate' to constrain paragraph
  2389. further. For example, to check for only captioned standalone
  2390. images, set it to:
  2391. \(lambda (paragraph) (org-element-property :caption paragraph))"
  2392. (let ((paragraph (case (org-element-type element)
  2393. (paragraph element)
  2394. (link (org-export-get-parent element)))))
  2395. (and (eq (org-element-type paragraph) 'paragraph)
  2396. (or (not (fboundp 'org-html-standalone-image-predicate))
  2397. (funcall org-html-standalone-image-predicate paragraph))
  2398. (catch 'exit
  2399. (let ((link-count 0))
  2400. (org-element-map (org-element-contents paragraph)
  2401. (cons 'plain-text org-element-all-objects)
  2402. #'(lambda (obj)
  2403. (when (case (org-element-type obj)
  2404. (plain-text (org-string-nw-p obj))
  2405. (link (or (> (incf link-count) 1)
  2406. (not (org-html-inline-image-p obj info))))
  2407. (otherwise t))
  2408. (throw 'exit nil)))
  2409. info nil 'link)
  2410. (= link-count 1))))))
  2411. (defun org-html-link (link desc info)
  2412. "Transcode a LINK object from Org to HTML.
  2413. DESC is the description part of the link, or the empty string.
  2414. INFO is a plist holding contextual information. See
  2415. `org-export-data'."
  2416. (let* ((home (when (plist-get info :html-link-home)
  2417. (org-trim (plist-get info :html-link-home))))
  2418. (use-abs-url (plist-get info :html-link-use-abs-url))
  2419. (link-org-files-as-html-maybe
  2420. (function
  2421. (lambda (raw-path info)
  2422. "Treat links to `file.org' as links to `file.html', if needed.
  2423. See `org-html-link-org-files-as-html'."
  2424. (cond
  2425. ((and (plist-get info :html-link-org-files-as-html)
  2426. (string= ".org"
  2427. (downcase (file-name-extension raw-path "."))))
  2428. (concat (file-name-sans-extension raw-path) "."
  2429. (plist-get info :html-extension)))
  2430. (t raw-path)))))
  2431. (type (org-element-property :type link))
  2432. (raw-path (org-element-property :path link))
  2433. ;; Ensure DESC really exists, or set it to nil.
  2434. (desc (org-string-nw-p desc))
  2435. (path
  2436. (cond
  2437. ((member type '("http" "https" "ftp" "mailto"))
  2438. (org-link-escape-browser
  2439. (org-link-unescape (concat type ":" raw-path))))
  2440. ((string= type "file")
  2441. ;; Treat links to ".org" files as ".html", if needed.
  2442. (setq raw-path
  2443. (funcall link-org-files-as-html-maybe raw-path info))
  2444. ;; If file path is absolute, prepend it with protocol
  2445. ;; component - "file:".
  2446. (cond
  2447. ((file-name-absolute-p raw-path)
  2448. (setq raw-path (concat "file:" raw-path)))
  2449. ((and home use-abs-url)
  2450. (setq raw-path (concat (file-name-as-directory home) raw-path))))
  2451. ;; Add search option, if any. A search option can be
  2452. ;; relative to a custom-id or a headline title. Append
  2453. ;; a hash sign to any unresolved option, as it might point
  2454. ;; to a target.
  2455. (let ((option (org-element-property :search-option link)))
  2456. (cond ((not option) raw-path)
  2457. ((eq (aref option 0) ?#) (concat raw-path option))
  2458. (t
  2459. (let ((destination
  2460. (org-publish-resolve-external-fuzzy-link
  2461. (org-element-property :path link) option)))
  2462. (concat raw-path
  2463. (if (not destination) (concat "#" option)
  2464. (concat "#sec-"
  2465. (mapconcat #'number-to-string
  2466. destination "-")))))))))
  2467. (t raw-path)))
  2468. ;; Extract attributes from parent's paragraph. HACK: Only do
  2469. ;; this for the first link in parent (inner image link for
  2470. ;; inline images). This is needed as long as attributes
  2471. ;; cannot be set on a per link basis.
  2472. (attributes-plist
  2473. (let* ((parent (org-export-get-parent-element link))
  2474. (link (let ((container (org-export-get-parent link)))
  2475. (if (and (eq (org-element-type container) 'link)
  2476. (org-html-inline-image-p link info))
  2477. container
  2478. link))))
  2479. (and (eq (org-element-map parent 'link 'identity info t) link)
  2480. (org-export-read-attribute :attr_html parent))))
  2481. (attributes
  2482. (let ((attr (org-html--make-attribute-string attributes-plist)))
  2483. (if (org-string-nw-p attr) (concat " " attr) "")))
  2484. protocol)
  2485. (cond
  2486. ;; Image file.
  2487. ((and (plist-get info :html-inline-images)
  2488. (org-export-inline-image-p
  2489. link (plist-get info :html-inline-image-rules)))
  2490. (org-html--format-image path attributes-plist info))
  2491. ;; Radio target: Transcode target's contents and use them as
  2492. ;; link's description.
  2493. ((string= type "radio")
  2494. (let ((destination (org-export-resolve-radio-link link info)))
  2495. (if (not destination) desc
  2496. (format "<a href=\"#%s\"%s>%s</a>"
  2497. (org-export-solidify-link-text
  2498. (org-element-property :value destination))
  2499. attributes desc))))
  2500. ;; Links pointing to a headline: Find destination and build
  2501. ;; appropriate referencing command.
  2502. ((member type '("custom-id" "fuzzy" "id"))
  2503. (let ((destination (if (string= type "fuzzy")
  2504. (org-export-resolve-fuzzy-link link info)
  2505. (org-export-resolve-id-link link info))))
  2506. (case (org-element-type destination)
  2507. ;; ID link points to an external file.
  2508. (plain-text
  2509. (let ((fragment (concat "ID-" path))
  2510. ;; Treat links to ".org" files as ".html", if needed.
  2511. (path (funcall link-org-files-as-html-maybe
  2512. destination info)))
  2513. (format "<a href=\"%s#%s\"%s>%s</a>"
  2514. path fragment attributes (or desc destination))))
  2515. ;; Fuzzy link points nowhere.
  2516. ((nil)
  2517. (format "<i>%s</i>"
  2518. (or desc
  2519. (org-export-data
  2520. (org-element-property :raw-link link) info))))
  2521. ;; Link points to a headline.
  2522. (headline
  2523. (let ((href (or (and (string= type "custom-id")
  2524. (org-element-property :CUSTOM_ID destination))
  2525. (org-export-get-headline-id destination info)))
  2526. ;; What description to use?
  2527. (desc
  2528. ;; Case 1: Headline is numbered and LINK has no
  2529. ;; description. Display section number.
  2530. (if (and (org-export-numbered-headline-p destination info)
  2531. (not desc))
  2532. (mapconcat 'number-to-string
  2533. (org-export-get-headline-number
  2534. destination info) ".")
  2535. ;; Case 2: Either the headline is un-numbered or
  2536. ;; LINK has a custom description. Display LINK's
  2537. ;; description or headline's title.
  2538. (or desc (org-export-data (org-element-property
  2539. :title destination) info)))))
  2540. (format "<a href=\"#%s\"%s>%s</a>"
  2541. (org-export-solidify-link-text href) attributes desc)))
  2542. ;; Fuzzy link points to a target or an element.
  2543. (t
  2544. (let* ((path (org-export-solidify-link-text path))
  2545. (org-html-standalone-image-predicate 'org-html--has-caption-p)
  2546. (number (cond
  2547. (desc nil)
  2548. ((org-html-standalone-image-p destination info)
  2549. (org-export-get-ordinal
  2550. (org-element-map destination 'link
  2551. 'identity info t)
  2552. info 'link 'org-html-standalone-image-p))
  2553. (t (org-export-get-ordinal
  2554. destination info nil 'org-html--has-caption-p))))
  2555. (desc (cond (desc)
  2556. ((not number) "No description for this link")
  2557. ((numberp number) (number-to-string number))
  2558. (t (mapconcat 'number-to-string number ".")))))
  2559. (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
  2560. ;; Coderef: replace link with the reference name or the
  2561. ;; equivalent line number.
  2562. ((string= type "coderef")
  2563. (let ((fragment (concat "coderef-" path)))
  2564. (format "<a href=\"#%s\"%s%s>%s</a>"
  2565. fragment
  2566. (org-trim
  2567. (format (concat "class=\"coderef\""
  2568. " onmouseover=\"CodeHighlightOn(this, '%s');\""
  2569. " onmouseout=\"CodeHighlightOff(this, '%s');\"")
  2570. fragment fragment))
  2571. attributes
  2572. (format (org-export-get-coderef-format path desc)
  2573. (org-export-resolve-coderef path info)))))
  2574. ;; Link type is handled by a special function.
  2575. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
  2576. (funcall protocol (org-link-unescape path) desc 'html))
  2577. ;; External link with a description part.
  2578. ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
  2579. ;; External link without a description part.
  2580. (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
  2581. ;; No path, only description. Try to do something useful.
  2582. (t (format "<i>%s</i>" desc)))))
  2583. ;;;; Node Property
  2584. (defun org-html-node-property (node-property contents info)
  2585. "Transcode a NODE-PROPERTY element from Org to HTML.
  2586. CONTENTS is nil. INFO is a plist holding contextual
  2587. information."
  2588. (format "%s:%s"
  2589. (org-element-property :key node-property)
  2590. (let ((value (org-element-property :value node-property)))
  2591. (if value (concat " " value) ""))))
  2592. ;;;; Paragraph
  2593. (defun org-html-paragraph (paragraph contents info)
  2594. "Transcode a PARAGRAPH element from Org to HTML.
  2595. CONTENTS is the contents of the paragraph, as a string. INFO is
  2596. the plist used as a communication channel."
  2597. (let* ((parent (org-export-get-parent paragraph))
  2598. (parent-type (org-element-type parent))
  2599. (style '((footnote-definition " class=\"footpara\"")))
  2600. (attributes (org-html--make-attribute-string
  2601. (org-export-read-attribute :attr_html paragraph)))
  2602. (extra (or (cadr (assoc parent-type style)) "")))
  2603. (cond
  2604. ((and (eq parent-type 'item)
  2605. (not (org-export-get-previous-element paragraph info))
  2606. (let ((followers (org-export-get-next-element paragraph info 2)))
  2607. (and (not (cdr followers))
  2608. (memq (org-element-type (car followers)) '(nil plain-list)))))
  2609. ;; First paragraph in an item has no tag if it is alone or
  2610. ;; followed, at most, by a sub-list.
  2611. contents)
  2612. ((org-html-standalone-image-p paragraph info)
  2613. ;; Standalone image.
  2614. (let ((caption
  2615. (let ((raw (org-export-data
  2616. (org-export-get-caption paragraph) info))
  2617. (org-html-standalone-image-predicate
  2618. 'org-html--has-caption-p))
  2619. (if (not (org-string-nw-p raw)) raw
  2620. (concat
  2621. "<span class=\"figure-number\">"
  2622. (format (org-html--translate "Figure %d:" info)
  2623. (org-export-get-ordinal
  2624. (org-element-map paragraph 'link
  2625. 'identity info t)
  2626. info nil 'org-html-standalone-image-p))
  2627. "</span> " raw))))
  2628. (label (org-element-property :name paragraph)))
  2629. (org-html--wrap-image contents info caption label)))
  2630. ;; Regular paragraph.
  2631. (t (format "<p%s%s>\n%s</p>"
  2632. (if (org-string-nw-p attributes)
  2633. (concat " " attributes) "")
  2634. extra contents)))))
  2635. ;;;; Plain List
  2636. ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
  2637. ;; the correct value for the item counter
  2638. (defun org-html-begin-plain-list (type &optional arg1)
  2639. "Insert the beginning of the HTML list depending on TYPE.
  2640. When ARG1 is a string, use it as the start parameter for ordered
  2641. lists."
  2642. (case type
  2643. (ordered
  2644. (format "<ol class=\"org-ol\"%s>"
  2645. (if arg1 (format " start=\"%d\"" arg1) "")))
  2646. (unordered "<ul class=\"org-ul\">")
  2647. (descriptive "<dl class=\"org-dl\">")))
  2648. (defun org-html-end-plain-list (type)
  2649. "Insert the end of the HTML list depending on TYPE."
  2650. (case type
  2651. (ordered "</ol>")
  2652. (unordered "</ul>")
  2653. (descriptive "</dl>")))
  2654. (defun org-html-plain-list (plain-list contents info)
  2655. "Transcode a PLAIN-LIST element from Org to HTML.
  2656. CONTENTS is the contents of the list. INFO is a plist holding
  2657. contextual information."
  2658. (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
  2659. (type (org-element-property :type plain-list)))
  2660. (format "%s\n%s%s"
  2661. (org-html-begin-plain-list type)
  2662. contents (org-html-end-plain-list type))))
  2663. ;;;; Plain Text
  2664. (defun org-html-convert-special-strings (string)
  2665. "Convert special characters in STRING to HTML."
  2666. (let ((all org-html-special-string-regexps)
  2667. e a re rpl start)
  2668. (while (setq a (pop all))
  2669. (setq re (car a) rpl (cdr a) start 0)
  2670. (while (string-match re string start)
  2671. (setq string (replace-match rpl t nil string))))
  2672. string))
  2673. (defun org-html-encode-plain-text (text)
  2674. "Convert plain text characters from TEXT to HTML equivalent.
  2675. Possible conversions are set in `org-html-protect-char-alist'."
  2676. (mapc
  2677. (lambda (pair)
  2678. (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
  2679. org-html-protect-char-alist)
  2680. text)
  2681. (defun org-html-plain-text (text info)
  2682. "Transcode a TEXT string from Org to HTML.
  2683. TEXT is the string to transcode. INFO is a plist holding
  2684. contextual information."
  2685. (let ((output text))
  2686. ;; Protect following characters: <, >, &.
  2687. (setq output (org-html-encode-plain-text output))
  2688. ;; Handle smart quotes. Be sure to provide original string since
  2689. ;; OUTPUT may have been modified.
  2690. (when (plist-get info :with-smart-quotes)
  2691. (setq output (org-export-activate-smart-quotes output :html info text)))
  2692. ;; Handle special strings.
  2693. (when (plist-get info :with-special-strings)
  2694. (setq output (org-html-convert-special-strings output)))
  2695. ;; Handle break preservation if required.
  2696. (when (plist-get info :preserve-breaks)
  2697. (setq output
  2698. (replace-regexp-in-string
  2699. "\\(\\\\\\\\\\)?[ \t]*\n"
  2700. (concat (org-html-close-tag "br" nil info) "\n") output)))
  2701. ;; Return value.
  2702. output))
  2703. ;; Planning
  2704. (defun org-html-planning (planning contents info)
  2705. "Transcode a PLANNING element from Org to HTML.
  2706. CONTENTS is nil. INFO is a plist used as a communication
  2707. channel."
  2708. (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
  2709. (format
  2710. "<p><span class=\"timestamp-wrapper\">%s</span></p>"
  2711. (mapconcat
  2712. 'identity
  2713. (delq nil
  2714. (list
  2715. (let ((closed (org-element-property :closed planning)))
  2716. (when closed
  2717. (format span-fmt org-closed-string
  2718. (org-translate-time
  2719. (org-element-property :raw-value closed)))))
  2720. (let ((deadline (org-element-property :deadline planning)))
  2721. (when deadline
  2722. (format span-fmt org-deadline-string
  2723. (org-translate-time
  2724. (org-element-property :raw-value deadline)))))
  2725. (let ((scheduled (org-element-property :scheduled planning)))
  2726. (when scheduled
  2727. (format span-fmt org-scheduled-string
  2728. (org-translate-time
  2729. (org-element-property :raw-value scheduled)))))))
  2730. " "))))
  2731. ;;;; Property Drawer
  2732. (defun org-html-property-drawer (property-drawer contents info)
  2733. "Transcode a PROPERTY-DRAWER element from Org to HTML.
  2734. CONTENTS holds the contents of the drawer. INFO is a plist
  2735. holding contextual information."
  2736. (and (org-string-nw-p contents)
  2737. (format "<pre class=\"example\">\n%s</pre>" contents)))
  2738. ;;;; Quote Block
  2739. (defun org-html-quote-block (quote-block contents info)
  2740. "Transcode a QUOTE-BLOCK element from Org to HTML.
  2741. CONTENTS holds the contents of the block. INFO is a plist
  2742. holding contextual information."
  2743. (format "<blockquote>\n%s</blockquote>" contents))
  2744. ;;;; Section
  2745. (defun org-html-section (section contents info)
  2746. "Transcode a SECTION element from Org to HTML.
  2747. CONTENTS holds the contents of the section. INFO is a plist
  2748. holding contextual information."
  2749. (let ((parent (org-export-get-parent-headline section)))
  2750. ;; Before first headline: no container, just return CONTENTS.
  2751. (if (not parent) contents
  2752. ;; Get div's class and id references.
  2753. (let* ((class-num (+ (org-export-get-relative-level parent info)
  2754. (1- (plist-get info :html-toplevel-hlevel))))
  2755. (section-number
  2756. (and (org-export-numbered-headline-p parent info)
  2757. (mapconcat
  2758. #'number-to-string
  2759. (org-export-get-headline-number parent info) "-"))))
  2760. ;; Build return value.
  2761. (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
  2762. class-num
  2763. (or (org-element-property :CUSTOM_ID parent)
  2764. section-number
  2765. (org-export-get-headline-id parent info))
  2766. contents)))))
  2767. ;;;; Radio Target
  2768. (defun org-html-radio-target (radio-target text info)
  2769. "Transcode a RADIO-TARGET object from Org to HTML.
  2770. TEXT is the text of the target. INFO is a plist holding
  2771. contextual information."
  2772. (let ((id (org-export-solidify-link-text
  2773. (org-element-property :value radio-target))))
  2774. (org-html--anchor id text nil info)))
  2775. ;;;; Special Block
  2776. (defun org-html-special-block (special-block contents info)
  2777. "Transcode a SPECIAL-BLOCK element from Org to HTML.
  2778. CONTENTS holds the contents of the block. INFO is a plist
  2779. holding contextual information."
  2780. (let* ((block-type (org-element-property :type special-block))
  2781. (contents (or contents ""))
  2782. (html5-fancy (and (org-html-html5-p info)
  2783. (plist-get info :html-html5-fancy)
  2784. (member block-type org-html-html5-elements)))
  2785. (attributes (org-export-read-attribute :attr_html special-block)))
  2786. (unless html5-fancy
  2787. (let ((class (plist-get attributes :class)))
  2788. (setq attributes (plist-put attributes :class
  2789. (if class (concat class " " block-type)
  2790. block-type)))))
  2791. (setq attributes (org-html--make-attribute-string attributes))
  2792. (when (not (equal attributes ""))
  2793. (setq attributes (concat " " attributes)))
  2794. (if html5-fancy
  2795. (format "<%s%s>\n%s</%s>" block-type attributes
  2796. contents block-type)
  2797. (format "<div%s>\n%s\n</div>" attributes contents))))
  2798. ;;;; Src Block
  2799. (defun org-html-src-block (src-block contents info)
  2800. "Transcode a SRC-BLOCK element from Org to HTML.
  2801. CONTENTS holds the contents of the item. INFO is a plist holding
  2802. contextual information."
  2803. (if (org-export-read-attribute :attr_html src-block :textarea)
  2804. (org-html--textarea-block src-block)
  2805. (let ((lang (org-element-property :language src-block))
  2806. (caption (org-export-get-caption src-block))
  2807. (code (org-html-format-code src-block info))
  2808. (label (let ((lbl (org-element-property :name src-block)))
  2809. (if (not lbl) ""
  2810. (format " id=\"%s\""
  2811. (org-export-solidify-link-text lbl))))))
  2812. (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
  2813. (format
  2814. "<div class=\"org-src-container\">\n%s%s\n</div>"
  2815. (if (not caption) ""
  2816. (format "<label class=\"org-src-name\">%s</label>"
  2817. (org-export-data caption info)))
  2818. (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
  2819. ;;;; Statistics Cookie
  2820. (defun org-html-statistics-cookie (statistics-cookie contents info)
  2821. "Transcode a STATISTICS-COOKIE object from Org to HTML.
  2822. CONTENTS is nil. INFO is a plist holding contextual information."
  2823. (let ((cookie-value (org-element-property :value statistics-cookie)))
  2824. (format "<code>%s</code>" cookie-value)))
  2825. ;;;; Strike-Through
  2826. (defun org-html-strike-through (strike-through contents info)
  2827. "Transcode STRIKE-THROUGH from Org to HTML.
  2828. CONTENTS is the text with strike-through markup. INFO is a plist
  2829. holding contextual information."
  2830. (format
  2831. (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
  2832. "%s")
  2833. contents))
  2834. ;;;; Subscript
  2835. (defun org-html-subscript (subscript contents info)
  2836. "Transcode a SUBSCRIPT object from Org to HTML.
  2837. CONTENTS is the contents of the object. INFO is a plist holding
  2838. contextual information."
  2839. (format "<sub>%s</sub>" contents))
  2840. ;;;; Superscript
  2841. (defun org-html-superscript (superscript contents info)
  2842. "Transcode a SUPERSCRIPT object from Org to HTML.
  2843. CONTENTS is the contents of the object. INFO is a plist holding
  2844. contextual information."
  2845. (format "<sup>%s</sup>" contents))
  2846. ;;;; Table Cell
  2847. (defun org-html-table-cell (table-cell contents info)
  2848. "Transcode a TABLE-CELL element from Org to HTML.
  2849. CONTENTS is nil. INFO is a plist used as a communication
  2850. channel."
  2851. (let* ((table-row (org-export-get-parent table-cell))
  2852. (table (org-export-get-parent-table table-cell))
  2853. (cell-attrs
  2854. (if (not (plist-get info :html-table-align-individual-fields)) ""
  2855. (format (if (and (boundp 'org-html-format-table-no-css)
  2856. org-html-format-table-no-css)
  2857. " align=\"%s\"" " class=\"%s\"")
  2858. (org-export-table-cell-alignment table-cell info)))))
  2859. (when (or (not contents) (string= "" (org-trim contents)))
  2860. (setq contents "&#xa0;"))
  2861. (cond
  2862. ((and (org-export-table-has-header-p table info)
  2863. (= 1 (org-export-table-row-group table-row info)))
  2864. (let ((header-tags (plist-get info :html-table-header-tags)))
  2865. (concat "\n" (format (car header-tags) "col" cell-attrs)
  2866. contents
  2867. (cdr header-tags))))
  2868. ((and (plist-get info :html-table-use-header-tags-for-first-column)
  2869. (zerop (cdr (org-export-table-cell-address table-cell info))))
  2870. (let ((header-tags (plist-get info :html-table-header-tags)))
  2871. (concat "\n" (format (car header-tags) "row" cell-attrs)
  2872. contents
  2873. (cdr header-tags))))
  2874. (t (let ((data-tags (plist-get info :html-table-data-tags)))
  2875. (concat "\n" (format (car data-tags) cell-attrs)
  2876. contents
  2877. (cdr data-tags)))))))
  2878. ;;;; Table Row
  2879. (defun org-html-table-row (table-row contents info)
  2880. "Transcode a TABLE-ROW element from Org to HTML.
  2881. CONTENTS is the contents of the row. INFO is a plist used as a
  2882. communication channel."
  2883. ;; Rules are ignored since table separators are deduced from
  2884. ;; borders of the current row.
  2885. (when (eq (org-element-property :type table-row) 'standard)
  2886. (let* ((rowgroup-number (org-export-table-row-group table-row info))
  2887. (row-number (org-export-table-row-number table-row info))
  2888. (start-rowgroup-p
  2889. (org-export-table-row-starts-rowgroup-p table-row info))
  2890. (end-rowgroup-p
  2891. (org-export-table-row-ends-rowgroup-p table-row info))
  2892. ;; `top-row-p' and `end-rowgroup-p' are not used directly
  2893. ;; but should be set so that `org-html-table-row-tags' can
  2894. ;; use them (see the docstring of this variable.)
  2895. (top-row-p (and (equal start-rowgroup-p '(top))
  2896. (equal end-rowgroup-p '(below top))))
  2897. (bottom-row-p (and (equal start-rowgroup-p '(above))
  2898. (equal end-rowgroup-p '(bottom above))))
  2899. (rowgroup-tags
  2900. (cond
  2901. ;; Case 1: Row belongs to second or subsequent rowgroups.
  2902. ((not (= 1 rowgroup-number))
  2903. '("<tbody>" . "\n</tbody>"))
  2904. ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
  2905. ((org-export-table-has-header-p
  2906. (org-export-get-parent-table table-row) info)
  2907. '("<thead>" . "\n</thead>"))
  2908. ;; Case 2: Row is from first and only row group.
  2909. (t '("<tbody>" . "\n</tbody>")))))
  2910. (concat
  2911. ;; Begin a rowgroup?
  2912. (when start-rowgroup-p (car rowgroup-tags))
  2913. ;; Actual table row
  2914. (concat "\n" (eval (car (plist-get info :html-table-row-tags)))
  2915. contents
  2916. "\n"
  2917. (eval (cdr (plist-get info :html-table-row-tags))))
  2918. ;; End a rowgroup?
  2919. (when end-rowgroup-p (cdr rowgroup-tags))))))
  2920. ;;;; Table
  2921. (defun org-html-table-first-row-data-cells (table info)
  2922. "Transcode the first row of TABLE.
  2923. INFO is a plist used as a communication channel."
  2924. (let ((table-row
  2925. (org-element-map table 'table-row
  2926. (lambda (row)
  2927. (unless (eq (org-element-property :type row) 'rule) row))
  2928. info 'first-match))
  2929. (special-column-p (org-export-table-has-special-column-p table)))
  2930. (if (not special-column-p) (org-element-contents table-row)
  2931. (cdr (org-element-contents table-row)))))
  2932. (defun org-html-table--table.el-table (table info)
  2933. "Format table.el tables into HTML.
  2934. INFO is a plist used as a communication channel."
  2935. (when (eq (org-element-property :type table) 'table.el)
  2936. (require 'table)
  2937. (let ((outbuf (with-current-buffer
  2938. (get-buffer-create "*org-export-table*")
  2939. (erase-buffer) (current-buffer))))
  2940. (with-temp-buffer
  2941. (insert (org-element-property :value table))
  2942. (goto-char 1)
  2943. (re-search-forward "^[ \t]*|[^|]" nil t)
  2944. (table-generate-source 'html outbuf))
  2945. (with-current-buffer outbuf
  2946. (prog1 (org-trim (buffer-string))
  2947. (kill-buffer) )))))
  2948. (defun org-html-table (table contents info)
  2949. "Transcode a TABLE element from Org to HTML.
  2950. CONTENTS is the contents of the table. INFO is a plist holding
  2951. contextual information."
  2952. (case (org-element-property :type table)
  2953. ;; Case 1: table.el table. Convert it using appropriate tools.
  2954. (table.el (org-html-table--table.el-table table info))
  2955. ;; Case 2: Standard table.
  2956. (t
  2957. (let* ((label (org-element-property :name table))
  2958. (caption (org-export-get-caption table))
  2959. (number (org-export-get-ordinal
  2960. table info nil 'org-html--has-caption-p))
  2961. (attributes
  2962. (org-html--make-attribute-string
  2963. (org-combine-plists
  2964. (and label (list :id (org-export-solidify-link-text label)))
  2965. (and (not (org-html-html5-p info))
  2966. (plist-get info :html-table-attributes))
  2967. (org-export-read-attribute :attr_html table))))
  2968. (alignspec
  2969. (if (and (boundp 'org-html-format-table-no-css)
  2970. org-html-format-table-no-css)
  2971. "align=\"%s\"" "class=\"%s\""))
  2972. (table-column-specs
  2973. (function
  2974. (lambda (table info)
  2975. (mapconcat
  2976. (lambda (table-cell)
  2977. (let ((alignment (org-export-table-cell-alignment
  2978. table-cell info)))
  2979. (concat
  2980. ;; Begin a colgroup?
  2981. (when (org-export-table-cell-starts-colgroup-p
  2982. table-cell info)
  2983. "\n<colgroup>")
  2984. ;; Add a column. Also specify it's alignment.
  2985. (format "\n%s"
  2986. (org-html-close-tag
  2987. "col" (concat " " (format alignspec alignment)) info))
  2988. ;; End a colgroup?
  2989. (when (org-export-table-cell-ends-colgroup-p
  2990. table-cell info)
  2991. "\n</colgroup>"))))
  2992. (org-html-table-first-row-data-cells table info) "\n")))))
  2993. (format "<table%s>\n%s\n%s\n%s</table>"
  2994. (if (equal attributes "") "" (concat " " attributes))
  2995. (if (not caption) ""
  2996. (format (if (plist-get info :html-table-caption-above)
  2997. "<caption class=\"t-above\">%s</caption>"
  2998. "<caption class=\"t-bottom\">%s</caption>")
  2999. (concat
  3000. "<span class=\"table-number\">"
  3001. (format (org-html--translate "Table %d:" info) number)
  3002. "</span> " (org-export-data caption info))))
  3003. (funcall table-column-specs table info)
  3004. contents)))))
  3005. ;;;; Target
  3006. (defun org-html-target (target contents info)
  3007. "Transcode a TARGET object from Org to HTML.
  3008. CONTENTS is nil. INFO is a plist holding contextual
  3009. information."
  3010. (let ((id (org-export-solidify-link-text
  3011. (org-element-property :value target))))
  3012. (org-html--anchor id nil nil info)))
  3013. ;;;; Timestamp
  3014. (defun org-html-timestamp (timestamp contents info)
  3015. "Transcode a TIMESTAMP object from Org to HTML.
  3016. CONTENTS is nil. INFO is a plist holding contextual
  3017. information."
  3018. (let ((value (org-html-plain-text
  3019. (org-timestamp-translate timestamp) info)))
  3020. (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
  3021. (replace-regexp-in-string "--" "&#x2013;" value))))
  3022. ;;;; Underline
  3023. (defun org-html-underline (underline contents info)
  3024. "Transcode UNDERLINE from Org to HTML.
  3025. CONTENTS is the text with underline markup. INFO is a plist
  3026. holding contextual information."
  3027. (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
  3028. "%s")
  3029. contents))
  3030. ;;;; Verbatim
  3031. (defun org-html-verbatim (verbatim contents info)
  3032. "Transcode VERBATIM from Org to HTML.
  3033. CONTENTS is nil. INFO is a plist holding contextual
  3034. information."
  3035. (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
  3036. (org-html-encode-plain-text (org-element-property :value verbatim))))
  3037. ;;;; Verse Block
  3038. (defun org-html-verse-block (verse-block contents info)
  3039. "Transcode a VERSE-BLOCK element from Org to HTML.
  3040. CONTENTS is verse block contents. INFO is a plist holding
  3041. contextual information."
  3042. ;; Replace each newline character with line break. Also replace
  3043. ;; each blank line with a line break.
  3044. (setq contents (replace-regexp-in-string
  3045. "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
  3046. (replace-regexp-in-string
  3047. "\\(\\\\\\\\\\)?[ \t]*\n"
  3048. (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
  3049. ;; Replace each white space at beginning of a line with a
  3050. ;; non-breaking space.
  3051. (while (string-match "^[ \t]+" contents)
  3052. (let* ((num-ws (length (match-string 0 contents)))
  3053. (ws (let (out) (dotimes (i num-ws out)
  3054. (setq out (concat out "&#xa0;"))))))
  3055. (setq contents (replace-match ws nil t contents))))
  3056. (format "<p class=\"verse\">\n%s</p>" contents))
  3057. ;;; Filter Functions
  3058. (defun org-html-final-function (contents backend info)
  3059. "Filter to indent the HTML and convert HTML entities."
  3060. (with-temp-buffer
  3061. (insert contents)
  3062. (set-auto-mode t)
  3063. (if (plist-get info :html-indent)
  3064. (indent-region (point-min) (point-max)))
  3065. (when (plist-get info :html-use-unicode-chars)
  3066. (require 'mm-url)
  3067. (mm-url-decode-entities))
  3068. (buffer-substring-no-properties (point-min) (point-max))))
  3069. ;;; End-user functions
  3070. ;;;###autoload
  3071. (defun org-html-export-as-html
  3072. (&optional async subtreep visible-only body-only ext-plist)
  3073. "Export current buffer to an HTML buffer.
  3074. If narrowing is active in the current buffer, only export its
  3075. narrowed part.
  3076. If a region is active, export that region.
  3077. A non-nil optional argument ASYNC means the process should happen
  3078. asynchronously. The resulting buffer should be accessible
  3079. through the `org-export-stack' interface.
  3080. When optional argument SUBTREEP is non-nil, export the sub-tree
  3081. at point, extracting information from the headline properties
  3082. first.
  3083. When optional argument VISIBLE-ONLY is non-nil, don't export
  3084. contents of hidden elements.
  3085. When optional argument BODY-ONLY is non-nil, only write code
  3086. between \"<body>\" and \"</body>\" tags.
  3087. EXT-PLIST, when provided, is a property list with external
  3088. parameters overriding Org default settings, but still inferior to
  3089. file-local settings.
  3090. Export is done in a buffer named \"*Org HTML Export*\", which
  3091. will be displayed when `org-export-show-temporary-export-buffer'
  3092. is non-nil."
  3093. (interactive)
  3094. (org-export-to-buffer 'html "*Org HTML Export*"
  3095. async subtreep visible-only body-only ext-plist
  3096. (lambda () (set-auto-mode t))))
  3097. ;;;###autoload
  3098. (defun org-html-convert-region-to-html ()
  3099. "Assume the current region has org-mode syntax, and convert it to HTML.
  3100. This can be used in any buffer. For example, you can write an
  3101. itemized list in org-mode syntax in an HTML buffer and use this
  3102. command to convert it."
  3103. (interactive)
  3104. (org-export-replace-region-by 'html))
  3105. ;;;###autoload
  3106. (defun org-html-export-to-html
  3107. (&optional async subtreep visible-only body-only ext-plist)
  3108. "Export current buffer to a HTML file.
  3109. If narrowing is active in the current buffer, only export its
  3110. narrowed part.
  3111. If a region is active, export that region.
  3112. A non-nil optional argument ASYNC means the process should happen
  3113. asynchronously. The resulting file should be accessible through
  3114. the `org-export-stack' interface.
  3115. When optional argument SUBTREEP is non-nil, export the sub-tree
  3116. at point, extracting information from the headline properties
  3117. first.
  3118. When optional argument VISIBLE-ONLY is non-nil, don't export
  3119. contents of hidden elements.
  3120. When optional argument BODY-ONLY is non-nil, only write code
  3121. between \"<body>\" and \"</body>\" tags.
  3122. EXT-PLIST, when provided, is a property list with external
  3123. parameters overriding Org default settings, but still inferior to
  3124. file-local settings.
  3125. Return output file's name."
  3126. (interactive)
  3127. (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
  3128. org-html-extension
  3129. "html")))
  3130. (file (org-export-output-file-name extension subtreep))
  3131. (org-export-coding-system org-html-coding-system))
  3132. (org-export-to-file 'html file
  3133. async subtreep visible-only body-only ext-plist)))
  3134. ;;;###autoload
  3135. (defun org-html-publish-to-html (plist filename pub-dir)
  3136. "Publish an org file to HTML.
  3137. FILENAME is the filename of the Org file to be published. PLIST
  3138. is the property list for the given project. PUB-DIR is the
  3139. publishing directory.
  3140. Return output file name."
  3141. (org-publish-org-to 'html filename
  3142. (concat "." (or (plist-get plist :html-extension)
  3143. org-html-extension
  3144. "html"))
  3145. plist pub-dir))
  3146. (provide 'ox-html)
  3147. ;; Local variables:
  3148. ;; generated-autoload-file: "org-loaddefs.el"
  3149. ;; End:
  3150. ;;; ox-html.el ends here