ox-html.el 124 KB

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