ox-html.el 106 KB

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