ox-html.el 113 KB

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