org-e-html.el 101 KB

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