org-e-html.el 101 KB

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