ox-html.el 133 KB

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