org-e-html.el 102 KB

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