ox-html.el 128 KB

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