org-e-html.el 103 KB

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