ox-html.el 102 KB

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