org-e-html.el 105 KB

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