ox-html.el 102 KB

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