ox-html.el 114 KB

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